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

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

Issue 2446163005: [NTP Snippets] FetchMore backend (Closed)
Patch Set: Address comments from https://codereview.chromium.org/2421463002/ Created 4 years, 1 month 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_REMOTE_NTP_SNIPPETS_SERVICE_H_ 5 #ifndef COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_SERVICE_H_
6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_SERVICE_H_ 6 #define COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_SERVICE_H_
7 7
8 #include <cstddef> 8 #include <cstddef>
9 #include <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 // tasks will be re-scheduled even if they already exist and have the correct 110 // tasks will be re-scheduled even if they already exist and have the correct
111 // periods. 111 // periods.
112 void RescheduleFetching(bool force); 112 void RescheduleFetching(bool force);
113 113
114 // ContentSuggestionsProvider implementation 114 // ContentSuggestionsProvider implementation
115 CategoryStatus GetCategoryStatus(Category category) override; 115 CategoryStatus GetCategoryStatus(Category category) override;
116 CategoryInfo GetCategoryInfo(Category category) override; 116 CategoryInfo GetCategoryInfo(Category category) override;
117 void DismissSuggestion(const ContentSuggestion::ID& suggestion_id) override; 117 void DismissSuggestion(const ContentSuggestion::ID& suggestion_id) override;
118 void FetchSuggestionImage(const ContentSuggestion::ID& suggestion_id, 118 void FetchSuggestionImage(const ContentSuggestion::ID& suggestion_id,
119 const ImageFetchedCallback& callback) override; 119 const ImageFetchedCallback& callback) override;
120 void FetchMore(const Category& category,
121 FetchedMoreCallback callback) override;
120 void ClearHistory( 122 void ClearHistory(
121 base::Time begin, 123 base::Time begin,
122 base::Time end, 124 base::Time end,
123 const base::Callback<bool(const GURL& url)>& filter) override; 125 const base::Callback<bool(const GURL& url)>& filter) override;
124 void ClearCachedSuggestions(Category category) override; 126 void ClearCachedSuggestions(Category category) override;
125 void GetDismissedSuggestionsForDebugging( 127 void GetDismissedSuggestionsForDebugging(
126 Category category, 128 Category category,
127 const DismissedSuggestionsCallback& callback) override; 129 const DismissedSuggestionsCallback& callback) override;
128 void ClearDismissedSuggestionsForDebugging(Category category) override; 130 void ClearDismissedSuggestionsForDebugging(Category category) override;
129 131
(...skipping 13 matching lines...) Expand all
143 } 145 }
144 146
145 // Dismissed snippets, only for unit tests. 147 // Dismissed snippets, only for unit tests.
146 const NTPSnippet::PtrVector& GetDismissedSnippetsForTesting( 148 const NTPSnippet::PtrVector& GetDismissedSnippetsForTesting(
147 Category category) const { 149 Category category) const {
148 return categories_.find(category)->second.dismissed; 150 return categories_.find(category)->second.dismissed;
149 } 151 }
150 152
151 private: 153 private:
152 friend class NTPSnippetsServiceTest; 154 friend class NTPSnippetsServiceTest;
155
153 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsServiceTest, 156 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsServiceTest,
154 RemoveExpiredDismissedContent); 157 RemoveExpiredDismissedContent);
155 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsServiceTest, RescheduleOnStateChange); 158 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsServiceTest, RescheduleOnStateChange);
156 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsServiceTest, StatusChanges); 159 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsServiceTest, StatusChanges);
157 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsServiceTest, 160 FRIEND_TEST_ALL_PREFIXES(NTPSnippetsServiceTest,
158 SuggestionsFetchedOnSignInAndSignOut); 161 SuggestionsFetchedOnSignInAndSignOut);
159 162
160 // Possible state transitions: 163 // Possible state transitions:
161 // NOT_INITED --------+ 164 // NOT_INITED --------+
162 // / \ | 165 // / \ |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 // image_fetcher::ImageFetcherDelegate implementation. 205 // image_fetcher::ImageFetcherDelegate implementation.
203 void OnImageDataFetched(const std::string& id_within_category, 206 void OnImageDataFetched(const std::string& id_within_category,
204 const std::string& image_data) override; 207 const std::string& image_data) override;
205 208
206 // Callbacks for the NTPSnippetsDatabase. 209 // Callbacks for the NTPSnippetsDatabase.
207 void OnDatabaseLoaded(NTPSnippet::PtrVector snippets); 210 void OnDatabaseLoaded(NTPSnippet::PtrVector snippets);
208 void OnDatabaseError(); 211 void OnDatabaseError();
209 212
210 // Callback for the NTPSnippetsFetcher. 213 // Callback for the NTPSnippetsFetcher.
211 void OnFetchFinished( 214 void OnFetchFinished(
215 bool fetched_more,
216 FetchedMoreCallback fetched_more_callback,
212 NTPSnippetsFetcher::OptionalFetchedCategories fetched_categories); 217 NTPSnippetsFetcher::OptionalFetchedCategories fetched_categories);
213 218
214 // Moves all snippets from |to_archive| into the archive of the |category|. 219 // Moves all snippets from |to_archive| into the archive of the |category|.
215 // It also deletes the snippets from the DB and keeps the archive reasonably 220 // It also deletes the snippets from the DB and keeps the archive reasonably
216 // short. 221 // short.
217 void ArchiveSnippets(Category category, NTPSnippet::PtrVector* to_archive); 222 void ArchiveSnippets(Category category, NTPSnippet::PtrVector* to_archive);
218 223
219 // Replace old snippets in |category| by newly available snippets. 224 // Adds newly available suggestions in |category| to the available ones.
220 void ReplaceSnippets(Category category, NTPSnippet::PtrVector new_snippets); 225 // If |replace_snippets| is set, archives existing suggestions.
226 void IncludeSnippets(const Category& category,
227 NTPSnippet::PtrVector new_snippets,
228 bool replace_snippets);
221 229
222 // Removes expired dismissed snippets from the service and the database. 230 // Removes expired dismissed snippets from the service and the database.
223 void ClearExpiredDismissedSnippets(); 231 void ClearExpiredDismissedSnippets();
224 232
225 // Removes images from the DB that are not referenced from any known snippet. 233 // Removes images from the DB that are not referenced from any known snippet.
226 // Needs to iterate the whole snippet database -- so do it often enough to 234 // Needs to iterate the whole snippet database -- so do it often enough to
227 // keep it small but not too often as it still iterates over the file system. 235 // keep it small but not too often as it still iterates over the file system.
228 void ClearOrphanedImages(); 236 void ClearOrphanedImages();
229 237
230 // Clears all stored snippets and updates the observer. 238 // Clears all stored snippets and updates the observer.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 void EnterStateDisabled(); 276 void EnterStateDisabled();
269 277
270 // Disables the service permanently because an unrecoverable error occurred. 278 // Disables the service permanently because an unrecoverable error occurred.
271 // Do not call directly, use |EnterState| instead. 279 // Do not call directly, use |EnterState| instead.
272 void EnterStateError(); 280 void EnterStateError();
273 281
274 // Converts the cached snippets in the given |category| to content suggestions 282 // Converts the cached snippets in the given |category| to content suggestions
275 // and notifies the observer. 283 // and notifies the observer.
276 void NotifyNewSuggestions(Category category); 284 void NotifyNewSuggestions(Category category);
277 285
286 // Converts the cached snippets in the given |category| to content suggestions
287 // and passes them to the |callback|.
288 void NotifyMoreSuggestions(Category category, FetchedMoreCallback callback);
289
278 // Updates the internal status for |category| to |category_status_| and 290 // Updates the internal status for |category| to |category_status_| and
279 // notifies the content suggestions observer if it changed. 291 // notifies the content suggestions observer if it changed.
280 void UpdateCategoryStatus(Category category, CategoryStatus status); 292 void UpdateCategoryStatus(Category category, CategoryStatus status);
281 // Calls UpdateCategoryStatus() for all provided categories. 293 // Calls UpdateCategoryStatus() for all provided categories.
282 void UpdateAllCategoryStatus(CategoryStatus status); 294 void UpdateAllCategoryStatus(CategoryStatus status);
283 295
284 void RestoreCategoriesFromPrefs(); 296 void RestoreCategoriesFromPrefs();
285 void StoreCategoriesToPrefs(); 297 void StoreCategoriesToPrefs();
286 298
299 // Implementation for |FetchSnippets| and |FetchMore| that calls the snippet
300 // fetcher and replaces or adds the fetched snippets depending on the
301 // |fetch_more| parameter.
302 void FetchSnippetsFromHostsImpl(const std::set<std::string>& hosts,
303 bool interactive_request,
304 bool fetch_more,
305 FetchedMoreCallback fetched_more_callback,
306 base::Optional<Category> exclusive_category);
307
308 // Returns a set of snippet IDs that should not be fetcheds. These IDs always
309 // include dismissed snippets. If |fetch_more| is set, they include all known
310 // snippet IDs.
311 std::set<std::string> CollectIdsToExclude(bool fetch_more) const;
312
313 void MarkEmptyCategoriesAsLoading();
314
287 State state_; 315 State state_;
288 316
289 PrefService* pref_service_; 317 PrefService* pref_service_;
290 318
291 const Category articles_category_; 319 const Category articles_category_;
292 320
293 // TODO(sfiera): Reduce duplication of CategoryContent with CategoryInfo. 321 // TODO(sfiera): Reduce duplication of CategoryContent with CategoryInfo.
294 struct CategoryContent { 322 struct CategoryContent {
295 CategoryStatus status = CategoryStatus::INITIALIZING; 323 CategoryStatus status = CategoryStatus::INITIALIZING;
296 324
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 387
360 // Request throttler for limiting requests to thumbnail images. 388 // Request throttler for limiting requests to thumbnail images.
361 RequestThrottler thumbnail_requests_throttler_; 389 RequestThrottler thumbnail_requests_throttler_;
362 390
363 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsService); 391 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsService);
364 }; 392 };
365 393
366 } // namespace ntp_snippets 394 } // namespace ntp_snippets
367 395
368 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_SERVICE_H_ 396 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698