| 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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 // |sync_disabled| indicates if syncing is being disabled or not. | 218 // |sync_disabled| indicates if syncing is being disabled or not. |
| 219 // See the implementation and Core::DoShutdown for details. | 219 // See the implementation and Core::DoShutdown for details. |
| 220 // Must be called *after* StopSyncingForShutdown. | 220 // Must be called *after* StopSyncingForShutdown. |
| 221 void Shutdown(bool sync_disabled); | 221 void Shutdown(bool sync_disabled); |
| 222 | 222 |
| 223 // Changes the set of data types that are currently being synced. | 223 // Changes the set of data types that are currently being synced. |
| 224 // The ready_task will be run when configuration is done with the | 224 // The ready_task will be run when configuration is done with the |
| 225 // set of all types that failed configuration (i.e., if its argument | 225 // set of all types that failed configuration (i.e., if its argument |
| 226 // is non-empty, then an error was encountered). | 226 // is non-empty, then an error was encountered). |
| 227 virtual void ConfigureDataTypes( | 227 virtual void ConfigureDataTypes( |
| 228 sync_api::ConfigureReason reason, | 228 const sync_api::ConfigureReason& reason, |
| 229 syncable::ModelTypeSet types_to_add, | 229 const syncable::ModelTypeSet& desired_types, |
| 230 syncable::ModelTypeSet types_to_remove, | 230 const syncable::ModelTypeSet& disabled_types, |
| 231 NigoriState nigori_state, | 231 NigoriState nigori_state, |
| 232 base::Callback<void(syncable::ModelTypeSet)> ready_task, | 232 const base::Callback<void(syncable::ModelTypeSet)>& ready_task, |
| 233 base::Callback<void()> retry_callback) OVERRIDE; | 233 const base::Callback<void()>& retry_callback) OVERRIDE; |
| 234 | |
| 235 // Makes an asynchronous call to syncer to switch to config mode. When done | |
| 236 // syncer will call us back on FinishConfigureDataTypes. | |
| 237 virtual void StartConfiguration(const base::Closure& callback); | |
| 238 | 234 |
| 239 // Turns on encryption of all present and future sync data. | 235 // Turns on encryption of all present and future sync data. |
| 240 virtual void EnableEncryptEverything(); | 236 virtual void EnableEncryptEverything(); |
| 241 | 237 |
| 242 // Activates change processing for the given data type. This must | 238 // Activates change processing for the given data type. This must |
| 243 // be called synchronously with the data type's model association so | 239 // be called synchronously with the data type's model association so |
| 244 // no changes are dropped between model association and change | 240 // no changes are dropped between model association and change |
| 245 // processor activation. | 241 // processor activation. |
| 246 void ActivateDataType( | 242 void ActivateDataType( |
| 247 syncable::ModelType type, ModelSafeGroup group, | 243 syncable::ModelType type, ModelSafeGroup group, |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 }; | 327 }; |
| 332 | 328 |
| 333 // Allows tests to perform alternate core initialization work. | 329 // Allows tests to perform alternate core initialization work. |
| 334 virtual void InitCore(const DoInitializeOptions& options); | 330 virtual void InitCore(const DoInitializeOptions& options); |
| 335 | 331 |
| 336 // Called from Core::OnSyncCycleCompleted to handle updating frontend | 332 // Called from Core::OnSyncCycleCompleted to handle updating frontend |
| 337 // thread components. | 333 // thread components. |
| 338 void HandleSyncCycleCompletedOnFrontendLoop( | 334 void HandleSyncCycleCompletedOnFrontendLoop( |
| 339 const sessions::SyncSessionSnapshot& snapshot); | 335 const sessions::SyncSessionSnapshot& snapshot); |
| 340 | 336 |
| 341 // Called to finish the job of ConfigureDataTypes once the syncer is in | 337 // Request the syncer to reconfigure with the specfied params. |
| 342 // configuration mode. | 338 // Virtual for testing. |
| 343 void FinishConfigureDataTypesOnFrontendLoop(); | 339 virtual void RequestConfigureSyncer( |
| 340 sync_api::ConfigureReason reason, |
| 341 syncable::ModelTypeSet types_to_config, |
| 342 const browser_sync::ModelSafeRoutingInfo routing_info, |
| 343 const base::Callback<void(syncable::ModelTypeSet)>& ready_task, |
| 344 const base::Closure& retry_callback); |
| 345 |
| 346 // Called when the syncer has finished performing a configuration. |
| 347 void FinishConfigureDataTypesOnFrontendLoop( |
| 348 const syncable::ModelTypeSet& types_to_configure, |
| 349 const syncable::ModelTypeSet& configured_types, |
| 350 const base::Callback<void(syncable::ModelTypeSet)>& ready_task); |
| 351 |
| 352 // Called when the syncer failed to perform a configuration and will |
| 353 // eventually retry. FinishingConfigurationOnFrontendLoop(..) will be called |
| 354 // on successful completion. |
| 355 void RetryConfigurationOnFrontendLoop( |
| 356 const base::Closure& retry_callback); |
| 344 | 357 |
| 345 bool IsDownloadingNigoriForTest() const; | 358 bool IsDownloadingNigoriForTest() const; |
| 346 | 359 |
| 347 private: | 360 private: |
| 348 // The real guts of SyncBackendHost, to keep the public client API clean. | 361 // The real guts of SyncBackendHost, to keep the public client API clean. |
| 349 class Core; | 362 class Core; |
| 350 | 363 |
| 351 // An enum representing the steps to initializing the SyncBackendHost. | 364 // An enum representing the steps to initializing the SyncBackendHost. |
| 352 enum InitializationState { | 365 enum InitializationState { |
| 353 NOT_ATTEMPTED, | 366 NOT_ATTEMPTED, |
| 354 CREATING_SYNC_MANAGER, // We're waiting for the first callback from the | 367 CREATING_SYNC_MANAGER, // We're waiting for the first callback from the |
| 355 // sync thread to inform us that the sync manager | 368 // sync thread to inform us that the sync manager |
| 356 // has been created. | 369 // has been created. |
| 357 NOT_INITIALIZED, // Initialization hasn't completed, but we've | 370 NOT_INITIALIZED, // Initialization hasn't completed, but we've |
| 358 // constructed a SyncManager. | 371 // constructed a SyncManager. |
| 359 DOWNLOADING_NIGORI, // The SyncManager is initialized, but | 372 DOWNLOADING_NIGORI, // The SyncManager is initialized, but |
| 360 // we're fetching encryption information. | 373 // we're fetching encryption information. |
| 361 REFRESHING_NIGORI, // The SyncManager is initialized, and we | 374 REFRESHING_NIGORI, // The SyncManager is initialized, and we |
| 362 // have the encryption information, but we | 375 // have the encryption information, but we |
| 363 // still need to refresh encryption. Also, we need | 376 // still need to refresh encryption. Also, we need |
| 364 // to update the device information in the nigori. | 377 // to update the device information in the nigori. |
| 365 INITIALIZED, // Initialization is complete. | 378 INITIALIZED, // Initialization is complete. |
| 366 }; | 379 }; |
| 367 | 380 |
| 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 | 381 // 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. | 382 // (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. | 383 // Note: it is illegal to call this before the backend is initialized. |
| 397 void AddExperimentalTypes(); | 384 void AddExperimentalTypes(); |
| 398 | 385 |
| 399 // Downloading of nigori failed and will be retried. | 386 // Downloading of nigori failed and will be retried. |
| 400 virtual void OnNigoriDownloadRetry(); | 387 virtual void OnNigoriDownloadRetry(); |
| 401 | 388 |
| 402 // InitializationComplete passes through the SyncBackendHost to forward | 389 // InitializationComplete passes through the SyncBackendHost to forward |
| 403 // on to |frontend_|, and so that tests can intercept here if they need to | 390 // on to |frontend_|, and so that tests can intercept here if they need to |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 | 489 |
| 503 sync_notifier::SyncNotifierFactory sync_notifier_factory_; | 490 sync_notifier::SyncNotifierFactory sync_notifier_factory_; |
| 504 | 491 |
| 505 ChromeExtensionsActivityMonitor extensions_activity_monitor_; | 492 ChromeExtensionsActivityMonitor extensions_activity_monitor_; |
| 506 | 493 |
| 507 scoped_ptr<SyncBackendRegistrar> registrar_; | 494 scoped_ptr<SyncBackendRegistrar> registrar_; |
| 508 | 495 |
| 509 // The frontend which we serve (and are owned by). | 496 // The frontend which we serve (and are owned by). |
| 510 SyncFrontend* frontend_; | 497 SyncFrontend* frontend_; |
| 511 | 498 |
| 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 | 499 // We cache the cryptographer's pending keys whenever NotifyPassphraseRequired |
| 516 // is called. This way, before the UI calls SetDecryptionPassphrase on the | 500 // is called. This way, before the UI calls SetDecryptionPassphrase on the |
| 517 // syncer, it can avoid the overhead of an asynchronous decryption call and | 501 // syncer, it can avoid the overhead of an asynchronous decryption call and |
| 518 // give the user immediate feedback about the passphrase entered by first | 502 // 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 | 503 // trying to decrypt the cached pending keys on the UI thread. Note that |
| 520 // SetDecryptionPassphrase can still fail after the cached pending keys are | 504 // SetDecryptionPassphrase can still fail after the cached pending keys are |
| 521 // successfully decrypted if the pending keys have changed since the time they | 505 // successfully decrypted if the pending keys have changed since the time they |
| 522 // were cached. | 506 // were cached. |
| 523 sync_pb::EncryptedData cached_pending_keys_; | 507 sync_pb::EncryptedData cached_pending_keys_; |
| 524 | 508 |
| 525 // UI-thread cache of the last SyncSessionSnapshot received from syncapi. | 509 // UI-thread cache of the last SyncSessionSnapshot received from syncapi. |
| 526 sessions::SyncSessionSnapshot last_snapshot_; | 510 sessions::SyncSessionSnapshot last_snapshot_; |
| 527 | 511 |
| 528 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); | 512 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); |
| 529 }; | 513 }; |
| 530 | 514 |
| 531 } // namespace browser_sync | 515 } // namespace browser_sync |
| 532 | 516 |
| 533 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ | 517 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ |
| OLD | NEW |