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

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

Issue 2421463002: FetchMore functionality backend (Closed)
Patch Set: NTBR. Rebasing a lot. 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 const 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 // image_fetcher::ImageFetcherDelegate implementation. 204 // image_fetcher::ImageFetcherDelegate implementation.
203 void OnImageDataFetched(const std::string& id_within_category, 205 void OnImageDataFetched(const std::string& id_within_category,
204 const std::string& image_data) override; 206 const std::string& image_data) override;
205 207
206 // Callbacks for the NTPSnippetsDatabase. 208 // Callbacks for the NTPSnippetsDatabase.
207 void OnDatabaseLoaded(NTPSnippet::PtrVector snippets); 209 void OnDatabaseLoaded(NTPSnippet::PtrVector snippets);
208 void OnDatabaseError(); 210 void OnDatabaseError();
209 211
210 // Callback for the NTPSnippetsFetcher. 212 // Callback for the NTPSnippetsFetcher.
211 void OnFetchFinished( 213 void OnFetchFinished(
214 bool fetched_more,
215 const FetchedMoreCallback& fetched_more_callback,
212 NTPSnippetsFetcher::OptionalFetchedCategories fetched_categories); 216 NTPSnippetsFetcher::OptionalFetchedCategories fetched_categories);
213 217
214 // Moves all snippets from |to_archive| into the archive of the |category|. 218 // 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 219 // It also deletes the snippets from the DB and keeps the archive reasonably
216 // short. 220 // short.
217 void ArchiveSnippets(Category category, NTPSnippet::PtrVector* to_archive); 221 void ArchiveSnippets(Category category, NTPSnippet::PtrVector* to_archive);
218 222
219 // Replace old snippets in |category| by newly available snippets. 223 // Add newly available snippets in |category| to the provided content.
vitaliii 2016/11/01 23:29:58 s/Add/Adds
fhorschig 2016/11/02 05:05:28 Done in CL 2446163005.
220 void ReplaceSnippets(Category category, NTPSnippet::PtrVector new_snippets); 224 // If |replace_snippets| is set, archive existing snippets.
vitaliii 2016/11/01 23:29:57 nit: remove "is set"
fhorschig 2016/11/02 05:05:28 Done in CL 2446163005.
225 void IncludeSnippets(const Category& category,
226 NTPSnippet::PtrVector new_snippets,
227 bool replace_snippets);
228
229 void SaveSnippets(const Category& category,
230 NTPSnippet::PtrVector new_snippets,
231 bool replace_snippets);
221 232
222 // Removes expired dismissed snippets from the service and the database. 233 // Removes expired dismissed snippets from the service and the database.
223 void ClearExpiredDismissedSnippets(); 234 void ClearExpiredDismissedSnippets();
224 235
225 // Removes images from the DB that are not referenced from any known snippet. 236 // 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 237 // 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. 238 // keep it small but not too often as it still iterates over the file system.
228 void ClearOrphanedImages(); 239 void ClearOrphanedImages();
229 240
230 // Clears all stored snippets and updates the observer. 241 // Clears all stored snippets and updates the observer.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 void EnterStateReady(); 276 void EnterStateReady();
266 277
267 // Disables the service. Do not call directly, use |EnterState| instead. 278 // Disables the service. Do not call directly, use |EnterState| instead.
268 void EnterStateDisabled(); 279 void EnterStateDisabled();
269 280
270 // Disables the service permanently because an unrecoverable error occurred. 281 // Disables the service permanently because an unrecoverable error occurred.
271 // Do not call directly, use |EnterState| instead. 282 // Do not call directly, use |EnterState| instead.
272 void EnterStateError(); 283 void EnterStateError();
273 284
274 // Converts the cached snippets in the given |category| to content suggestions 285 // Converts the cached snippets in the given |category| to content suggestions
275 // and notifies the observer. 286 // and calls a passed callback. If no callbakc is given it notifies the
vitaliii 2016/11/01 23:29:58 s/callbakc/callbaCK s/it/,
fhorschig 2016/11/02 05:05:28 Done in CL 2446163005.
287 // observer.
288 void NotifyNewSuggestionsOrInvokeCallback(
289 Category category,
290 FetchedMoreCallback fetched_more_callback);
291 // Triggers notification of observer by calling
292 // |NotifyNewSuggestionsOrInvokeCallback| with a null callback.
276 void NotifyNewSuggestions(Category category); 293 void NotifyNewSuggestions(Category category);
277 294
278 // Updates the internal status for |category| to |category_status_| and 295 // Updates the internal status for |category| to |category_status_| and
279 // notifies the content suggestions observer if it changed. 296 // notifies the content suggestions observer if it changed.
280 void UpdateCategoryStatus(Category category, CategoryStatus status); 297 void UpdateCategoryStatus(Category category, CategoryStatus status);
281 // Calls UpdateCategoryStatus() for all provided categories. 298 // Calls UpdateCategoryStatus() for all provided categories.
282 void UpdateAllCategoryStatus(CategoryStatus status); 299 void UpdateAllCategoryStatus(CategoryStatus status);
283 300
284 void RestoreCategoriesFromPrefs(); 301 void RestoreCategoriesFromPrefs();
285 void StoreCategoriesToPrefs(); 302 void StoreCategoriesToPrefs();
286 303
304 // Implementation for |FetchSnippets| and |FetchMore| that calls the snippet
305 // fetcher and replaces or adds the fetched snippets depending on the passed
306 // |strategy|.
307 void FetchSnippetsFromHostsImpl(
308 const std::set<std::string>& hosts,
309 bool interactive_request,
310 bool fetch_more,
311 base::Optional<Category> exclusive_category,
312 const FetchedMoreCallback& fetched_more_callback);
313 void MarkEmptyCategoriesAsLoading(NTPSnippetsFetcher::Params* params);
314 void AssignExpiryDates(NTPSnippet::PtrVector* snippets);
315 void AddIncompleteSnippets(NTPSnippet::PtrVector* snippets);
316 void FinishFetch(
317 NTPSnippetsFetcher::OptionalFetchedCategories fetched_categories,
318 bool replace_existing_snippets);
319 // Returns a set of snippet ids that are should not be fetched in subsequent
vitaliii 2016/11/01 23:29:58 grammar: remove "are"
fhorschig 2016/11/02 05:05:28 Done in CL 2446163005.
320 // requests. These IDs akways include dismissed snippets.
vitaliii 2016/11/01 23:29:57 IDs is inconsistent with the previous line. s/akwa
fhorschig 2016/11/02 05:05:28 Done in CL 2446163005.
321 // For |fetch more| requests, all known snippets are returned.
322 std::set<std::string> CollectIdsToExclude(bool fetch_more);
323 void MarkEmptyCategoriesAsLoading();
324
287 State state_; 325 State state_;
288 326
289 PrefService* pref_service_; 327 PrefService* pref_service_;
290 328
291 const Category articles_category_; 329 const Category articles_category_;
292 330
293 // TODO(sfiera): Reduce duplication of CategoryContent with CategoryInfo. 331 // TODO(sfiera): Reduce duplication of CategoryContent with CategoryInfo.
294 struct CategoryContent { 332 struct CategoryContent {
295 CategoryStatus status = CategoryStatus::INITIALIZING; 333 CategoryStatus status = CategoryStatus::INITIALIZING;
296 334
(...skipping 20 matching lines...) Expand all
317 355
318 // Returns a non-dismissed snippet with the given |id_within_category|, or 356 // Returns a non-dismissed snippet with the given |id_within_category|, or
319 // null if none exist. 357 // null if none exist.
320 const NTPSnippet* FindSnippet(const std::string& id_within_category) const; 358 const NTPSnippet* FindSnippet(const std::string& id_within_category) const;
321 359
322 CategoryContent(); 360 CategoryContent();
323 CategoryContent(CategoryContent&&); 361 CategoryContent(CategoryContent&&);
324 ~CategoryContent(); 362 ~CategoryContent();
325 CategoryContent& operator=(CategoryContent&&); 363 CategoryContent& operator=(CategoryContent&&);
326 }; 364 };
327 std::map<Category, CategoryContent, Category::CompareByID> categories_; 365 using CategoryContentMap =
366 std::map<Category, CategoryContent, Category::CompareByID>;
367 CategoryContentMap categories_;
328 368
329 // The ISO 639-1 code of the language used by the application. 369 // The ISO 639-1 code of the language used by the application.
330 const std::string application_language_code_; 370 const std::string application_language_code_;
331 371
332 // Classifier that tells us how active the user is. Not owned. 372 // Classifier that tells us how active the user is. Not owned.
333 const UserClassifier* user_classifier_; 373 const UserClassifier* user_classifier_;
334 374
335 // Scheduler for fetching snippets. Not owned. 375 // Scheduler for fetching snippets. Not owned.
336 NTPSnippetsScheduler* scheduler_; 376 NTPSnippetsScheduler* scheduler_;
337 377
(...skipping 21 matching lines...) Expand all
359 399
360 // Request throttler for limiting requests to thumbnail images. 400 // Request throttler for limiting requests to thumbnail images.
361 RequestThrottler thumbnail_requests_throttler_; 401 RequestThrottler thumbnail_requests_throttler_;
362 402
363 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsService); 403 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsService);
364 }; 404 };
365 405
366 } // namespace ntp_snippets 406 } // namespace ntp_snippets
367 407
368 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_SERVICE_H_ 408 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698