Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 // for creating transactions. | 224 // for creating transactions. |
| 225 sync_api::UserShare* GetUserShare() const; | 225 sync_api::UserShare* GetUserShare() const; |
| 226 | 226 |
| 227 // Called from any thread to obtain current status information in detailed or | 227 // Called from any thread to obtain current status information in detailed or |
| 228 // summarized form. | 228 // summarized form. |
| 229 Status GetDetailedStatus(); | 229 Status GetDetailedStatus(); |
| 230 StatusSummary GetStatusSummary(); | 230 StatusSummary GetStatusSummary(); |
| 231 const GoogleServiceAuthError& GetAuthError() const; | 231 const GoogleServiceAuthError& GetAuthError() const; |
| 232 const sessions::SyncSessionSnapshot* GetLastSessionSnapshot() const; | 232 const sessions::SyncSessionSnapshot* GetLastSessionSnapshot() const; |
| 233 | 233 |
| 234 const FilePath& sync_data_folder_path() const { | |
| 235 return sync_data_folder_path_; | |
| 236 } | |
| 237 | |
| 238 // Determines if the underlying sync engine has made any local changes to | 234 // Determines if the underlying sync engine has made any local changes to |
| 239 // items that have not yet been synced with the server. | 235 // items that have not yet been synced with the server. |
| 240 // ONLY CALL THIS IF OnInitializationComplete was called! | 236 // ONLY CALL THIS IF OnInitializationComplete was called! |
| 241 bool HasUnsyncedItems() const; | 237 bool HasUnsyncedItems() const; |
| 242 | 238 |
| 243 // Whether or not we are syncing encryption keys. | 239 // Whether or not we are syncing encryption keys. |
| 244 bool IsNigoriEnabled() const; | 240 bool IsNigoriEnabled() const; |
| 245 | 241 |
| 246 // Whether or not the Nigori node is encrypted using an explicit passphrase. | 242 // Whether or not the Nigori node is encrypted using an explicit passphrase. |
| 247 bool IsUsingExplicitPassphrase(); | 243 bool IsUsingExplicitPassphrase(); |
| 248 | 244 |
| 249 // True if the cryptographer has any keys available to attempt decryption. | 245 // True if the cryptographer has any keys available to attempt decryption. |
| 250 // Could mean we've downloaded and loaded Nigori objects, or we bootstrapped | 246 // Could mean we've downloaded and loaded Nigori objects, or we bootstrapped |
| 251 // using a token previously received. | 247 // using a token previously received. |
| 252 bool IsCryptographerReady(const sync_api::BaseTransaction* trans) const; | 248 bool IsCryptographerReady(const sync_api::BaseTransaction* trans) const; |
| 253 | 249 |
| 254 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) const; | 250 void GetModelSafeRoutingInfo(ModelSafeRoutingInfo* out) const; |
| 255 | 251 |
| 256 protected: | 252 protected: |
| 253 // The types and functions below are protected so that test | |
| 254 // subclasses can use them. | |
| 255 // | |
| 256 // TODO(akalin): Figure out a better way for tests to hook into | |
| 257 // SyncBackendHost. | |
| 258 | |
| 257 // An enum representing the steps to initializing the SyncBackendHost. | 259 // An enum representing the steps to initializing the SyncBackendHost. |
| 258 enum InitializationState { | 260 enum InitializationState { |
| 259 NOT_ATTEMPTED, | 261 NOT_ATTEMPTED, |
| 260 CREATING_SYNC_MANAGER, // We're waiting for the first callback from the | 262 CREATING_SYNC_MANAGER, // We're waiting for the first callback from the |
| 261 // sync thread to inform us that the sync manager | 263 // sync thread to inform us that the sync manager |
| 262 // has been created. | 264 // has been created. |
| 263 NOT_INITIALIZED, // Initialization hasn't completed, but we've | 265 NOT_INITIALIZED, // Initialization hasn't completed, but we've |
| 264 // constructed a SyncManager. | 266 // constructed a SyncManager. |
| 265 DOWNLOADING_NIGORI, // The SyncManager is initialized, but | 267 DOWNLOADING_NIGORI, // The SyncManager is initialized, but |
| 266 // we're fetching encryption information. | 268 // we're fetching encryption information. |
| 267 REFRESHING_ENCRYPTION, // The SyncManager is initialized, and we | 269 REFRESHING_ENCRYPTION, // The SyncManager is initialized, and we |
| 268 // have the encryption information, but we | 270 // have the encryption information, but we |
| 269 // still need to refresh encryption. | 271 // still need to refresh encryption. |
| 270 INITIALIZED, // Initialization is complete. | 272 INITIALIZED, // Initialization is complete. |
| 271 }; | 273 }; |
| 272 | 274 |
| 275 typedef base::Callback<sync_api::HttpPostProviderFactory*(void)> | |
| 276 MakeHttpBridgeFactoryFn; | |
| 277 | |
| 278 struct DoInitializeOptions { | |
| 279 DoInitializeOptions( | |
| 280 MessageLoop* sync_loop, | |
| 281 SyncBackendRegistrar* registrar, | |
| 282 const WeakHandle<JsEventHandler>& event_handler, | |
| 283 const GURL& service_url, | |
| 284 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, | |
| 285 const sync_api::SyncCredentials& credentials, | |
| 286 sync_notifier::SyncNotifierFactory* sync_notifier_factory, | |
| 287 bool delete_sync_data_folder, | |
| 288 const std::string& restored_key_for_bootstrapping, | |
| 289 bool setup_for_test_mode); | |
| 290 ~DoInitializeOptions(); | |
| 291 | |
| 292 MessageLoop* sync_loop; | |
| 293 SyncBackendRegistrar* registrar; | |
| 294 WeakHandle<JsEventHandler> event_handler; | |
| 295 GURL service_url; | |
| 296 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn; | |
| 297 sync_api::SyncCredentials credentials; | |
| 298 sync_notifier::SyncNotifierFactory* const sync_notifier_factory; | |
| 299 std::string lsid; | |
| 300 bool delete_sync_data_folder; | |
| 301 std::string restored_key_for_bootstrapping; | |
| 302 bool setup_for_test_mode; | |
| 303 }; | |
| 304 | |
| 305 // Allows tests to perform alternate core initialization work. | |
| 306 virtual void InitCore(const DoInitializeOptions& options); | |
| 307 | |
| 308 // Called from Core::OnSyncCycleCompleted to handle updating frontend | |
| 309 // thread components. | |
| 310 void HandleSyncCycleCompletedOnFrontendLoop( | |
| 311 sessions::SyncSessionSnapshot* snapshot); | |
| 312 | |
| 313 // Called to finish the job of ConfigureDataTypes once the syncer is in | |
| 314 // configuration mode. | |
| 315 void FinishConfigureDataTypesOnFrontendLoop(); | |
| 316 | |
| 317 InitializationState initialization_state_; | |
|
Nicolas Zea
2011/12/14 20:37:25
I think style guide prefers private member, protec
akalin
2011/12/15 01:21:05
Done. Actually only really need to check whether
| |
| 318 | |
| 319 private: | |
| 273 // The real guts of SyncBackendHost, to keep the public client API clean. | 320 // The real guts of SyncBackendHost, to keep the public client API clean. |
| 274 class Core : public base::RefCountedThreadSafe<SyncBackendHost::Core>, | 321 class Core : public base::RefCountedThreadSafe<SyncBackendHost::Core>, |
| 275 public sync_api::SyncManager::Observer { | 322 public sync_api::SyncManager::Observer { |
| 276 public: | 323 public: |
| 277 Core(const std::string& name, SyncBackendHost* backend); | 324 Core(const std::string& name, |
| 325 const FilePath& sync_data_folder_path, | |
| 326 const base::WeakPtr<SyncBackendHost>& backend); | |
| 278 | 327 |
| 279 // SyncManager::Observer implementation. The Core just acts like an air | 328 // SyncManager::Observer implementation. The Core just acts like an air |
| 280 // traffic controller here, forwarding incoming messages to appropriate | 329 // traffic controller here, forwarding incoming messages to appropriate |
| 281 // landing threads. | 330 // landing threads. |
| 282 virtual void OnSyncCycleCompleted( | 331 virtual void OnSyncCycleCompleted( |
| 283 const sessions::SyncSessionSnapshot* snapshot) OVERRIDE; | 332 const sessions::SyncSessionSnapshot* snapshot) OVERRIDE; |
| 284 virtual void OnInitializationComplete( | 333 virtual void OnInitializationComplete( |
| 285 const WeakHandle<JsBackend>& js_backend, | 334 const WeakHandle<JsBackend>& js_backend, |
| 286 bool success) OVERRIDE; | 335 bool success) OVERRIDE; |
| 287 virtual void OnAuthError( | 336 virtual void OnAuthError( |
| 288 const GoogleServiceAuthError& auth_error) OVERRIDE; | 337 const GoogleServiceAuthError& auth_error) OVERRIDE; |
| 289 virtual void OnPassphraseRequired( | 338 virtual void OnPassphraseRequired( |
| 290 sync_api::PassphraseRequiredReason reason) OVERRIDE; | 339 sync_api::PassphraseRequiredReason reason) OVERRIDE; |
| 291 virtual void OnPassphraseAccepted( | 340 virtual void OnPassphraseAccepted( |
| 292 const std::string& bootstrap_token) OVERRIDE; | 341 const std::string& bootstrap_token) OVERRIDE; |
| 293 virtual void OnStopSyncingPermanently() OVERRIDE; | 342 virtual void OnStopSyncingPermanently() OVERRIDE; |
| 294 virtual void OnUpdatedToken(const std::string& token) OVERRIDE; | 343 virtual void OnUpdatedToken(const std::string& token) OVERRIDE; |
| 295 virtual void OnClearServerDataFailed() OVERRIDE; | 344 virtual void OnClearServerDataFailed() OVERRIDE; |
| 296 virtual void OnClearServerDataSucceeded() OVERRIDE; | 345 virtual void OnClearServerDataSucceeded() OVERRIDE; |
| 297 virtual void OnEncryptedTypesChanged( | 346 virtual void OnEncryptedTypesChanged( |
| 298 syncable::ModelTypeSet encrypted_types, | 347 syncable::ModelTypeSet encrypted_types, |
| 299 bool encrypt_everything) OVERRIDE; | 348 bool encrypt_everything) OVERRIDE; |
| 300 virtual void OnEncryptionComplete() OVERRIDE; | 349 virtual void OnEncryptionComplete() OVERRIDE; |
| 301 virtual void OnActionableError( | 350 virtual void OnActionableError( |
| 302 const browser_sync::SyncProtocolError& sync_error) OVERRIDE; | 351 const browser_sync::SyncProtocolError& sync_error) OVERRIDE; |
| 303 | 352 |
| 304 struct DoInitializeOptions { | |
| 305 DoInitializeOptions( | |
| 306 MessageLoop* sync_loop, | |
| 307 SyncBackendRegistrar* registrar, | |
| 308 const WeakHandle<JsEventHandler>& event_handler, | |
| 309 const GURL& service_url, | |
| 310 const scoped_refptr<net::URLRequestContextGetter>& | |
| 311 request_context_getter, | |
| 312 const sync_api::SyncCredentials& credentials, | |
| 313 bool delete_sync_data_folder, | |
| 314 const std::string& restored_key_for_bootstrapping, | |
| 315 bool setup_for_test_mode); | |
| 316 ~DoInitializeOptions(); | |
| 317 | |
| 318 MessageLoop* sync_loop; | |
| 319 SyncBackendRegistrar* registrar; | |
| 320 WeakHandle<JsEventHandler> event_handler; | |
| 321 GURL service_url; | |
| 322 scoped_refptr<net::URLRequestContextGetter> request_context_getter; | |
| 323 sync_api::SyncCredentials credentials; | |
| 324 std::string lsid; | |
| 325 bool delete_sync_data_folder; | |
| 326 std::string restored_key_for_bootstrapping; | |
| 327 bool setup_for_test_mode; | |
| 328 }; | |
| 329 | |
| 330 // Note: | 353 // Note: |
| 331 // | 354 // |
| 332 // The Do* methods are the various entry points from our | 355 // The Do* methods are the various entry points from our |
| 333 // SyncBackendHost. They are all called on the sync thread to | 356 // SyncBackendHost. They are all called on the sync thread to |
| 334 // actually perform synchronous (and potentially blocking) syncapi | 357 // actually perform synchronous (and potentially blocking) syncapi |
| 335 // operations. | 358 // operations. |
| 336 // | 359 // |
| 337 // Called to perform initialization of the syncapi on behalf of | 360 // Called to perform initialization of the syncapi on behalf of |
| 338 // SyncBackendHost::Initialize. | 361 // SyncBackendHost::Initialize. |
| 339 void DoInitialize(const DoInitializeOptions& options); | 362 void DoInitialize(const DoInitializeOptions& options); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 400 sync_api::SyncManager* sync_manager() { return sync_manager_.get(); } | 423 sync_api::SyncManager* sync_manager() { return sync_manager_.get(); } |
| 401 | 424 |
| 402 // Delete the sync data folder to cleanup backend data. Happens the first | 425 // Delete the sync data folder to cleanup backend data. Happens the first |
| 403 // time sync is enabled for a user (to prevent accidentally reusing old | 426 // time sync is enabled for a user (to prevent accidentally reusing old |
| 404 // sync databases), as well as shutdown when you're no longer syncing. | 427 // sync databases), as well as shutdown when you're no longer syncing. |
| 405 void DeleteSyncDataFolder(); | 428 void DeleteSyncDataFolder(); |
| 406 | 429 |
| 407 // A callback from the SyncerThread when it is safe to continue config. | 430 // A callback from the SyncerThread when it is safe to continue config. |
| 408 void FinishConfigureDataTypes(); | 431 void FinishConfigureDataTypes(); |
| 409 | 432 |
| 410 // Called to handle updating frontend thread components whenever we may | |
| 411 // need to alert the frontend that the backend is intialized. | |
| 412 void HandleInitializationCompletedOnFrontendLoop( | |
| 413 const WeakHandle<JsBackend>& js_backend, | |
| 414 bool success); | |
| 415 | |
| 416 // Called when configuration of the Nigori node has completed as | |
| 417 // part of the initialization process. | |
| 418 void HandleNigoriConfigurationCompletedOnFrontendLoop( | |
| 419 const WeakHandle<JsBackend>& js_backend, | |
| 420 syncable::ModelTypeSet failed_configuration_types); | |
| 421 | |
| 422 private: | 433 private: |
| 423 friend class base::RefCountedThreadSafe<SyncBackendHost::Core>; | 434 friend class base::RefCountedThreadSafe<SyncBackendHost::Core>; |
| 424 friend class SyncBackendHostForProfileSyncTest; | 435 friend class SyncBackendHostForProfileSyncTest; |
| 425 | 436 |
| 426 virtual ~Core(); | 437 virtual ~Core(); |
| 427 | 438 |
| 428 // Invoked when initialization of syncapi is complete and we can start | 439 // Invoked when initialization of syncapi is complete and we can start |
| 429 // our timer. | 440 // our timer. |
| 430 // This must be called from the thread on which SaveChanges is intended to | 441 // This must be called from the thread on which SaveChanges is intended to |
| 431 // be run on; the host's |sync_thread_|. | 442 // be run on; the host's |sync_thread_|. |
| 432 void StartSavingChanges(); | 443 void StartSavingChanges(); |
| 433 | 444 |
| 434 // Invoked periodically to tell the syncapi to persist its state | 445 // Invoked periodically to tell the syncapi to persist its state |
| 435 // by writing to disk. | 446 // by writing to disk. |
| 436 // This is called from the thread we were created on (which is the | 447 // This is called from the thread we were created on (which is the |
| 437 // SyncBackendHost |sync_thread_|), using a repeating timer that is kicked | 448 // SyncBackendHost |sync_thread_|), using a repeating timer that is kicked |
| 438 // off as soon as the SyncManager tells us it completed | 449 // off as soon as the SyncManager tells us it completed |
| 439 // initialization. | 450 // initialization. |
| 440 void SaveChanges(); | 451 void SaveChanges(); |
| 441 | 452 |
| 442 // Let the front end handle the actionable error event. | |
| 443 void HandleActionableErrorEventOnFrontendLoop( | |
| 444 const browser_sync::SyncProtocolError& sync_error); | |
| 445 | |
| 446 // Dispatched to from OnAuthError to handle updating frontend UI | |
| 447 // components. | |
| 448 void HandleAuthErrorEventOnFrontendLoop( | |
| 449 const GoogleServiceAuthError& new_auth_error); | |
| 450 | |
| 451 // Invoked when a passphrase is required to decrypt a set of Nigori keys, | |
| 452 // or for encrypting. |reason| denotes why the passhrase was required. | |
| 453 void NotifyPassphraseRequired(sync_api::PassphraseRequiredReason reason); | |
| 454 | |
| 455 // Invoked when the passphrase provided by the user has been accepted. | |
| 456 void NotifyPassphraseAccepted(const std::string& bootstrap_token); | |
| 457 | |
| 458 // Invoked when an updated token is available from the sync server. | |
| 459 void NotifyUpdatedToken(const std::string& token); | |
| 460 | |
| 461 // Invoked when the set of encrypted types or the encrypt | |
| 462 // everything flag changes. | |
| 463 void NotifyEncryptedTypesChanged( | |
| 464 syncable::ModelTypeSet encrypted_types, | |
| 465 bool encrypt_everything); | |
| 466 | |
| 467 // Invoked when sync finishes encrypting new datatypes. | |
| 468 void NotifyEncryptionComplete(); | |
| 469 | |
| 470 // Called from Core::OnSyncCycleCompleted to handle updating frontend | |
| 471 // thread components. | |
| 472 void HandleSyncCycleCompletedOnFrontendLoop( | |
| 473 sessions::SyncSessionSnapshot* snapshot); | |
| 474 | |
| 475 void HandleStopSyncingPermanentlyOnFrontendLoop(); | |
| 476 | |
| 477 // Called to handle success/failure of clearing server data | |
| 478 void HandleClearServerDataSucceededOnFrontendLoop(); | |
| 479 void HandleClearServerDataFailedOnFrontendLoop(); | |
| 480 | |
| 481 void FinishConfigureDataTypesOnFrontendLoop(); | |
| 482 | |
| 483 // Name used for debugging. | 453 // Name used for debugging. |
| 484 const std::string name_; | 454 const std::string name_; |
| 485 | 455 |
| 486 // Our parent SyncBackendHost | 456 // Path of the folder that stores the sync data files. |
| 487 SyncBackendHost* host_; | 457 const FilePath sync_data_folder_path_; |
| 458 | |
| 459 // Our parent SyncBackendHost. | |
| 460 WeakHandle<SyncBackendHost> host_; | |
| 488 | 461 |
| 489 // The loop where all the sync backend operations happen. | 462 // The loop where all the sync backend operations happen. |
| 490 // Non-NULL only between calls to DoInitialize() and DoShutdown(). | 463 // Non-NULL only between calls to DoInitialize() and DoShutdown(). |
| 491 MessageLoop* sync_loop_; | 464 MessageLoop* sync_loop_; |
| 492 | 465 |
| 493 // Our parent's registrar (not owned). Non-NULL only between | 466 // Our parent's registrar (not owned). Non-NULL only between |
| 494 // calls to DoInitialize() and DoShutdown(). | 467 // calls to DoInitialize() and DoShutdown(). |
| 495 SyncBackendRegistrar* registrar_; | 468 SyncBackendRegistrar* registrar_; |
| 496 | 469 |
| 497 // The timer used to periodically call SaveChanges. | 470 // The timer used to periodically call SaveChanges. |
| 498 base::RepeatingTimer<Core> save_changes_timer_; | 471 base::RepeatingTimer<Core> save_changes_timer_; |
| 499 | 472 |
| 500 // The top-level syncapi entry point. Lives on the sync thread. | 473 // The top-level syncapi entry point. Lives on the sync thread. |
| 501 scoped_ptr<sync_api::SyncManager> sync_manager_; | 474 scoped_ptr<sync_api::SyncManager> sync_manager_; |
| 502 | 475 |
| 503 DISALLOW_COPY_AND_ASSIGN(Core); | 476 DISALLOW_COPY_AND_ASSIGN(Core); |
| 504 }; | 477 }; |
| 505 | 478 |
| 479 struct PendingConfigureDataTypesState { | |
| 480 PendingConfigureDataTypesState(); | |
| 481 ~PendingConfigureDataTypesState(); | |
| 482 | |
| 483 // The ready_task will be run when configuration is done with the | |
| 484 // set of all types that failed configuration (i.e., if its | |
| 485 // argument is non-empty, then an error was encountered). | |
| 486 base::Callback<void(syncable::ModelTypeSet)> ready_task; | |
| 487 | |
| 488 // The set of types that we are waiting to be initially synced in a | |
| 489 // configuration cycle. | |
| 490 syncable::ModelTypeSet types_to_add; | |
| 491 | |
| 492 // Additional details about which types were added. | |
| 493 syncable::ModelTypeSet added_types; | |
| 494 sync_api::ConfigureReason reason; | |
| 495 }; | |
| 496 | |
| 506 // Checks if we have received a notice to turn on experimental datatypes | 497 // Checks if we have received a notice to turn on experimental datatypes |
| 507 // (via the nigori node) and informs the frontend if that is the case. | 498 // (via the nigori node) and informs the frontend if that is the case. |
| 508 // Note: it is illegal to call this before the backend is initialized. | 499 // Note: it is illegal to call this before the backend is initialized. |
| 509 void AddExperimentalTypes(); | 500 void AddExperimentalTypes(); |
| 510 | 501 |
| 511 // InitializationComplete passes through the SyncBackendHost to forward | 502 // InitializationComplete passes through the SyncBackendHost to forward |
| 512 // on to |frontend_|, and so that tests can intercept here if they need to | 503 // on to |frontend_|, and so that tests can intercept here if they need to |
| 513 // set up initial conditions. | 504 // set up initial conditions. |
| 514 virtual void HandleInitializationCompletedOnFrontendLoop( | 505 virtual void HandleInitializationCompletedOnFrontendLoop( |
| 515 const WeakHandle<JsBackend>& js_backend, | 506 const WeakHandle<JsBackend>& js_backend, |
| 516 bool success); | 507 bool success); |
| 517 | 508 |
| 518 // Called to finish the job of ConfigureDataTypes once the syncer is in | |
| 519 // configuration mode. | |
| 520 void FinishConfigureDataTypesOnFrontendLoop(); | |
| 521 | |
| 522 // Allows tests to perform alternate core initialization work. | |
| 523 virtual void InitCore(const Core::DoInitializeOptions& options); | |
| 524 | |
| 525 // Factory method for HttpPostProviderFactories. Should be | |
| 526 // thread-safe. | |
| 527 virtual sync_api::HttpPostProviderFactory* MakeHttpBridgeFactory( | |
| 528 const scoped_refptr<net::URLRequestContextGetter>& getter); | |
| 529 | |
| 530 // Helpers to persist a token that can be used to bootstrap sync encryption | 509 // Helpers to persist a token that can be used to bootstrap sync encryption |
| 531 // across browser restart to avoid requiring the user to re-enter their | 510 // across browser restart to avoid requiring the user to re-enter their |
| 532 // passphrase. |token| must be valid UTF-8 as we use the PrefService for | 511 // passphrase. |token| must be valid UTF-8 as we use the PrefService for |
| 533 // storage. | 512 // storage. |
| 534 void PersistEncryptionBootstrapToken(const std::string& token); | 513 void PersistEncryptionBootstrapToken(const std::string& token); |
| 535 | 514 |
| 536 // Our core, which communicates directly to the syncapi. | |
| 537 scoped_refptr<Core> core_; | |
| 538 | |
| 539 InitializationState initialization_state_; | |
| 540 | |
| 541 private: | |
| 542 struct PendingConfigureDataTypesState { | |
| 543 PendingConfigureDataTypesState(); | |
| 544 ~PendingConfigureDataTypesState(); | |
| 545 | |
| 546 // The ready_task will be run when configuration is done with the | |
| 547 // set of all types that failed configuration (i.e., if its | |
| 548 // argument is non-empty, then an error was encountered). | |
| 549 base::Callback<void(syncable::ModelTypeSet)> ready_task; | |
| 550 | |
| 551 // The set of types that we are waiting to be initially synced in a | |
| 552 // configuration cycle. | |
| 553 syncable::ModelTypeSet types_to_add; | |
| 554 | |
| 555 // Additional details about which types were added. | |
| 556 syncable::ModelTypeSet added_types; | |
| 557 sync_api::ConfigureReason reason; | |
| 558 }; | |
| 559 | |
| 560 // For convenience, checks if initialization state is INITIALIZED. | 515 // For convenience, checks if initialization state is INITIALIZED. |
| 561 bool initialized() const { return initialization_state_ == INITIALIZED; } | 516 bool initialized() const { return initialization_state_ == INITIALIZED; } |
| 562 | 517 |
| 518 // Let the front end handle the actionable error event. | |
| 519 void HandleActionableErrorEventOnFrontendLoop( | |
| 520 const browser_sync::SyncProtocolError& sync_error); | |
| 521 | |
| 522 // Invoked when a passphrase is required to decrypt a set of Nigori keys, | |
| 523 // or for encrypting. |reason| denotes why the passhrase was required. | |
| 524 void NotifyPassphraseRequired(sync_api::PassphraseRequiredReason reason); | |
| 525 | |
| 526 // Invoked when the passphrase provided by the user has been accepted. | |
| 527 void NotifyPassphraseAccepted(const std::string& bootstrap_token); | |
| 528 | |
| 529 // Invoked when an updated token is available from the sync server. | |
| 530 void NotifyUpdatedToken(const std::string& token); | |
| 531 | |
| 532 // Invoked when the set of encrypted types or the encrypt | |
| 533 // everything flag changes. | |
| 534 void NotifyEncryptedTypesChanged( | |
| 535 syncable::ModelTypeSet encrypted_types, | |
| 536 bool encrypt_everything); | |
| 537 | |
| 538 // Invoked when sync finishes encrypting new datatypes. | |
| 539 void NotifyEncryptionComplete(); | |
| 540 | |
| 541 void HandleStopSyncingPermanentlyOnFrontendLoop(); | |
| 542 | |
| 543 // Called to handle success/failure of clearing server data | |
| 544 void HandleClearServerDataSucceededOnFrontendLoop(); | |
| 545 void HandleClearServerDataFailedOnFrontendLoop(); | |
| 546 | |
| 547 // Dispatched to from OnAuthError to handle updating frontend UI | |
| 548 // components. | |
| 549 void HandleAuthErrorEventOnFrontendLoop( | |
| 550 const GoogleServiceAuthError& new_auth_error); | |
| 551 | |
| 552 // Called when configuration of the Nigori node has completed as | |
| 553 // part of the initialization process. | |
| 554 void HandleNigoriConfigurationCompletedOnFrontendLoop( | |
| 555 const WeakHandle<JsBackend>& js_backend, | |
| 556 syncable::ModelTypeSet failed_configuration_types); | |
| 557 | |
| 563 // Must be called on |frontend_loop_|. |done_callback| is called on | 558 // Must be called on |frontend_loop_|. |done_callback| is called on |
| 564 // |frontend_loop_|. | 559 // |frontend_loop_|. |
| 565 void RefreshEncryption(const base::Closure& done_callback); | 560 void RefreshEncryption(const base::Closure& done_callback); |
| 566 | 561 |
| 567 // Handles stopping the core's SyncManager, accounting for whether | 562 // Handles stopping the core's SyncManager, accounting for whether |
| 568 // initialization is done yet. | 563 // initialization is done yet. |
| 569 void StopSyncManagerForShutdown(const base::Closure& closure); | 564 void StopSyncManagerForShutdown(const base::Closure& closure); |
| 570 | 565 |
| 566 base::WeakPtrFactory<SyncBackendHost> weak_ptr_factory_; | |
| 567 | |
| 571 // A thread where all the sync operations happen. | 568 // A thread where all the sync operations happen. |
| 572 base::Thread sync_thread_; | 569 base::Thread sync_thread_; |
| 573 | 570 |
| 574 // A reference to the MessageLoop used to construct |this|, so we know how | 571 // A reference to the MessageLoop used to construct |this|, so we know how |
| 575 // to safely talk back to the SyncFrontend. | 572 // to safely talk back to the SyncFrontend. |
| 576 MessageLoop* const frontend_loop_; | 573 MessageLoop* const frontend_loop_; |
| 577 | 574 |
| 578 Profile* const profile_; | 575 Profile* const profile_; |
| 579 | 576 |
| 580 const base::WeakPtr<SyncPrefs> sync_prefs_; | |
| 581 | |
| 582 // Name used for debugging (set from profile_->GetDebugName()). | 577 // Name used for debugging (set from profile_->GetDebugName()). |
| 583 const std::string name_; | 578 const std::string name_; |
| 584 | 579 |
| 580 // Our core, which communicates directly to the syncapi. | |
| 581 scoped_refptr<Core> core_; | |
| 582 | |
| 583 const base::WeakPtr<SyncPrefs> sync_prefs_; | |
| 584 | |
| 585 sync_notifier::SyncNotifierFactory sync_notifier_factory_; | 585 sync_notifier::SyncNotifierFactory sync_notifier_factory_; |
| 586 | 586 |
| 587 scoped_ptr<SyncBackendRegistrar> registrar_; | 587 scoped_ptr<SyncBackendRegistrar> registrar_; |
| 588 | 588 |
| 589 // The frontend which we serve (and are owned by). | 589 // The frontend which we serve (and are owned by). |
| 590 SyncFrontend* frontend_; | 590 SyncFrontend* frontend_; |
| 591 | 591 |
| 592 // Path of the folder that stores the sync data files. | |
| 593 FilePath sync_data_folder_path_; | |
| 594 | |
| 595 scoped_ptr<PendingConfigureDataTypesState> pending_download_state_; | 592 scoped_ptr<PendingConfigureDataTypesState> pending_download_state_; |
| 596 scoped_ptr<PendingConfigureDataTypesState> pending_config_mode_state_; | 593 scoped_ptr<PendingConfigureDataTypesState> pending_config_mode_state_; |
| 597 | 594 |
| 598 // UI-thread cache of the last AuthErrorState received from syncapi. | 595 // UI-thread cache of the last AuthErrorState received from syncapi. |
| 599 GoogleServiceAuthError last_auth_error_; | 596 GoogleServiceAuthError last_auth_error_; |
| 600 | 597 |
| 601 // UI-thread cache of the last SyncSessionSnapshot received from syncapi. | 598 // UI-thread cache of the last SyncSessionSnapshot received from syncapi. |
| 602 scoped_ptr<sessions::SyncSessionSnapshot> last_snapshot_; | 599 scoped_ptr<sessions::SyncSessionSnapshot> last_snapshot_; |
| 603 | 600 |
| 604 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); | 601 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); |
| 605 }; | 602 }; |
| 606 | 603 |
| 607 } // namespace browser_sync | 604 } // namespace browser_sync |
| 608 | 605 |
| 609 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ | 606 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ |
| OLD | NEW |