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> | |
Marc Treib
2016/09/07 13:23:48
Is this required?
jkrcal
2016/09/07 14:19:07
Not for the changes I did. Still, std::set is used
| |
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" | |
24 | 26 |
25 namespace gfx { | 27 namespace gfx { |
26 class Image; | 28 class Image; |
27 } | 29 } |
28 | 30 |
29 namespace ntp_snippets { | 31 namespace ntp_snippets { |
30 | 32 |
31 class NTPSnippetsService; | 33 class NTPSnippetsService; |
32 | 34 |
33 // Retrieves suggestions from a number of ContentSuggestionsProviders and serves | 35 // Retrieves suggestions from a number of ContentSuggestionsProviders and serves |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 protected: | 76 protected: |
75 virtual ~Observer() {} | 77 virtual ~Observer() {} |
76 }; | 78 }; |
77 | 79 |
78 enum State { | 80 enum State { |
79 ENABLED, | 81 ENABLED, |
80 DISABLED, | 82 DISABLED, |
81 }; | 83 }; |
82 | 84 |
83 ContentSuggestionsService(State state, | 85 ContentSuggestionsService(State state, |
84 history::HistoryService* history_service); | 86 history::HistoryService* history_service, |
87 PrefService* pref_service); | |
Marc Treib
2016/09/07 13:23:48
Forward-declare PrefService
jkrcal
2016/09/07 14:19:07
Done.
| |
85 ~ContentSuggestionsService() override; | 88 ~ContentSuggestionsService() override; |
86 | 89 |
87 // Inherited from KeyedService. | 90 // Inherited from KeyedService. |
88 void Shutdown() override; | 91 void Shutdown() override; |
89 | 92 |
90 State state() { return state_; } | 93 State state() { return state_; } |
91 | 94 |
92 // Gets all categories for which a provider is registered. The categories | 95 // Gets all categories for which a provider is registered. The categories |
93 // may or may not be available, see |GetCategoryStatus()|. | 96 // may or may not be available, see |GetCategoryStatus()|. |
94 const std::vector<Category>& GetCategories() const { return categories_; } | 97 const std::vector<Category>& GetCategories() const { return categories_; } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 | 168 |
166 CategoryFactory* category_factory() { return &category_factory_; } | 169 CategoryFactory* category_factory() { return &category_factory_; } |
167 | 170 |
168 // The reference to the NTPSnippetsService provider should only be set by the | 171 // The reference to the NTPSnippetsService provider should only be set by the |
169 // factory and only be used for scheduling, periodic fetching and debugging. | 172 // factory and only be used for scheduling, periodic fetching and debugging. |
170 NTPSnippetsService* ntp_snippets_service() { return ntp_snippets_service_; } | 173 NTPSnippetsService* ntp_snippets_service() { return ntp_snippets_service_; } |
171 void set_ntp_snippets_service(NTPSnippetsService* ntp_snippets_service) { | 174 void set_ntp_snippets_service(NTPSnippetsService* ntp_snippets_service) { |
172 ntp_snippets_service_ = ntp_snippets_service; | 175 ntp_snippets_service_ = ntp_snippets_service; |
173 } | 176 } |
174 | 177 |
178 UserClassifier* user_classifier() { return &user_classifier_;} | |
179 | |
175 private: | 180 private: |
176 friend class ContentSuggestionsServiceTest; | 181 friend class ContentSuggestionsServiceTest; |
177 | 182 |
178 // Implementation of ContentSuggestionsProvider::Observer. | 183 // Implementation of ContentSuggestionsProvider::Observer. |
179 void OnNewSuggestions(ContentSuggestionsProvider* provider, | 184 void OnNewSuggestions(ContentSuggestionsProvider* provider, |
180 Category category, | 185 Category category, |
181 std::vector<ContentSuggestion> suggestions) override; | 186 std::vector<ContentSuggestion> suggestions) override; |
182 void OnCategoryStatusChanged(ContentSuggestionsProvider* provider, | 187 void OnCategoryStatusChanged(ContentSuggestionsProvider* provider, |
183 Category category, | 188 Category category, |
184 CategoryStatus new_status) override; | 189 CategoryStatus new_status) override; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 | 257 |
253 base::ObserverList<Observer> observers_; | 258 base::ObserverList<Observer> observers_; |
254 | 259 |
255 const std::vector<ContentSuggestion> no_suggestions_; | 260 const std::vector<ContentSuggestion> no_suggestions_; |
256 | 261 |
257 // Keep a direct reference to this special provider to redirect scheduling, | 262 // Keep a direct reference to this special provider to redirect scheduling, |
258 // background fetching and debugging calls to it. If the NTPSnippetsService is | 263 // background fetching and debugging calls to it. If the NTPSnippetsService is |
259 // loaded, it is also present in |providers_|, otherwise this is a nullptr. | 264 // loaded, it is also present in |providers_|, otherwise this is a nullptr. |
260 NTPSnippetsService* ntp_snippets_service_; | 265 NTPSnippetsService* ntp_snippets_service_; |
261 | 266 |
267 UserClassifier user_classifier_; | |
268 | |
262 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService); | 269 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService); |
263 }; | 270 }; |
264 | 271 |
265 } // namespace ntp_snippets | 272 } // namespace ntp_snippets |
266 | 273 |
267 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ | 274 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ |
OLD | NEW |