| 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 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 void DeleteSyncDataFolder(); | 381 void DeleteSyncDataFolder(); |
| 382 | 382 |
| 383 void ConnectChildJsEventRouter(); | 383 void ConnectChildJsEventRouter(); |
| 384 | 384 |
| 385 void DisconnectChildJsEventRouter(); | 385 void DisconnectChildJsEventRouter(); |
| 386 | 386 |
| 387 void DoProcessMessage( | 387 void DoProcessMessage( |
| 388 const std::string& name, const JsArgList& args, | 388 const std::string& name, const JsArgList& args, |
| 389 const JsEventHandler* sender); | 389 const JsEventHandler* sender); |
| 390 | 390 |
| 391 // A callback from the SyncerThread when it is safe to continue config. |
| 392 void FinishConfigureDataTypes(); |
| 393 |
| 391 #if defined(UNIT_TEST) | 394 #if defined(UNIT_TEST) |
| 392 // Special form of initialization that does not try and authenticate the | 395 // Special form of initialization that does not try and authenticate the |
| 393 // last known user (since it will fail in test mode) and does some extra | 396 // last known user (since it will fail in test mode) and does some extra |
| 394 // setup to nudge the syncapi into a usable state. | 397 // setup to nudge the syncapi into a usable state. |
| 395 void DoInitializeForTest(const std::wstring& test_user, | 398 void DoInitializeForTest(const std::wstring& test_user, |
| 396 sync_api::HttpPostProviderFactory* factory, | 399 sync_api::HttpPostProviderFactory* factory, |
| 397 bool delete_sync_data_folder) { | 400 bool delete_sync_data_folder) { |
| 398 // Construct dummy credentials for test. | 401 // Construct dummy credentials for test. |
| 399 sync_api::SyncCredentials credentials; | 402 sync_api::SyncCredentials credentials; |
| 400 credentials.email = WideToUTF8(test_user); | 403 credentials.email = WideToUTF8(test_user); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 void HandleClearServerDataFailedOnFrontendLoop(); | 478 void HandleClearServerDataFailedOnFrontendLoop(); |
| 476 | 479 |
| 477 // Called from Core::OnInitializationComplete to handle updating | 480 // Called from Core::OnInitializationComplete to handle updating |
| 478 // frontend thread components. | 481 // frontend thread components. |
| 479 void HandleInitalizationCompletedOnFrontendLoop(); | 482 void HandleInitalizationCompletedOnFrontendLoop(); |
| 480 | 483 |
| 481 void RouteJsEventOnFrontendLoop( | 484 void RouteJsEventOnFrontendLoop( |
| 482 const std::string& name, const JsArgList& args, | 485 const std::string& name, const JsArgList& args, |
| 483 const JsEventHandler* dst); | 486 const JsEventHandler* dst); |
| 484 | 487 |
| 488 void FinishConfigureDataTypesOnFrontendLoop(); |
| 489 |
| 485 // Return true if a model lives on the current thread. | 490 // Return true if a model lives on the current thread. |
| 486 bool IsCurrentThreadSafeForModel(syncable::ModelType model_type); | 491 bool IsCurrentThreadSafeForModel(syncable::ModelType model_type); |
| 487 | 492 |
| 488 // Our parent SyncBackendHost | 493 // Our parent SyncBackendHost |
| 489 SyncBackendHost* host_; | 494 SyncBackendHost* host_; |
| 490 | 495 |
| 491 // The timer used to periodically call SaveChanges. | 496 // The timer used to periodically call SaveChanges. |
| 492 base::RepeatingTimer<Core> save_changes_timer_; | 497 base::RepeatingTimer<Core> save_changes_timer_; |
| 493 | 498 |
| 494 // The top-level syncapi entry point. | 499 // The top-level syncapi entry point. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 515 // on to |frontend_|, and so that tests can intercept here if they need to | 520 // on to |frontend_|, and so that tests can intercept here if they need to |
| 516 // set up initial conditions. | 521 // set up initial conditions. |
| 517 virtual void HandleInitializationCompletedOnFrontendLoop(); | 522 virtual void HandleInitializationCompletedOnFrontendLoop(); |
| 518 | 523 |
| 519 // Posts a nudge request on the core thread. | 524 // Posts a nudge request on the core thread. |
| 520 virtual void RequestNudge(); | 525 virtual void RequestNudge(); |
| 521 | 526 |
| 522 // Posts a config request on the core thread. | 527 // Posts a config request on the core thread. |
| 523 virtual void RequestConfig(const syncable::ModelTypeBitSet& added_types); | 528 virtual void RequestConfig(const syncable::ModelTypeBitSet& added_types); |
| 524 | 529 |
| 530 // Called to finish the job of ConfigureDataTypes once the syncer is in |
| 531 // configuration mode. |
| 532 void FinishConfigureDataTypes(); |
| 533 void FinishConfigureDataTypesOnFrontendLoop(); |
| 534 |
| 525 // Allows tests to perform alternate core initialization work. | 535 // Allows tests to perform alternate core initialization work. |
| 526 virtual void InitCore(const Core::DoInitializeOptions& options); | 536 virtual void InitCore(const Core::DoInitializeOptions& options); |
| 527 | 537 |
| 528 // Factory method for HttpPostProviderFactories. | 538 // Factory method for HttpPostProviderFactories. |
| 529 virtual sync_api::HttpPostProviderFactory* MakeHttpBridgeFactory( | 539 virtual sync_api::HttpPostProviderFactory* MakeHttpBridgeFactory( |
| 530 URLRequestContextGetter* getter); | 540 URLRequestContextGetter* getter); |
| 531 | 541 |
| 532 MessageLoop* core_loop() { return core_thread_.message_loop(); } | 542 MessageLoop* core_loop() { return core_thread_.message_loop(); } |
| 533 | 543 |
| 534 void set_syncapi_initialized() { syncapi_initialized_ = true; } | 544 void set_syncapi_initialized() { syncapi_initialized_ = true; } |
| 535 | 545 |
| 536 // Helpers to persist a token that can be used to bootstrap sync encryption | 546 // Helpers to persist a token that can be used to bootstrap sync encryption |
| 537 // across browser restart to avoid requiring the user to re-enter their | 547 // across browser restart to avoid requiring the user to re-enter their |
| 538 // passphrase. |token| must be valid UTF-8 as we use the PrefService for | 548 // passphrase. |token| must be valid UTF-8 as we use the PrefService for |
| 539 // storage. | 549 // storage. |
| 540 void PersistEncryptionBootstrapToken(const std::string& token); | 550 void PersistEncryptionBootstrapToken(const std::string& token); |
| 541 std::string RestoreEncryptionBootstrapToken(); | 551 std::string RestoreEncryptionBootstrapToken(); |
| 542 | 552 |
| 543 // Our core, which communicates directly to the syncapi. | 553 // Our core, which communicates directly to the syncapi. |
| 544 scoped_refptr<Core> core_; | 554 scoped_refptr<Core> core_; |
| 545 | 555 |
| 546 private: | 556 private: |
| 547 UIModelWorker* ui_worker(); | 557 UIModelWorker* ui_worker(); |
| 548 | 558 |
| 549 void ConfigureAutofillMigration(); | 559 void ConfigureAutofillMigration(); |
| 550 | 560 |
| 551 // Depending on switches::kUseNewSyncerThread, kicks the syncapi to respond | |
| 552 // to a change in the set of enabled data types. | |
| 553 void ScheduleSyncEventForConfigChange( | |
| 554 bool deleted_type, | |
| 555 const syncable::ModelTypeBitSet& added_types); | |
| 556 | |
| 557 // A thread we dedicate for use by our Core to perform initialization, | 561 // A thread we dedicate for use by our Core to perform initialization, |
| 558 // authentication, handle messages from the syncapi, and periodically tell | 562 // authentication, handle messages from the syncapi, and periodically tell |
| 559 // the syncapi to persist itself. | 563 // the syncapi to persist itself. |
| 560 base::Thread core_thread_; | 564 base::Thread core_thread_; |
| 561 | 565 |
| 562 // A reference to the MessageLoop used to construct |this|, so we know how | 566 // A reference to the MessageLoop used to construct |this|, so we know how |
| 563 // to safely talk back to the SyncFrontend. | 567 // to safely talk back to the SyncFrontend. |
| 564 MessageLoop* const frontend_loop_; | 568 MessageLoop* const frontend_loop_; |
| 565 | 569 |
| 566 Profile* profile_; | 570 Profile* profile_; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 593 | 597 |
| 594 // The frontend which we serve (and are owned by). | 598 // The frontend which we serve (and are owned by). |
| 595 SyncFrontend* frontend_; | 599 SyncFrontend* frontend_; |
| 596 | 600 |
| 597 // The change processors that handle the different data types. | 601 // The change processors that handle the different data types. |
| 598 std::map<syncable::ModelType, ChangeProcessor*> processors_; | 602 std::map<syncable::ModelType, ChangeProcessor*> processors_; |
| 599 | 603 |
| 600 // Path of the folder that stores the sync data files. | 604 // Path of the folder that stores the sync data files. |
| 601 FilePath sync_data_folder_path_; | 605 FilePath sync_data_folder_path_; |
| 602 | 606 |
| 603 // A task that should be called once data type configuration is | 607 struct PendingConfigureDataTypesState { |
| 604 // complete. | 608 PendingConfigureDataTypesState(); |
| 605 scoped_ptr<CancelableTask> configure_ready_task_; | 609 // A task that should be called once data type configuration is |
| 610 // complete. |
| 611 scoped_ptr<CancelableTask> ready_task; |
| 606 | 612 |
| 607 // The set of types that we are waiting to be initially synced in a | 613 // The set of types that we are waiting to be initially synced in a |
| 608 // configuration cycle. | 614 // configuration cycle. |
| 609 syncable::ModelTypeSet configure_initial_sync_types_; | 615 syncable::ModelTypeSet initial_types; |
| 616 |
| 617 // Additional details about which types were added / removed. |
| 618 bool deleted_type; |
| 619 syncable::ModelTypeBitSet added_types; |
| 620 }; |
| 621 |
| 622 scoped_ptr<PendingConfigureDataTypesState> pending_download_state_; |
| 623 scoped_ptr<PendingConfigureDataTypesState> pending_config_mode_state_; |
| 610 | 624 |
| 611 // UI-thread cache of the last AuthErrorState received from syncapi. | 625 // UI-thread cache of the last AuthErrorState received from syncapi. |
| 612 GoogleServiceAuthError last_auth_error_; | 626 GoogleServiceAuthError last_auth_error_; |
| 613 | 627 |
| 614 // UI-thread cache of the last SyncSessionSnapshot received from syncapi. | 628 // UI-thread cache of the last SyncSessionSnapshot received from syncapi. |
| 615 scoped_ptr<sessions::SyncSessionSnapshot> last_snapshot_; | 629 scoped_ptr<sessions::SyncSessionSnapshot> last_snapshot_; |
| 616 | 630 |
| 617 // While two impls are in flight, using this for sanity checking. Bug 26339. | 631 // While two impls are in flight, using this for sanity checking. Bug 26339. |
| 618 const bool using_new_syncer_thread_; | 632 const bool using_new_syncer_thread_; |
| 619 | 633 |
| 620 // Whether we've processed the initialization complete callback. | 634 // Whether we've processed the initialization complete callback. |
| 621 bool syncapi_initialized_; | 635 bool syncapi_initialized_; |
| 622 | 636 |
| 623 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); | 637 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); |
| 624 }; | 638 }; |
| 625 | 639 |
| 626 } // namespace browser_sync | 640 } // namespace browser_sync |
| 627 | 641 |
| 628 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ | 642 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ |
| OLD | NEW |