| 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 <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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 protected: | 79 protected: |
| 76 virtual ~Observer() {} | 80 virtual ~Observer() {} |
| 77 }; | 81 }; |
| 78 | 82 |
| 79 enum State { | 83 enum State { |
| 80 ENABLED, | 84 ENABLED, |
| 81 DISABLED, | 85 DISABLED, |
| 82 }; | 86 }; |
| 83 | 87 |
| 84 ContentSuggestionsService(State state, | 88 ContentSuggestionsService(State state, |
| 85 history::HistoryService* history_service); | 89 history::HistoryService* history_service, |
| 90 PrefService* pref_service); |
| 86 ~ContentSuggestionsService() override; | 91 ~ContentSuggestionsService() override; |
| 87 | 92 |
| 88 // Inherited from KeyedService. | 93 // Inherited from KeyedService. |
| 89 void Shutdown() override; | 94 void Shutdown() override; |
| 90 | 95 |
| 91 State state() { return state_; } | 96 State state() { return state_; } |
| 92 | 97 |
| 93 // Gets all categories for which a provider is registered. The categories | 98 // Gets all categories for which a provider is registered. The categories |
| 94 // may or may not be available, see |GetCategoryStatus()|. | 99 // may or may not be available, see |GetCategoryStatus()|. |
| 95 const std::vector<Category>& GetCategories() const { return categories_; } | 100 const std::vector<Category>& GetCategories() const { return categories_; } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 | 171 |
| 167 CategoryFactory* category_factory() { return &category_factory_; } | 172 CategoryFactory* category_factory() { return &category_factory_; } |
| 168 | 173 |
| 169 // The reference to the NTPSnippetsService provider should only be set by the | 174 // The reference to the NTPSnippetsService provider should only be set by the |
| 170 // factory and only be used for scheduling, periodic fetching and debugging. | 175 // factory and only be used for scheduling, periodic fetching and debugging. |
| 171 NTPSnippetsService* ntp_snippets_service() { return ntp_snippets_service_; } | 176 NTPSnippetsService* ntp_snippets_service() { return ntp_snippets_service_; } |
| 172 void set_ntp_snippets_service(NTPSnippetsService* ntp_snippets_service) { | 177 void set_ntp_snippets_service(NTPSnippetsService* ntp_snippets_service) { |
| 173 ntp_snippets_service_ = ntp_snippets_service; | 178 ntp_snippets_service_ = ntp_snippets_service; |
| 174 } | 179 } |
| 175 | 180 |
| 181 UserClassifier* user_classifier() { return &user_classifier_;} |
| 182 |
| 176 private: | 183 private: |
| 177 friend class ContentSuggestionsServiceTest; | 184 friend class ContentSuggestionsServiceTest; |
| 178 | 185 |
| 179 // Implementation of ContentSuggestionsProvider::Observer. | 186 // Implementation of ContentSuggestionsProvider::Observer. |
| 180 void OnNewSuggestions(ContentSuggestionsProvider* provider, | 187 void OnNewSuggestions(ContentSuggestionsProvider* provider, |
| 181 Category category, | 188 Category category, |
| 182 std::vector<ContentSuggestion> suggestions) override; | 189 std::vector<ContentSuggestion> suggestions) override; |
| 183 void OnCategoryStatusChanged(ContentSuggestionsProvider* provider, | 190 void OnCategoryStatusChanged(ContentSuggestionsProvider* provider, |
| 184 Category category, | 191 Category category, |
| 185 CategoryStatus new_status) override; | 192 CategoryStatus new_status) override; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 | 260 |
| 254 base::ObserverList<Observer> observers_; | 261 base::ObserverList<Observer> observers_; |
| 255 | 262 |
| 256 const std::vector<ContentSuggestion> no_suggestions_; | 263 const std::vector<ContentSuggestion> no_suggestions_; |
| 257 | 264 |
| 258 // Keep a direct reference to this special provider to redirect scheduling, | 265 // Keep a direct reference to this special provider to redirect scheduling, |
| 259 // background fetching and debugging calls to it. If the NTPSnippetsService is | 266 // background fetching and debugging calls to it. If the NTPSnippetsService is |
| 260 // loaded, it is also present in |providers_|, otherwise this is a nullptr. | 267 // loaded, it is also present in |providers_|, otherwise this is a nullptr. |
| 261 NTPSnippetsService* ntp_snippets_service_; | 268 NTPSnippetsService* ntp_snippets_service_; |
| 262 | 269 |
| 270 UserClassifier user_classifier_; |
| 271 |
| 263 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService); | 272 DISALLOW_COPY_AND_ASSIGN(ContentSuggestionsService); |
| 264 }; | 273 }; |
| 265 | 274 |
| 266 } // namespace ntp_snippets | 275 } // namespace ntp_snippets |
| 267 | 276 |
| 268 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ | 277 #endif // COMPONENTS_NTP_SNIPPETS_CONTENT_SUGGESTIONS_SERVICE_H_ |
| OLD | NEW |