OLD | NEW |
---|---|
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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 | 164 |
165 // Called on |frontend_loop_| to kick off asynchronous initialization. | 165 // Called on |frontend_loop_| to kick off asynchronous initialization. |
166 // As a fallback when no cached auth information is available, try to | 166 // As a fallback when no cached auth information is available, try to |
167 // bootstrap authentication using |lsid|, if it isn't empty. | 167 // bootstrap authentication using |lsid|, if it isn't empty. |
168 // Optionally delete the Sync Data folder (if it's corrupt). | 168 // Optionally delete the Sync Data folder (if it's corrupt). |
169 // |report_unrecoverable_error_function| can be NULL. | 169 // |report_unrecoverable_error_function| can be NULL. |
170 // Note: |unrecoverable_error_handler| may be invoked from any thread. | 170 // Note: |unrecoverable_error_handler| may be invoked from any thread. |
171 void Initialize(SyncFrontend* frontend, | 171 void Initialize(SyncFrontend* frontend, |
172 const WeakHandle<JsEventHandler>& event_handler, | 172 const WeakHandle<JsEventHandler>& event_handler, |
173 const GURL& service_url, | 173 const GURL& service_url, |
174 syncable::ModelTypeSet initial_types, | |
175 const sync_api::SyncCredentials& credentials, | 174 const sync_api::SyncCredentials& credentials, |
176 bool delete_sync_data_folder, | 175 bool delete_sync_data_folder, |
177 UnrecoverableErrorHandler* unrecoverable_error_handler, | 176 UnrecoverableErrorHandler* unrecoverable_error_handler, |
178 ReportUnrecoverableErrorFunction | 177 ReportUnrecoverableErrorFunction |
179 report_unrecoverable_error_function); | 178 report_unrecoverable_error_function); |
180 | 179 |
181 // Called from |frontend_loop| to update SyncCredentials. | 180 // Called from |frontend_loop| to update SyncCredentials. |
182 void UpdateCredentials(const sync_api::SyncCredentials& credentials); | 181 void UpdateCredentials(const sync_api::SyncCredentials& credentials); |
183 | 182 |
184 // This starts the SyncerThread running a Syncer object to communicate with | 183 // This starts the SyncerThread running a Syncer object to communicate with |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
283 protected: | 282 protected: |
284 // The types and functions below are protected so that test | 283 // The types and functions below are protected so that test |
285 // subclasses can use them. | 284 // subclasses can use them. |
286 // | 285 // |
287 // TODO(akalin): Figure out a better way for tests to hook into | 286 // TODO(akalin): Figure out a better way for tests to hook into |
288 // SyncBackendHost. | 287 // SyncBackendHost. |
289 | 288 |
290 typedef base::Callback<sync_api::HttpPostProviderFactory*(void)> | 289 typedef base::Callback<sync_api::HttpPostProviderFactory*(void)> |
291 MakeHttpBridgeFactoryFn; | 290 MakeHttpBridgeFactoryFn; |
292 | 291 |
292 struct PendingConfigureDataTypesState { | |
293 PendingConfigureDataTypesState(); | |
294 ~PendingConfigureDataTypesState(); | |
295 | |
296 // The ready_task will be run when configuration is done with the | |
297 // set of all types that failed configuration (i.e., if its | |
298 // argument is non-empty, then an error was encountered). | |
299 base::Callback<void(syncable::ModelTypeSet)> ready_task; | |
300 | |
301 // The retry callback will be run when the download failed due to a | |
302 // transient error. This is to notify DTM so it can apropriately inform | |
303 // the UI. Note: The retry_callback will be run only once and after | |
304 // that we will not notify DTM until the sync is successful or in a | |
305 // permanent error state. | |
306 base::Callback<void()> retry_callback; | |
307 | |
308 // The set of types that we are waiting to be initially synced in a | |
309 // configuration cycle. | |
310 syncable::ModelTypeSet types_to_add; | |
311 | |
312 // Additional details about which types were added. | |
313 syncable::ModelTypeSet added_types; | |
314 sync_api::ConfigureReason reason; | |
315 bool retry_in_progress; | |
316 }; | |
317 | |
293 struct DoInitializeOptions { | 318 struct DoInitializeOptions { |
294 DoInitializeOptions( | 319 DoInitializeOptions( |
295 MessageLoop* sync_loop, | 320 MessageLoop* sync_loop, |
296 SyncBackendRegistrar* registrar, | 321 SyncBackendRegistrar* registrar, |
297 const ModelSafeRoutingInfo& routing_info, | 322 const ModelSafeRoutingInfo& routing_info, |
298 const std::vector<ModelSafeWorker*>& workers, | 323 const std::vector<ModelSafeWorker*>& workers, |
299 ExtensionsActivityMonitor* extensions_activity_monitor, | 324 ExtensionsActivityMonitor* extensions_activity_monitor, |
300 const WeakHandle<JsEventHandler>& event_handler, | 325 const WeakHandle<JsEventHandler>& event_handler, |
301 const GURL& service_url, | 326 const GURL& service_url, |
302 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, | 327 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 | 360 |
336 // Called from Core::OnSyncCycleCompleted to handle updating frontend | 361 // Called from Core::OnSyncCycleCompleted to handle updating frontend |
337 // thread components. | 362 // thread components. |
338 void HandleSyncCycleCompletedOnFrontendLoop( | 363 void HandleSyncCycleCompletedOnFrontendLoop( |
339 const sessions::SyncSessionSnapshot& snapshot); | 364 const sessions::SyncSessionSnapshot& snapshot); |
340 | 365 |
341 // Called to finish the job of ConfigureDataTypes once the syncer is in | 366 // Called to finish the job of ConfigureDataTypes once the syncer is in |
342 // configuration mode. | 367 // configuration mode. |
343 void FinishConfigureDataTypesOnFrontendLoop(); | 368 void FinishConfigureDataTypesOnFrontendLoop(); |
344 | 369 |
345 bool IsDownloadingNigoriForTest() const; | 370 scoped_ptr<PendingConfigureDataTypesState> pending_download_state_; |
rlarocque
2012/06/04 20:07:09
The moves in this file were necessary to make pend
| |
371 scoped_ptr<PendingConfigureDataTypesState> pending_config_mode_state_; | |
346 | 372 |
347 private: | 373 private: |
348 // The real guts of SyncBackendHost, to keep the public client API clean. | 374 // The real guts of SyncBackendHost, to keep the public client API clean. |
349 class Core; | 375 class Core; |
350 | 376 |
351 // An enum representing the steps to initializing the SyncBackendHost. | 377 // An enum representing the steps to initializing the SyncBackendHost. |
352 enum InitializationState { | 378 enum InitializationState { |
353 NOT_ATTEMPTED, | 379 NOT_ATTEMPTED, |
354 CREATING_SYNC_MANAGER, // We're waiting for the first callback from the | 380 CREATING_SYNC_MANAGER, // We're waiting for the first callback from the |
355 // sync thread to inform us that the sync manager | 381 // sync thread to inform us that the sync manager |
356 // has been created. | 382 // has been created. |
357 NOT_INITIALIZED, // Initialization hasn't completed, but we've | 383 NOT_INITIALIZED, // Initialization hasn't completed, but we've |
358 // constructed a SyncManager. | 384 // constructed a SyncManager. |
359 DOWNLOADING_NIGORI, // The SyncManager is initialized, but | 385 DOWNLOADING_NIGORI, // The SyncManager is initialized, but |
360 // we're fetching encryption information. | 386 // we're fetching encryption information. |
361 REFRESHING_NIGORI, // The SyncManager is initialized, and we | 387 REFRESHING_NIGORI, // The SyncManager is initialized, and we |
362 // have the encryption information, but we | 388 // have the encryption information, but we |
363 // still need to refresh encryption. Also, we need | 389 // still need to refresh encryption. Also, we need |
364 // to update the device information in the nigori. | 390 // to update the device information in the nigori. |
365 INITIALIZED, // Initialization is complete. | 391 INITIALIZED, // Initialization is complete. |
366 }; | 392 }; |
367 | 393 |
368 struct PendingConfigureDataTypesState { | |
369 PendingConfigureDataTypesState(); | |
370 ~PendingConfigureDataTypesState(); | |
371 | |
372 // The ready_task will be run when configuration is done with the | |
373 // set of all types that failed configuration (i.e., if its | |
374 // argument is non-empty, then an error was encountered). | |
375 base::Callback<void(syncable::ModelTypeSet)> ready_task; | |
376 | |
377 // The retry callback will be run when the download failed due to a | |
378 // transient error. This is to notify DTM so it can apropriately inform | |
379 // the UI. Note: The retry_callback will be run only once and after | |
380 // that we will not notify DTM until the sync is successful or in a | |
381 // permanent error state. | |
382 base::Callback<void()> retry_callback; | |
383 | |
384 // The set of types that we are waiting to be initially synced in a | |
385 // configuration cycle. | |
386 syncable::ModelTypeSet types_to_add; | |
387 | |
388 // Additional details about which types were added. | |
389 syncable::ModelTypeSet added_types; | |
390 sync_api::ConfigureReason reason; | |
391 bool retry_in_progress; | |
392 }; | |
393 | |
394 // Checks if we have received a notice to turn on experimental datatypes | 394 // Checks if we have received a notice to turn on experimental datatypes |
395 // (via the nigori node) and informs the frontend if that is the case. | 395 // (via the nigori node) and informs the frontend if that is the case. |
396 // Note: it is illegal to call this before the backend is initialized. | 396 // Note: it is illegal to call this before the backend is initialized. |
397 void AddExperimentalTypes(); | 397 void AddExperimentalTypes(); |
398 | 398 |
399 // Downloading of nigori failed and will be retried. | 399 // Downloading of nigori failed and will be retried. |
400 virtual void OnNigoriDownloadRetry(); | 400 virtual void OnNigoriDownloadRetry(); |
401 | 401 |
402 // InitializationComplete passes through the SyncBackendHost to forward | 402 // InitializationComplete passes through the SyncBackendHost to forward |
403 // on to |frontend_|, and so that tests can intercept here if they need to | 403 // on to |frontend_|, and so that tests can intercept here if they need to |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
460 // frontend UI components. | 460 // frontend UI components. |
461 void HandleConnectionStatusChangeOnFrontendLoop( | 461 void HandleConnectionStatusChangeOnFrontendLoop( |
462 sync_api::ConnectionStatus status); | 462 sync_api::ConnectionStatus status); |
463 | 463 |
464 // Called when configuration of the Nigori node has completed as | 464 // Called when configuration of the Nigori node has completed as |
465 // part of the initialization process. | 465 // part of the initialization process. |
466 void HandleNigoriConfigurationCompletedOnFrontendLoop( | 466 void HandleNigoriConfigurationCompletedOnFrontendLoop( |
467 const WeakHandle<JsBackend>& js_backend, | 467 const WeakHandle<JsBackend>& js_backend, |
468 syncable::ModelTypeSet failed_configuration_types); | 468 syncable::ModelTypeSet failed_configuration_types); |
469 | 469 |
470 // Called when the SyncManager has been constructed and initialized. | |
471 void HandleSyncManagerInitializationOnFrontendLoop( | |
472 const WeakHandle<JsBackend>& js_backend, bool success, | |
473 syncable::ModelTypeSet initial_sync_ended_types); | |
474 | |
470 // Must be called on |frontend_loop_|. |done_callback| is called on | 475 // Must be called on |frontend_loop_|. |done_callback| is called on |
471 // |frontend_loop_|. | 476 // |frontend_loop_|. |
472 void RefreshNigori(const base::Closure& done_callback); | 477 void RefreshNigori(const base::Closure& done_callback); |
473 | 478 |
474 // Handles stopping the core's SyncManager, accounting for whether | 479 // Handles stopping the core's SyncManager, accounting for whether |
475 // initialization is done yet. | 480 // initialization is done yet. |
476 void StopSyncManagerForShutdown(const base::Closure& closure); | 481 void StopSyncManagerForShutdown(const base::Closure& closure); |
477 | 482 |
478 base::WeakPtrFactory<SyncBackendHost> weak_ptr_factory_; | 483 base::WeakPtrFactory<SyncBackendHost> weak_ptr_factory_; |
479 | 484 |
(...skipping 22 matching lines...) Expand all Loading... | |
502 | 507 |
503 sync_notifier::SyncNotifierFactory sync_notifier_factory_; | 508 sync_notifier::SyncNotifierFactory sync_notifier_factory_; |
504 | 509 |
505 ChromeExtensionsActivityMonitor extensions_activity_monitor_; | 510 ChromeExtensionsActivityMonitor extensions_activity_monitor_; |
506 | 511 |
507 scoped_ptr<SyncBackendRegistrar> registrar_; | 512 scoped_ptr<SyncBackendRegistrar> registrar_; |
508 | 513 |
509 // The frontend which we serve (and are owned by). | 514 // The frontend which we serve (and are owned by). |
510 SyncFrontend* frontend_; | 515 SyncFrontend* frontend_; |
511 | 516 |
512 scoped_ptr<PendingConfigureDataTypesState> pending_download_state_; | |
513 scoped_ptr<PendingConfigureDataTypesState> pending_config_mode_state_; | |
514 | |
515 // We cache the cryptographer's pending keys whenever NotifyPassphraseRequired | 517 // We cache the cryptographer's pending keys whenever NotifyPassphraseRequired |
516 // is called. This way, before the UI calls SetDecryptionPassphrase on the | 518 // is called. This way, before the UI calls SetDecryptionPassphrase on the |
517 // syncer, it can avoid the overhead of an asynchronous decryption call and | 519 // syncer, it can avoid the overhead of an asynchronous decryption call and |
518 // give the user immediate feedback about the passphrase entered by first | 520 // give the user immediate feedback about the passphrase entered by first |
519 // trying to decrypt the cached pending keys on the UI thread. Note that | 521 // trying to decrypt the cached pending keys on the UI thread. Note that |
520 // SetDecryptionPassphrase can still fail after the cached pending keys are | 522 // SetDecryptionPassphrase can still fail after the cached pending keys are |
521 // successfully decrypted if the pending keys have changed since the time they | 523 // successfully decrypted if the pending keys have changed since the time they |
522 // were cached. | 524 // were cached. |
523 sync_pb::EncryptedData cached_pending_keys_; | 525 sync_pb::EncryptedData cached_pending_keys_; |
524 | 526 |
525 // UI-thread cache of the last SyncSessionSnapshot received from syncapi. | 527 // UI-thread cache of the last SyncSessionSnapshot received from syncapi. |
526 sessions::SyncSessionSnapshot last_snapshot_; | 528 sessions::SyncSessionSnapshot last_snapshot_; |
527 | 529 |
528 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); | 530 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); |
529 }; | 531 }; |
530 | 532 |
531 } // namespace browser_sync | 533 } // namespace browser_sync |
532 | 534 |
533 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ | 535 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ |
OLD | NEW |