| 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 CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ |
| 6 #define CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ | 6 #define CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
| 16 #include "base/location.h" | 16 #include "base/location.h" |
| 17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 19 #include "base/observer_list.h" | 19 #include "base/observer_list.h" |
| 20 #include "base/string16.h" | 20 #include "base/string16.h" |
| 21 #include "base/time.h" | 21 #include "base/time.h" |
| 22 #include "base/timer.h" | 22 #include "base/timer.h" |
| 23 #include "chrome/browser/invalidation/invalidation_frontend.h" | 23 #include "chrome/browser/invalidation/invalidation_frontend.h" |
| 24 #include "chrome/browser/invalidation/invalidator_storage.h" | 24 #include "chrome/browser/invalidation/invalidator_storage.h" |
| 25 #include "chrome/browser/signin/oauth2_token_service.h" |
| 25 #include "chrome/browser/signin/signin_global_error.h" | 26 #include "chrome/browser/signin/signin_global_error.h" |
| 26 #include "chrome/browser/sync/backend_unrecoverable_error_handler.h" | 27 #include "chrome/browser/sync/backend_unrecoverable_error_handler.h" |
| 27 #include "chrome/browser/sync/failed_datatypes_handler.h" | 28 #include "chrome/browser/sync/failed_datatypes_handler.h" |
| 28 #include "chrome/browser/sync/glue/data_type_controller.h" | 29 #include "chrome/browser/sync/glue/data_type_controller.h" |
| 29 #include "chrome/browser/sync/glue/data_type_manager.h" | 30 #include "chrome/browser/sync/glue/data_type_manager.h" |
| 30 #include "chrome/browser/sync/glue/data_type_manager_observer.h" | 31 #include "chrome/browser/sync/glue/data_type_manager_observer.h" |
| 31 #include "chrome/browser/sync/glue/sync_backend_host.h" | 32 #include "chrome/browser/sync/glue/sync_backend_host.h" |
| 32 #include "chrome/browser/sync/profile_sync_service_base.h" | 33 #include "chrome/browser/sync/profile_sync_service_base.h" |
| 33 #include "chrome/browser/sync/profile_sync_service_observer.h" | 34 #include "chrome/browser/sync/profile_sync_service_observer.h" |
| 34 #include "chrome/browser/sync/sync_prefs.h" | 35 #include "chrome/browser/sync/sync_prefs.h" |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 // data from the sync server. | 156 // data from the sync server. |
| 156 // | 157 // |
| 157 class ProfileSyncService : public ProfileSyncServiceBase, | 158 class ProfileSyncService : public ProfileSyncServiceBase, |
| 158 public browser_sync::SyncFrontend, | 159 public browser_sync::SyncFrontend, |
| 159 public browser_sync::SyncPrefObserver, | 160 public browser_sync::SyncPrefObserver, |
| 160 public browser_sync::DataTypeManagerObserver, | 161 public browser_sync::DataTypeManagerObserver, |
| 161 public SigninGlobalError::AuthStatusProvider, | 162 public SigninGlobalError::AuthStatusProvider, |
| 162 public syncer::UnrecoverableErrorHandler, | 163 public syncer::UnrecoverableErrorHandler, |
| 163 public content::NotificationObserver, | 164 public content::NotificationObserver, |
| 164 public BrowserContextKeyedService, | 165 public BrowserContextKeyedService, |
| 165 public invalidation::InvalidationFrontend { | 166 public invalidation::InvalidationFrontend, |
| 167 public OAuth2TokenService::Consumer { |
| 166 public: | 168 public: |
| 167 typedef browser_sync::SyncBackendHost::Status Status; | 169 typedef browser_sync::SyncBackendHost::Status Status; |
| 168 | 170 |
| 169 enum SyncEventCodes { | 171 enum SyncEventCodes { |
| 170 MIN_SYNC_EVENT_CODE = 0, | 172 MIN_SYNC_EVENT_CODE = 0, |
| 171 | 173 |
| 172 // Events starting the sync service. | 174 // Events starting the sync service. |
| 173 START_FROM_NTP = 1, // Sync was started from the ad in NTP | 175 START_FROM_NTP = 1, // Sync was started from the ad in NTP |
| 174 START_FROM_WRENCH = 2, // Sync was started from the Wrench menu. | 176 START_FROM_WRENCH = 2, // Sync was started from the Wrench menu. |
| 175 START_FROM_OPTIONS = 3, // Sync was started from Wrench->Options. | 177 START_FROM_OPTIONS = 3, // Sync was started from Wrench->Options. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 | 242 |
| 241 void RegisterAuthNotifications(); | 243 void RegisterAuthNotifications(); |
| 242 | 244 |
| 243 // Returns true if sync is enabled/not suppressed and the user is logged in. | 245 // Returns true if sync is enabled/not suppressed and the user is logged in. |
| 244 // (being logged in does not mean that tokens are available - tokens may | 246 // (being logged in does not mean that tokens are available - tokens may |
| 245 // be missing because they have not loaded yet, or because they were deleted | 247 // be missing because they have not loaded yet, or because they were deleted |
| 246 // due to http://crbug.com/121755). | 248 // due to http://crbug.com/121755). |
| 247 // Virtual to enable mocking in tests. | 249 // Virtual to enable mocking in tests. |
| 248 virtual bool IsSyncEnabledAndLoggedIn(); | 250 virtual bool IsSyncEnabledAndLoggedIn(); |
| 249 | 251 |
| 250 // Return whether all sync tokens are loaded and available for the backend to | 252 // Return whether OAuth2 refresh token is loaded and available for the backend |
| 251 // start up. Virtual to enable mocking in tests. | 253 // to start up. Virtual to enable mocking in tests. |
| 252 virtual bool IsSyncTokenAvailable(); | 254 virtual bool IsOAuthRefreshTokenAvailable(); |
| 253 | 255 |
| 254 // Registers a data type controller with the sync service. This | 256 // Registers a data type controller with the sync service. This |
| 255 // makes the data type controller available for use, it does not | 257 // makes the data type controller available for use, it does not |
| 256 // enable or activate the synchronization of the data type (see | 258 // enable or activate the synchronization of the data type (see |
| 257 // ActivateDataType). Takes ownership of the pointer. | 259 // ActivateDataType). Takes ownership of the pointer. |
| 258 void RegisterDataTypeController( | 260 void RegisterDataTypeController( |
| 259 browser_sync::DataTypeController* data_type_controller); | 261 browser_sync::DataTypeController* data_type_controller); |
| 260 | 262 |
| 261 // Returns the session model associator associated with this type, but only if | 263 // Returns the session model associator associated with this type, but only if |
| 262 // the associator is running. If it is doing anything else, it will return | 264 // the associator is running. If it is doing anything else, it will return |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 syncer::InvalidationHandler* handler, | 612 syncer::InvalidationHandler* handler, |
| 611 const syncer::ObjectIdSet& ids) OVERRIDE; | 613 const syncer::ObjectIdSet& ids) OVERRIDE; |
| 612 virtual void UnregisterInvalidationHandler( | 614 virtual void UnregisterInvalidationHandler( |
| 613 syncer::InvalidationHandler* handler) OVERRIDE; | 615 syncer::InvalidationHandler* handler) OVERRIDE; |
| 614 virtual void AcknowledgeInvalidation( | 616 virtual void AcknowledgeInvalidation( |
| 615 const invalidation::ObjectId& id, | 617 const invalidation::ObjectId& id, |
| 616 const syncer::AckHandle& ack_handle) OVERRIDE; | 618 const syncer::AckHandle& ack_handle) OVERRIDE; |
| 617 | 619 |
| 618 virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE; | 620 virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE; |
| 619 | 621 |
| 622 // OAuth2TokenService::Consumer implementation |
| 623 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
| 624 const std::string& access_token, |
| 625 const base::Time& expiration_time) OVERRIDE; |
| 626 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
| 627 const GoogleServiceAuthError& error) OVERRIDE; |
| 628 |
| 620 // BrowserContextKeyedService implementation. This must be called exactly | 629 // BrowserContextKeyedService implementation. This must be called exactly |
| 621 // once (before this object is destroyed). | 630 // once (before this object is destroyed). |
| 622 virtual void Shutdown() OVERRIDE; | 631 virtual void Shutdown() OVERRIDE; |
| 623 | 632 |
| 624 // Simulate an incoming notification for the given id and payload. | 633 // Simulate an incoming notification for the given id and payload. |
| 625 void EmitInvalidationForTest( | 634 void EmitInvalidationForTest( |
| 626 const invalidation::ObjectId& id, | 635 const invalidation::ObjectId& id, |
| 627 const std::string& payload); | 636 const std::string& payload); |
| 628 | 637 |
| 629 // Called when a datatype (SyncableService) has a need for sync to start | 638 // Called when a datatype (SyncableService) has a need for sync to start |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 // because OnPassphraseAccepted() was called, or because we've gotten a | 729 // because OnPassphraseAccepted() was called, or because we've gotten a |
| 721 // OnPassphraseRequired() but no data types are enabled). | 730 // OnPassphraseRequired() but no data types are enabled). |
| 722 void ResolvePassphraseRequired(); | 731 void ResolvePassphraseRequired(); |
| 723 | 732 |
| 724 // During initial signin, ProfileSyncService caches the user's signin | 733 // During initial signin, ProfileSyncService caches the user's signin |
| 725 // passphrase so it can be used to encrypt/decrypt data after sync starts up. | 734 // passphrase so it can be used to encrypt/decrypt data after sync starts up. |
| 726 // This routine is invoked once the backend has started up to use the | 735 // This routine is invoked once the backend has started up to use the |
| 727 // cached passphrase and clear it out when it is done. | 736 // cached passphrase and clear it out when it is done. |
| 728 void ConsumeCachedPassphraseIfPossible(); | 737 void ConsumeCachedPassphraseIfPossible(); |
| 729 | 738 |
| 739 // RequestAccessToken initiates RPC to request downscoped access token from |
| 740 // refresh token. This happens when TokenService loads OAuth2 login token and |
| 741 // when sync server returns AUTH_ERROR which indicates it is time to refresh |
| 742 // token. |
| 743 virtual void RequestAccessToken( |
| 744 bool invalidate_previous_token, |
| 745 bool invoke_callback); |
| 746 |
| 730 // If |delete_sync_data_folder| is true, then this method will delete all | 747 // If |delete_sync_data_folder| is true, then this method will delete all |
| 731 // previous "Sync Data" folders. (useful if the folder is partial/corrupt). | 748 // previous "Sync Data" folders. (useful if the folder is partial/corrupt). |
| 732 void InitializeBackend(bool delete_sync_data_folder); | 749 void InitializeBackend(bool delete_sync_data_folder); |
| 733 | 750 |
| 734 // Initializes the various settings from the command line. | 751 // Initializes the various settings from the command line. |
| 735 void InitSettings(); | 752 void InitSettings(); |
| 736 | 753 |
| 737 // Sets the last synced time to the current time. | 754 // Sets the last synced time to the current time. |
| 738 void UpdateLastSyncedTime(); | 755 void UpdateLastSyncedTime(); |
| 739 | 756 |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 // Dispatches invalidations to handlers. Set in Initialize() and | 954 // Dispatches invalidations to handlers. Set in Initialize() and |
| 938 // unset in Shutdown(). | 955 // unset in Shutdown(). |
| 939 scoped_ptr<syncer::InvalidatorRegistrar> invalidator_registrar_; | 956 scoped_ptr<syncer::InvalidatorRegistrar> invalidator_registrar_; |
| 940 // Queues any acknowledgements received while the backend is uninitialized. | 957 // Queues any acknowledgements received while the backend is uninitialized. |
| 941 AckHandleReplayQueue ack_replay_queue_; | 958 AckHandleReplayQueue ack_replay_queue_; |
| 942 | 959 |
| 943 // Sync's internal debug info listener. Used to record datatype configuration | 960 // Sync's internal debug info listener. Used to record datatype configuration |
| 944 // and association information. | 961 // and association information. |
| 945 syncer::WeakHandle<syncer::DataTypeDebugInfoListener> debug_info_listener_; | 962 syncer::WeakHandle<syncer::DataTypeDebugInfoListener> debug_info_listener_; |
| 946 | 963 |
| 964 // ProfileSyncService needs to remember access token in order to invalidate it |
| 965 // with OAuth2TokenService. |
| 966 std::string access_token_; |
| 967 |
| 968 // ProfileSyncService needs to hold reference to access_token_request_ for |
| 969 // the duration of request in order to receive callbacks. |
| 970 scoped_ptr<OAuth2TokenService::Request> access_token_request_; |
| 971 |
| 947 DISALLOW_COPY_AND_ASSIGN(ProfileSyncService); | 972 DISALLOW_COPY_AND_ASSIGN(ProfileSyncService); |
| 948 }; | 973 }; |
| 949 | 974 |
| 950 bool ShouldShowActionOnUI( | 975 bool ShouldShowActionOnUI( |
| 951 const syncer::SyncProtocolError& error); | 976 const syncer::SyncProtocolError& error); |
| 952 | 977 |
| 953 | 978 |
| 954 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ | 979 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ |
| OLD | NEW |