OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_NTP_SNIPPETS_SERVICE_H_ | 5 #ifndef COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ |
6 #define COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ | 6 #define COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <set> | 11 #include <set> |
12 #include <string> | 12 #include <string> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/callback_forward.h" | 15 #include "base/callback_forward.h" |
16 #include "base/gtest_prod_util.h" | 16 #include "base/gtest_prod_util.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/observer_list.h" | 18 #include "base/observer_list.h" |
19 #include "base/timer/timer.h" | 19 #include "base/timer/timer.h" |
20 #include "components/image_fetcher/image_fetcher_delegate.h" | 20 #include "components/image_fetcher/image_fetcher_delegate.h" |
21 #include "components/keyed_service/core/keyed_service.h" | 21 #include "components/keyed_service/core/keyed_service.h" |
22 #include "components/ntp_snippets/content_suggestion.h" | 22 #include "components/ntp_snippets/content_suggestion.h" |
23 #include "components/ntp_snippets/content_suggestions_category.h" | 23 #include "components/ntp_snippets/content_suggestions_category.h" |
| 24 #include "components/ntp_snippets/content_suggestions_category_factory.h" |
24 #include "components/ntp_snippets/content_suggestions_category_status.h" | 25 #include "components/ntp_snippets/content_suggestions_category_status.h" |
25 #include "components/ntp_snippets/content_suggestions_provider.h" | 26 #include "components/ntp_snippets/content_suggestions_provider.h" |
26 #include "components/ntp_snippets/ntp_snippet.h" | 27 #include "components/ntp_snippets/ntp_snippet.h" |
27 #include "components/ntp_snippets/ntp_snippets_fetcher.h" | 28 #include "components/ntp_snippets/ntp_snippets_fetcher.h" |
28 #include "components/ntp_snippets/ntp_snippets_scheduler.h" | 29 #include "components/ntp_snippets/ntp_snippets_scheduler.h" |
29 #include "components/ntp_snippets/ntp_snippets_status_service.h" | 30 #include "components/ntp_snippets/ntp_snippets_status_service.h" |
30 #include "components/suggestions/suggestions_service.h" | 31 #include "components/suggestions/suggestions_service.h" |
31 #include "components/sync_driver/sync_service_observer.h" | 32 #include "components/sync_driver/sync_service_observer.h" |
32 | 33 |
33 class PrefRegistrySimple; | 34 class PrefRegistrySimple; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 public image_fetcher::ImageFetcherDelegate, | 70 public image_fetcher::ImageFetcherDelegate, |
70 public ContentSuggestionsProvider { | 71 public ContentSuggestionsProvider { |
71 public: | 72 public: |
72 // |application_language_code| should be a ISO 639-1 compliant string, e.g. | 73 // |application_language_code| should be a ISO 639-1 compliant string, e.g. |
73 // 'en' or 'en-US'. Note that this code should only specify the language, not | 74 // 'en' or 'en-US'. Note that this code should only specify the language, not |
74 // the locale, so 'en_US' (English language with US locale) and 'en-GB_US' | 75 // the locale, so 'en_US' (English language with US locale) and 'en-GB_US' |
75 // (British English person in the US) are not language codes. | 76 // (British English person in the US) are not language codes. |
76 NTPSnippetsService(bool enabled, | 77 NTPSnippetsService(bool enabled, |
77 PrefService* pref_service, | 78 PrefService* pref_service, |
78 suggestions::SuggestionsService* suggestions_service, | 79 suggestions::SuggestionsService* suggestions_service, |
| 80 ContentSuggestionsCategoryFactory* category_factory, |
79 const std::string& application_language_code, | 81 const std::string& application_language_code, |
80 NTPSnippetsScheduler* scheduler, | 82 NTPSnippetsScheduler* scheduler, |
81 std::unique_ptr<NTPSnippetsFetcher> snippets_fetcher, | 83 std::unique_ptr<NTPSnippetsFetcher> snippets_fetcher, |
82 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher, | 84 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher, |
83 std::unique_ptr<image_fetcher::ImageDecoder> image_decoder, | 85 std::unique_ptr<image_fetcher::ImageDecoder> image_decoder, |
84 std::unique_ptr<NTPSnippetsDatabase> database, | 86 std::unique_ptr<NTPSnippetsDatabase> database, |
85 std::unique_ptr<NTPSnippetsStatusService> status_service); | 87 std::unique_ptr<NTPSnippetsStatusService> status_service); |
86 | 88 |
87 ~NTPSnippetsService() override; | 89 ~NTPSnippetsService() override; |
88 | 90 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 return snippets_status_service_->disabled_reason(); | 134 return snippets_status_service_->disabled_reason(); |
133 } | 135 } |
134 | 136 |
135 // (Re)schedules the periodic fetching of snippets. This is necessary because | 137 // (Re)schedules the periodic fetching of snippets. This is necessary because |
136 // the schedule depends on the time of day. | 138 // the schedule depends on the time of day. |
137 void RescheduleFetching(); | 139 void RescheduleFetching(); |
138 | 140 |
139 // ContentSuggestionsProvider implementation | 141 // ContentSuggestionsProvider implementation |
140 // TODO(pke): At some point reorder the implementations in the .cc file | 142 // TODO(pke): At some point reorder the implementations in the .cc file |
141 // accordingly. | 143 // accordingly. |
| 144 std::vector<ContentSuggestionsCategory> GetProvidedCategories() override; |
142 void SetObserver(Observer* observer) override; | 145 void SetObserver(Observer* observer) override; |
143 ContentSuggestionsCategoryStatus GetCategoryStatus( | 146 ContentSuggestionsCategoryStatus GetCategoryStatus( |
144 ContentSuggestionsCategory category) override; | 147 ContentSuggestionsCategory category) override; |
145 void DismissSuggestion(const std::string& suggestion_id) override; | 148 void DismissSuggestion(const std::string& suggestion_id) override; |
146 void FetchSuggestionImage(const std::string& suggestion_id, | 149 void FetchSuggestionImage(const std::string& suggestion_id, |
147 const ImageFetchedCallback& callback) override; | 150 const ImageFetchedCallback& callback) override; |
148 void ClearCachedSuggestionsForDebugging() override; | 151 void ClearCachedSuggestionsForDebugging() override; |
149 void ClearDismissedSuggestionsForDebugging() override; | 152 void ClearDismissedSuggestionsForDebugging() override; |
150 | 153 |
151 // Returns the lists of suggestion hosts the snippets are restricted to. | 154 // Returns the lists of suggestion hosts the snippets are restricted to. |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 // The database for persisting snippets. | 319 // The database for persisting snippets. |
317 std::unique_ptr<NTPSnippetsDatabase> database_; | 320 std::unique_ptr<NTPSnippetsDatabase> database_; |
318 | 321 |
319 // The service that provides events and data about the signin and sync state. | 322 // The service that provides events and data about the signin and sync state. |
320 std::unique_ptr<NTPSnippetsStatusService> snippets_status_service_; | 323 std::unique_ptr<NTPSnippetsStatusService> snippets_status_service_; |
321 | 324 |
322 // Set to true if FetchSnippets is called before the database has been loaded. | 325 // Set to true if FetchSnippets is called before the database has been loaded. |
323 // The fetch will be executed after the database load finishes. | 326 // The fetch will be executed after the database load finishes. |
324 bool fetch_after_load_; | 327 bool fetch_after_load_; |
325 | 328 |
| 329 const ContentSuggestionsCategory provided_category_; |
| 330 |
326 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsService); | 331 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsService); |
327 }; | 332 }; |
328 | 333 |
329 // TODO(pke): Remove this when snippets internals don't access this service | 334 // TODO(pke): Remove this when snippets internals don't access this service |
330 // directly anymore. | 335 // directly anymore. |
331 class NTPSnippetsServiceObserver { | 336 class NTPSnippetsServiceObserver { |
332 public: | 337 public: |
333 // Sent every time the service loads a new set of data. | 338 // Sent every time the service loads a new set of data. |
334 virtual void NTPSnippetsServiceLoaded() = 0; | 339 virtual void NTPSnippetsServiceLoaded() = 0; |
335 | 340 |
336 // Sent when the service is shutting down. | 341 // Sent when the service is shutting down. |
337 virtual void NTPSnippetsServiceShutdown() = 0; | 342 virtual void NTPSnippetsServiceShutdown() = 0; |
338 | 343 |
339 // Sent when the state of the service is changing. Something changed in its | 344 // Sent when the state of the service is changing. Something changed in its |
340 // dependencies so it's notifying observers about incoming data changes. | 345 // dependencies so it's notifying observers about incoming data changes. |
341 // If the service might be enabled, DisabledReason::NONE will be provided. | 346 // If the service might be enabled, DisabledReason::NONE will be provided. |
342 virtual void NTPSnippetsServiceDisabledReasonChanged(DisabledReason) = 0; | 347 virtual void NTPSnippetsServiceDisabledReasonChanged(DisabledReason) = 0; |
343 | 348 |
344 protected: | 349 protected: |
345 virtual ~NTPSnippetsServiceObserver() {} | 350 virtual ~NTPSnippetsServiceObserver() {} |
346 }; | 351 }; |
347 | 352 |
348 } // namespace ntp_snippets | 353 } // namespace ntp_snippets |
349 | 354 |
350 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ | 355 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ |
OLD | NEW |