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

Side by Side Diff: chrome/browser/sync/glue/sync_backend_host.h

Issue 61183003: Refactor SyncBackendHost (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove double virtual Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ 5 #ifndef CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_
6 #define CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ 6 #define CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "base/threading/thread.h" 14 #include "base/threading/thread.h"
17 #include "chrome/browser/invalidation/invalidation_service.h"
18 #include "chrome/browser/sync/glue/backend_data_type_configurer.h" 15 #include "chrome/browser/sync/glue/backend_data_type_configurer.h"
19 #include "chrome/browser/sync/glue/extensions_activity_monitor.h"
20 #include "content/public/browser/notification_observer.h"
21 #include "content/public/browser/notification_registrar.h"
22 #include "google_apis/gaia/google_service_auth_error.h"
23 #include "sync/internal_api/public/base/model_type.h" 16 #include "sync/internal_api/public/base/model_type.h"
24 #include "sync/internal_api/public/configure_reason.h" 17 #include "sync/internal_api/public/configure_reason.h"
25 #include "sync/internal_api/public/engine/model_safe_worker.h"
26 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" 18 #include "sync/internal_api/public/sessions/sync_session_snapshot.h"
27 #include "sync/internal_api/public/sync_encryption_handler.h"
28 #include "sync/internal_api/public/sync_manager.h" 19 #include "sync/internal_api/public/sync_manager.h"
29 #include "sync/internal_api/public/util/report_unrecoverable_error_function.h" 20 #include "sync/internal_api/public/util/report_unrecoverable_error_function.h"
30 #include "sync/internal_api/public/util/unrecoverable_error_handler.h" 21 #include "sync/internal_api/public/util/unrecoverable_error_handler.h"
31 #include "sync/internal_api/public/util/weak_handle.h" 22 #include "sync/internal_api/public/util/weak_handle.h"
32 #include "sync/notifier/invalidation_handler.h"
33 #include "sync/protocol/encryption.pb.h"
34 #include "sync/protocol/sync_protocol_error.h"
35 #include "sync/util/extensions_activity.h"
36 #include "url/gurl.h"
37 23
38 class Profile; 24 class GURL;
39 25
40 namespace base { 26 namespace base {
41 class MessageLoop; 27 class MessageLoop;
42 } 28 }
43 29
44 namespace syncer { 30 namespace syncer {
45 class SyncManagerFactory; 31 class SyncManagerFactory;
46 } 32 }
47 33
48 namespace browser_sync { 34 namespace browser_sync {
49 35
50 class ChangeProcessor; 36 class ChangeProcessor;
51 class InvalidatorStorage; 37 class SyncFrontend;
52 class SyncBackendRegistrar;
53 class SyncPrefs;
54 class SyncedDeviceTracker; 38 class SyncedDeviceTracker;
55 struct Experiments;
56 39
57 // SyncFrontend is the interface used by SyncBackendHost to communicate with 40 // An API to "host" the top level syncapi element.
Nicolas Zea 2013/11/06 18:03:21 nit: syncapi -> SyncAPI Also , typically the inte
rlarocque 2013/11/06 21:48:47 Done.
58 // the entity that created it and, presumably, is interested in sync-related 41 //
59 // activity. 42 // See SyncBackendHostImpl for documentation.
60 // NOTE: All methods will be invoked by a SyncBackendHost on the same thread 43 class SyncBackendHost : public BackendDataTypeConfigurer {
61 // used to create that SyncBackendHost.
62 class SyncFrontend {
63 public:
64 SyncFrontend() {}
65
66 // The backend has completed initialization and it is now ready to
67 // accept and process changes. If success is false, initialization
68 // wasn't able to be completed and should be retried.
69 //
70 // |js_backend| is what about:sync interacts with; it's different
71 // from the 'Backend' in 'OnBackendInitialized' (unfortunately). It
72 // is initialized only if |success| is true.
73 virtual void OnBackendInitialized(
74 const syncer::WeakHandle<syncer::JsBackend>& js_backend,
75 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&
76 debug_info_listener,
77 bool success) = 0;
78
79 // The backend queried the server recently and received some updates.
80 virtual void OnSyncCycleCompleted() = 0;
81
82 // Configure ran into some kind of error. But it is scheduled to be
83 // retried.
84 virtual void OnSyncConfigureRetry() = 0;
85
86 // The status of the connection to the sync server has changed.
87 virtual void OnConnectionStatusChange(
88 syncer::ConnectionStatus status) = 0;
89
90 // We are no longer permitted to communicate with the server. Sync should
91 // be disabled and state cleaned up at once.
92 virtual void OnStopSyncingPermanently() = 0;
93
94 // The syncer requires a passphrase to decrypt sensitive updates. This is
95 // called when the first sensitive data type is setup by the user and anytime
96 // the passphrase is changed by another synced client. |reason| denotes why
97 // the passphrase was required. |pending_keys| is a copy of the
98 // cryptographer's pending keys to be passed on to the frontend in order to
99 // be cached.
100 virtual void OnPassphraseRequired(
101 syncer::PassphraseRequiredReason reason,
102 const sync_pb::EncryptedData& pending_keys) = 0;
103
104 // Called when the passphrase provided by the user is
105 // accepted. After this is called, updates to sensitive nodes are
106 // encrypted using the accepted passphrase.
107 virtual void OnPassphraseAccepted() = 0;
108
109 // Called when the set of encrypted types or the encrypt everything
110 // flag has been changed. Note that encryption isn't complete until
111 // the OnEncryptionComplete() notification has been sent (see
112 // below).
113 //
114 // |encrypted_types| will always be a superset of
115 // syncer::Cryptographer::SensitiveTypes(). If |encrypt_everything| is
116 // true, |encrypted_types| will be the set of all known types.
117 //
118 // Until this function is called, observers can assume that the set
119 // of encrypted types is syncer::Cryptographer::SensitiveTypes() and that
120 // the encrypt everything flag is false.
121 virtual void OnEncryptedTypesChanged(
122 syncer::ModelTypeSet encrypted_types,
123 bool encrypt_everything) = 0;
124
125 // Called after we finish encrypting the current set of encrypted
126 // types.
127 virtual void OnEncryptionComplete() = 0;
128
129 // Called to perform migration of |types|.
130 virtual void OnMigrationNeededForTypes(syncer::ModelTypeSet types) = 0;
131
132 // Inform the Frontend that new datatypes are available for registration.
133 virtual void OnExperimentsChanged(
134 const syncer::Experiments& experiments) = 0;
135
136 // Called when the sync cycle returns there is an user actionable error.
137 virtual void OnActionableError(const syncer::SyncProtocolError& error) = 0;
138
139 protected:
140 // Don't delete through SyncFrontend interface.
141 virtual ~SyncFrontend() {
142 }
143 private:
144 DISALLOW_COPY_AND_ASSIGN(SyncFrontend);
145 };
146
147 // A UI-thread safe API into the sync backend that "hosts" the top-level
148 // syncapi element, the SyncManager, on its own thread. This class handles
149 // dispatch of potentially blocking calls to appropriate threads and ensures
150 // that the SyncFrontend is only accessed on the UI loop.
151 class SyncBackendHost
152 : public BackendDataTypeConfigurer,
153 public content::NotificationObserver,
154 public syncer::InvalidationHandler {
155 public: 44 public:
156 typedef syncer::SyncStatus Status; 45 typedef syncer::SyncStatus Status;
157 46
158 // Create a SyncBackendHost with a reference to the |frontend| that 47 SyncBackendHost();
159 // it serves and communicates to via the SyncFrontend interface (on 48 virtual ~SyncBackendHost() = 0;
Nicolas Zea 2013/11/06 18:03:21 This shouldn't be purely virtual
rlarocque 2013/11/06 21:48:47 Why?
Nicolas Zea 2013/11/06 22:18:25 Because it's kind of confusing and against the sty
rlarocque 2013/11/06 22:48:47 OK. Fixed.
160 // the same thread it used to call the constructor). Must outlive
161 // |sync_prefs| and |invalidator_storage|.
162 SyncBackendHost(
163 const std::string& name,
164 Profile* profile,
165 const base::WeakPtr<SyncPrefs>& sync_prefs);
166 49
167 // For testing. 50 virtual void Initialize(
168 // TODO(skrul): Extract an interface so this is not needed.
169 explicit SyncBackendHost(Profile* profile);
170 virtual ~SyncBackendHost();
171
172 // Called on |frontend_loop_| to kick off asynchronous initialization.
173 // As a fallback when no cached auth information is available, try to
174 // bootstrap authentication using |lsid|, if it isn't empty.
175 // Optionally delete the Sync Data folder (if it's corrupt).
176 // |report_unrecoverable_error_function| can be NULL.
177 // Note: |unrecoverable_error_handler| may be invoked from any thread.
178 void Initialize(
179 SyncFrontend* frontend, 51 SyncFrontend* frontend,
180 scoped_ptr<base::Thread> sync_thread, 52 scoped_ptr<base::Thread> sync_thread,
181 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, 53 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler,
182 const GURL& service_url, 54 const GURL& service_url,
183 const syncer::SyncCredentials& credentials, 55 const syncer::SyncCredentials& credentials,
184 bool delete_sync_data_folder, 56 bool delete_sync_data_folder,
185 scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory, 57 scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory,
186 scoped_ptr<syncer::UnrecoverableErrorHandler> unrecoverable_error_handler, 58 scoped_ptr<syncer::UnrecoverableErrorHandler> unrecoverable_error_handler,
187 syncer::ReportUnrecoverableErrorFunction 59 syncer::ReportUnrecoverableErrorFunction
188 report_unrecoverable_error_function); 60 report_unrecoverable_error_function) = 0;
189 61
190 // Called on |frontend_loop| to update SyncCredentials. 62 virtual void UpdateCredentials(
191 virtual void UpdateCredentials(const syncer::SyncCredentials& credentials); 63 const syncer::SyncCredentials& credentials) = 0;
192 64
193 // This starts the SyncerThread running a Syncer object to communicate with 65 virtual void StartSyncingWithServer() = 0;
194 // sync servers. Until this is called, no changes will leave or enter this
195 // browser from the cloud / sync servers.
196 // Called on |frontend_loop_|.
197 virtual void StartSyncingWithServer();
198 66
199 // Called on |frontend_loop_| to asynchronously set a new passphrase for 67 virtual void SetEncryptionPassphrase(
200 // encryption. Note that it is an error to call SetEncryptionPassphrase under 68 const std::string& passphrase,
201 // the following circumstances: 69 bool is_explicit) = 0;
202 // - An explicit passphrase has already been set 70 virtual bool SetDecryptionPassphrase(const std::string& passphrase)
203 // - |is_explicit| is true and we have pending keys. 71 WARN_UNUSED_RESULT = 0;
204 // When |is_explicit| is false, a couple of things could happen:
205 // - If there are pending keys, we try to decrypt them. If decryption works,
206 // this acts like a call to SetDecryptionPassphrase. If not, the GAIA
207 // passphrase passed in is cached so we can re-encrypt with it in future.
208 // - If there are no pending keys, data is encrypted with |passphrase| (this
209 // is a no-op if data was already encrypted with |passphrase|.)
210 void SetEncryptionPassphrase(const std::string& passphrase, bool is_explicit);
211 72
212 // Called on |frontend_loop_| to use the provided passphrase to asynchronously 73 virtual void StopSyncingForShutdown() = 0;
213 // attempt decryption. Returns false immediately if the passphrase could not
214 // be used to decrypt a locally cached copy of encrypted keys; returns true
215 // otherwise. If new encrypted keys arrive during the asynchronous call,
216 // OnPassphraseRequired may be triggered at a later time. It is an error to
217 // call this when there are no pending keys.
218 bool SetDecryptionPassphrase(const std::string& passphrase)
219 WARN_UNUSED_RESULT;
220
221 // Called on |frontend_loop_| to kick off shutdown procedure. Attempts to cut
222 // short any long-lived or blocking sync thread tasks so that the shutdown on
223 // sync thread task that we're about to post won't have to wait very long.
224 virtual void StopSyncingForShutdown();
225
226 // Called on |frontend_loop_| to kick off shutdown.
227 // See the implementation and Core::DoShutdown for details.
228 // Must be called *after* StopSyncingForShutdown. Caller should claim sync
229 // thread using STOP_AND_CLAIM_THREAD or DISABLE_AND_CLAIM_THREAD if sync
230 // backend might be recreated later because otherwise:
231 // * sync loop may be stopped on main loop and cause it to be blocked.
232 // * new/old backend may interfere with each other if new backend is created
233 // before old one finishes cleanup.
234 enum ShutdownOption { 74 enum ShutdownOption {
235 STOP, // Stop syncing and let backend stop sync thread. 75 STOP, // Stop syncing and let backend stop sync thread.
236 STOP_AND_CLAIM_THREAD, // Stop syncing and return sync thread. 76 STOP_AND_CLAIM_THREAD, // Stop syncing and return sync thread.
237 DISABLE_AND_CLAIM_THREAD, // Disable sync and return sync thread. 77 DISABLE_AND_CLAIM_THREAD, // Disable sync and return sync thread.
238 }; 78 };
239 scoped_ptr<base::Thread> Shutdown(ShutdownOption option); 79 virtual scoped_ptr<base::Thread> Shutdown(ShutdownOption option) = 0;
240 80
241 // Removes all current registrations from the backend on the 81 virtual void UnregisterInvalidationIds() = 0;
242 // InvalidationService.
243 void UnregisterInvalidationIds();
244 82
245 // Changes the set of data types that are currently being synced.
246 // The ready_task will be run when configuration is done with the
247 // set of all types that failed configuration (i.e., if its argument
248 // is non-empty, then an error was encountered).
249 virtual void ConfigureDataTypes( 83 virtual void ConfigureDataTypes(
250 syncer::ConfigureReason reason, 84 syncer::ConfigureReason reason,
251 const DataTypeConfigStateMap& config_state_map, 85 const DataTypeConfigStateMap& config_state_map,
252 const base::Callback<void(syncer::ModelTypeSet, 86 const base::Callback<void(syncer::ModelTypeSet,
253 syncer::ModelTypeSet)>& ready_task, 87 syncer::ModelTypeSet)>& ready_task,
254 const base::Callback<void()>& retry_callback) OVERRIDE; 88 const base::Callback<void()>& retry_callback) OVERRIDE = 0;
255 89
256 // Turns on encryption of all present and future sync data. 90 virtual void EnableEncryptEverything() = 0;
257 virtual void EnableEncryptEverything();
258 91
259 // Activates change processing for the given data type. This must 92 virtual void ActivateDataType(
260 // be called synchronously with the data type's model association so
261 // no changes are dropped between model association and change
262 // processor activation.
263 void ActivateDataType(
264 syncer::ModelType type, syncer::ModelSafeGroup group, 93 syncer::ModelType type, syncer::ModelSafeGroup group,
265 ChangeProcessor* change_processor); 94 ChangeProcessor* change_processor) = 0;
95 virtual void DeactivateDataType(syncer::ModelType type) = 0;
266 96
267 // Deactivates change processing for the given data type. 97 virtual syncer::UserShare* GetUserShare() const = 0;
268 void DeactivateDataType(syncer::ModelType type);
269 98
270 // Called on |frontend_loop_| to obtain a handle to the UserShare needed for 99 virtual Status GetDetailedStatus() = 0;
271 // creating transactions. Should not be called before we signal 100 virtual syncer::sessions::SyncSessionSnapshot
272 // initialization is complete with OnBackendInitialized(). 101 GetLastSessionSnapshot() const = 0;
273 syncer::UserShare* GetUserShare() const;
274 102
275 // Called from any thread to obtain current status information in detailed or 103 virtual bool HasUnsyncedItems() const = 0;
276 // summarized form.
277 Status GetDetailedStatus();
278 syncer::sessions::SyncSessionSnapshot GetLastSessionSnapshot() const;
279 104
280 // Determines if the underlying sync engine has made any local changes to 105 virtual bool IsNigoriEnabled() const = 0;
281 // items that have not yet been synced with the server. 106 virtual syncer::PassphraseType GetPassphraseType() const = 0;
282 // ONLY CALL THIS IF OnInitializationComplete was called! 107 virtual base::Time GetExplicitPassphraseTime() const = 0;
283 bool HasUnsyncedItems() const; 108 virtual bool IsCryptographerReady(
109 const syncer::BaseTransaction* trans) const = 0;
284 110
285 // Whether or not we are syncing encryption keys. 111 virtual void GetModelSafeRoutingInfo(
286 bool IsNigoriEnabled() const; 112 syncer::ModelSafeRoutingInfo* out) const = 0;
287 113
288 // Returns the type of passphrase being used to encrypt data. See 114 virtual SyncedDeviceTracker* GetSyncedDeviceTracker() const = 0;
289 // sync_encryption_handler.h.
290 syncer::PassphraseType GetPassphraseType() const;
291 115
292 // If an explicit passphrase is in use, returns the time at which that 116 virtual base::MessageLoop* GetSyncLoopForTesting() = 0;
293 // passphrase was set (if available).
294 base::Time GetExplicitPassphraseTime() const;
295
296 // True if the cryptographer has any keys available to attempt decryption.
297 // Could mean we've downloaded and loaded Nigori objects, or we bootstrapped
298 // using a token previously received.
299 bool IsCryptographerReady(const syncer::BaseTransaction* trans) const;
300
301 void GetModelSafeRoutingInfo(syncer::ModelSafeRoutingInfo* out) const;
302
303 // Fetches the DeviceInfo tracker.
304 virtual SyncedDeviceTracker* GetSyncedDeviceTracker() const;
305
306 base::MessageLoop* GetSyncLoopForTesting();
307
308 protected:
309 // The types and functions below are protected so that test
310 // subclasses can use them.
311 //
312 // TODO(akalin): Figure out a better way for tests to hook into
313 // SyncBackendHost.
314
315 // Utility struct for holding initialization options.
316 struct DoInitializeOptions {
317 DoInitializeOptions(
318 base::MessageLoop* sync_loop,
319 SyncBackendRegistrar* registrar,
320 const syncer::ModelSafeRoutingInfo& routing_info,
321 const std::vector<syncer::ModelSafeWorker*>& workers,
322 const scoped_refptr<syncer::ExtensionsActivity>& extensions_activity,
323 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler,
324 const GURL& service_url,
325 scoped_ptr<syncer::HttpPostProviderFactory> http_bridge_factory,
326 const syncer::SyncCredentials& credentials,
327 const std::string& invalidator_client_id,
328 scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory,
329 bool delete_sync_data_folder,
330 const std::string& restored_key_for_bootstrapping,
331 const std::string& restored_keystore_key_for_bootstrapping,
332 scoped_ptr<syncer::InternalComponentsFactory>
333 internal_components_factory,
334 scoped_ptr<syncer::UnrecoverableErrorHandler>
335 unrecoverable_error_handler,
336 syncer::ReportUnrecoverableErrorFunction
337 report_unrecoverable_error_function);
338 ~DoInitializeOptions();
339
340 base::MessageLoop* sync_loop;
341 SyncBackendRegistrar* registrar;
342 syncer::ModelSafeRoutingInfo routing_info;
343 std::vector<syncer::ModelSafeWorker*> workers;
344 scoped_refptr<syncer::ExtensionsActivity> extensions_activity;
345 syncer::WeakHandle<syncer::JsEventHandler> event_handler;
346 GURL service_url;
347 // Overridden by tests.
348 scoped_ptr<syncer::HttpPostProviderFactory> http_bridge_factory;
349 syncer::SyncCredentials credentials;
350 const std::string invalidator_client_id;
351 scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory;
352 std::string lsid;
353 bool delete_sync_data_folder;
354 std::string restored_key_for_bootstrapping;
355 std::string restored_keystore_key_for_bootstrapping;
356 scoped_ptr<syncer::InternalComponentsFactory> internal_components_factory;
357 scoped_ptr<syncer::UnrecoverableErrorHandler> unrecoverable_error_handler;
358 syncer::ReportUnrecoverableErrorFunction
359 report_unrecoverable_error_function;
360 };
361
362 // Allows tests to perform alternate core initialization work.
363 virtual void InitCore(scoped_ptr<DoInitializeOptions> options);
364
365 // Request the syncer to reconfigure with the specfied params.
366 // Virtual for testing.
367 virtual void RequestConfigureSyncer(
368 syncer::ConfigureReason reason,
369 syncer::ModelTypeSet to_download,
370 syncer::ModelTypeSet to_purge,
371 syncer::ModelTypeSet to_journal,
372 syncer::ModelTypeSet to_unapply,
373 syncer::ModelTypeSet to_ignore,
374 const syncer::ModelSafeRoutingInfo& routing_info,
375 const base::Callback<void(syncer::ModelTypeSet,
376 syncer::ModelTypeSet)>& ready_task,
377 const base::Closure& retry_callback);
378
379 // Called when the syncer has finished performing a configuration.
380 void FinishConfigureDataTypesOnFrontendLoop(
381 const syncer::ModelTypeSet enabled_types,
382 const syncer::ModelTypeSet succeeded_configuration_types,
383 const syncer::ModelTypeSet failed_configuration_types,
384 const base::Callback<void(syncer::ModelTypeSet,
385 syncer::ModelTypeSet)>& ready_task);
386
387 // Reports backend initialization success. Includes some objects from sync
388 // manager initialization to be passed back to the UI thread.
389 virtual void HandleInitializationSuccessOnFrontendLoop(
390 const syncer::WeakHandle<syncer::JsBackend> js_backend,
391 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>
392 debug_info_listener);
393
394 // Downloading of control types failed and will be retried. Invokes the
395 // frontend's sync configure retry method.
396 void HandleControlTypesDownloadRetry();
397
398 SyncFrontend* frontend() { return frontend_; }
399
400 private:
401 // The real guts of SyncBackendHost, to keep the public client API clean.
402 class Core;
403
404 // An enum representing the steps to initializing the SyncBackendHost.
405 enum InitializationState {
406 NOT_ATTEMPTED,
407 CREATING_SYNC_MANAGER, // We're waiting for the first callback from the
408 // sync thread to inform us that the sync
409 // manager has been created.
410 NOT_INITIALIZED, // Initialization hasn't completed, but we've
411 // constructed a SyncManager.
412 INITIALIZATING_CONTROL_TYPES, // Downloading control types and
413 // initializing their handlers.
414 INITIALIZED, // Initialization is complete.
415 };
416
417 // Checks if we have received a notice to turn on experimental datatypes
418 // (via the nigori node) and informs the frontend if that is the case.
419 // Note: it is illegal to call this before the backend is initialized.
420 void AddExperimentalTypes();
421
422 // Handles backend initialization failure.
423 void HandleInitializationFailureOnFrontendLoop();
424
425 // Called from Core::OnSyncCycleCompleted to handle updating frontend
426 // thread components.
427 void HandleSyncCycleCompletedOnFrontendLoop(
428 const syncer::sessions::SyncSessionSnapshot& snapshot);
429
430 // Called when the syncer failed to perform a configuration and will
431 // eventually retry. FinishingConfigurationOnFrontendLoop(..) will be called
432 // on successful completion.
433 void RetryConfigurationOnFrontendLoop(const base::Closure& retry_callback);
434
435 // Helpers to persist a token that can be used to bootstrap sync encryption
436 // across browser restart to avoid requiring the user to re-enter their
437 // passphrase. |token| must be valid UTF-8 as we use the PrefService for
438 // storage.
439 void PersistEncryptionBootstrapToken(
440 const std::string& token,
441 syncer::BootstrapTokenType token_type);
442
443 // For convenience, checks if initialization state is INITIALIZED.
444 bool initialized() const { return initialized_; }
445
446 // Let the front end handle the actionable error event.
447 void HandleActionableErrorEventOnFrontendLoop(
448 const syncer::SyncProtocolError& sync_error);
449
450 // Checks if |passphrase| can be used to decrypt the cryptographer's pending
451 // keys that were cached during NotifyPassphraseRequired. Returns true if
452 // decryption was successful. Returns false otherwise. Must be called with a
453 // non-empty pending keys cache.
454 bool CheckPassphraseAgainstCachedPendingKeys(
455 const std::string& passphrase) const;
456
457 // Invoked when a passphrase is required to decrypt a set of Nigori keys,
458 // or for encrypting. |reason| denotes why the passphrase was required.
459 // |pending_keys| is a copy of the cryptographer's pending keys, that are
460 // cached by the frontend. If there are no pending keys, or if the passphrase
461 // required reason is REASON_ENCRYPTION, an empty EncryptedData object is
462 // passed.
463 void NotifyPassphraseRequired(syncer::PassphraseRequiredReason reason,
464 sync_pb::EncryptedData pending_keys);
465
466 // Invoked when the passphrase provided by the user has been accepted.
467 void NotifyPassphraseAccepted();
468
469 // Invoked when the set of encrypted types or the encrypt
470 // everything flag changes.
471 void NotifyEncryptedTypesChanged(
472 syncer::ModelTypeSet encrypted_types,
473 bool encrypt_everything);
474
475 // Invoked when sync finishes encrypting new datatypes.
476 void NotifyEncryptionComplete();
477
478 // Invoked when the passphrase state has changed. Caches the passphrase state
479 // for later use on the UI thread.
480 // If |type| is FROZEN_IMPLICIT_PASSPHRASE or CUSTOM_PASSPHRASE,
481 // |explicit_passphrase_time| is the time at which that passphrase was set
482 // (if available).
483 void HandlePassphraseTypeChangedOnFrontendLoop(
484 syncer::PassphraseType type,
485 base::Time explicit_passphrase_time);
486
487 void HandleStopSyncingPermanentlyOnFrontendLoop();
488
489 // Dispatched to from OnConnectionStatusChange to handle updating
490 // frontend UI components.
491 void HandleConnectionStatusChangeOnFrontendLoop(
492 syncer::ConnectionStatus status);
493
494 // syncer::InvalidationHandler-like functions.
495 void HandleInvalidatorStateChangeOnFrontendLoop(
496 syncer::InvalidatorState state);
497 void HandleIncomingInvalidationOnFrontendLoop(
498 const syncer::ObjectIdInvalidationMap& invalidation_map);
499
500 // NotificationObserver implementation.
501 virtual void Observe(
502 int type,
503 const content::NotificationSource& source,
504 const content::NotificationDetails& details) OVERRIDE;
505
506 // InvalidationHandler implementation.
507 virtual void OnInvalidatorStateChange(
508 syncer::InvalidatorState state) OVERRIDE;
509 virtual void OnIncomingInvalidation(
510 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE;
511
512 content::NotificationRegistrar notification_registrar_;
513
514 // A reference to the MessageLoop used to construct |this|, so we know how
515 // to safely talk back to the SyncFrontend.
516 base::MessageLoop* const frontend_loop_;
517
518 Profile* const profile_;
519
520 // Name used for debugging (set from profile_->GetDebugName()).
521 const std::string name_;
522
523 // Our core, which communicates directly to the syncapi. Use refptr instead
524 // of WeakHandle because |core_| is created on UI loop but released on
525 // sync loop.
526 scoped_refptr<Core> core_;
527
528 bool initialized_;
529
530 const base::WeakPtr<SyncPrefs> sync_prefs_;
531
532 ExtensionsActivityMonitor extensions_activity_monitor_;
533
534 scoped_ptr<SyncBackendRegistrar> registrar_;
535
536 // The frontend which we serve (and are owned by).
537 SyncFrontend* frontend_;
538
539 // We cache the cryptographer's pending keys whenever NotifyPassphraseRequired
540 // is called. This way, before the UI calls SetDecryptionPassphrase on the
541 // syncer, it can avoid the overhead of an asynchronous decryption call and
542 // give the user immediate feedback about the passphrase entered by first
543 // trying to decrypt the cached pending keys on the UI thread. Note that
544 // SetDecryptionPassphrase can still fail after the cached pending keys are
545 // successfully decrypted if the pending keys have changed since the time they
546 // were cached.
547 sync_pb::EncryptedData cached_pending_keys_;
548
549 // The state of the passphrase required to decrypt the bag of encryption keys
550 // in the nigori node. Updated whenever a new nigori node arrives or the user
551 // manually changes their passphrase state. Cached so we can synchronously
552 // check it from the UI thread.
553 syncer::PassphraseType cached_passphrase_type_;
554
555 // If an explicit passphrase is in use, the time at which the passphrase was
556 // first set (if available).
557 base::Time cached_explicit_passphrase_time_;
558
559 // UI-thread cache of the last SyncSessionSnapshot received from syncapi.
560 syncer::sessions::SyncSessionSnapshot last_snapshot_;
561
562 invalidation::InvalidationService* invalidator_;
563 bool invalidation_handler_registered_;
564
565 base::WeakPtrFactory<SyncBackendHost> weak_ptr_factory_;
566 117
567 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); 118 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost);
568 }; 119 };
569 120
570 } // namespace browser_sync 121 } // namespace browser_sync
571 122
572 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ 123 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/sync/glue/sync_backend_host.cc » ('j') | chrome/browser/sync/glue/sync_backend_host_core.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698