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

Unified Diff: components/ntp_snippets/ntp_snippets_service.h

Issue 1737563003: [NTP Snippets] Persist the set of snippets in a pref (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@snippets_merge
Patch Set: noyau review Created 4 years, 10 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
« no previous file with comments | « components/ntp_snippets/ntp_snippet.cc ('k') | components/ntp_snippets/ntp_snippets_service.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1b46bad976bd93300f8ddb6621e81300bd6acb82..a37b08e74afce82611310aabf7bf306004e7f735 100644
--- a/components/ntp_snippets/ntp_snippets_service.h
+++ b/components/ntp_snippets/ntp_snippets_service.h
@@ -20,6 +20,17 @@
#include "components/ntp_snippets/ntp_snippets_fetcher.h"
#include "components/ntp_snippets/ntp_snippets_scheduler.h"
+class PrefService;
+
+namespace base {
+class FilePath;
+class ListValue;
+}
+
+namespace user_prefs {
+class PrefRegistrySyncable;
+}
+
namespace ntp_snippets {
class NTPSnippetsServiceObserver;
@@ -35,12 +46,15 @@ class NTPSnippetsService : public KeyedService, NTPSnippetsFetcher::Observer {
// '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 code.
- NTPSnippetsService(scoped_refptr<base::SequencedTaskRunner> file_task_runner,
+ NTPSnippetsService(PrefService* pref_service,
+ scoped_refptr<base::SequencedTaskRunner> file_task_runner,
const std::string& application_language_code,
NTPSnippetsScheduler* scheduler,
scoped_ptr<NTPSnippetsFetcher> snippets_fetcher);
~NTPSnippetsService() override;
+ static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
+
void Init(bool enabled);
// Fetches snippets from the server. |overwrite| is true if existing snippets
@@ -80,14 +94,24 @@ class NTPSnippetsService : public KeyedService, NTPSnippetsFetcher::Observer {
}
private:
- void OnFileReadDone(const std::string* json, bool success);
void OnSnippetsDownloaded(const base::FilePath& download_path);
+ void OnFileReadDone(const std::string* json, bool success);
- // Expects the JSON to be a list of dictionaries with keys matching the
- // properties of a snippet (url, title, site_title, etc...). The url is the
- // only mandatory value.
+ // Expects a top-level dictionary containing a "recos" list, which will be
+ // passed to |LoadFromJSONList|.
bool LoadFromJSONString(const std::string& str);
+ // Expects a list of dictionaries each containing a "contentInfo" dictionary
+ // with keys matching the properties of a snippet (url, title, site_title,
+ // etc...). The url is the only mandatory value.
+ bool LoadFromJSONList(const base::ListValue& list);
+
+ // TODO(treib): Investigate a better storage, maybe LevelDB or SQLite?
+ void LoadFromPrefs();
+ void StoreToPrefs();
+
+ PrefService* pref_service_;
+
// True if the suggestions are loaded.
bool loaded_;
« no previous file with comments | « components/ntp_snippets/ntp_snippet.cc ('k') | components/ntp_snippets/ntp_snippets_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698