| 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_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 <map> | 10 #include <map> |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 } | 109 } |
| 110 | 110 |
| 111 // (Re)schedules the periodic fetching of snippets. If |force| is true, the | 111 // (Re)schedules the periodic fetching of snippets. If |force| is true, the |
| 112 // tasks will be re-scheduled even if they already exist and have the correct | 112 // tasks will be re-scheduled even if they already exist and have the correct |
| 113 // periods. | 113 // periods. |
| 114 void RescheduleFetching(bool force); | 114 void RescheduleFetching(bool force); |
| 115 | 115 |
| 116 // ContentSuggestionsProvider implementation | 116 // ContentSuggestionsProvider implementation |
| 117 CategoryStatus GetCategoryStatus(Category category) override; | 117 CategoryStatus GetCategoryStatus(Category category) override; |
| 118 CategoryInfo GetCategoryInfo(Category category) override; | 118 CategoryInfo GetCategoryInfo(Category category) override; |
| 119 void DismissSuggestion(const std::string& suggestion_id) override; | 119 void DismissSuggestion(const ContentSuggestion::ID& suggestion_id) override; |
| 120 void FetchSuggestionImage(const std::string& suggestion_id, | 120 void FetchSuggestionImage(const ContentSuggestion::ID& suggestion_id, |
| 121 const ImageFetchedCallback& callback) override; | 121 const ImageFetchedCallback& callback) override; |
| 122 void ClearHistory( | 122 void ClearHistory( |
| 123 base::Time begin, | 123 base::Time begin, |
| 124 base::Time end, | 124 base::Time end, |
| 125 const base::Callback<bool(const GURL& url)>& filter) override; | 125 const base::Callback<bool(const GURL& url)>& filter) override; |
| 126 void ClearCachedSuggestions(Category category) override; | 126 void ClearCachedSuggestions(Category category) override; |
| 127 void GetDismissedSuggestionsForDebugging( | 127 void GetDismissedSuggestionsForDebugging( |
| 128 Category category, | 128 Category category, |
| 129 const DismissedSuggestionsCallback& callback) override; | 129 const DismissedSuggestionsCallback& callback) override; |
| 130 void ClearDismissedSuggestionsForDebugging(Category category) override; | 130 void ClearDismissedSuggestionsForDebugging(Category category) override; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 // |OnStateChanged| is called and sync is enabled. | 190 // |OnStateChanged| is called and sync is enabled. |
| 191 // - ERROR_OCCURRED: when an unrecoverable error occurred. | 191 // - ERROR_OCCURRED: when an unrecoverable error occurred. |
| 192 DISABLED, | 192 DISABLED, |
| 193 | 193 |
| 194 // The service or one of its dependencies encountered an unrecoverable error | 194 // The service or one of its dependencies encountered an unrecoverable error |
| 195 // and the service can't be used anymore. | 195 // and the service can't be used anymore. |
| 196 ERROR_OCCURRED | 196 ERROR_OCCURRED |
| 197 }; | 197 }; |
| 198 | 198 |
| 199 // Returns the URL of the image of a snippet if it is among the current or | 199 // Returns the URL of the image of a snippet if it is among the current or |
| 200 // among the archived snippets in |category|. Returns an empty URL, otherwise. | 200 // among the archived snippets in the matching category. Returns an empty URL |
| 201 GURL FindSnippetImageUrl(Category category, | 201 // otherwise. |
| 202 const std::string& snippet_id) const; | 202 GURL FindSnippetImageUrl(const ContentSuggestion::ID& suggestion_id) const; |
| 203 | 203 |
| 204 // image_fetcher::ImageFetcherDelegate implementation. | 204 // image_fetcher::ImageFetcherDelegate implementation. |
| 205 void OnImageDataFetched(const std::string& suggestion_id, | 205 void OnImageDataFetched(const std::string& within_category_id, |
| 206 const std::string& image_data) override; | 206 const std::string& image_data) override; |
| 207 | 207 |
| 208 // Callbacks for the NTPSnippetsDatabase. | 208 // Callbacks for the NTPSnippetsDatabase. |
| 209 void OnDatabaseLoaded(NTPSnippet::PtrVector snippets); | 209 void OnDatabaseLoaded(NTPSnippet::PtrVector snippets); |
| 210 void OnDatabaseError(); | 210 void OnDatabaseError(); |
| 211 | 211 |
| 212 // Callback for the SuggestionsService. | 212 // Callback for the SuggestionsService. |
| 213 void OnSuggestionsChanged(const suggestions::SuggestionsProfile& suggestions); | 213 void OnSuggestionsChanged(const suggestions::SuggestionsProfile& suggestions); |
| 214 | 214 |
| 215 // Callback for the NTPSnippetsFetcher. | 215 // Callback for the NTPSnippetsFetcher. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 233 // (neither in the current set, nor in the archived set). | 233 // (neither in the current set, nor in the archived set). |
| 234 void ClearOrphanedImages(); | 234 void ClearOrphanedImages(); |
| 235 | 235 |
| 236 // Clears all stored snippets and updates the observer. | 236 // Clears all stored snippets and updates the observer. |
| 237 void NukeAllSnippets(); | 237 void NukeAllSnippets(); |
| 238 | 238 |
| 239 // Completes the initialization phase of the service, registering the last | 239 // Completes the initialization phase of the service, registering the last |
| 240 // observers. This is done after construction, once the database is loaded. | 240 // observers. This is done after construction, once the database is loaded. |
| 241 void FinishInitialization(); | 241 void FinishInitialization(); |
| 242 | 242 |
| 243 void OnSnippetImageFetchedFromDatabase(const ImageFetchedCallback& callback, | 243 void OnSnippetImageFetchedFromDatabase( |
| 244 const std::string& suggestion_id, | 244 const ImageFetchedCallback& callback, |
| 245 std::string data); | 245 const ContentSuggestion::ID& suggestion_id, |
| 246 std::string data); |
| 246 | 247 |
| 247 void OnSnippetImageDecodedFromDatabase(const ImageFetchedCallback& callback, | 248 void OnSnippetImageDecodedFromDatabase( |
| 248 const std::string& suggestion_id, | 249 const ImageFetchedCallback& callback, |
| 249 const gfx::Image& image); | 250 const ContentSuggestion::ID& suggestion_id, |
| 251 const gfx::Image& image); |
| 250 | 252 |
| 251 void FetchSnippetImageFromNetwork(const std::string& suggestion_id, | 253 void FetchSnippetImageFromNetwork(const ContentSuggestion::ID& suggestion_id, |
| 252 const ImageFetchedCallback& callback); | 254 const ImageFetchedCallback& callback); |
| 253 | 255 |
| 254 void OnSnippetImageDecodedFromNetwork(const ImageFetchedCallback& callback, | 256 void OnSnippetImageDecodedFromNetwork(const ImageFetchedCallback& callback, |
| 255 const std::string& suggestion_id, | 257 const std::string& within_category_id, |
| 256 const gfx::Image& image); | 258 const gfx::Image& image); |
| 257 | 259 |
| 258 // Triggers a state transition depending on the provided reason to be | 260 // Triggers a state transition depending on the provided reason to be |
| 259 // disabled (or lack thereof). This method is called when a change is detected | 261 // disabled (or lack thereof). This method is called when a change is detected |
| 260 // by |snippets_status_service_|. | 262 // by |snippets_status_service_|. |
| 261 void OnDisabledReasonChanged(DisabledReason disabled_reason); | 263 void OnDisabledReasonChanged(DisabledReason disabled_reason); |
| 262 | 264 |
| 263 // Verifies state transitions (see |State|'s documentation) and applies them. | 265 // Verifies state transitions (see |State|'s documentation) and applies them. |
| 264 // Also updates the provider status. Does nothing except updating the provider | 266 // Also updates the provider status. Does nothing except updating the provider |
| 265 // status if called with the current state. | 267 // status if called with the current state. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 | 313 |
| 312 // All previous suggestions that we keep around in memory because they can | 314 // All previous suggestions that we keep around in memory because they can |
| 313 // be on some open NTP. We do not persist this list so that on a new start | 315 // be on some open NTP. We do not persist this list so that on a new start |
| 314 // of Chrome, this is empty. | 316 // of Chrome, this is empty. |
| 315 NTPSnippet::PtrVector archived; | 317 NTPSnippet::PtrVector archived; |
| 316 | 318 |
| 317 // Suggestions that the user dismissed. We keep these around until they | 319 // Suggestions that the user dismissed. We keep these around until they |
| 318 // expire so we won't re-add them to |snippets| on the next fetch. | 320 // expire so we won't re-add them to |snippets| on the next fetch. |
| 319 NTPSnippet::PtrVector dismissed; | 321 NTPSnippet::PtrVector dismissed; |
| 320 | 322 |
| 323 // Returns a non-dismissed snippet with the given |within_category_id|, or |
| 324 // null if none exist. |
| 325 const NTPSnippet* FindSnippet(const std::string& within_category_id) const; |
| 326 |
| 321 CategoryContent(); | 327 CategoryContent(); |
| 322 CategoryContent(CategoryContent&&); | 328 CategoryContent(CategoryContent&&); |
| 323 ~CategoryContent(); | 329 ~CategoryContent(); |
| 324 CategoryContent& operator=(CategoryContent&&); | 330 CategoryContent& operator=(CategoryContent&&); |
| 325 }; | 331 }; |
| 326 std::map<Category, CategoryContent, Category::CompareByID> categories_; | 332 std::map<Category, CategoryContent, Category::CompareByID> categories_; |
| 327 | 333 |
| 328 // The ISO 639-1 code of the language used by the application. | 334 // The ISO 639-1 code of the language used by the application. |
| 329 const std::string application_language_code_; | 335 const std::string application_language_code_; |
| 330 | 336 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 361 | 367 |
| 362 // Request throttler for limiting requests to thumbnail images. | 368 // Request throttler for limiting requests to thumbnail images. |
| 363 RequestThrottler thumbnail_requests_throttler_; | 369 RequestThrottler thumbnail_requests_throttler_; |
| 364 | 370 |
| 365 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsService); | 371 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsService); |
| 366 }; | 372 }; |
| 367 | 373 |
| 368 } // namespace ntp_snippets | 374 } // namespace ntp_snippets |
| 369 | 375 |
| 370 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ | 376 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ |
| OLD | NEW |