| 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 COMPONENTS_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ | 5 #ifndef COMPONENTS_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ |
| 6 #define COMPONENTS_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ | 6 #define COMPONENTS_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "components/signin/core/browser/signin_manager_base.h" | 30 #include "components/signin/core/browser/signin_manager_base.h" |
| 31 #include "components/sync/base/experiments.h" | 31 #include "components/sync/base/experiments.h" |
| 32 #include "components/sync/base/model_type.h" | 32 #include "components/sync/base/model_type.h" |
| 33 #include "components/sync/base/sync_prefs.h" | 33 #include "components/sync/base/sync_prefs.h" |
| 34 #include "components/sync/base/unrecoverable_error_handler.h" | 34 #include "components/sync/base/unrecoverable_error_handler.h" |
| 35 #include "components/sync/device_info/local_device_info_provider.h" | 35 #include "components/sync/device_info/local_device_info_provider.h" |
| 36 #include "components/sync/driver/data_type_controller.h" | 36 #include "components/sync/driver/data_type_controller.h" |
| 37 #include "components/sync/driver/data_type_manager.h" | 37 #include "components/sync/driver/data_type_manager.h" |
| 38 #include "components/sync/driver/data_type_manager_observer.h" | 38 #include "components/sync/driver/data_type_manager_observer.h" |
| 39 #include "components/sync/driver/data_type_status_table.h" | 39 #include "components/sync/driver/data_type_status_table.h" |
| 40 #include "components/sync/driver/glue/sync_backend_host.h" | |
| 41 #include "components/sync/driver/startup_controller.h" | 40 #include "components/sync/driver/startup_controller.h" |
| 42 #include "components/sync/driver/sync_client.h" | 41 #include "components/sync/driver/sync_client.h" |
| 43 #include "components/sync/driver/sync_frontend.h" | |
| 44 #include "components/sync/driver/sync_service.h" | 42 #include "components/sync/driver/sync_service.h" |
| 45 #include "components/sync/driver/sync_stopped_reporter.h" | 43 #include "components/sync/driver/sync_stopped_reporter.h" |
| 46 #include "components/sync/engine/events/protocol_event_observer.h" | 44 #include "components/sync/engine/events/protocol_event_observer.h" |
| 47 #include "components/sync/engine/model_safe_worker.h" | 45 #include "components/sync/engine/model_safe_worker.h" |
| 48 #include "components/sync/engine/net/network_time_update_callback.h" | 46 #include "components/sync/engine/net/network_time_update_callback.h" |
| 49 #include "components/sync/engine/shutdown_reason.h" | 47 #include "components/sync/engine/shutdown_reason.h" |
| 48 #include "components/sync/engine/sync_engine.h" |
| 49 #include "components/sync/engine/sync_engine_host.h" |
| 50 #include "components/sync/engine/sync_manager_factory.h" | 50 #include "components/sync/engine/sync_manager_factory.h" |
| 51 #include "components/sync/js/sync_js_controller.h" | 51 #include "components/sync/js/sync_js_controller.h" |
| 52 #include "components/sync/syncable/user_share.h" | 52 #include "components/sync/syncable/user_share.h" |
| 53 #include "components/version_info/version_info.h" | 53 #include "components/version_info/version_info.h" |
| 54 #include "google_apis/gaia/google_service_auth_error.h" | 54 #include "google_apis/gaia/google_service_auth_error.h" |
| 55 #include "google_apis/gaia/oauth2_token_service.h" | 55 #include "google_apis/gaia/oauth2_token_service.h" |
| 56 #include "net/base/backoff_entry.h" | 56 #include "net/base/backoff_entry.h" |
| 57 #include "url/gurl.h" | 57 #include "url/gurl.h" |
| 58 | 58 |
| 59 class Profile; | 59 class Profile; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 // | 165 // |
| 166 // SetFirstSetupComplete() should be called once the user has finished setting | 166 // SetFirstSetupComplete() should be called once the user has finished setting |
| 167 // up sync at least once on their account. GetSetupInProgressHandle() should | 167 // up sync at least once on their account. GetSetupInProgressHandle() should |
| 168 // be called while the user is actively configuring their account. The handle | 168 // be called while the user is actively configuring their account. The handle |
| 169 // should be deleted once configuration is complete. | 169 // should be deleted once configuration is complete. |
| 170 // | 170 // |
| 171 // Once first setup has completed and there are no outstanding | 171 // Once first setup has completed and there are no outstanding |
| 172 // setup-in-progress handles, CanConfigureDataTypes() will return true and | 172 // setup-in-progress handles, CanConfigureDataTypes() will return true and |
| 173 // datatype configuration can begin. | 173 // datatype configuration can begin. |
| 174 class ProfileSyncService : public syncer::SyncService, | 174 class ProfileSyncService : public syncer::SyncService, |
| 175 public syncer::SyncFrontend, | 175 public syncer::SyncEngineHost, |
| 176 public syncer::SyncPrefObserver, | 176 public syncer::SyncPrefObserver, |
| 177 public syncer::DataTypeManagerObserver, | 177 public syncer::DataTypeManagerObserver, |
| 178 public syncer::UnrecoverableErrorHandler, | 178 public syncer::UnrecoverableErrorHandler, |
| 179 public KeyedService, | 179 public KeyedService, |
| 180 public OAuth2TokenService::Consumer, | 180 public OAuth2TokenService::Consumer, |
| 181 public OAuth2TokenService::Observer, | 181 public OAuth2TokenService::Observer, |
| 182 public SigninManagerBase::Observer, | 182 public SigninManagerBase::Observer, |
| 183 public GaiaCookieManagerService::Observer { | 183 public GaiaCookieManagerService::Observer { |
| 184 public: | 184 public: |
| 185 typedef syncer::SyncBackendHost::Status Status; | 185 typedef syncer::SyncEngine::Status Status; |
| 186 typedef base::Callback<bool(void)> PlatformSyncAllowedProvider; | 186 typedef base::Callback<bool(void)> PlatformSyncAllowedProvider; |
| 187 | 187 |
| 188 enum SyncEventCodes { | 188 enum SyncEventCodes { |
| 189 MIN_SYNC_EVENT_CODE = 0, | 189 MIN_SYNC_EVENT_CODE = 0, |
| 190 | 190 |
| 191 // Events starting the sync service. | 191 // Events starting the sync service. |
| 192 START_FROM_NTP = 1, // Sync was started from the ad in NTP | 192 START_FROM_NTP = 1, // Sync was started from the ad in NTP |
| 193 START_FROM_WRENCH = 2, // Sync was started from the Wrench menu. | 193 START_FROM_WRENCH = 2, // Sync was started from the Wrench menu. |
| 194 START_FROM_OPTIONS = 3, // Sync was started from Wrench->Options. | 194 START_FROM_OPTIONS = 3, // Sync was started from Wrench->Options. |
| 195 START_FROM_BOOKMARK_MANAGER = 4, // Sync was started from Bookmark manager. | 195 START_FROM_BOOKMARK_MANAGER = 4, // Sync was started from Bookmark manager. |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 virtual syncer::DeviceInfoTracker* GetDeviceInfoTracker() const; | 351 virtual syncer::DeviceInfoTracker* GetDeviceInfoTracker() const; |
| 352 | 352 |
| 353 // Fills state_map with a map of current data types that are possible to | 353 // Fills state_map with a map of current data types that are possible to |
| 354 // sync, as well as their states. | 354 // sync, as well as their states. |
| 355 void GetDataTypeControllerStates( | 355 void GetDataTypeControllerStates( |
| 356 syncer::DataTypeController::StateMap* state_map) const; | 356 syncer::DataTypeController::StateMap* state_map) const; |
| 357 | 357 |
| 358 // Called when asynchronous session restore has completed. | 358 // Called when asynchronous session restore has completed. |
| 359 void OnSessionRestoreComplete(); | 359 void OnSessionRestoreComplete(); |
| 360 | 360 |
| 361 // SyncFrontend implementation. | 361 // SyncEngineHost implementation. |
| 362 void OnBackendInitialized( | 362 void OnBackendInitialized( |
| 363 const syncer::WeakHandle<syncer::JsBackend>& js_backend, | 363 const syncer::WeakHandle<syncer::JsBackend>& js_backend, |
| 364 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& | 364 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& |
| 365 debug_info_listener, | 365 debug_info_listener, |
| 366 const std::string& cache_guid, | 366 const std::string& cache_guid, |
| 367 bool success) override; | 367 bool success) override; |
| 368 void OnSyncCycleCompleted() override; | 368 void OnSyncCycleCompleted() override; |
| 369 void OnProtocolEvent(const syncer::ProtocolEvent& event) override; | 369 void OnProtocolEvent(const syncer::ProtocolEvent& event) override; |
| 370 void OnDirectoryTypeCommitCounterUpdated( | 370 void OnDirectoryTypeCommitCounterUpdated( |
| 371 syncer::ModelType type, | 371 syncer::ModelType type, |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 // Return SyncCredentials from the OAuth2TokenService. | 635 // Return SyncCredentials from the OAuth2TokenService. |
| 636 syncer::SyncCredentials GetCredentials(); | 636 syncer::SyncCredentials GetCredentials(); |
| 637 | 637 |
| 638 virtual syncer::WeakHandle<syncer::JsEventHandler> GetJsEventHandler(); | 638 virtual syncer::WeakHandle<syncer::JsEventHandler> GetJsEventHandler(); |
| 639 | 639 |
| 640 // Helper method for managing encryption UI. | 640 // Helper method for managing encryption UI. |
| 641 bool IsEncryptedDatatypeEnabled() const; | 641 bool IsEncryptedDatatypeEnabled() const; |
| 642 | 642 |
| 643 // Helper for OnUnrecoverableError. | 643 // Helper for OnUnrecoverableError. |
| 644 // TODO(tim): Use an enum for |delete_sync_database| here, in ShutdownImpl, | 644 // TODO(tim): Use an enum for |delete_sync_database| here, in ShutdownImpl, |
| 645 // and in SyncBackendHost::Shutdown. | 645 // and in SyncEngine::Shutdown. |
| 646 void OnUnrecoverableErrorImpl(const tracked_objects::Location& from_here, | 646 void OnUnrecoverableErrorImpl(const tracked_objects::Location& from_here, |
| 647 const std::string& message, | 647 const std::string& message, |
| 648 bool delete_sync_database); | 648 bool delete_sync_database); |
| 649 | 649 |
| 650 // Stops the sync engine. Does NOT set IsSyncRequested to false. Use | 650 // Stops the sync engine. Does NOT set IsSyncRequested to false. Use |
| 651 // RequestStop for that. |data_fate| controls whether the local sync data is | 651 // RequestStop for that. |data_fate| controls whether the local sync data is |
| 652 // deleted or kept when the engine shuts down. | 652 // deleted or kept when the engine shuts down. |
| 653 void StopImpl(SyncStopDataFate data_fate); | 653 void StopImpl(SyncStopDataFate data_fate); |
| 654 | 654 |
| 655 // Update the last auth error and notify observers of error state. | 655 // Update the last auth error and notify observers of error state. |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 // Called when a SetupInProgressHandle issued by this instance is destroyed. | 768 // Called when a SetupInProgressHandle issued by this instance is destroyed. |
| 769 virtual void OnSetupInProgressHandleDestroyed(); | 769 virtual void OnSetupInProgressHandleDestroyed(); |
| 770 | 770 |
| 771 // This is a cache of the last authentication response we received from the | 771 // This is a cache of the last authentication response we received from the |
| 772 // sync server. The UI queries this to display appropriate messaging to the | 772 // sync server. The UI queries this to display appropriate messaging to the |
| 773 // user. | 773 // user. |
| 774 GoogleServiceAuthError last_auth_error_; | 774 GoogleServiceAuthError last_auth_error_; |
| 775 | 775 |
| 776 // Our asynchronous backend to communicate with sync components living on | 776 // Our asynchronous backend to communicate with sync components living on |
| 777 // other threads. | 777 // other threads. |
| 778 std::unique_ptr<syncer::SyncBackendHost> backend_; | 778 std::unique_ptr<syncer::SyncEngine> backend_; |
| 779 | 779 |
| 780 // Was the last SYNC_PASSPHRASE_REQUIRED notification sent because it | 780 // Was the last SYNC_PASSPHRASE_REQUIRED notification sent because it |
| 781 // was required for encryption, decryption with a cached passphrase, or | 781 // was required for encryption, decryption with a cached passphrase, or |
| 782 // because a new passphrase is required? | 782 // because a new passphrase is required? |
| 783 syncer::PassphraseRequiredReason passphrase_required_reason_; | 783 syncer::PassphraseRequiredReason passphrase_required_reason_; |
| 784 | 784 |
| 785 // This profile's SyncClient, which abstracts away non-Sync dependencies and | 785 // This profile's SyncClient, which abstracts away non-Sync dependencies and |
| 786 // the Sync API component factory. | 786 // the Sync API component factory. |
| 787 std::unique_ptr<syncer::SyncClient> sync_client_; | 787 std::unique_ptr<syncer::SyncClient> sync_client_; |
| 788 | 788 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 822 // is equal to !IsFirstSetupComplete() at the time of OnBackendInitialized(). | 822 // is equal to !IsFirstSetupComplete() at the time of OnBackendInitialized(). |
| 823 bool is_first_time_sync_configure_; | 823 bool is_first_time_sync_configure_; |
| 824 | 824 |
| 825 // Number of UIs currently configuring the Sync service. When this number | 825 // Number of UIs currently configuring the Sync service. When this number |
| 826 // is decremented back to zero, Sync setup is marked no longer in progress. | 826 // is decremented back to zero, Sync setup is marked no longer in progress. |
| 827 int outstanding_setup_in_progress_handles_ = 0; | 827 int outstanding_setup_in_progress_handles_ = 0; |
| 828 | 828 |
| 829 // List of available data type controllers. | 829 // List of available data type controllers. |
| 830 syncer::DataTypeController::TypeMap data_type_controllers_; | 830 syncer::DataTypeController::TypeMap data_type_controllers_; |
| 831 | 831 |
| 832 // Whether the SyncBackendHost has been initialized. | 832 // Whether the SyncEngine has been initialized. |
| 833 bool backend_initialized_; | 833 bool backend_initialized_; |
| 834 | 834 |
| 835 // Set when sync receives DISABLED_BY_ADMIN error from server. Prevents | 835 // Set when sync receives DISABLED_BY_ADMIN error from server. Prevents |
| 836 // ProfileSyncService from starting backend till browser restarted or user | 836 // ProfileSyncService from starting backend till browser restarted or user |
| 837 // signed out. | 837 // signed out. |
| 838 bool sync_disabled_by_admin_; | 838 bool sync_disabled_by_admin_; |
| 839 | 839 |
| 840 // Set to true if a signin has completed but we're still waiting for the | 840 // Set to true if a signin has completed but we're still waiting for the |
| 841 // backend to refresh its credentials. | 841 // backend to refresh its credentials. |
| 842 bool is_auth_in_progress_; | 842 bool is_auth_in_progress_; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 995 base::WeakPtrFactory<ProfileSyncService> weak_factory_; | 995 base::WeakPtrFactory<ProfileSyncService> weak_factory_; |
| 996 | 996 |
| 997 DISALLOW_COPY_AND_ASSIGN(ProfileSyncService); | 997 DISALLOW_COPY_AND_ASSIGN(ProfileSyncService); |
| 998 }; | 998 }; |
| 999 | 999 |
| 1000 bool ShouldShowActionOnUI(const syncer::SyncProtocolError& error); | 1000 bool ShouldShowActionOnUI(const syncer::SyncProtocolError& error); |
| 1001 | 1001 |
| 1002 } // namespace browser_sync | 1002 } // namespace browser_sync |
| 1003 | 1003 |
| 1004 #endif // COMPONENTS_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ | 1004 #endif // COMPONENTS_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ |
| OLD | NEW |