| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 155 |
| 157 void LoadingSnippetsFinished(); | 156 void LoadingSnippetsFinished(); |
| 158 | 157 |
| 159 // Checks whether the state of the sync service is incompatible with showing | 158 // Checks whether the state of the sync service is incompatible with showing |
| 160 // snippets. We need history sync to be active. | 159 // snippets. We need history sync to be active. |
| 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, | |
| 167 INITED, | 165 INITED, |
| 168 SHUT_DOWN | 166 SHUT_DOWN |
| 169 } state_; | 167 } state_; |
| 170 | 168 |
| 169 // When |enabled_| is true the service will fetch snippets from the server |
| 170 // using |snippets_fetcher_|, load snippets from device storage, and schedule |
| 171 // the |scheduler_|. |
| 171 bool enabled_; | 172 bool enabled_; |
| 172 | 173 |
| 173 PrefService* pref_service_; | 174 PrefService* pref_service_; |
| 174 | 175 |
| 175 sync_driver::SyncService* sync_service_; | 176 sync_driver::SyncService* sync_service_; |
| 176 | 177 |
| 177 // The observer for the SyncService. When the sync state changes, | 178 // The observer for the SyncService. When the sync state changes, |
| 178 // SyncService will call |OnStateChanged|, which is propagated to the | 179 // SyncService will call |OnStateChanged|, which is propagated to the |
| 179 // snippet observers. | 180 // snippet observers. |
| 180 ScopedObserver<sync_driver::SyncService, sync_driver::SyncServiceObserver> | 181 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. | 230 // or because a requirement (e.g. History Sync) is not fulfilled anymore. |
| 230 virtual void NTPSnippetsServiceDisabled() = 0; | 231 virtual void NTPSnippetsServiceDisabled() = 0; |
| 231 | 232 |
| 232 protected: | 233 protected: |
| 233 virtual ~NTPSnippetsServiceObserver() {} | 234 virtual ~NTPSnippetsServiceObserver() {} |
| 234 }; | 235 }; |
| 235 | 236 |
| 236 } // namespace ntp_snippets | 237 } // namespace ntp_snippets |
| 237 | 238 |
| 238 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ | 239 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ |
| OLD | NEW |