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 base::Callback<void(syncer::ModelTypeSet)> ready_task, | 227 const base::Callback<void(syncer::ModelTypeSet)>& ready_task, |
228 base::Callback<void()> retry_callback) OVERRIDE; | 228 const 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); | |
233 | 229 |
234 // Turns on encryption of all present and future sync data. | 230 // Turns on encryption of all present and future sync data. |
235 virtual void EnableEncryptEverything(); | 231 virtual void EnableEncryptEverything(); |
236 | 232 |
237 // Activates change processing for the given data type. This must | 233 // Activates change processing for the given data type. This must |
238 // be called synchronously with the data type's model association so | 234 // be called synchronously with the data type's model association so |
239 // no changes are dropped between model association and change | 235 // no changes are dropped between model association and change |
240 // processor activation. | 236 // processor activation. |
241 void ActivateDataType( | 237 void ActivateDataType( |
242 syncer::ModelType type, syncer::ModelSafeGroup group, | 238 syncer::ModelType type, syncer::ModelSafeGroup group, |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 std::string restored_key_for_bootstrapping; | 316 std::string restored_key_for_bootstrapping; |
321 syncer::SyncManager::TestingMode testing_mode; | 317 syncer::SyncManager::TestingMode testing_mode; |
322 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler; | 318 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler; |
323 syncer::ReportUnrecoverableErrorFunction | 319 syncer::ReportUnrecoverableErrorFunction |
324 report_unrecoverable_error_function; | 320 report_unrecoverable_error_function; |
325 }; | 321 }; |
326 | 322 |
327 // Allows tests to perform alternate core initialization work. | 323 // Allows tests to perform alternate core initialization work. |
328 virtual void InitCore(const DoInitializeOptions& options); | 324 virtual void InitCore(const DoInitializeOptions& options); |
329 | 325 |
330 // Called from Core::OnSyncCycleCompleted to handle updating frontend | 326 // Request the syncer to reconfigure with the specfied params. |
331 // thread components. | 327 // Virtual for testing. |
332 void HandleSyncCycleCompletedOnFrontendLoop( | 328 virtual void RequestConfigureSyncer( |
333 const syncer::sessions::SyncSessionSnapshot& snapshot); | 329 syncer::ConfigureReason reason, |
| 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 to finish the job of ConfigureDataTypes once the syncer is in | 335 // Called when the syncer has finished performing a configuration. |
336 // configuration mode. | 336 void FinishConfigureDataTypesOnFrontendLoop( |
337 void FinishConfigureDataTypesOnFrontendLoop(); | 337 const syncer::ModelTypeSet types_to_configure, |
338 | 338 const syncer::ModelTypeSet configured_types, |
339 bool IsDownloadingNigoriForTest() const; | 339 const base::Callback<void(syncer::ModelTypeSet)>& ready_task); |
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 | |
388 // Checks if we have received a notice to turn on experimental datatypes | 362 // Checks if we have received a notice to turn on experimental datatypes |
389 // (via the nigori node) and informs the frontend if that is the case. | 363 // (via the nigori node) and informs the frontend if that is the case. |
390 // Note: it is illegal to call this before the backend is initialized. | 364 // Note: it is illegal to call this before the backend is initialized. |
391 void AddExperimentalTypes(); | 365 void AddExperimentalTypes(); |
392 | 366 |
393 // Downloading of nigori failed and will be retried. | 367 // Downloading of nigori failed and will be retried. |
394 virtual void OnNigoriDownloadRetry(); | 368 void OnNigoriDownloadRetry(); |
395 | 369 |
396 // InitializationComplete passes through the SyncBackendHost to forward | 370 // InitializationComplete passes through the SyncBackendHost to forward |
397 // on to |frontend_|, and so that tests can intercept here if they need to | 371 // on to |frontend_|, and so that tests can intercept here if they need to |
398 // set up initial conditions. | 372 // set up initial conditions. |
399 virtual void HandleInitializationCompletedOnFrontendLoop( | 373 void HandleInitializationCompletedOnFrontendLoop( |
400 const syncer::WeakHandle<syncer::JsBackend>& js_backend, | 374 const syncer::WeakHandle<syncer::JsBackend>& js_backend, |
401 bool success); | 375 bool success); |
402 | 376 |
| 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 |
403 // Helpers to persist a token that can be used to bootstrap sync encryption | 387 // Helpers to persist a token that can be used to bootstrap sync encryption |
404 // across browser restart to avoid requiring the user to re-enter their | 388 // across browser restart to avoid requiring the user to re-enter their |
405 // passphrase. |token| must be valid UTF-8 as we use the PrefService for | 389 // passphrase. |token| must be valid UTF-8 as we use the PrefService for |
406 // storage. | 390 // storage. |
407 void PersistEncryptionBootstrapToken(const std::string& token); | 391 void PersistEncryptionBootstrapToken(const std::string& token); |
408 | 392 |
409 // For convenience, checks if initialization state is INITIALIZED. | 393 // For convenience, checks if initialization state is INITIALIZED. |
410 bool initialized() const { return initialization_state_ == INITIALIZED; } | 394 bool initialized() const { return initialization_state_ == INITIALIZED; } |
411 | 395 |
412 // Let the front end handle the actionable error event. | 396 // Let the front end handle the actionable error event. |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 | 476 |
493 syncer::SyncNotifierFactory sync_notifier_factory_; | 477 syncer::SyncNotifierFactory sync_notifier_factory_; |
494 | 478 |
495 ChromeExtensionsActivityMonitor extensions_activity_monitor_; | 479 ChromeExtensionsActivityMonitor extensions_activity_monitor_; |
496 | 480 |
497 scoped_ptr<SyncBackendRegistrar> registrar_; | 481 scoped_ptr<SyncBackendRegistrar> registrar_; |
498 | 482 |
499 // The frontend which we serve (and are owned by). | 483 // The frontend which we serve (and are owned by). |
500 SyncFrontend* frontend_; | 484 SyncFrontend* frontend_; |
501 | 485 |
502 scoped_ptr<PendingConfigureDataTypesState> pending_download_state_; | |
503 scoped_ptr<PendingConfigureDataTypesState> pending_config_mode_state_; | |
504 | |
505 // We cache the cryptographer's pending keys whenever NotifyPassphraseRequired | 486 // We cache the cryptographer's pending keys whenever NotifyPassphraseRequired |
506 // is called. This way, before the UI calls SetDecryptionPassphrase on the | 487 // is called. This way, before the UI calls SetDecryptionPassphrase on the |
507 // syncer, it can avoid the overhead of an asynchronous decryption call and | 488 // syncer, it can avoid the overhead of an asynchronous decryption call and |
508 // give the user immediate feedback about the passphrase entered by first | 489 // give the user immediate feedback about the passphrase entered by first |
509 // trying to decrypt the cached pending keys on the UI thread. Note that | 490 // trying to decrypt the cached pending keys on the UI thread. Note that |
510 // SetDecryptionPassphrase can still fail after the cached pending keys are | 491 // SetDecryptionPassphrase can still fail after the cached pending keys are |
511 // successfully decrypted if the pending keys have changed since the time they | 492 // successfully decrypted if the pending keys have changed since the time they |
512 // were cached. | 493 // were cached. |
513 sync_pb::EncryptedData cached_pending_keys_; | 494 sync_pb::EncryptedData cached_pending_keys_; |
514 | 495 |
515 // UI-thread cache of the last SyncSessionSnapshot received from syncapi. | 496 // UI-thread cache of the last SyncSessionSnapshot received from syncapi. |
516 syncer::sessions::SyncSessionSnapshot last_snapshot_; | 497 syncer::sessions::SyncSessionSnapshot last_snapshot_; |
517 | 498 |
518 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); | 499 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); |
519 }; | 500 }; |
520 | 501 |
521 } // namespace browser_sync | 502 } // namespace browser_sync |
522 | 503 |
523 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ | 504 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ |
OLD | NEW |