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

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

Issue 2568033005: [NTP::SectionOrder] Replace CategoryFactory with a category ranker. (Closed)
Patch Set: Created 4 years 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_factory.h" 23 #include "components/ntp_snippets/category.h"
24 #include "components/ntp_snippets/category_status.h" 24 #include "components/ntp_snippets/category_status.h"
25 #include "components/ntp_snippets/content_suggestions_provider.h" 25 #include "components/ntp_snippets/content_suggestions_provider.h"
26 #include "components/ntp_snippets/section_rankers/section_ranker.h"
26 #include "components/ntp_snippets/user_classifier.h" 27 #include "components/ntp_snippets/user_classifier.h"
27 #include "components/signin/core/browser/signin_manager.h" 28 #include "components/signin/core/browser/signin_manager.h"
28 29
29 class PrefService; 30 class PrefService;
30 class PrefRegistrySimple; 31 class PrefRegistrySimple;
31 32
32 namespace ntp_snippets { 33 namespace ntp_snippets {
33 34
34 class RemoteSuggestionsProvider; 35 class RemoteSuggestionsProvider;
35 36
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 }; 82 };
82 83
83 enum State { 84 enum State {
84 ENABLED, 85 ENABLED,
85 DISABLED, 86 DISABLED,
86 }; 87 };
87 88
88 ContentSuggestionsService(State state, 89 ContentSuggestionsService(State state,
89 SigninManagerBase* signin_manager, 90 SigninManagerBase* signin_manager,
90 history::HistoryService* history_service, 91 history::HistoryService* history_service,
91 PrefService* pref_service); 92 PrefService* pref_service,
93 std::unique_ptr<SectionRanker> section_ranker);
92 ~ContentSuggestionsService() override; 94 ~ContentSuggestionsService() override;
93 95
94 // Inherited from KeyedService. 96 // Inherited from KeyedService.
95 void Shutdown() override; 97 void Shutdown() override;
96 98
97 static void RegisterProfilePrefs(PrefRegistrySimple* registry); 99 static void RegisterProfilePrefs(PrefRegistrySimple* registry);
98 100
99 State state() { return state_; } 101 State state() { return state_; }
100 102
101 // Gets all categories for which a provider is registered. The categories 103 // Gets all categories for which a provider is registered. The categories
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 Category category, 186 Category category,
185 const DismissedSuggestionsCallback& callback); 187 const DismissedSuggestionsCallback& callback);
186 188
187 // Only for debugging use through the internals page. Some providers 189 // Only for debugging use through the internals page. Some providers
188 // internally store a list of dismissed suggestions to prevent them from 190 // internally store a list of dismissed suggestions to prevent them from
189 // reappearing. This function clears all suggestions of the given |category| 191 // reappearing. This function clears all suggestions of the given |category|
190 // from such lists, making dismissed suggestions reappear (if the provider 192 // from such lists, making dismissed suggestions reappear (if the provider
191 // supports it). 193 // supports it).
192 void ClearDismissedSuggestionsForDebugging(Category category); 194 void ClearDismissedSuggestionsForDebugging(Category category);
193 195
194 CategoryFactory* category_factory() { return &category_factory_; }
195
196 // The reference to the RemoteSuggestionsProvider provider should only be set 196 // The reference to the RemoteSuggestionsProvider provider should only be set
197 // by the factory and only be used for scheduling, periodic fetching and 197 // by the factory and only be used for scheduling, periodic fetching and
198 // debugging. 198 // debugging.
199 RemoteSuggestionsProvider* ntp_snippets_service() { 199 RemoteSuggestionsProvider* ntp_snippets_service() {
200 return ntp_snippets_service_; 200 return ntp_snippets_service_;
201 } 201 }
202 void set_ntp_snippets_service( 202 void set_ntp_snippets_service(
203 RemoteSuggestionsProvider* ntp_snippets_service) { 203 RemoteSuggestionsProvider* ntp_snippets_service) {
204 ntp_snippets_service_ = ntp_snippets_service; 204 ntp_snippets_service_ = ntp_snippets_service;
205 } 205 }
206 206
207 UserClassifier* user_classifier() { return &user_classifier_; } 207 UserClassifier* user_classifier() { return &user_classifier_; }
208 SectionRanker* section_ranker() { return section_ranker_.get(); }
208 209
209 private: 210 private:
210 friend class ContentSuggestionsServiceTest; 211 friend class ContentSuggestionsServiceTest;
211 212
212 // Implementation of ContentSuggestionsProvider::Observer. 213 // Implementation of ContentSuggestionsProvider::Observer.
213 void OnNewSuggestions(ContentSuggestionsProvider* provider, 214 void OnNewSuggestions(ContentSuggestionsProvider* provider,
214 Category category, 215 Category category,
215 std::vector<ContentSuggestion> suggestions) override; 216 std::vector<ContentSuggestion> suggestions) override;
216 void OnCategoryStatusChanged(ContentSuggestionsProvider* provider, 217 void OnCategoryStatusChanged(ContentSuggestionsProvider* provider,
217 Category category, 218 Category category,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 260
260 // Re-enables a dismissed category, making querying its provider possible. 261 // Re-enables a dismissed category, making querying its provider possible.
261 void RestoreDismissedCategory(Category category); 262 void RestoreDismissedCategory(Category category);
262 263
263 void RestoreDismissedCategoriesFromPrefs(); 264 void RestoreDismissedCategoriesFromPrefs();
264 void StoreDismissedCategoriesToPrefs(); 265 void StoreDismissedCategoriesToPrefs();
265 266
266 // Whether the content suggestions feature is enabled. 267 // Whether the content suggestions feature is enabled.
267 State state_; 268 State state_;
268 269
269 // Provides new and existing categories and an order for them.
270 CategoryFactory category_factory_;
271
272 // All registered providers, owned by the service. 270 // All registered providers, owned by the service.
273 std::vector<std::unique_ptr<ContentSuggestionsProvider>> providers_; 271 std::vector<std::unique_ptr<ContentSuggestionsProvider>> providers_;
274 272
275 // All registered categories and their providers. A provider may be contained 273 // All registered categories and their providers. A provider may be contained
276 // multiple times, if it provides multiple categories. The keys of this map 274 // multiple times, if it provides multiple categories. The keys of this map
277 // are exactly the entries of |categories_| and the values are a subset of 275 // are exactly the entries of |categories_| and the values are a subset of
278 // |providers_|. 276 // |providers_|.
279 std::map<Category, ContentSuggestionsProvider*, Category::CompareByID> 277 std::map<Category, ContentSuggestionsProvider*, Category::CompareByID>
280 providers_by_category_; 278 providers_by_category_;
281 279
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 // Keep a direct reference to this special provider to redirect scheduling, 313 // Keep a direct reference to this special provider to redirect scheduling,
316 // background fetching and debugging calls to it. If the 314 // background fetching and debugging calls to it. If the
317 // RemoteSuggestionsProvider is loaded, it is also present in |providers_|, 315 // RemoteSuggestionsProvider is loaded, it is also present in |providers_|,
318 // otherwise this is a nullptr. 316 // otherwise this is a nullptr.
319 RemoteSuggestionsProvider* ntp_snippets_service_; 317 RemoteSuggestionsProvider* ntp_snippets_service_;
320 318
321 PrefService* pref_service_; 319 PrefService* pref_service_;
322 320
323 UserClassifier user_classifier_; 321 UserClassifier user_classifier_;
324 322
323 // Probider order for categories.
Marc Treib 2016/12/13 12:22:42 s/Probider/Provides/ ?
vitaliii 2016/12/14 08:59:38 Done.
324 std::unique_ptr<SectionRanker> section_ranker_;
325
325 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService); 326 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService);
326 }; 327 };
327 328
328 } // namespace ntp_snippets 329 } // namespace ntp_snippets
329 330
330 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ 331 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698