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

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

Issue 2315273002: Measure usage metrics to prepare for adaptive fetching rates in M55 (Closed)
Patch Set: Bernhard's comments Created 4 years, 3 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 <string> 11 #include <string>
11 #include <vector> 12 #include <vector>
12 13
13 #include "base/callback_forward.h" 14 #include "base/callback_forward.h"
14 #include "base/observer_list.h" 15 #include "base/observer_list.h"
15 #include "base/optional.h" 16 #include "base/optional.h"
16 #include "base/scoped_observer.h" 17 #include "base/scoped_observer.h"
17 #include "base/time/time.h" 18 #include "base/time/time.h"
18 #include "components/history/core/browser/history_service.h" 19 #include "components/history/core/browser/history_service.h"
19 #include "components/history/core/browser/history_service_observer.h" 20 #include "components/history/core/browser/history_service_observer.h"
20 #include "components/keyed_service/core/keyed_service.h" 21 #include "components/keyed_service/core/keyed_service.h"
21 #include "components/ntp_snippets/category_factory.h" 22 #include "components/ntp_snippets/category_factory.h"
22 #include "components/ntp_snippets/category_status.h" 23 #include "components/ntp_snippets/category_status.h"
23 #include "components/ntp_snippets/content_suggestions_provider.h" 24 #include "components/ntp_snippets/content_suggestions_provider.h"
25 #include "components/ntp_snippets/user_classifier.h"
26
27 class PrefService;
24 28
25 namespace gfx { 29 namespace gfx {
26 class Image; 30 class Image;
27 } 31 }
28 32
29 namespace ntp_snippets { 33 namespace ntp_snippets {
30 34
31 class NTPSnippetsService; 35 class NTPSnippetsService;
32 36
33 // Retrieves suggestions from a number of ContentSuggestionsProviders and serves 37 // Retrieves suggestions from a number of ContentSuggestionsProviders and serves
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 protected: 78 protected:
75 virtual ~Observer() {} 79 virtual ~Observer() {}
76 }; 80 };
77 81
78 enum State { 82 enum State {
79 ENABLED, 83 ENABLED,
80 DISABLED, 84 DISABLED,
81 }; 85 };
82 86
83 ContentSuggestionsService(State state, 87 ContentSuggestionsService(State state,
84 history::HistoryService* history_service); 88 history::HistoryService* history_service,
89 PrefService* pref_service);
85 ~ContentSuggestionsService() override; 90 ~ContentSuggestionsService() override;
86 91
87 // Inherited from KeyedService. 92 // Inherited from KeyedService.
88 void Shutdown() override; 93 void Shutdown() override;
89 94
90 State state() { return state_; } 95 State state() { return state_; }
91 96
92 // Gets all categories for which a provider is registered. The categories 97 // Gets all categories for which a provider is registered. The categories
93 // may or may not be available, see |GetCategoryStatus()|. 98 // may or may not be available, see |GetCategoryStatus()|.
94 const std::vector<Category>& GetCategories() const { return categories_; } 99 const std::vector<Category>& GetCategories() const { return categories_; }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 170
166 CategoryFactory* category_factory() { return &category_factory_; } 171 CategoryFactory* category_factory() { return &category_factory_; }
167 172
168 // The reference to the NTPSnippetsService provider should only be set by the 173 // The reference to the NTPSnippetsService provider should only be set by the
169 // factory and only be used for scheduling, periodic fetching and debugging. 174 // factory and only be used for scheduling, periodic fetching and debugging.
170 NTPSnippetsService* ntp_snippets_service() { return ntp_snippets_service_; } 175 NTPSnippetsService* ntp_snippets_service() { return ntp_snippets_service_; }
171 void set_ntp_snippets_service(NTPSnippetsService* ntp_snippets_service) { 176 void set_ntp_snippets_service(NTPSnippetsService* ntp_snippets_service) {
172 ntp_snippets_service_ = ntp_snippets_service; 177 ntp_snippets_service_ = ntp_snippets_service;
173 } 178 }
174 179
180 UserClassifier* user_classifier() { return &user_classifier_;}
181
175 private: 182 private:
176 friend class ContentSuggestionsServiceTest; 183 friend class ContentSuggestionsServiceTest;
177 184
178 // Implementation of ContentSuggestionsProvider::Observer. 185 // Implementation of ContentSuggestionsProvider::Observer.
179 void OnNewSuggestions(ContentSuggestionsProvider* provider, 186 void OnNewSuggestions(ContentSuggestionsProvider* provider,
180 Category category, 187 Category category,
181 std::vector<ContentSuggestion> suggestions) override; 188 std::vector<ContentSuggestion> suggestions) override;
182 void OnCategoryStatusChanged(ContentSuggestionsProvider* provider, 189 void OnCategoryStatusChanged(ContentSuggestionsProvider* provider,
183 Category category, 190 Category category,
184 CategoryStatus new_status) override; 191 CategoryStatus new_status) override;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 259
253 base::ObserverList<Observer> observers_; 260 base::ObserverList<Observer> observers_;
254 261
255 const std::vector<ContentSuggestion> no_suggestions_; 262 const std::vector<ContentSuggestion> no_suggestions_;
256 263
257 // Keep a direct reference to this special provider to redirect scheduling, 264 // Keep a direct reference to this special provider to redirect scheduling,
258 // background fetching and debugging calls to it. If the NTPSnippetsService is 265 // background fetching and debugging calls to it. If the NTPSnippetsService is
259 // loaded, it is also present in |providers_|, otherwise this is a nullptr. 266 // loaded, it is also present in |providers_|, otherwise this is a nullptr.
260 NTPSnippetsService* ntp_snippets_service_; 267 NTPSnippetsService* ntp_snippets_service_;
261 268
269 UserClassifier user_classifier_;
270
262 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService); 271 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService);
263 }; 272 };
264 273
265 } // namespace ntp_snippets 274 } // namespace ntp_snippets
266 275
267 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ 276 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_
OLDNEW
« no previous file with comments | « components/ntp_snippets/BUILD.gn ('k') | components/ntp_snippets/content_suggestions_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698