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

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

Issue 2774663002: [Remote suggestions] Refactor the scheduler (Closed)
Patch Set: Fix iOS compile Created 3 years, 9 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 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 79
80 protected: 80 protected:
81 virtual ~Observer() = default; 81 virtual ~Observer() = default;
82 }; 82 };
83 83
84 enum State { 84 enum State {
85 ENABLED, 85 ENABLED,
86 DISABLED, 86 DISABLED,
87 }; 87 };
88 88
89 ContentSuggestionsService(State state, 89 ContentSuggestionsService(
Marc Treib 2017/03/27 11:31:00 Add a comment saying which of the passed-in ptrs m
jkrcal 2017/03/27 14:09:31 Done.
90 SigninManagerBase* signin_manager, 90 State state,
91 history::HistoryService* history_service, 91 SigninManagerBase* signin_manager,
92 PrefService* pref_service, 92 history::HistoryService* history_service,
93 std::unique_ptr<CategoryRanker> category_ranker); 93 PrefService* pref_service,
94 std::unique_ptr<CategoryRanker> category_ranker,
95 std::unique_ptr<UserClassifier> user_classifier,
96 std::unique_ptr<RemoteSuggestionsScheduler> remote_suggestions_scheduler);
94 ~ContentSuggestionsService() override; 97 ~ContentSuggestionsService() override;
95 98
96 // Inherited from KeyedService. 99 // Inherited from KeyedService.
97 void Shutdown() override; 100 void Shutdown() override;
98 101
99 static void RegisterProfilePrefs(PrefRegistrySimple* registry); 102 static void RegisterProfilePrefs(PrefRegistrySimple* registry);
100 103
101 State state() { return state_; } 104 State state() { return state_; }
102 105
103 // Gets all categories for which a provider is registered. The categories may 106 // Gets all categories for which a provider is registered. The categories may
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 // TODO(jkrcal) Move the getter into the scheduler interface (the setter is 217 // TODO(jkrcal) Move the getter into the scheduler interface (the setter is
215 // then not needed any more). crbug.com/695447 218 // then not needed any more). crbug.com/695447
216 void set_remote_suggestions_provider( 219 void set_remote_suggestions_provider(
217 RemoteSuggestionsProvider* remote_suggestions_provider) { 220 RemoteSuggestionsProvider* remote_suggestions_provider) {
218 remote_suggestions_provider_ = remote_suggestions_provider; 221 remote_suggestions_provider_ = remote_suggestions_provider;
219 } 222 }
220 RemoteSuggestionsProvider* remote_suggestions_provider_for_debugging() { 223 RemoteSuggestionsProvider* remote_suggestions_provider_for_debugging() {
221 return remote_suggestions_provider_; 224 return remote_suggestions_provider_;
222 } 225 }
223 226
224 // The reference to RemoteSuggestionsScheduler should only be set by the 227 // The interface is suited for informing about external events that have
225 // factory. The interface is suited for informing about external events that 228 // influence on scheduling remote fetches.
Marc Treib 2017/03/27 11:31:00 Mention that it can be null?
jkrcal 2017/03/27 14:09:31 Done.
226 // have influence on scheduling remote fetches.
227 void set_remote_suggestions_scheduler(
228 ntp_snippets::RemoteSuggestionsScheduler* remote_suggestions_scheduler) {
229 remote_suggestions_scheduler_ = remote_suggestions_scheduler;
230 }
231 RemoteSuggestionsScheduler* remote_suggestions_scheduler() { 229 RemoteSuggestionsScheduler* remote_suggestions_scheduler() {
232 return remote_suggestions_scheduler_; 230 return remote_suggestions_scheduler_.get();
233 } 231 }
234 232
235 UserClassifier* user_classifier() { return &user_classifier_; } 233 // TODO(jkrcal): The getter is only used from the bridge and from
234 // snippets-internals. Can we get rid of it with the metrics refactoring?
235 UserClassifier* user_classifier() { return user_classifier_.get(); }
236
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,
243 Category category, 244 Category category,
244 std::vector<ContentSuggestion> suggestions) override; 245 std::vector<ContentSuggestion> suggestions) override;
245 void OnCategoryStatusChanged(ContentSuggestionsProvider* provider, 246 void OnCategoryStatusChanged(ContentSuggestionsProvider* provider,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 334
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 // scheduling remote fetches. Not owned.
345 RemoteSuggestionsScheduler* remote_suggestions_scheduler_;
346
347 PrefService* pref_service_; 344 PrefService* pref_service_;
348 345
349 UserClassifier user_classifier_; 346 // Interface for informing about external events that have influence on
347 // scheduling remote fetches.
348 std::unique_ptr<RemoteSuggestionsScheduler> remote_suggestions_scheduler_;
349
350 // Classifies the user on the basis of long-term user interactions.
351 std::unique_ptr<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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698