| 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 |
| 259 typedef base::Callback<sync_api::HttpPostProviderFactory*(void)> |
| 260 MakeHttpBridgeFactoryFn; |
| 261 |
| 262 struct DoInitializeOptions { |
| 263 DoInitializeOptions( |
| 264 MessageLoop* sync_loop, |
| 265 SyncBackendRegistrar* registrar, |
| 266 const WeakHandle<JsEventHandler>& event_handler, |
| 267 const GURL& service_url, |
| 268 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, |
| 269 const sync_api::SyncCredentials& credentials, |
| 270 sync_notifier::SyncNotifierFactory* sync_notifier_factory, |
| 271 bool delete_sync_data_folder, |
| 272 const std::string& restored_key_for_bootstrapping, |
| 273 bool setup_for_test_mode); |
| 274 ~DoInitializeOptions(); |
| 275 |
| 276 MessageLoop* sync_loop; |
| 277 SyncBackendRegistrar* registrar; |
| 278 WeakHandle<JsEventHandler> event_handler; |
| 279 GURL service_url; |
| 280 // Overridden by tests. |
| 281 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn; |
| 282 sync_api::SyncCredentials credentials; |
| 283 sync_notifier::SyncNotifierFactory* const sync_notifier_factory; |
| 284 std::string lsid; |
| 285 bool delete_sync_data_folder; |
| 286 std::string restored_key_for_bootstrapping; |
| 287 bool setup_for_test_mode; |
| 288 }; |
| 289 |
| 290 // Allows tests to perform alternate core initialization work. |
| 291 virtual void InitCore(const DoInitializeOptions& options); |
| 292 |
| 293 // Called from Core::OnSyncCycleCompleted to handle updating frontend |
| 294 // thread components. |
| 295 void HandleSyncCycleCompletedOnFrontendLoop( |
| 296 sessions::SyncSessionSnapshot* snapshot); |
| 297 |
| 298 // Called to finish the job of ConfigureDataTypes once the syncer is in |
| 299 // configuration mode. |
| 300 void FinishConfigureDataTypesOnFrontendLoop(); |
| 301 |
| 302 bool IsDownloadingNigoriForTest() const; |
| 303 |
| 304 private: |
| 257 // An enum representing the steps to initializing the SyncBackendHost. | 305 // An enum representing the steps to initializing the SyncBackendHost. |
| 258 enum InitializationState { | 306 enum InitializationState { |
| 259 NOT_ATTEMPTED, | 307 NOT_ATTEMPTED, |
| 260 CREATING_SYNC_MANAGER, // We're waiting for the first callback from the | 308 CREATING_SYNC_MANAGER, // We're waiting for the first callback from the |
| 261 // sync thread to inform us that the sync manager | 309 // sync thread to inform us that the sync manager |
| 262 // has been created. | 310 // has been created. |
| 263 NOT_INITIALIZED, // Initialization hasn't completed, but we've | 311 NOT_INITIALIZED, // Initialization hasn't completed, but we've |
| 264 // constructed a SyncManager. | 312 // constructed a SyncManager. |
| 265 DOWNLOADING_NIGORI, // The SyncManager is initialized, but | 313 DOWNLOADING_NIGORI, // The SyncManager is initialized, but |
| 266 // we're fetching encryption information. | 314 // we're fetching encryption information. |
| 267 REFRESHING_ENCRYPTION, // The SyncManager is initialized, and we | 315 REFRESHING_ENCRYPTION, // The SyncManager is initialized, and we |
| 268 // have the encryption information, but we | 316 // have the encryption information, but we |
| 269 // still need to refresh encryption. | 317 // still need to refresh encryption. |
| 270 INITIALIZED, // Initialization is complete. | 318 INITIALIZED, // Initialization is complete. |
| 271 }; | 319 }; |
| 272 | 320 |
| 273 // The real guts of SyncBackendHost, to keep the public client API clean. | 321 // The real guts of SyncBackendHost, to keep the public client API clean. |
| 274 class Core : public base::RefCountedThreadSafe<SyncBackendHost::Core>, | 322 class Core : public base::RefCountedThreadSafe<SyncBackendHost::Core>, |
| 275 public sync_api::SyncManager::Observer { | 323 public sync_api::SyncManager::Observer { |
| 276 public: | 324 public: |
| 277 Core(const std::string& name, SyncBackendHost* backend); | 325 Core(const std::string& name, |
| 326 const FilePath& sync_data_folder_path, |
| 327 const base::WeakPtr<SyncBackendHost>& backend); |
| 278 | 328 |
| 279 // SyncManager::Observer implementation. The Core just acts like an air | 329 // SyncManager::Observer implementation. The Core just acts like an air |
| 280 // traffic controller here, forwarding incoming messages to appropriate | 330 // traffic controller here, forwarding incoming messages to appropriate |
| 281 // landing threads. | 331 // landing threads. |
| 282 virtual void OnSyncCycleCompleted( | 332 virtual void OnSyncCycleCompleted( |
| 283 const sessions::SyncSessionSnapshot* snapshot) OVERRIDE; | 333 const sessions::SyncSessionSnapshot* snapshot) OVERRIDE; |
| 284 virtual void OnInitializationComplete( | 334 virtual void OnInitializationComplete( |
| 285 const WeakHandle<JsBackend>& js_backend, | 335 const WeakHandle<JsBackend>& js_backend, |
| 286 bool success) OVERRIDE; | 336 bool success) OVERRIDE; |
| 287 virtual void OnAuthError( | 337 virtual void OnAuthError( |
| 288 const GoogleServiceAuthError& auth_error) OVERRIDE; | 338 const GoogleServiceAuthError& auth_error) OVERRIDE; |
| 289 virtual void OnPassphraseRequired( | 339 virtual void OnPassphraseRequired( |
| 290 sync_api::PassphraseRequiredReason reason) OVERRIDE; | 340 sync_api::PassphraseRequiredReason reason) OVERRIDE; |
| 291 virtual void OnPassphraseAccepted( | 341 virtual void OnPassphraseAccepted( |
| 292 const std::string& bootstrap_token) OVERRIDE; | 342 const std::string& bootstrap_token) OVERRIDE; |
| 293 virtual void OnStopSyncingPermanently() OVERRIDE; | 343 virtual void OnStopSyncingPermanently() OVERRIDE; |
| 294 virtual void OnUpdatedToken(const std::string& token) OVERRIDE; | 344 virtual void OnUpdatedToken(const std::string& token) OVERRIDE; |
| 295 virtual void OnClearServerDataFailed() OVERRIDE; | 345 virtual void OnClearServerDataFailed() OVERRIDE; |
| 296 virtual void OnClearServerDataSucceeded() OVERRIDE; | 346 virtual void OnClearServerDataSucceeded() OVERRIDE; |
| 297 virtual void OnEncryptedTypesChanged( | 347 virtual void OnEncryptedTypesChanged( |
| 298 syncable::ModelTypeSet encrypted_types, | 348 syncable::ModelTypeSet encrypted_types, |
| 299 bool encrypt_everything) OVERRIDE; | 349 bool encrypt_everything) OVERRIDE; |
| 300 virtual void OnEncryptionComplete() OVERRIDE; | 350 virtual void OnEncryptionComplete() OVERRIDE; |
| 301 virtual void OnActionableError( | 351 virtual void OnActionableError( |
| 302 const browser_sync::SyncProtocolError& sync_error) OVERRIDE; | 352 const browser_sync::SyncProtocolError& sync_error) OVERRIDE; |
| 303 | 353 |
| 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: | 354 // Note: |
| 331 // | 355 // |
| 332 // The Do* methods are the various entry points from our | 356 // The Do* methods are the various entry points from our |
| 333 // SyncBackendHost. They are all called on the sync thread to | 357 // SyncBackendHost. They are all called on the sync thread to |
| 334 // actually perform synchronous (and potentially blocking) syncapi | 358 // actually perform synchronous (and potentially blocking) syncapi |
| 335 // operations. | 359 // operations. |
| 336 // | 360 // |
| 337 // Called to perform initialization of the syncapi on behalf of | 361 // Called to perform initialization of the syncapi on behalf of |
| 338 // SyncBackendHost::Initialize. | 362 // SyncBackendHost::Initialize. |
| 339 void DoInitialize(const DoInitializeOptions& options); | 363 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(); } | 424 sync_api::SyncManager* sync_manager() { return sync_manager_.get(); } |
| 401 | 425 |
| 402 // Delete the sync data folder to cleanup backend data. Happens the first | 426 // 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 | 427 // 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. | 428 // sync databases), as well as shutdown when you're no longer syncing. |
| 405 void DeleteSyncDataFolder(); | 429 void DeleteSyncDataFolder(); |
| 406 | 430 |
| 407 // A callback from the SyncerThread when it is safe to continue config. | 431 // A callback from the SyncerThread when it is safe to continue config. |
| 408 void FinishConfigureDataTypes(); | 432 void FinishConfigureDataTypes(); |
| 409 | 433 |
| 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: | 434 private: |
| 423 friend class base::RefCountedThreadSafe<SyncBackendHost::Core>; | 435 friend class base::RefCountedThreadSafe<SyncBackendHost::Core>; |
| 424 friend class SyncBackendHostForProfileSyncTest; | 436 friend class SyncBackendHostForProfileSyncTest; |
| 425 | 437 |
| 426 virtual ~Core(); | 438 virtual ~Core(); |
| 427 | 439 |
| 428 // Invoked when initialization of syncapi is complete and we can start | 440 // Invoked when initialization of syncapi is complete and we can start |
| 429 // our timer. | 441 // our timer. |
| 430 // This must be called from the thread on which SaveChanges is intended to | 442 // This must be called from the thread on which SaveChanges is intended to |
| 431 // be run on; the host's |sync_thread_|. | 443 // be run on; the host's |sync_thread_|. |
| 432 void StartSavingChanges(); | 444 void StartSavingChanges(); |
| 433 | 445 |
| 434 // Invoked periodically to tell the syncapi to persist its state | 446 // Invoked periodically to tell the syncapi to persist its state |
| 435 // by writing to disk. | 447 // by writing to disk. |
| 436 // This is called from the thread we were created on (which is the | 448 // This is called from the thread we were created on (which is the |
| 437 // SyncBackendHost |sync_thread_|), using a repeating timer that is kicked | 449 // SyncBackendHost |sync_thread_|), using a repeating timer that is kicked |
| 438 // off as soon as the SyncManager tells us it completed | 450 // off as soon as the SyncManager tells us it completed |
| 439 // initialization. | 451 // initialization. |
| 440 void SaveChanges(); | 452 void SaveChanges(); |
| 441 | 453 |
| 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. | 454 // Name used for debugging. |
| 484 const std::string name_; | 455 const std::string name_; |
| 485 | 456 |
| 486 // Our parent SyncBackendHost | 457 // Path of the folder that stores the sync data files. |
| 487 SyncBackendHost* host_; | 458 const FilePath sync_data_folder_path_; |
| 459 |
| 460 // Our parent SyncBackendHost. |
| 461 WeakHandle<SyncBackendHost> host_; |
| 488 | 462 |
| 489 // The loop where all the sync backend operations happen. | 463 // The loop where all the sync backend operations happen. |
| 490 // Non-NULL only between calls to DoInitialize() and DoShutdown(). | 464 // Non-NULL only between calls to DoInitialize() and DoShutdown(). |
| 491 MessageLoop* sync_loop_; | 465 MessageLoop* sync_loop_; |
| 492 | 466 |
| 493 // Our parent's registrar (not owned). Non-NULL only between | 467 // Our parent's registrar (not owned). Non-NULL only between |
| 494 // calls to DoInitialize() and DoShutdown(). | 468 // calls to DoInitialize() and DoShutdown(). |
| 495 SyncBackendRegistrar* registrar_; | 469 SyncBackendRegistrar* registrar_; |
| 496 | 470 |
| 497 // The timer used to periodically call SaveChanges. | 471 // The timer used to periodically call SaveChanges. |
| 498 base::RepeatingTimer<Core> save_changes_timer_; | 472 base::RepeatingTimer<Core> save_changes_timer_; |
| 499 | 473 |
| 500 // The top-level syncapi entry point. Lives on the sync thread. | 474 // The top-level syncapi entry point. Lives on the sync thread. |
| 501 scoped_ptr<sync_api::SyncManager> sync_manager_; | 475 scoped_ptr<sync_api::SyncManager> sync_manager_; |
| 502 | 476 |
| 503 DISALLOW_COPY_AND_ASSIGN(Core); | 477 DISALLOW_COPY_AND_ASSIGN(Core); |
| 504 }; | 478 }; |
| 505 | 479 |
| 480 struct PendingConfigureDataTypesState { |
| 481 PendingConfigureDataTypesState(); |
| 482 ~PendingConfigureDataTypesState(); |
| 483 |
| 484 // The ready_task will be run when configuration is done with the |
| 485 // set of all types that failed configuration (i.e., if its |
| 486 // argument is non-empty, then an error was encountered). |
| 487 base::Callback<void(syncable::ModelTypeSet)> ready_task; |
| 488 |
| 489 // The set of types that we are waiting to be initially synced in a |
| 490 // configuration cycle. |
| 491 syncable::ModelTypeSet types_to_add; |
| 492 |
| 493 // Additional details about which types were added. |
| 494 syncable::ModelTypeSet added_types; |
| 495 sync_api::ConfigureReason reason; |
| 496 }; |
| 497 |
| 506 // Checks if we have received a notice to turn on experimental datatypes | 498 // 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. | 499 // (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. | 500 // Note: it is illegal to call this before the backend is initialized. |
| 509 void AddExperimentalTypes(); | 501 void AddExperimentalTypes(); |
| 510 | 502 |
| 511 // InitializationComplete passes through the SyncBackendHost to forward | 503 // InitializationComplete passes through the SyncBackendHost to forward |
| 512 // on to |frontend_|, and so that tests can intercept here if they need to | 504 // on to |frontend_|, and so that tests can intercept here if they need to |
| 513 // set up initial conditions. | 505 // set up initial conditions. |
| 514 virtual void HandleInitializationCompletedOnFrontendLoop( | 506 virtual void HandleInitializationCompletedOnFrontendLoop( |
| 515 const WeakHandle<JsBackend>& js_backend, | 507 const WeakHandle<JsBackend>& js_backend, |
| 516 bool success); | 508 bool success); |
| 517 | 509 |
| 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 | 510 // 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 | 511 // 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 | 512 // passphrase. |token| must be valid UTF-8 as we use the PrefService for |
| 533 // storage. | 513 // storage. |
| 534 void PersistEncryptionBootstrapToken(const std::string& token); | 514 void PersistEncryptionBootstrapToken(const std::string& token); |
| 535 | 515 |
| 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. | 516 // For convenience, checks if initialization state is INITIALIZED. |
| 561 bool initialized() const { return initialization_state_ == INITIALIZED; } | 517 bool initialized() const { return initialization_state_ == INITIALIZED; } |
| 562 | 518 |
| 519 // Let the front end handle the actionable error event. |
| 520 void HandleActionableErrorEventOnFrontendLoop( |
| 521 const browser_sync::SyncProtocolError& sync_error); |
| 522 |
| 523 // Invoked when a passphrase is required to decrypt a set of Nigori keys, |
| 524 // or for encrypting. |reason| denotes why the passhrase was required. |
| 525 void NotifyPassphraseRequired(sync_api::PassphraseRequiredReason reason); |
| 526 |
| 527 // Invoked when the passphrase provided by the user has been accepted. |
| 528 void NotifyPassphraseAccepted(const std::string& bootstrap_token); |
| 529 |
| 530 // Invoked when an updated token is available from the sync server. |
| 531 void NotifyUpdatedToken(const std::string& token); |
| 532 |
| 533 // Invoked when the set of encrypted types or the encrypt |
| 534 // everything flag changes. |
| 535 void NotifyEncryptedTypesChanged( |
| 536 syncable::ModelTypeSet encrypted_types, |
| 537 bool encrypt_everything); |
| 538 |
| 539 // Invoked when sync finishes encrypting new datatypes. |
| 540 void NotifyEncryptionComplete(); |
| 541 |
| 542 void HandleStopSyncingPermanentlyOnFrontendLoop(); |
| 543 |
| 544 // Called to handle success/failure of clearing server data |
| 545 void HandleClearServerDataSucceededOnFrontendLoop(); |
| 546 void HandleClearServerDataFailedOnFrontendLoop(); |
| 547 |
| 548 // Dispatched to from OnAuthError to handle updating frontend UI |
| 549 // components. |
| 550 void HandleAuthErrorEventOnFrontendLoop( |
| 551 const GoogleServiceAuthError& new_auth_error); |
| 552 |
| 553 // Called when configuration of the Nigori node has completed as |
| 554 // part of the initialization process. |
| 555 void HandleNigoriConfigurationCompletedOnFrontendLoop( |
| 556 const WeakHandle<JsBackend>& js_backend, |
| 557 syncable::ModelTypeSet failed_configuration_types); |
| 558 |
| 563 // Must be called on |frontend_loop_|. |done_callback| is called on | 559 // Must be called on |frontend_loop_|. |done_callback| is called on |
| 564 // |frontend_loop_|. | 560 // |frontend_loop_|. |
| 565 void RefreshEncryption(const base::Closure& done_callback); | 561 void RefreshEncryption(const base::Closure& done_callback); |
| 566 | 562 |
| 567 // Handles stopping the core's SyncManager, accounting for whether | 563 // Handles stopping the core's SyncManager, accounting for whether |
| 568 // initialization is done yet. | 564 // initialization is done yet. |
| 569 void StopSyncManagerForShutdown(const base::Closure& closure); | 565 void StopSyncManagerForShutdown(const base::Closure& closure); |
| 570 | 566 |
| 567 base::WeakPtrFactory<SyncBackendHost> weak_ptr_factory_; |
| 568 |
| 571 // A thread where all the sync operations happen. | 569 // A thread where all the sync operations happen. |
| 572 base::Thread sync_thread_; | 570 base::Thread sync_thread_; |
| 573 | 571 |
| 574 // A reference to the MessageLoop used to construct |this|, so we know how | 572 // A reference to the MessageLoop used to construct |this|, so we know how |
| 575 // to safely talk back to the SyncFrontend. | 573 // to safely talk back to the SyncFrontend. |
| 576 MessageLoop* const frontend_loop_; | 574 MessageLoop* const frontend_loop_; |
| 577 | 575 |
| 578 Profile* const profile_; | 576 Profile* const profile_; |
| 579 | 577 |
| 580 const base::WeakPtr<SyncPrefs> sync_prefs_; | |
| 581 | |
| 582 // Name used for debugging (set from profile_->GetDebugName()). | 578 // Name used for debugging (set from profile_->GetDebugName()). |
| 583 const std::string name_; | 579 const std::string name_; |
| 584 | 580 |
| 581 // Our core, which communicates directly to the syncapi. |
| 582 scoped_refptr<Core> core_; |
| 583 |
| 584 InitializationState initialization_state_; |
| 585 |
| 586 const base::WeakPtr<SyncPrefs> sync_prefs_; |
| 587 |
| 585 sync_notifier::SyncNotifierFactory sync_notifier_factory_; | 588 sync_notifier::SyncNotifierFactory sync_notifier_factory_; |
| 586 | 589 |
| 587 scoped_ptr<SyncBackendRegistrar> registrar_; | 590 scoped_ptr<SyncBackendRegistrar> registrar_; |
| 588 | 591 |
| 589 // The frontend which we serve (and are owned by). | 592 // The frontend which we serve (and are owned by). |
| 590 SyncFrontend* frontend_; | 593 SyncFrontend* frontend_; |
| 591 | 594 |
| 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_; | 595 scoped_ptr<PendingConfigureDataTypesState> pending_download_state_; |
| 596 scoped_ptr<PendingConfigureDataTypesState> pending_config_mode_state_; | 596 scoped_ptr<PendingConfigureDataTypesState> pending_config_mode_state_; |
| 597 | 597 |
| 598 // UI-thread cache of the last AuthErrorState received from syncapi. | 598 // UI-thread cache of the last AuthErrorState received from syncapi. |
| 599 GoogleServiceAuthError last_auth_error_; | 599 GoogleServiceAuthError last_auth_error_; |
| 600 | 600 |
| 601 // UI-thread cache of the last SyncSessionSnapshot received from syncapi. | 601 // UI-thread cache of the last SyncSessionSnapshot received from syncapi. |
| 602 scoped_ptr<sessions::SyncSessionSnapshot> last_snapshot_; | 602 scoped_ptr<sessions::SyncSessionSnapshot> last_snapshot_; |
| 603 | 603 |
| 604 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); | 604 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); |
| 605 }; | 605 }; |
| 606 | 606 |
| 607 } // namespace browser_sync | 607 } // namespace browser_sync |
| 608 | 608 |
| 609 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ | 609 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ |
| OLD | NEW |