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> |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 class NTPSnippetsDatabase; | 61 class NTPSnippetsDatabase; |
62 class NTPSnippetsServiceObserver; | 62 class NTPSnippetsServiceObserver; |
63 | 63 |
64 // Stores and vends fresh content data for the NTP. | 64 // Stores and vends fresh content data for the NTP. |
65 // TODO(pke): Rename this service to ArticleSuggestionsService and move to | 65 // TODO(pke): Rename this service to ArticleSuggestionsService and move to |
66 // a subdirectory. | 66 // a subdirectory. |
67 class NTPSnippetsService : public KeyedService, | 67 class NTPSnippetsService : public KeyedService, |
68 public image_fetcher::ImageFetcherDelegate, | 68 public image_fetcher::ImageFetcherDelegate, |
69 public ContentSuggestionsProvider { | 69 public ContentSuggestionsProvider { |
70 public: | 70 public: |
71 using ImageFetchedCallback = | |
72 base::Callback<void(const std::string& suggestion_id, const gfx::Image&)>; | |
73 | |
74 // |application_language_code| should be a ISO 639-1 compliant string, e.g. | 71 // |application_language_code| should be a ISO 639-1 compliant string, e.g. |
75 // 'en' or 'en-US'. Note that this code should only specify the language, not | 72 // 'en' or 'en-US'. Note that this code should only specify the language, not |
76 // the locale, so 'en_US' (English language with US locale) and 'en-GB_US' | 73 // the locale, so 'en_US' (English language with US locale) and 'en-GB_US' |
77 // (British English person in the US) are not language codes. | 74 // (British English person in the US) are not language codes. |
78 NTPSnippetsService(bool enabled, | 75 NTPSnippetsService(bool enabled, |
79 PrefService* pref_service, | 76 PrefService* pref_service, |
80 suggestions::SuggestionsService* suggestions_service, | 77 suggestions::SuggestionsService* suggestions_service, |
81 const std::string& application_language_code, | 78 const std::string& application_language_code, |
82 NTPSnippetsScheduler* scheduler, | 79 NTPSnippetsScheduler* scheduler, |
83 std::unique_ptr<NTPSnippetsFetcher> snippets_fetcher, | 80 std::unique_ptr<NTPSnippetsFetcher> snippets_fetcher, |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 | 230 |
234 void OnSnippetImageDecoded(const std::string& snippet_id, | 231 void OnSnippetImageDecoded(const std::string& snippet_id, |
235 const ImageFetchedCallback& callback, | 232 const ImageFetchedCallback& callback, |
236 const gfx::Image& image); | 233 const gfx::Image& image); |
237 | 234 |
238 void FetchSnippetImageFromNetwork(const std::string& snippet_id, | 235 void FetchSnippetImageFromNetwork(const std::string& snippet_id, |
239 const ImageFetchedCallback& callback); | 236 const ImageFetchedCallback& callback); |
240 | 237 |
241 // Triggers a state transition depending on the provided reason to be | 238 // Triggers a state transition depending on the provided reason to be |
242 // disabled (or lack thereof). This method is called when a change is detected | 239 // disabled (or lack thereof). This method is called when a change is detected |
243 // by |snippets_status_service_| | 240 // by |snippets_status_service_|. |
244 void UpdateStateForStatus(DisabledReason disabled_reason); | 241 void UpdateStateForStatus(DisabledReason disabled_reason); |
245 | 242 |
246 // Verifies state transitions (see |State|'s documentation) and applies them. | 243 // Verifies state transitions (see |State|'s documentation) and applies them. |
247 // Also updates the provider status. Does nothing except updating the provider | 244 // Also updates the provider status. Does nothing except updating the provider |
248 // status if called with the current state. | 245 // status if called with the current state. |
249 void EnterState(State state, ContentSuggestionsCategoryStatus status); | 246 void EnterState(State state, ContentSuggestionsCategoryStatus status); |
250 | 247 |
251 // Enables the service and triggers a fetch if required. Do not call directly, | 248 // Enables the service and triggers a fetch if required. Do not call directly, |
252 // use |EnterState| instead. | 249 // use |EnterState| instead. |
253 void EnterStateEnabled(bool fetch_snippets); | 250 void EnterStateEnabled(bool fetch_snippets); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 // If the service might be enabled, DisabledReason::NONE will be provided. | 336 // If the service might be enabled, DisabledReason::NONE will be provided. |
340 virtual void NTPSnippetsServiceDisabledReasonChanged(DisabledReason) = 0; | 337 virtual void NTPSnippetsServiceDisabledReasonChanged(DisabledReason) = 0; |
341 | 338 |
342 protected: | 339 protected: |
343 virtual ~NTPSnippetsServiceObserver() {} | 340 virtual ~NTPSnippetsServiceObserver() {} |
344 }; | 341 }; |
345 | 342 |
346 } // namespace ntp_snippets | 343 } // namespace ntp_snippets |
347 | 344 |
348 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ | 345 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ |
OLD | NEW |