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

Side by Side Diff: components/ntp_snippets/ntp_snippets_service.h

Issue 1863133003: [NTP Snippets] Re-fetch snippets on ML changes only when the hosts actually change (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@snippets_thumbnails
Patch Set: s/vector/set/ Created 4 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ 5 #ifndef COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_
6 #define COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ 6 #define COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <set>
10 #include <string> 11 #include <string>
11 #include <vector> 12 #include <vector>
12 13
13 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
14 #include "base/macros.h" 15 #include "base/macros.h"
15 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
16 #include "base/observer_list.h" 17 #include "base/observer_list.h"
17 #include "base/sequenced_task_runner.h" 18 #include "base/sequenced_task_runner.h"
18 #include "base/timer/timer.h" 19 #include "base/timer/timer.h"
19 #include "components/keyed_service/core/keyed_service.h" 20 #include "components/keyed_service/core/keyed_service.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 private: 112 private:
112 friend class NTPSnippetsServiceTest; 113 friend class NTPSnippetsServiceTest;
113 114
114 void OnSuggestionsChanged(const suggestions::SuggestionsProfile& suggestions); 115 void OnSuggestionsChanged(const suggestions::SuggestionsProfile& suggestions);
115 void OnSnippetsDownloaded(const std::string& snippets_json); 116 void OnSnippetsDownloaded(const std::string& snippets_json);
116 117
117 void OnJsonParsed(const std::string& snippets_json, 118 void OnJsonParsed(const std::string& snippets_json,
118 scoped_ptr<base::Value> parsed); 119 scoped_ptr<base::Value> parsed);
119 void OnJsonError(const std::string& snippets_json, const std::string& error); 120 void OnJsonError(const std::string& snippets_json, const std::string& error);
120 121
121 void FetchSnippetsImpl(const std::vector<std::string>& hosts); 122 void FetchSnippetsImpl(const std::set<std::string>& hosts);
122 123
123 // Expects a top-level dictionary containing a "recos" list, which will be 124 // Expects a top-level dictionary containing a "recos" list, which will be
124 // passed to LoadFromListValue(). 125 // passed to LoadFromListValue().
125 bool LoadFromValue(const base::Value& value); 126 bool LoadFromValue(const base::Value& value);
126 127
127 // Expects a list of dictionaries each containing a "contentInfo" dictionary 128 // Expects a list of dictionaries each containing a "contentInfo" dictionary
128 // with keys matching the properties of a snippet (url, title, site_title, 129 // with keys matching the properties of a snippet (url, title, site_title,
129 // etc...). The URL is the only mandatory value. 130 // etc...). The URL is the only mandatory value.
130 bool LoadFromListValue(const base::ListValue& list); 131 bool LoadFromListValue(const base::ListValue& list);
131 132
132 // TODO(treib): Investigate a better storage, maybe LevelDB or SQLite? 133 // TODO(treib): Investigate a better storage, maybe LevelDB or SQLite?
133 void LoadSnippetsFromPrefs(); 134 void LoadSnippetsFromPrefs();
134 void StoreSnippetsToPrefs(); 135 void StoreSnippetsToPrefs();
135 136
136 void LoadDiscardedSnippetsFromPrefs(); 137 void LoadDiscardedSnippetsFromPrefs();
137 void StoreDiscardedSnippetsToPrefs(); 138 void StoreDiscardedSnippetsToPrefs();
138 139
140 std::set<std::string> GetSnippetHostsFromPrefs() const;
141 void StoreSnippetHostsToPrefs(const std::set<std::string>& hosts);
142
139 bool HasDiscardedSnippet(const GURL& url) const; 143 bool HasDiscardedSnippet(const GURL& url) const;
140 144
141 void RemoveExpiredSnippets(); 145 void RemoveExpiredSnippets();
142 146
143 PrefService* pref_service_; 147 PrefService* pref_service_;
144 148
145 suggestions::SuggestionsService* suggestions_service_; 149 suggestions::SuggestionsService* suggestions_service_;
146 150
147 // True if the suggestions are loaded. 151 // True if the suggestions are loaded.
148 bool loaded_; 152 bool loaded_;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 // Send when the service is shutting down. 201 // Send when the service is shutting down.
198 virtual void NTPSnippetsServiceShutdown(NTPSnippetsService* service) = 0; 202 virtual void NTPSnippetsServiceShutdown(NTPSnippetsService* service) = 0;
199 203
200 protected: 204 protected:
201 virtual ~NTPSnippetsServiceObserver() {} 205 virtual ~NTPSnippetsServiceObserver() {}
202 }; 206 };
203 207
204 } // namespace ntp_snippets 208 } // namespace ntp_snippets
205 209
206 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ 210 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_
OLDNEW
« no previous file with comments | « components/ntp_snippets/ntp_snippets_fetcher.cc ('k') | components/ntp_snippets/ntp_snippets_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698