OLD | NEW |
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 Loading... |
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, | 120 void Fetch(const Category& category, |
121 FetchedMoreCallback callback) override; | 121 std::set<std::string> known_suggestion_ids, |
| 122 FetchingCallback callback) override; |
122 void ClearHistory( | 123 void ClearHistory( |
123 base::Time begin, | 124 base::Time begin, |
124 base::Time end, | 125 base::Time end, |
125 const base::Callback<bool(const GURL& url)>& filter) override; | 126 const base::Callback<bool(const GURL& url)>& filter) override; |
126 void ClearCachedSuggestions(Category category) override; | 127 void ClearCachedSuggestions(Category category) override; |
127 void GetDismissedSuggestionsForDebugging( | 128 void GetDismissedSuggestionsForDebugging( |
128 Category category, | 129 Category category, |
129 const DismissedSuggestionsCallback& callback) override; | 130 const DismissedSuggestionsCallback& callback) override; |
130 void ClearDismissedSuggestionsForDebugging(Category category) override; | 131 void ClearDismissedSuggestionsForDebugging(Category category) override; |
131 | 132 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 void OnImageDataFetched(const std::string& id_within_category, | 207 void OnImageDataFetched(const std::string& id_within_category, |
207 const std::string& image_data) override; | 208 const std::string& image_data) override; |
208 | 209 |
209 // Callbacks for the NTPSnippetsDatabase. | 210 // Callbacks for the NTPSnippetsDatabase. |
210 void OnDatabaseLoaded(NTPSnippet::PtrVector snippets); | 211 void OnDatabaseLoaded(NTPSnippet::PtrVector snippets); |
211 void OnDatabaseError(); | 212 void OnDatabaseError(); |
212 | 213 |
213 // Callback for the NTPSnippetsFetcher. | 214 // Callback for the NTPSnippetsFetcher. |
214 void OnFetchFinished( | 215 void OnFetchFinished( |
215 bool fetched_more, | 216 bool fetched_more, |
216 FetchedMoreCallback fetched_more_callback, | 217 FetchingCallback fetched_more_callback, |
217 NTPSnippetsFetcher::OptionalFetchedCategories fetched_categories); | 218 NTPSnippetsFetcher::OptionalFetchedCategories fetched_categories); |
218 | 219 |
219 // Moves all snippets from |to_archive| into the archive of the |category|. | 220 // Moves all snippets from |to_archive| into the archive of the |category|. |
220 // It also deletes the snippets from the DB and keeps the archive reasonably | 221 // It also deletes the snippets from the DB and keeps the archive reasonably |
221 // short. | 222 // short. |
222 void ArchiveSnippets(Category category, NTPSnippet::PtrVector* to_archive); | 223 void ArchiveSnippets(Category category, NTPSnippet::PtrVector* to_archive); |
223 | 224 |
224 // Adds newly available suggestions in |category| to the available ones. | 225 // Adds newly available suggestions in |category| to the available ones. |
225 // If |replace_snippets| is set, archives existing suggestions. | 226 // If |replace_snippets| is set, archives existing suggestions. |
226 void IncludeSnippets(const Category& category, | 227 void IncludeSnippets(const Category& category, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 // Disables the service permanently because an unrecoverable error occurred. | 279 // Disables the service permanently because an unrecoverable error occurred. |
279 // Do not call directly, use |EnterState| instead. | 280 // Do not call directly, use |EnterState| instead. |
280 void EnterStateError(); | 281 void EnterStateError(); |
281 | 282 |
282 // Converts the cached snippets in the given |category| to content suggestions | 283 // Converts the cached snippets in the given |category| to content suggestions |
283 // and notifies the observer. | 284 // and notifies the observer. |
284 void NotifyNewSuggestions(Category category); | 285 void NotifyNewSuggestions(Category category); |
285 | 286 |
286 // Converts the cached snippets in the given |category| to content suggestions | 287 // Converts the cached snippets in the given |category| to content suggestions |
287 // and passes them to the |callback|. | 288 // and passes them to the |callback|. |
288 void NotifyMoreSuggestions(Category category, FetchedMoreCallback callback); | 289 void NotifyMoreSuggestions(Category category, FetchingCallback callback); |
289 | 290 |
290 // Updates the internal status for |category| to |category_status_| and | 291 // Updates the internal status for |category| to |category_status_| and |
291 // notifies the content suggestions observer if it changed. | 292 // notifies the content suggestions observer if it changed. |
292 void UpdateCategoryStatus(Category category, CategoryStatus status); | 293 void UpdateCategoryStatus(Category category, CategoryStatus status); |
293 // Calls UpdateCategoryStatus() for all provided categories. | 294 // Calls UpdateCategoryStatus() for all provided categories. |
294 void UpdateAllCategoryStatus(CategoryStatus status); | 295 void UpdateAllCategoryStatus(CategoryStatus status); |
295 | 296 |
296 void RestoreCategoriesFromPrefs(); | 297 void RestoreCategoriesFromPrefs(); |
297 void StoreCategoriesToPrefs(); | 298 void StoreCategoriesToPrefs(); |
298 | 299 |
299 // Implementation for |FetchSnippets| and |FetchMore| that calls the snippet | 300 // Implementation for |FetchSnippets| and |Fetch| that calls the snippet |
300 // fetcher and replaces or adds the fetched snippets depending on the | 301 // fetcher and replaces or adds the fetched snippets depending on the |
301 // |fetch_more| parameter. | 302 // |fetch_more| parameter. |
302 void FetchSnippetsFromHostsImpl(const std::set<std::string>& hosts, | 303 void FetchSnippetsFromHostsImpl(const std::set<std::string>& hosts, |
303 bool interactive_request, | 304 bool interactive_request, |
304 bool fetch_more, | 305 bool fetch_more, |
305 FetchedMoreCallback fetched_more_callback, | 306 std::set<std::string> known_suggestion_ids, |
306 base::Optional<Category> exclusive_category); | 307 base::Optional<Category> exclusive_category, |
| 308 FetchingCallback fetched_more_callback); |
307 | 309 |
308 // Returns a set of snippet IDs that should not be fetcheds. These IDs always | 310 // Returns a set of snippet IDs that should not be fetched. These IDs always |
309 // include dismissed snippets. If |fetch_more| is set, they include all known | 311 // include dismissed snippets. If |fetch_more| is set, they include all known |
310 // snippet IDs. | 312 // snippet IDs. |
311 std::set<std::string> CollectIdsToExclude(bool fetch_more) const; | 313 std::set<std::string> CollectIdsToExclude( |
| 314 bool fetch_more, |
| 315 std::set<std::string> additional_ids) const; |
312 | 316 |
313 void MarkEmptyCategoriesAsLoading(); | 317 void MarkEmptyCategoriesAsLoading(); |
314 | 318 |
315 State state_; | 319 State state_; |
316 | 320 |
317 PrefService* pref_service_; | 321 PrefService* pref_service_; |
318 | 322 |
319 const Category articles_category_; | 323 const Category articles_category_; |
320 | 324 |
321 // TODO(sfiera): Reduce duplication of CategoryContent with CategoryInfo. | 325 // TODO(sfiera): Reduce duplication of CategoryContent with CategoryInfo. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 | 391 |
388 // Request throttler for limiting requests to thumbnail images. | 392 // Request throttler for limiting requests to thumbnail images. |
389 RequestThrottler thumbnail_requests_throttler_; | 393 RequestThrottler thumbnail_requests_throttler_; |
390 | 394 |
391 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsService); | 395 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsService); |
392 }; | 396 }; |
393 | 397 |
394 } // namespace ntp_snippets | 398 } // namespace ntp_snippets |
395 | 399 |
396 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_SERVICE_H_ | 400 #endif // COMPONENTS_NTP_SNIPPETS_REMOTE_NTP_SNIPPETS_SERVICE_H_ |
OLD | NEW |