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

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

Issue 2051823003: [NTP Snippets] More reliable service initialization (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « no previous file | components/ntp_snippets/ntp_snippets_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 // that case the service will stay disabled until it is shut 170 // that case the service will stay disabled until it is shut
171 // down. It can also enter this state after the database is 171 // down. It can also enter this state after the database is
172 // done loading and GetStateForDependenciesStatus identifies 172 // done loading and GetStateForDependenciesStatus identifies
173 // the next state to be DISABLED. 173 // the next state to be DISABLED.
174 // - READY: if GetStateForDependenciesStatus returns it, after the database 174 // - READY: if GetStateForDependenciesStatus returns it, after the database
175 // is done loading. 175 // is done loading.
176 NOT_INITED, 176 NOT_INITED,
177 177
178 // The service registered observers, timers, etc. and is ready to answer to 178 // The service registered observers, timers, etc. and is ready to answer to
179 // queries, fetch snippets... Can change to states: 179 // queries, fetch snippets... Can change to states:
180 // - READY: noop
dgn 2016/06/09 15:12:14 removed since now same-state transitions are gener
181 // - DISABLED: when the global Chrome state changes, for example after 180 // - DISABLED: when the global Chrome state changes, for example after
182 // |OnStateChanged| is called and sync is disabled. 181 // |OnStateChanged| is called and sync is disabled.
183 // - SHUT_DOWN: when |Shutdown| is called, during the browser shutdown. 182 // - SHUT_DOWN: when |Shutdown| is called, during the browser shutdown.
184 READY, 183 READY,
185 184
186 // The service is disabled and unregistered the related resources. 185 // The service is disabled and unregistered the related resources.
187 // Can change to states: 186 // Can change to states:
188 // - DISABLED: noop
189 // - READY: when the global Chrome state changes, for example after 187 // - READY: when the global Chrome state changes, for example after
190 // |OnStateChanged| is called and sync is enabled. 188 // |OnStateChanged| is called and sync is enabled.
191 // - SHUT_DOWN: when |Shutdown| is called, during the browser shutdown. 189 // - SHUT_DOWN: when |Shutdown| is called, during the browser shutdown.
192 DISABLED, 190 DISABLED,
193 191
194 // The service shutdown and can't be used anymore. This state is checked 192 // The service shutdown and can't be used anymore. This state is checked
195 // for early exit in callbacks from observers. 193 // for early exit in callbacks from observers.
196 SHUT_DOWN 194 SHUT_DOWN
197 }; 195 };
198 196
199 // sync_driver::SyncServiceObserver implementation. 197 // sync_driver::SyncServiceObserver implementation.
200 void OnStateChanged() override; 198 void OnStateChanged() override;
201 199
202 // Callback for the NTPSnippetsDatabase. 200 // Callback for the NTPSnippetsDatabase.
203 void OnDatabaseLoaded(NTPSnippet::PtrVector snippets); 201 void OnDatabaseLoaded(NTPSnippet::PtrVector snippets);
204 202
205 // Callback for the SuggestionsService. 203 // Callback for the SuggestionsService.
206 void OnSuggestionsChanged(const suggestions::SuggestionsProfile& suggestions); 204 void OnSuggestionsChanged(const suggestions::SuggestionsProfile& suggestions);
207 205
208 // Callback for the NTPSnippetsFetcher. 206 // Callback for the NTPSnippetsFetcher.
209 void OnFetchFinished(NTPSnippetsFetcher::OptionalSnippets snippets); 207 void OnFetchFinished(NTPSnippetsFetcher::OptionalSnippets snippets);
210 208
211 // Merges newly available snippets with the previously available list. 209 // Merges newly available snippets with the previously available list.
212 void MergeSnippets(NTPSnippet::PtrVector new_snippets); 210 void MergeSnippets(NTPSnippet::PtrVector new_snippets);
213 211
214 std::set<std::string> GetSnippetHostsFromPrefs() const; 212 std::set<std::string> GetSnippetHostsFromPrefs() const;
215 void StoreSnippetHostsToPrefs(const std::set<std::string>& hosts); 213 void StoreSnippetHostsToPrefs(const std::set<std::string>& hosts);
216 214
215 // Removes the expired snippets (including discarded) from the service and the
216 // database, and schedules another pass for the next expiration.
217 void ClearExpiredSnippets();
218
219 // Completes the initialization phase of the service, registering the last
220 // observers. This is done after construction, once the database is loaded.
221 void FinishInitialization();
222
217 void LoadingSnippetsFinished(); 223 void LoadingSnippetsFinished();
218 224
219 // Returns whether the service should be enabled or disable depending on its 225 // Returns whether the service should be enabled or disable depending on its
220 // internal state and the state of its dependencies. 226 // internal state and the state of its dependencies.
221 State GetStateForDependenciesStatus(); 227 State GetStateForDependenciesStatus();
222 228
223 // Verifies state transitions (see |State|'s documentation) and applies them. 229 // Verifies state transitions (see |State|'s documentation) and applies them.
230 // Does nothing if called with the current state.
224 void EnterState(State state); 231 void EnterState(State state);
225 232
226 // Enables the service and triggers a fetch if required. Do not call directly, 233 // Enables the service and triggers a fetch if required. Do not call directly,
227 // use |EnterState| instead. 234 // use |EnterState| instead.
228 void EnterStateEnabled(bool fetch_snippets); 235 void EnterStateEnabled(bool fetch_snippets);
229 236
230 // Disables the service. Do not call directly, use |EnterState| instead. 237 // Disables the service. Do not call directly, use |EnterState| instead.
231 void EnterStateDisabled(); 238 void EnterStateDisabled();
232 239
233 // Applies the effects of the transition to the SHUT_DOWN state. Do not call 240 // Applies the effects of the transition to the SHUT_DOWN state. Do not call
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 // or because a requirement (e.g. History Sync) is not fulfilled anymore. 313 // or because a requirement (e.g. History Sync) is not fulfilled anymore.
307 virtual void NTPSnippetsServiceDisabled() = 0; 314 virtual void NTPSnippetsServiceDisabled() = 0;
308 315
309 protected: 316 protected:
310 virtual ~NTPSnippetsServiceObserver() {} 317 virtual ~NTPSnippetsServiceObserver() {}
311 }; 318 };
312 319
313 } // namespace ntp_snippets 320 } // namespace ntp_snippets
314 321
315 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_ 322 #endif // COMPONENTS_NTP_SNIPPETS_NTP_SNIPPETS_SERVICE_H_
OLDNEW
« no previous file with comments | « no previous file | components/ntp_snippets/ntp_snippets_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698