Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(384)

Unified Diff: components/ntp_snippets/ntp_snippets_service.h

Issue 1987333003: [NTP Snippets] Persist snippets in a LevelDB instead of prefs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/ntp_snippets/ntp_snippets_service.h
diff --git a/components/ntp_snippets/ntp_snippets_service.h b/components/ntp_snippets/ntp_snippets_service.h
index a5bac53c11f3fe8e0bd2034c6e06dcb037ef7eed..c407163fdd8887696a46c2492f06dff02cbb4264 100644
--- a/components/ntp_snippets/ntp_snippets_service.h
+++ b/components/ntp_snippets/ntp_snippets_service.h
@@ -16,7 +16,6 @@
#include "base/macros.h"
#include "base/observer_list.h"
#include "base/scoped_observer.h"
-#include "base/sequenced_task_runner.h"
#include "base/timer/timer.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/ntp_snippets/ntp_snippet.h"
@@ -50,6 +49,7 @@ class SyncService;
namespace ntp_snippets {
+class NTPSnippetsDatabase;
class NTPSnippetsServiceObserver;
// Stores and vends fresh content data for the NTP.
@@ -63,15 +63,14 @@ class NTPSnippetsService : public KeyedService,
// 'en' or 'en-US'. Note that this code should only specify the language, not
// the locale, so 'en_US' (English language with US locale) and 'en-GB_US'
// (British English person in the US) are not language codes.
- NTPSnippetsService(
- PrefService* pref_service,
- sync_driver::SyncService* sync_service,
- suggestions::SuggestionsService* suggestions_service,
- scoped_refptr<base::SequencedTaskRunner> file_task_runner,
- const std::string& application_language_code,
- NTPSnippetsScheduler* scheduler,
- std::unique_ptr<NTPSnippetsFetcher> snippets_fetcher,
- std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher);
+ NTPSnippetsService(PrefService* pref_service,
+ sync_driver::SyncService* sync_service,
+ suggestions::SuggestionsService* suggestions_service,
+ const std::string& application_language_code,
+ NTPSnippetsScheduler* scheduler,
+ std::unique_ptr<NTPSnippetsFetcher> snippets_fetcher,
+ std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher,
+ std::unique_ptr<NTPSnippetsDatabase> database);
~NTPSnippetsService() override;
static void RegisterProfilePrefs(PrefRegistrySimple* registry);
@@ -81,6 +80,11 @@ class NTPSnippetsService : public KeyedService,
// Inherited from KeyedService.
void Shutdown() override;
+ // Returns whether the initial set of snippets has been loaded from the
+ // database. While this is false, the list of snippets will be empty, and all
+ // modifications to it (fetch, discard, etc) will be ignored.
+ bool loaded() const { return state_ == State::LOADED; }
+
// Fetches snippets from the server and adds them to the current ones.
void FetchSnippets();
// Fetches snippets from the server for specified hosts (overriding
@@ -139,17 +143,17 @@ class NTPSnippetsService : public KeyedService,
// sync_driver::SyncServiceObserver implementation.
void OnStateChanged() override;
+ // Callback for the NTPSnippetsDatabase.
+ void OnDatabaseLoaded(NTPSnippet::PtrVector snippets);
+
+ // Callback for the SuggestionsService.
void OnSuggestionsChanged(const suggestions::SuggestionsProfile& suggestions);
+
+ // Callback for the NTPSnippetsFetcher.
void OnFetchFinished(NTPSnippetsFetcher::OptionalSnippets snippets);
// Merges newly available snippets with the previously available list.
void MergeSnippets(NTPSnippet::PtrVector new_snippets);
- // TODO(treib): Investigate a better storage, maybe LevelDB or SQLite?
- void LoadSnippetsFromPrefs();
- void StoreSnippetsToPrefs();
-
- void LoadDiscardedSnippetsFromPrefs();
- void StoreDiscardedSnippetsToPrefs();
std::set<std::string> GetSnippetHostsFromPrefs() const;
void StoreSnippetHostsToPrefs(const std::set<std::string>& hosts);
@@ -165,6 +169,7 @@ class NTPSnippetsService : public KeyedService,
enum class State {
NOT_INITED,
INITED,
Bernhard Bauer 2016/05/25 15:01:15 We should add some comments now for what these sta
Marc Treib 2016/05/27 14:03:12 Sure, done. dgn's https://codereview.chromium.org/
+ LOADED,
SHUT_DOWN
} state_;
@@ -182,9 +187,6 @@ class NTPSnippetsService : public KeyedService,
suggestions::SuggestionsService* suggestions_service_;
- // The SequencedTaskRunner on which file system operations will be run.
- scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
-
// All current suggestions (i.e. not discarded ones).
NTPSnippet::PtrVector snippets_;
Marc Treib 2016/05/23 14:00:58 To be discussed: Should we remove this (and discar
Bernhard Bauer 2016/05/25 15:01:15 Yeah, that probably makes sense -- and it will all
Marc Treib 2016/05/27 14:03:12 It'll change the interface though (getting snippet
Bernhard Bauer 2016/05/27 16:06:43 Hm... y'know, I'm thinking it might be worth front
Marc Treib 2016/05/30 13:22:00 It will require re-thinking the NTPSnippetsService
@@ -216,6 +218,9 @@ class NTPSnippetsService : public KeyedService,
std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher_;
+ // The database for persisting snippets.
+ std::unique_ptr<NTPSnippetsDatabase> database_;
+
DISALLOW_COPY_AND_ASSIGN(NTPSnippetsService);
};

Powered by Google App Engine
This is Rietveld 408576698