Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Side by Side Diff: components/ntp_snippets/ntp_snippets_service.h

Issue 1997473004: Snippets are enabled when search suggestions are enabled. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Set shutdown_ Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 void StoreSnippetHostsToPrefs(const std::set<std::string>& hosts); 154 void StoreSnippetHostsToPrefs(const std::set<std::string>& hosts);
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 // Whether Shutdown has been called.
dgn 2016/05/24 16:38:35 treib@ is adding a LOADED state, and I'm adding a
Marc Treib 2016/05/24 16:55:24 +1 :)
Michael van Ouwerkerk 2016/05/24 16:58:09 Done.
166 NOT_INITED, 165 bool shutdown_;
167 INITED,
168 SHUT_DOWN
169 } state_;
170 166
167 // When |enabled_| is true the service will fetch snippets from the server
168 // using |snippets_fetcher_|, load snippets from device storage, and schedule
169 // the |scheduler_|.
171 bool enabled_; 170 bool enabled_;
172 171
173 PrefService* pref_service_; 172 PrefService* pref_service_;
174 173
175 sync_driver::SyncService* sync_service_; 174 sync_driver::SyncService* sync_service_;
176 175
177 // The observer for the SyncService. When the sync state changes, 176 // The observer for the SyncService. When the sync state changes,
178 // SyncService will call |OnStateChanged|, which is propagated to the 177 // SyncService will call |OnStateChanged|, which is propagated to the
179 // snippet observers. 178 // snippet observers.
180 ScopedObserver<sync_driver::SyncService, sync_driver::SyncServiceObserver> 179 ScopedObserver<sync_driver::SyncService, sync_driver::SyncServiceObserver>
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 // or because a requirement (e.g. History Sync) is not fulfilled anymore. 228 // or because a requirement (e.g. History Sync) is not fulfilled anymore.
230 virtual void NTPSnippetsServiceDisabled() = 0; 229 virtual void NTPSnippetsServiceDisabled() = 0;
231 230
232 protected: 231 protected:
233 virtual ~NTPSnippetsServiceObserver() {} 232 virtual ~NTPSnippetsServiceObserver() {}
234 }; 233 };
235 234
236 } // namespace ntp_snippets 235 } // namespace ntp_snippets
237 236
238 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ 237 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698