Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_CONTENT_SUGGESTIONS_SERVICE_H_ | 5 #ifndef COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ |
| 6 #define COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ | 6 #define COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/callback_forward.h" | 14 #include "base/callback_forward.h" |
| 15 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
| 16 #include "base/optional.h" | 16 #include "base/optional.h" |
| 17 #include "base/scoped_observer.h" | 17 #include "base/scoped_observer.h" |
| 18 #include "base/task/cancelable_task_tracker.h" | |
| 18 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 19 #include "components/history/core/browser/history_service.h" | 20 #include "components/history/core/browser/history_service.h" |
| 20 #include "components/history/core/browser/history_service_observer.h" | 21 #include "components/history/core/browser/history_service_observer.h" |
| 21 #include "components/keyed_service/core/keyed_service.h" | 22 #include "components/keyed_service/core/keyed_service.h" |
| 22 #include "components/ntp_snippets/callbacks.h" | 23 #include "components/ntp_snippets/callbacks.h" |
| 23 #include "components/ntp_snippets/category.h" | 24 #include "components/ntp_snippets/category.h" |
| 24 #include "components/ntp_snippets/category_rankers/category_ranker.h" | 25 #include "components/ntp_snippets/category_rankers/category_ranker.h" |
| 25 #include "components/ntp_snippets/category_status.h" | 26 #include "components/ntp_snippets/category_status.h" |
| 26 #include "components/ntp_snippets/content_suggestions_provider.h" | 27 #include "components/ntp_snippets/content_suggestions_provider.h" |
| 27 #include "components/ntp_snippets/remote/remote_suggestions_scheduler.h" | 28 #include "components/ntp_snippets/remote/remote_suggestions_scheduler.h" |
| 28 #include "components/ntp_snippets/user_classifier.h" | 29 #include "components/ntp_snippets/user_classifier.h" |
| 29 #include "components/signin/core/browser/signin_manager.h" | 30 #include "components/signin/core/browser/signin_manager.h" |
| 30 | 31 |
| 31 class PrefService; | 32 class PrefService; |
| 32 class PrefRegistrySimple; | 33 class PrefRegistrySimple; |
| 33 | 34 |
| 35 namespace favicon { | |
| 36 class LargeIconService; | |
| 37 } // namespace favicon | |
| 38 | |
| 39 namespace favicon_base { | |
| 40 struct LargeIconImageResult; | |
| 41 } // namespace favicon_base | |
| 42 | |
| 34 namespace ntp_snippets { | 43 namespace ntp_snippets { |
| 35 | 44 |
| 36 class RemoteSuggestionsProvider; | 45 class RemoteSuggestionsProvider; |
| 37 | 46 |
| 38 // Retrieves suggestions from a number of ContentSuggestionsProviders and serves | 47 // Retrieves suggestions from a number of ContentSuggestionsProviders and serves |
| 39 // them grouped into categories. There can be at most one provider per category. | 48 // them grouped into categories. There can be at most one provider per category. |
| 40 class ContentSuggestionsService : public KeyedService, | 49 class ContentSuggestionsService : public KeyedService, |
| 41 public ContentSuggestionsProvider::Observer, | 50 public ContentSuggestionsProvider::Observer, |
| 42 public SigninManagerBase::Observer, | 51 public SigninManagerBase::Observer, |
| 43 public history::HistoryServiceObserver { | 52 public history::HistoryServiceObserver { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 | 92 |
| 84 enum State { | 93 enum State { |
| 85 ENABLED, | 94 ENABLED, |
| 86 DISABLED, | 95 DISABLED, |
| 87 }; | 96 }; |
| 88 | 97 |
| 89 ContentSuggestionsService( | 98 ContentSuggestionsService( |
| 90 State state, | 99 State state, |
| 91 SigninManagerBase* signin_manager, // Can be nullptr in unittests. | 100 SigninManagerBase* signin_manager, // Can be nullptr in unittests. |
| 92 history::HistoryService* history_service, // Can be nullptr in unittests. | 101 history::HistoryService* history_service, // Can be nullptr in unittests. |
| 102 favicon::LargeIconService* | |
| 103 large_icon_service, // Can be nullptr in unittests. | |
|
Bernhard Bauer
2017/03/31 16:45:16
Nit: I would move the comment to the previous line
jkrcal
2017/04/03 12:37:36
Done.
| |
| 93 PrefService* pref_service, | 104 PrefService* pref_service, |
| 94 std::unique_ptr<CategoryRanker> category_ranker, | 105 std::unique_ptr<CategoryRanker> category_ranker, |
| 95 std::unique_ptr<UserClassifier> user_classifier, | 106 std::unique_ptr<UserClassifier> user_classifier, |
| 96 std::unique_ptr<RemoteSuggestionsScheduler> | 107 std::unique_ptr<RemoteSuggestionsScheduler> |
| 97 remote_suggestions_scheduler // Can be nullptr in unittests. | 108 remote_suggestions_scheduler // Can be nullptr in unittests. |
| 98 ); | 109 ); |
| 99 ~ContentSuggestionsService() override; | 110 ~ContentSuggestionsService() override; |
| 100 | 111 |
| 101 // Inherited from KeyedService. | 112 // Inherited from KeyedService. |
| 102 void Shutdown() override; | 113 void Shutdown() override; |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 void NotifyCategoryStatusChanged(Category category); | 308 void NotifyCategoryStatusChanged(Category category); |
| 298 | 309 |
| 299 void OnSignInStateChanged(); | 310 void OnSignInStateChanged(); |
| 300 | 311 |
| 301 // Re-enables a dismissed category, making querying its provider possible. | 312 // Re-enables a dismissed category, making querying its provider possible. |
| 302 void RestoreDismissedCategory(Category category); | 313 void RestoreDismissedCategory(Category category); |
| 303 | 314 |
| 304 void RestoreDismissedCategoriesFromPrefs(); | 315 void RestoreDismissedCategoriesFromPrefs(); |
| 305 void StoreDismissedCategoriesToPrefs(); | 316 void StoreDismissedCategoriesToPrefs(); |
| 306 | 317 |
| 318 // Callbacks for fetching favicons. | |
| 319 void OnGetFaviconFromCacheFinished( | |
| 320 const GURL& publisher_url, | |
| 321 int minimum_size_in_pixel, | |
| 322 int desired_size_in_pixel, | |
| 323 const ImageFetchedCallback& callback, | |
| 324 bool continue_to_google_server, | |
| 325 const favicon_base::LargeIconImageResult& result); | |
| 326 void OnGetFaviconFromGoogleServerFinished( | |
| 327 const GURL& publisher_url, | |
| 328 int minimum_size_in_pixel, | |
| 329 int desired_size_in_pixel, | |
| 330 const ImageFetchedCallback& callback, | |
| 331 bool success); | |
| 332 | |
| 307 // Whether the content suggestions feature is enabled. | 333 // Whether the content suggestions feature is enabled. |
| 308 State state_; | 334 State state_; |
| 309 | 335 |
| 310 // All registered providers, owned by the service. | 336 // All registered providers, owned by the service. |
| 311 std::vector<std::unique_ptr<ContentSuggestionsProvider>> providers_; | 337 std::vector<std::unique_ptr<ContentSuggestionsProvider>> providers_; |
| 312 | 338 |
| 313 // All registered categories and their providers. A provider may be contained | 339 // All registered categories and their providers. A provider may be contained |
| 314 // multiple times, if it provides multiple categories. The keys of this map | 340 // multiple times, if it provides multiple categories. The keys of this map |
| 315 // are exactly the entries of |categories_| and the values are a subset of | 341 // are exactly the entries of |categories_| and the values are a subset of |
| 316 // |providers_|. | 342 // |providers_|. |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 342 | 368 |
| 343 // Observer for the HistoryService. All providers are notified when history is | 369 // Observer for the HistoryService. All providers are notified when history is |
| 344 // deleted. | 370 // deleted. |
| 345 ScopedObserver<history::HistoryService, history::HistoryServiceObserver> | 371 ScopedObserver<history::HistoryService, history::HistoryServiceObserver> |
| 346 history_service_observer_; | 372 history_service_observer_; |
| 347 | 373 |
| 348 base::ObserverList<Observer> observers_; | 374 base::ObserverList<Observer> observers_; |
| 349 | 375 |
| 350 const std::vector<ContentSuggestion> no_suggestions_; | 376 const std::vector<ContentSuggestion> no_suggestions_; |
| 351 | 377 |
| 378 base::CancelableTaskTracker favicons_task_tracker_; | |
| 379 | |
| 352 // Keep a direct reference to this special provider to redirect debugging | 380 // Keep a direct reference to this special provider to redirect debugging |
| 353 // calls to it. If the RemoteSuggestionsProvider is loaded, it is also present | 381 // calls to it. If the RemoteSuggestionsProvider is loaded, it is also present |
| 354 // in |providers_|, otherwise this is a nullptr. | 382 // in |providers_|, otherwise this is a nullptr. |
| 355 RemoteSuggestionsProvider* remote_suggestions_provider_; | 383 RemoteSuggestionsProvider* remote_suggestions_provider_; |
| 356 | 384 |
| 385 favicon::LargeIconService* large_icon_service_; | |
| 386 | |
| 357 PrefService* pref_service_; | 387 PrefService* pref_service_; |
| 358 | 388 |
| 359 // Interface for informing about external events that have influence on | 389 // Interface for informing about external events that have influence on |
| 360 // scheduling remote fetches. | 390 // scheduling remote fetches. |
| 361 std::unique_ptr<RemoteSuggestionsScheduler> remote_suggestions_scheduler_; | 391 std::unique_ptr<RemoteSuggestionsScheduler> remote_suggestions_scheduler_; |
| 362 | 392 |
| 363 // Classifies the user on the basis of long-term user interactions. | 393 // Classifies the user on the basis of long-term user interactions. |
| 364 std::unique_ptr<UserClassifier> user_classifier_; | 394 std::unique_ptr<UserClassifier> user_classifier_; |
| 365 | 395 |
| 366 // Provides order for categories. | 396 // Provides order for categories. |
| 367 std::unique_ptr<CategoryRanker> category_ranker_; | 397 std::unique_ptr<CategoryRanker> category_ranker_; |
| 368 | 398 |
| 369 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService); | 399 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService); |
| 370 }; | 400 }; |
| 371 | 401 |
| 372 } // namespace ntp_snippets | 402 } // namespace ntp_snippets |
| 373 | 403 |
| 374 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ | 404 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ |
| OLD | NEW |