| 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/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "components/history/core/browser/history_service.h" | 19 #include "components/history/core/browser/history_service.h" |
| 20 #include "components/history/core/browser/history_service_observer.h" | 20 #include "components/history/core/browser/history_service_observer.h" |
| 21 #include "components/keyed_service/core/keyed_service.h" | 21 #include "components/keyed_service/core/keyed_service.h" |
| 22 #include "components/ntp_snippets/callbacks.h" | 22 #include "components/ntp_snippets/callbacks.h" |
| 23 #include "components/ntp_snippets/category.h" | 23 #include "components/ntp_snippets/category.h" |
| 24 #include "components/ntp_snippets/category_rankers/category_ranker.h" | 24 #include "components/ntp_snippets/category_rankers/category_ranker.h" |
| 25 #include "components/ntp_snippets/category_status.h" | 25 #include "components/ntp_snippets/category_status.h" |
| 26 #include "components/ntp_snippets/content_suggestions_provider.h" | 26 #include "components/ntp_snippets/content_suggestions_provider.h" |
| 27 #include "components/ntp_snippets/remote/remote_suggestions_scheduler.h" |
| 27 #include "components/ntp_snippets/user_classifier.h" | 28 #include "components/ntp_snippets/user_classifier.h" |
| 28 #include "components/signin/core/browser/signin_manager.h" | 29 #include "components/signin/core/browser/signin_manager.h" |
| 29 | 30 |
| 30 class PrefService; | 31 class PrefService; |
| 31 class PrefRegistrySimple; | 32 class PrefRegistrySimple; |
| 32 | 33 |
| 33 namespace ntp_snippets { | 34 namespace ntp_snippets { |
| 34 | 35 |
| 35 class RemoteSuggestionsProvider; | 36 class RemoteSuggestionsProvider; |
| 36 class RemoteSuggestionsScheduler; | |
| 37 | 37 |
| 38 // Retrieves suggestions from a number of ContentSuggestionsProviders and serves | 38 // Retrieves suggestions from a number of ContentSuggestionsProviders and serves |
| 39 // them grouped into categories. There can be at most one provider per category. | 39 // them grouped into categories. There can be at most one provider per category. |
| 40 class ContentSuggestionsService : public KeyedService, | 40 class ContentSuggestionsService : public KeyedService, |
| 41 public ContentSuggestionsProvider::Observer, | 41 public ContentSuggestionsProvider::Observer, |
| 42 public SigninManagerBase::Observer, | 42 public SigninManagerBase::Observer, |
| 43 public history::HistoryServiceObserver { | 43 public history::HistoryServiceObserver { |
| 44 public: | 44 public: |
| 45 class Observer { | 45 class Observer { |
| 46 public: | 46 public: |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 remote_suggestions_provider_ = remote_suggestions_provider; | 218 remote_suggestions_provider_ = remote_suggestions_provider; |
| 219 } | 219 } |
| 220 RemoteSuggestionsProvider* remote_suggestions_provider_for_debugging() { | 220 RemoteSuggestionsProvider* remote_suggestions_provider_for_debugging() { |
| 221 return remote_suggestions_provider_; | 221 return remote_suggestions_provider_; |
| 222 } | 222 } |
| 223 | 223 |
| 224 // The reference to RemoteSuggestionsScheduler should only be set by the | 224 // The reference to RemoteSuggestionsScheduler should only be set by the |
| 225 // factory. The interface is suited for informing about external events that | 225 // factory. The interface is suited for informing about external events that |
| 226 // have influence on scheduling remote fetches. | 226 // have influence on scheduling remote fetches. |
| 227 void set_remote_suggestions_scheduler( | 227 void set_remote_suggestions_scheduler( |
| 228 ntp_snippets::RemoteSuggestionsScheduler* remote_suggestions_scheduler) { | 228 std::unique_ptr<ntp_snippets::RemoteSuggestionsScheduler> |
| 229 remote_suggestions_scheduler_ = remote_suggestions_scheduler; | 229 remote_suggestions_scheduler) { |
| 230 remote_suggestions_scheduler_ = std::move(remote_suggestions_scheduler); |
| 230 } | 231 } |
| 231 RemoteSuggestionsScheduler* remote_suggestions_scheduler() { | 232 RemoteSuggestionsScheduler* remote_suggestions_scheduler() { |
| 232 return remote_suggestions_scheduler_; | 233 return remote_suggestions_scheduler_.get(); |
| 233 } | 234 } |
| 234 | 235 |
| 235 UserClassifier* user_classifier() { return &user_classifier_; } | 236 UserClassifier* user_classifier() { return &user_classifier_; } |
| 236 CategoryRanker* category_ranker() { return category_ranker_.get(); } | 237 CategoryRanker* category_ranker() { return category_ranker_.get(); } |
| 237 | 238 |
| 238 private: | 239 private: |
| 239 friend class ContentSuggestionsServiceTest; | 240 friend class ContentSuggestionsServiceTest; |
| 240 | 241 |
| 241 // Implementation of ContentSuggestionsProvider::Observer. | 242 // Implementation of ContentSuggestionsProvider::Observer. |
| 242 void OnNewSuggestions(ContentSuggestionsProvider* provider, | 243 void OnNewSuggestions(ContentSuggestionsProvider* provider, |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 base::ObserverList<Observer> observers_; | 335 base::ObserverList<Observer> observers_; |
| 335 | 336 |
| 336 const std::vector<ContentSuggestion> no_suggestions_; | 337 const std::vector<ContentSuggestion> no_suggestions_; |
| 337 | 338 |
| 338 // Keep a direct reference to this special provider to redirect debugging | 339 // Keep a direct reference to this special provider to redirect debugging |
| 339 // calls to it. If the RemoteSuggestionsProvider is loaded, it is also present | 340 // calls to it. If the RemoteSuggestionsProvider is loaded, it is also present |
| 340 // in |providers_|, otherwise this is a nullptr. | 341 // in |providers_|, otherwise this is a nullptr. |
| 341 RemoteSuggestionsProvider* remote_suggestions_provider_; | 342 RemoteSuggestionsProvider* remote_suggestions_provider_; |
| 342 | 343 |
| 343 // Interface for informing about external events that have influence on | 344 // Interface for informing about external events that have influence on |
| 344 // scheduling remote fetches. Not owned. | 345 // scheduling remote fetches. |
| 345 RemoteSuggestionsScheduler* remote_suggestions_scheduler_; | 346 std::unique_ptr<ntp_snippets::RemoteSuggestionsScheduler> |
| 347 remote_suggestions_scheduler_; |
| 346 | 348 |
| 347 PrefService* pref_service_; | 349 PrefService* pref_service_; |
| 348 | 350 |
| 349 UserClassifier user_classifier_; | 351 UserClassifier user_classifier_; |
| 350 | 352 |
| 351 // Provides order for categories. | 353 // Provides order for categories. |
| 352 std::unique_ptr<CategoryRanker> category_ranker_; | 354 std::unique_ptr<CategoryRanker> category_ranker_; |
| 353 | 355 |
| 354 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService); | 356 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService); |
| 355 }; | 357 }; |
| 356 | 358 |
| 357 } // namespace ntp_snippets | 359 } // namespace ntp_snippets |
| 358 | 360 |
| 359 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ | 361 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ |
| OLD | NEW |