| 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 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 217 |
| 218 // Changes the set of data types that are currently being synced. | 218 // Changes the set of data types that are currently being synced. |
| 219 // The ready_task will be run when configuration is done with the | 219 // The ready_task will be run when configuration is done with the |
| 220 // set of all types that failed configuration (i.e., if its argument | 220 // set of all types that failed configuration (i.e., if its argument |
| 221 // is non-empty, then an error was encountered). | 221 // is non-empty, then an error was encountered). |
| 222 virtual void ConfigureDataTypes( | 222 virtual void ConfigureDataTypes( |
| 223 syncer::ConfigureReason reason, | 223 syncer::ConfigureReason reason, |
| 224 syncer::ModelTypeSet types_to_add, | 224 syncer::ModelTypeSet types_to_add, |
| 225 syncer::ModelTypeSet types_to_remove, | 225 syncer::ModelTypeSet types_to_remove, |
| 226 NigoriState nigori_state, | 226 NigoriState nigori_state, |
| 227 const base::Callback<void(syncer::ModelTypeSet)>& ready_task, | 227 base::Callback<void(syncer::ModelTypeSet)> ready_task, |
| 228 const base::Callback<void()>& retry_callback) OVERRIDE; | 228 base::Callback<void()> retry_callback) OVERRIDE; |
| 229 |
| 230 // Makes an asynchronous call to syncer to switch to config mode. When done |
| 231 // syncer will call us back on FinishConfigureDataTypes. |
| 232 virtual void StartConfiguration(const base::Closure& callback); |
| 229 | 233 |
| 230 // Turns on encryption of all present and future sync data. | 234 // Turns on encryption of all present and future sync data. |
| 231 virtual void EnableEncryptEverything(); | 235 virtual void EnableEncryptEverything(); |
| 232 | 236 |
| 233 // Activates change processing for the given data type. This must | 237 // Activates change processing for the given data type. This must |
| 234 // be called synchronously with the data type's model association so | 238 // be called synchronously with the data type's model association so |
| 235 // no changes are dropped between model association and change | 239 // no changes are dropped between model association and change |
| 236 // processor activation. | 240 // processor activation. |
| 237 void ActivateDataType( | 241 void ActivateDataType( |
| 238 syncer::ModelType type, syncer::ModelSafeGroup group, | 242 syncer::ModelType type, syncer::ModelSafeGroup group, |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 std::string restored_key_for_bootstrapping; | 320 std::string restored_key_for_bootstrapping; |
| 317 syncer::SyncManager::TestingMode testing_mode; | 321 syncer::SyncManager::TestingMode testing_mode; |
| 318 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler; | 322 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler; |
| 319 syncer::ReportUnrecoverableErrorFunction | 323 syncer::ReportUnrecoverableErrorFunction |
| 320 report_unrecoverable_error_function; | 324 report_unrecoverable_error_function; |
| 321 }; | 325 }; |
| 322 | 326 |
| 323 // Allows tests to perform alternate core initialization work. | 327 // Allows tests to perform alternate core initialization work. |
| 324 virtual void InitCore(const DoInitializeOptions& options); | 328 virtual void InitCore(const DoInitializeOptions& options); |
| 325 | 329 |
| 326 // Request the syncer to reconfigure with the specfied params. | 330 // Called from Core::OnSyncCycleCompleted to handle updating frontend |
| 327 // Virtual for testing. | 331 // thread components. |
| 328 virtual void RequestConfigureSyncer( | 332 void HandleSyncCycleCompletedOnFrontendLoop( |
| 329 syncer::ConfigureReason reason, | 333 const syncer::sessions::SyncSessionSnapshot& snapshot); |
| 330 syncer::ModelTypeSet types_to_config, | |
| 331 const syncer::ModelSafeRoutingInfo& routing_info, | |
| 332 const base::Callback<void(syncer::ModelTypeSet)>& ready_task, | |
| 333 const base::Closure& retry_callback); | |
| 334 | 334 |
| 335 // Called when the syncer has finished performing a configuration. | 335 // Called to finish the job of ConfigureDataTypes once the syncer is in |
| 336 void FinishConfigureDataTypesOnFrontendLoop( | 336 // configuration mode. |
| 337 const syncer::ModelTypeSet types_to_configure, | 337 void FinishConfigureDataTypesOnFrontendLoop(); |
| 338 const syncer::ModelTypeSet configured_types, | 338 |
| 339 const base::Callback<void(syncer::ModelTypeSet)>& ready_task); | 339 bool IsDownloadingNigoriForTest() const; |
| 340 | 340 |
| 341 private: | 341 private: |
| 342 // The real guts of SyncBackendHost, to keep the public client API clean. | 342 // The real guts of SyncBackendHost, to keep the public client API clean. |
| 343 class Core; | 343 class Core; |
| 344 | 344 |
| 345 // An enum representing the steps to initializing the SyncBackendHost. | 345 // An enum representing the steps to initializing the SyncBackendHost. |
| 346 enum InitializationState { | 346 enum InitializationState { |
| 347 NOT_ATTEMPTED, | 347 NOT_ATTEMPTED, |
| 348 CREATING_SYNC_MANAGER, // We're waiting for the first callback from the | 348 CREATING_SYNC_MANAGER, // We're waiting for the first callback from the |
| 349 // sync thread to inform us that the sync manager | 349 // sync thread to inform us that the sync manager |
| 350 // has been created. | 350 // has been created. |
| 351 NOT_INITIALIZED, // Initialization hasn't completed, but we've | 351 NOT_INITIALIZED, // Initialization hasn't completed, but we've |
| 352 // constructed a SyncManager. | 352 // constructed a SyncManager. |
| 353 DOWNLOADING_NIGORI, // The SyncManager is initialized, but | 353 DOWNLOADING_NIGORI, // The SyncManager is initialized, but |
| 354 // we're fetching encryption information. | 354 // we're fetching encryption information. |
| 355 REFRESHING_NIGORI, // The SyncManager is initialized, and we | 355 REFRESHING_NIGORI, // The SyncManager is initialized, and we |
| 356 // have the encryption information, but we | 356 // have the encryption information, but we |
| 357 // still need to refresh encryption. Also, we need | 357 // still need to refresh encryption. Also, we need |
| 358 // to update the device information in the nigori. | 358 // to update the device information in the nigori. |
| 359 INITIALIZED, // Initialization is complete. | 359 INITIALIZED, // Initialization is complete. |
| 360 }; | 360 }; |
| 361 | 361 |
| 362 struct PendingConfigureDataTypesState { |
| 363 PendingConfigureDataTypesState(); |
| 364 ~PendingConfigureDataTypesState(); |
| 365 |
| 366 // The ready_task will be run when configuration is done with the |
| 367 // set of all types that failed configuration (i.e., if its |
| 368 // argument is non-empty, then an error was encountered). |
| 369 base::Callback<void(syncer::ModelTypeSet)> ready_task; |
| 370 |
| 371 // The retry callback will be run when the download failed due to a |
| 372 // transient error. This is to notify DTM so it can apropriately inform |
| 373 // the UI. Note: The retry_callback will be run only once and after |
| 374 // that we will not notify DTM until the sync is successful or in a |
| 375 // permanent error state. |
| 376 base::Callback<void()> retry_callback; |
| 377 |
| 378 // The set of types that we are waiting to be initially synced in a |
| 379 // configuration cycle. |
| 380 syncer::ModelTypeSet types_to_add; |
| 381 |
| 382 // Additional details about which types were added. |
| 383 syncer::ModelTypeSet added_types; |
| 384 syncer::ConfigureReason reason; |
| 385 bool retry_in_progress; |
| 386 }; |
| 387 |
| 362 // Checks if we have received a notice to turn on experimental datatypes | 388 // Checks if we have received a notice to turn on experimental datatypes |
| 363 // (via the nigori node) and informs the frontend if that is the case. | 389 // (via the nigori node) and informs the frontend if that is the case. |
| 364 // Note: it is illegal to call this before the backend is initialized. | 390 // Note: it is illegal to call this before the backend is initialized. |
| 365 void AddExperimentalTypes(); | 391 void AddExperimentalTypes(); |
| 366 | 392 |
| 367 // Downloading of nigori failed and will be retried. | 393 // Downloading of nigori failed and will be retried. |
| 368 void OnNigoriDownloadRetry(); | 394 virtual void OnNigoriDownloadRetry(); |
| 369 | 395 |
| 370 // InitializationComplete passes through the SyncBackendHost to forward | 396 // InitializationComplete passes through the SyncBackendHost to forward |
| 371 // on to |frontend_|, and so that tests can intercept here if they need to | 397 // on to |frontend_|, and so that tests can intercept here if they need to |
| 372 // set up initial conditions. | 398 // set up initial conditions. |
| 373 void HandleInitializationCompletedOnFrontendLoop( | 399 virtual void HandleInitializationCompletedOnFrontendLoop( |
| 374 const syncer::WeakHandle<syncer::JsBackend>& js_backend, | 400 const syncer::WeakHandle<syncer::JsBackend>& js_backend, |
| 375 bool success); | 401 bool success); |
| 376 | 402 |
| 377 // Called from Core::OnSyncCycleCompleted to handle updating frontend | |
| 378 // thread components. | |
| 379 void HandleSyncCycleCompletedOnFrontendLoop( | |
| 380 const syncer::sessions::SyncSessionSnapshot& snapshot); | |
| 381 | |
| 382 // Called when the syncer failed to perform a configuration and will | |
| 383 // eventually retry. FinishingConfigurationOnFrontendLoop(..) will be called | |
| 384 // on successful completion. | |
| 385 void RetryConfigurationOnFrontendLoop(const base::Closure& retry_callback); | |
| 386 | |
| 387 // Helpers to persist a token that can be used to bootstrap sync encryption | 403 // Helpers to persist a token that can be used to bootstrap sync encryption |
| 388 // across browser restart to avoid requiring the user to re-enter their | 404 // across browser restart to avoid requiring the user to re-enter their |
| 389 // passphrase. |token| must be valid UTF-8 as we use the PrefService for | 405 // passphrase. |token| must be valid UTF-8 as we use the PrefService for |
| 390 // storage. | 406 // storage. |
| 391 void PersistEncryptionBootstrapToken(const std::string& token); | 407 void PersistEncryptionBootstrapToken(const std::string& token); |
| 392 | 408 |
| 393 // For convenience, checks if initialization state is INITIALIZED. | 409 // For convenience, checks if initialization state is INITIALIZED. |
| 394 bool initialized() const { return initialization_state_ == INITIALIZED; } | 410 bool initialized() const { return initialization_state_ == INITIALIZED; } |
| 395 | 411 |
| 396 // Let the front end handle the actionable error event. | 412 // Let the front end handle the actionable error event. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 | 492 |
| 477 syncer::SyncNotifierFactory sync_notifier_factory_; | 493 syncer::SyncNotifierFactory sync_notifier_factory_; |
| 478 | 494 |
| 479 ChromeExtensionsActivityMonitor extensions_activity_monitor_; | 495 ChromeExtensionsActivityMonitor extensions_activity_monitor_; |
| 480 | 496 |
| 481 scoped_ptr<SyncBackendRegistrar> registrar_; | 497 scoped_ptr<SyncBackendRegistrar> registrar_; |
| 482 | 498 |
| 483 // The frontend which we serve (and are owned by). | 499 // The frontend which we serve (and are owned by). |
| 484 SyncFrontend* frontend_; | 500 SyncFrontend* frontend_; |
| 485 | 501 |
| 502 scoped_ptr<PendingConfigureDataTypesState> pending_download_state_; |
| 503 scoped_ptr<PendingConfigureDataTypesState> pending_config_mode_state_; |
| 504 |
| 486 // We cache the cryptographer's pending keys whenever NotifyPassphraseRequired | 505 // We cache the cryptographer's pending keys whenever NotifyPassphraseRequired |
| 487 // is called. This way, before the UI calls SetDecryptionPassphrase on the | 506 // is called. This way, before the UI calls SetDecryptionPassphrase on the |
| 488 // syncer, it can avoid the overhead of an asynchronous decryption call and | 507 // syncer, it can avoid the overhead of an asynchronous decryption call and |
| 489 // give the user immediate feedback about the passphrase entered by first | 508 // give the user immediate feedback about the passphrase entered by first |
| 490 // trying to decrypt the cached pending keys on the UI thread. Note that | 509 // trying to decrypt the cached pending keys on the UI thread. Note that |
| 491 // SetDecryptionPassphrase can still fail after the cached pending keys are | 510 // SetDecryptionPassphrase can still fail after the cached pending keys are |
| 492 // successfully decrypted if the pending keys have changed since the time they | 511 // successfully decrypted if the pending keys have changed since the time they |
| 493 // were cached. | 512 // were cached. |
| 494 sync_pb::EncryptedData cached_pending_keys_; | 513 sync_pb::EncryptedData cached_pending_keys_; |
| 495 | 514 |
| 496 // UI-thread cache of the last SyncSessionSnapshot received from syncapi. | 515 // UI-thread cache of the last SyncSessionSnapshot received from syncapi. |
| 497 syncer::sessions::SyncSessionSnapshot last_snapshot_; | 516 syncer::sessions::SyncSessionSnapshot last_snapshot_; |
| 498 | 517 |
| 499 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); | 518 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); |
| 500 }; | 519 }; |
| 501 | 520 |
| 502 } // namespace browser_sync | 521 } // namespace browser_sync |
| 503 | 522 |
| 504 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ | 523 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ |
| OLD | NEW |