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

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

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

Powered by Google App Engine
This is Rietveld 408576698