| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 public sync_driver::SyncServiceObserver { | 57 public sync_driver::SyncServiceObserver { |
| 58 public: | 58 public: |
| 59 using ImageFetchedCallback = | 59 using ImageFetchedCallback = |
| 60 base::Callback<void(const std::string& snippet_id, const gfx::Image&)>; | 60 base::Callback<void(const std::string& snippet_id, const gfx::Image&)>; |
| 61 | 61 |
| 62 // |application_language_code| should be a ISO 639-1 compliant string, e.g. | 62 // |application_language_code| should be a ISO 639-1 compliant string, e.g. |
| 63 // 'en' or 'en-US'. Note that this code should only specify the language, not | 63 // 'en' or 'en-US'. Note that this code should only specify the language, not |
| 64 // the locale, so 'en_US' (English language with US locale) and 'en-GB_US' | 64 // the locale, so 'en_US' (English language with US locale) and 'en-GB_US' |
| 65 // (British English person in the US) are not language codes. | 65 // (British English person in the US) are not language codes. |
| 66 NTPSnippetsService( | 66 NTPSnippetsService( |
| 67 bool enabled, |
| 67 PrefService* pref_service, | 68 PrefService* pref_service, |
| 68 sync_driver::SyncService* sync_service, | 69 sync_driver::SyncService* sync_service, |
| 69 suggestions::SuggestionsService* suggestions_service, | 70 suggestions::SuggestionsService* suggestions_service, |
| 70 scoped_refptr<base::SequencedTaskRunner> file_task_runner, | 71 scoped_refptr<base::SequencedTaskRunner> file_task_runner, |
| 71 const std::string& application_language_code, | 72 const std::string& application_language_code, |
| 72 NTPSnippetsScheduler* scheduler, | 73 NTPSnippetsScheduler* scheduler, |
| 73 std::unique_ptr<NTPSnippetsFetcher> snippets_fetcher, | 74 std::unique_ptr<NTPSnippetsFetcher> snippets_fetcher, |
| 74 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher); | 75 std::unique_ptr<image_fetcher::ImageFetcher> image_fetcher); |
| 75 ~NTPSnippetsService() override; | 76 ~NTPSnippetsService() override; |
| 76 | 77 |
| 77 static void RegisterProfilePrefs(PrefRegistrySimple* registry); | 78 static void RegisterProfilePrefs(PrefRegistrySimple* registry); |
| 78 | 79 |
| 79 void Init(bool enabled); | |
| 80 | |
| 81 // Inherited from KeyedService. | 80 // Inherited from KeyedService. |
| 82 void Shutdown() override; | 81 void Shutdown() override; |
| 83 | 82 |
| 84 // Fetches snippets from the server and adds them to the current ones. | 83 // Fetches snippets from the server and adds them to the current ones. |
| 85 void FetchSnippets(); | 84 void FetchSnippets(); |
| 86 // Fetches snippets from the server for specified hosts (overriding | 85 // Fetches snippets from the server for specified hosts (overriding |
| 87 // suggestions from the suggestion service) and adds them to the current ones. | 86 // suggestions from the suggestion service) and adds them to the current ones. |
| 88 void FetchSnippetsFromHosts(const std::set<std::string>& hosts); | 87 void FetchSnippetsFromHosts(const std::set<std::string>& hosts); |
| 89 | 88 |
| 90 // Available snippets. | 89 // Available snippets. |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 // Note: The state is considered compatible if the service is still | 160 // Note: The state is considered compatible if the service is still |
| 162 // initializing and the sync state is not known. | 161 // initializing and the sync state is not known. |
| 163 bool IsSyncStateIncompatible(); | 162 bool IsSyncStateIncompatible(); |
| 164 | 163 |
| 165 enum class State { | 164 enum class State { |
| 166 NOT_INITED, | 165 NOT_INITED, |
| 167 INITED, | 166 INITED, |
| 168 SHUT_DOWN | 167 SHUT_DOWN |
| 169 } state_; | 168 } state_; |
| 170 | 169 |
| 170 // When |enabled_| is true the service will fetch snippets from the server |
| 171 // using |snippets_fetcher_|, load snippets from device storage, and schedule |
| 172 // the |scheduler_|. |
| 171 bool enabled_; | 173 bool enabled_; |
| 172 | 174 |
| 173 PrefService* pref_service_; | 175 PrefService* pref_service_; |
| 174 | 176 |
| 175 sync_driver::SyncService* sync_service_; | 177 sync_driver::SyncService* sync_service_; |
| 176 | 178 |
| 177 // The observer for the SyncService. When the sync state changes, | 179 // The observer for the SyncService. When the sync state changes, |
| 178 // SyncService will call |OnStateChanged|, which is propagated to the | 180 // SyncService will call |OnStateChanged|, which is propagated to the |
| 179 // snippet observers. | 181 // snippet observers. |
| 180 ScopedObserver<sync_driver::SyncService, sync_driver::SyncServiceObserver> | 182 ScopedObserver<sync_driver::SyncService, sync_driver::SyncServiceObserver> |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 // or because a requirement (e.g. History Sync) is not fulfilled anymore. | 231 // or because a requirement (e.g. History Sync) is not fulfilled anymore. |
| 230 virtual void NTPSnippetsServiceDisabled() = 0; | 232 virtual void NTPSnippetsServiceDisabled() = 0; |
| 231 | 233 |
| 232 protected: | 234 protected: |
| 233 virtual ~NTPSnippetsServiceObserver() {} | 235 virtual ~NTPSnippetsServiceObserver() {} |
| 234 }; | 236 }; |
| 235 | 237 |
| 236 } // namespace ntp_snippets | 238 } // namespace ntp_snippets |
| 237 | 239 |
| 238 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ | 240 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ |
| OLD | NEW |