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

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

Issue 10483015: [Sync] Refactor sync configuration logic. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 6 months 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 #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
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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 bool delete_sync_data_folder; 322 bool delete_sync_data_folder;
327 std::string restored_key_for_bootstrapping; 323 std::string restored_key_for_bootstrapping;
328 sync_api::SyncManager::TestingMode testing_mode; 324 sync_api::SyncManager::TestingMode testing_mode;
329 UnrecoverableErrorHandler* unrecoverable_error_handler; 325 UnrecoverableErrorHandler* unrecoverable_error_handler;
330 ReportUnrecoverableErrorFunction report_unrecoverable_error_function; 326 ReportUnrecoverableErrorFunction report_unrecoverable_error_function;
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 // Request the syncer to reconfigure with the specfied params.
337 // thread components. 333 // Virtual for testing.
338 void HandleSyncCycleCompletedOnFrontendLoop( 334 virtual void RequestConfigureSyncer(
339 const sessions::SyncSessionSnapshot& snapshot); 335 sync_api::ConfigureReason reason,
336 syncable::ModelTypeSet types_to_config,
337 const browser_sync::ModelSafeRoutingInfo routing_info,
338 const base::Callback<void(syncable::ModelTypeSet)>& ready_task,
339 const base::Closure& retry_callback);
340 340
341 // Called to finish the job of ConfigureDataTypes once the syncer is in 341 // Called when the syncer has finished performing a configuration.
342 // configuration mode. 342 void FinishConfigureDataTypesOnFrontendLoop(
343 void FinishConfigureDataTypesOnFrontendLoop(); 343 const syncable::ModelTypeSet& types_to_configure,
344 344 const syncable::ModelTypeSet& configured_types,
345 bool IsDownloadingNigoriForTest() const; 345 const base::Callback<void(syncable::ModelTypeSet)>& ready_task);
346 346
347 private: 347 private:
348 // The real guts of SyncBackendHost, to keep the public client API clean. 348 // The real guts of SyncBackendHost, to keep the public client API clean.
349 class Core; 349 class Core;
350 350
351 // An enum representing the steps to initializing the SyncBackendHost. 351 // An enum representing the steps to initializing the SyncBackendHost.
352 enum InitializationState { 352 enum InitializationState {
353 NOT_ATTEMPTED, 353 NOT_ATTEMPTED,
354 CREATING_SYNC_MANAGER, // We're waiting for the first callback from the 354 CREATING_SYNC_MANAGER, // We're waiting for the first callback from the
355 // sync thread to inform us that the sync manager 355 // sync thread to inform us that the sync manager
356 // has been created. 356 // has been created.
357 NOT_INITIALIZED, // Initialization hasn't completed, but we've 357 NOT_INITIALIZED, // Initialization hasn't completed, but we've
358 // constructed a SyncManager. 358 // constructed a SyncManager.
359 DOWNLOADING_NIGORI, // The SyncManager is initialized, but 359 DOWNLOADING_NIGORI, // The SyncManager is initialized, but
360 // we're fetching encryption information. 360 // we're fetching encryption information.
361 REFRESHING_NIGORI, // The SyncManager is initialized, and we 361 REFRESHING_NIGORI, // The SyncManager is initialized, and we
362 // have the encryption information, but we 362 // have the encryption information, but we
363 // still need to refresh encryption. Also, we need 363 // still need to refresh encryption. Also, we need
364 // to update the device information in the nigori. 364 // to update the device information in the nigori.
365 INITIALIZED, // Initialization is complete. 365 INITIALIZED, // Initialization is complete.
366 }; 366 };
367 367
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 368 // 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. 369 // (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. 370 // Note: it is illegal to call this before the backend is initialized.
397 void AddExperimentalTypes(); 371 void AddExperimentalTypes();
398 372
399 // Downloading of nigori failed and will be retried. 373 // Downloading of nigori failed and will be retried.
400 virtual void OnNigoriDownloadRetry(); 374 void OnNigoriDownloadRetry();
401 375
402 // InitializationComplete passes through the SyncBackendHost to forward 376 // InitializationComplete passes through the SyncBackendHost to forward
403 // on to |frontend_|, and so that tests can intercept here if they need to 377 // on to |frontend_|, and so that tests can intercept here if they need to
404 // set up initial conditions. 378 // set up initial conditions.
405 virtual void HandleInitializationCompletedOnFrontendLoop( 379 void HandleInitializationCompletedOnFrontendLoop(
406 const WeakHandle<JsBackend>& js_backend, 380 const WeakHandle<JsBackend>& js_backend,
407 bool success); 381 bool success);
408 382
383 // Called from Core::OnSyncCycleCompleted to handle updating frontend
384 // thread components.
385 void HandleSyncCycleCompletedOnFrontendLoop(
386 const sessions::SyncSessionSnapshot& snapshot);
387
388 // Called when the syncer failed to perform a configuration and will
389 // eventually retry. FinishingConfigurationOnFrontendLoop(..) will be called
390 // on successful completion.
391 void RetryConfigurationOnFrontendLoop(
392 const base::Closure& retry_callback);
393
409 // Helpers to persist a token that can be used to bootstrap sync encryption 394 // Helpers to persist a token that can be used to bootstrap sync encryption
410 // across browser restart to avoid requiring the user to re-enter their 395 // across browser restart to avoid requiring the user to re-enter their
411 // passphrase. |token| must be valid UTF-8 as we use the PrefService for 396 // passphrase. |token| must be valid UTF-8 as we use the PrefService for
412 // storage. 397 // storage.
413 void PersistEncryptionBootstrapToken(const std::string& token); 398 void PersistEncryptionBootstrapToken(const std::string& token);
414 399
415 // For convenience, checks if initialization state is INITIALIZED. 400 // For convenience, checks if initialization state is INITIALIZED.
416 bool initialized() const { return initialization_state_ == INITIALIZED; } 401 bool initialized() const { return initialization_state_ == INITIALIZED; }
417 402
418 // Let the front end handle the actionable error event. 403 // Let the front end handle the actionable error event.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 487
503 sync_notifier::SyncNotifierFactory sync_notifier_factory_; 488 sync_notifier::SyncNotifierFactory sync_notifier_factory_;
504 489
505 ChromeExtensionsActivityMonitor extensions_activity_monitor_; 490 ChromeExtensionsActivityMonitor extensions_activity_monitor_;
506 491
507 scoped_ptr<SyncBackendRegistrar> registrar_; 492 scoped_ptr<SyncBackendRegistrar> registrar_;
508 493
509 // The frontend which we serve (and are owned by). 494 // The frontend which we serve (and are owned by).
510 SyncFrontend* frontend_; 495 SyncFrontend* frontend_;
511 496
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 497 // We cache the cryptographer's pending keys whenever NotifyPassphraseRequired
516 // is called. This way, before the UI calls SetDecryptionPassphrase on the 498 // is called. This way, before the UI calls SetDecryptionPassphrase on the
517 // syncer, it can avoid the overhead of an asynchronous decryption call and 499 // syncer, it can avoid the overhead of an asynchronous decryption call and
518 // give the user immediate feedback about the passphrase entered by first 500 // 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 501 // trying to decrypt the cached pending keys on the UI thread. Note that
520 // SetDecryptionPassphrase can still fail after the cached pending keys are 502 // SetDecryptionPassphrase can still fail after the cached pending keys are
521 // successfully decrypted if the pending keys have changed since the time they 503 // successfully decrypted if the pending keys have changed since the time they
522 // were cached. 504 // were cached.
523 sync_pb::EncryptedData cached_pending_keys_; 505 sync_pb::EncryptedData cached_pending_keys_;
524 506
525 // UI-thread cache of the last SyncSessionSnapshot received from syncapi. 507 // UI-thread cache of the last SyncSessionSnapshot received from syncapi.
526 sessions::SyncSessionSnapshot last_snapshot_; 508 sessions::SyncSessionSnapshot last_snapshot_;
527 509
528 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); 510 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost);
529 }; 511 };
530 512
531 } // namespace browser_sync 513 } // namespace browser_sync
532 514
533 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ 515 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698