| 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" |
| 35 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" | 36 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" |
| 36 #include "content/public/browser/notification_observer.h" | 37 #include "content/public/browser/notification_observer.h" |
| 37 #include "content/public/browser/notification_registrar.h" | 38 #include "content/public/browser/notification_registrar.h" |
| 38 #include "content/public/browser/notification_types.h" | 39 #include "content/public/browser/notification_types.h" |
| 39 #include "google_apis/gaia/google_service_auth_error.h" | 40 #include "google_apis/gaia/google_service_auth_error.h" |
| 40 #include "googleurl/src/gurl.h" | 41 #include "googleurl/src/gurl.h" |
| 42 #include "net/base/backoff_entry.h" |
| 41 #include "sync/internal_api/public/base/model_type.h" | 43 #include "sync/internal_api/public/base/model_type.h" |
| 42 #include "sync/internal_api/public/engine/model_safe_worker.h" | 44 #include "sync/internal_api/public/engine/model_safe_worker.h" |
| 43 #include "sync/internal_api/public/sync_manager_factory.h" | 45 #include "sync/internal_api/public/sync_manager_factory.h" |
| 44 #include "sync/internal_api/public/util/experiments.h" | 46 #include "sync/internal_api/public/util/experiments.h" |
| 45 #include "sync/internal_api/public/util/unrecoverable_error_handler.h" | 47 #include "sync/internal_api/public/util/unrecoverable_error_handler.h" |
| 46 #include "sync/js/sync_js_controller.h" | 48 #include "sync/js/sync_js_controller.h" |
| 47 | 49 |
| 48 class Profile; | 50 class Profile; |
| 49 class ProfileSyncComponentsFactory; | 51 class ProfileSyncComponentsFactory; |
| 50 class SigninManagerBase; | 52 class SigninManagerBase; |
| 51 class SyncGlobalError; | 53 class SyncGlobalError; |
| 52 | 54 |
| 53 namespace browser_sync { | 55 namespace browser_sync { |
| 54 class BackendMigrator; | 56 class BackendMigrator; |
| 55 class ChangeProcessor; | 57 class ChangeProcessor; |
| 56 class DeviceInfo; | 58 class DeviceInfo; |
| 57 class DataTypeManager; | 59 class DataTypeManager; |
| 58 class JsController; | 60 class JsController; |
| 59 class SessionModelAssociator; | 61 class SessionModelAssociator; |
| 60 | 62 |
| 61 namespace sessions { class SyncSessionSnapshot; } | 63 namespace sessions { class SyncSessionSnapshot; } |
| 62 } | 64 } |
| 63 | 65 |
| 64 namespace syncer { | 66 namespace syncer { |
| 67 class BackoffDelayProvider; |
| 65 class BaseTransaction; | 68 class BaseTransaction; |
| 66 class InvalidatorRegistrar; | 69 class InvalidatorRegistrar; |
| 67 struct SyncCredentials; | 70 struct SyncCredentials; |
| 68 struct UserShare; | 71 struct UserShare; |
| 69 } | 72 } |
| 70 | 73 |
| 71 namespace sync_pb { | 74 namespace sync_pb { |
| 72 class EncryptedData; | 75 class EncryptedData; |
| 73 } // namespace sync_pb | 76 } // namespace sync_pb |
| 74 | 77 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 // data from the sync server. | 158 // data from the sync server. |
| 156 // | 159 // |
| 157 class ProfileSyncService : public ProfileSyncServiceBase, | 160 class ProfileSyncService : public ProfileSyncServiceBase, |
| 158 public browser_sync::SyncFrontend, | 161 public browser_sync::SyncFrontend, |
| 159 public browser_sync::SyncPrefObserver, | 162 public browser_sync::SyncPrefObserver, |
| 160 public browser_sync::DataTypeManagerObserver, | 163 public browser_sync::DataTypeManagerObserver, |
| 161 public SigninGlobalError::AuthStatusProvider, | 164 public SigninGlobalError::AuthStatusProvider, |
| 162 public syncer::UnrecoverableErrorHandler, | 165 public syncer::UnrecoverableErrorHandler, |
| 163 public content::NotificationObserver, | 166 public content::NotificationObserver, |
| 164 public BrowserContextKeyedService, | 167 public BrowserContextKeyedService, |
| 165 public invalidation::InvalidationFrontend { | 168 public invalidation::InvalidationFrontend, |
| 169 public OAuth2TokenService::Consumer { |
| 166 public: | 170 public: |
| 167 typedef browser_sync::SyncBackendHost::Status Status; | 171 typedef browser_sync::SyncBackendHost::Status Status; |
| 168 | 172 |
| 169 enum SyncEventCodes { | 173 enum SyncEventCodes { |
| 170 MIN_SYNC_EVENT_CODE = 0, | 174 MIN_SYNC_EVENT_CODE = 0, |
| 171 | 175 |
| 172 // Events starting the sync service. | 176 // Events starting the sync service. |
| 173 START_FROM_NTP = 1, // Sync was started from the ad in NTP | 177 START_FROM_NTP = 1, // Sync was started from the ad in NTP |
| 174 START_FROM_WRENCH = 2, // Sync was started from the Wrench menu. | 178 START_FROM_WRENCH = 2, // Sync was started from the Wrench menu. |
| 175 START_FROM_OPTIONS = 3, // Sync was started from Wrench->Options. | 179 START_FROM_OPTIONS = 3, // Sync was started from Wrench->Options. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 | 244 |
| 241 void RegisterAuthNotifications(); | 245 void RegisterAuthNotifications(); |
| 242 | 246 |
| 243 // Returns true if sync is enabled/not suppressed and the user is logged in. | 247 // 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 | 248 // (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 | 249 // be missing because they have not loaded yet, or because they were deleted |
| 246 // due to http://crbug.com/121755). | 250 // due to http://crbug.com/121755). |
| 247 // Virtual to enable mocking in tests. | 251 // Virtual to enable mocking in tests. |
| 248 virtual bool IsSyncEnabledAndLoggedIn(); | 252 virtual bool IsSyncEnabledAndLoggedIn(); |
| 249 | 253 |
| 250 // Return whether all sync tokens are loaded and available for the backend to | 254 // Return whether OAuth2 refresh token is loaded and available for the backend |
| 251 // start up. Virtual to enable mocking in tests. | 255 // to start up. Virtual to enable mocking in tests. |
| 252 virtual bool IsSyncTokenAvailable(); | 256 virtual bool IsOAuthRefreshTokenAvailable(); |
| 253 | 257 |
| 254 // Registers a data type controller with the sync service. This | 258 // Registers a data type controller with the sync service. This |
| 255 // makes the data type controller available for use, it does not | 259 // makes the data type controller available for use, it does not |
| 256 // enable or activate the synchronization of the data type (see | 260 // enable or activate the synchronization of the data type (see |
| 257 // ActivateDataType). Takes ownership of the pointer. | 261 // ActivateDataType). Takes ownership of the pointer. |
| 258 void RegisterDataTypeController( | 262 void RegisterDataTypeController( |
| 259 browser_sync::DataTypeController* data_type_controller); | 263 browser_sync::DataTypeController* data_type_controller); |
| 260 | 264 |
| 261 // Returns the session model associator associated with this type, but only if | 265 // 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 | 266 // 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, | 614 syncer::InvalidationHandler* handler, |
| 611 const syncer::ObjectIdSet& ids) OVERRIDE; | 615 const syncer::ObjectIdSet& ids) OVERRIDE; |
| 612 virtual void UnregisterInvalidationHandler( | 616 virtual void UnregisterInvalidationHandler( |
| 613 syncer::InvalidationHandler* handler) OVERRIDE; | 617 syncer::InvalidationHandler* handler) OVERRIDE; |
| 614 virtual void AcknowledgeInvalidation( | 618 virtual void AcknowledgeInvalidation( |
| 615 const invalidation::ObjectId& id, | 619 const invalidation::ObjectId& id, |
| 616 const syncer::AckHandle& ack_handle) OVERRIDE; | 620 const syncer::AckHandle& ack_handle) OVERRIDE; |
| 617 | 621 |
| 618 virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE; | 622 virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE; |
| 619 | 623 |
| 624 // OAuth2TokenService::Consumer implementation |
| 625 virtual void OnGetTokenSuccess( |
| 626 const OAuth2TokenService::Request* request, |
| 627 const std::string& access_token, |
| 628 const base::Time& expiration_time) OVERRIDE; |
| 629 virtual void OnGetTokenFailure( |
| 630 const OAuth2TokenService::Request* request, |
| 631 const GoogleServiceAuthError& error) OVERRIDE; |
| 632 |
| 620 // BrowserContextKeyedService implementation. This must be called exactly | 633 // BrowserContextKeyedService implementation. This must be called exactly |
| 621 // once (before this object is destroyed). | 634 // once (before this object is destroyed). |
| 622 virtual void Shutdown() OVERRIDE; | 635 virtual void Shutdown() OVERRIDE; |
| 623 | 636 |
| 624 // Simulate an incoming notification for the given id and payload. | 637 // Simulate an incoming notification for the given id and payload. |
| 625 void EmitInvalidationForTest( | 638 void EmitInvalidationForTest( |
| 626 const invalidation::ObjectId& id, | 639 const invalidation::ObjectId& id, |
| 627 const std::string& payload); | 640 const std::string& payload); |
| 628 | 641 |
| 629 // Called when a datatype (SyncableService) has a need for sync to start | 642 // 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 | 733 // because OnPassphraseAccepted() was called, or because we've gotten a |
| 721 // OnPassphraseRequired() but no data types are enabled). | 734 // OnPassphraseRequired() but no data types are enabled). |
| 722 void ResolvePassphraseRequired(); | 735 void ResolvePassphraseRequired(); |
| 723 | 736 |
| 724 // During initial signin, ProfileSyncService caches the user's signin | 737 // During initial signin, ProfileSyncService caches the user's signin |
| 725 // passphrase so it can be used to encrypt/decrypt data after sync starts up. | 738 // 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 | 739 // This routine is invoked once the backend has started up to use the |
| 727 // cached passphrase and clear it out when it is done. | 740 // cached passphrase and clear it out when it is done. |
| 728 void ConsumeCachedPassphraseIfPossible(); | 741 void ConsumeCachedPassphraseIfPossible(); |
| 729 | 742 |
| 743 // RequestAccessToken initiates RPC to request downscoped access token from |
| 744 // refresh token. This happens when TokenService loads OAuth2 login token and |
| 745 // when sync server returns AUTH_ERROR which indicates it is time to refresh |
| 746 // token. |
| 747 virtual void RequestAccessToken(); |
| 748 |
| 730 // If |delete_sync_data_folder| is true, then this method will delete all | 749 // 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). | 750 // previous "Sync Data" folders. (useful if the folder is partial/corrupt). |
| 732 void InitializeBackend(bool delete_sync_data_folder); | 751 void InitializeBackend(bool delete_sync_data_folder); |
| 733 | 752 |
| 734 // Initializes the various settings from the command line. | 753 // Initializes the various settings from the command line. |
| 735 void InitSettings(); | 754 void InitSettings(); |
| 736 | 755 |
| 737 // Sets the last synced time to the current time. | 756 // Sets the last synced time to the current time. |
| 738 void UpdateLastSyncedTime(); | 757 void UpdateLastSyncedTime(); |
| 739 | 758 |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 // Dispatches invalidations to handlers. Set in Initialize() and | 961 // Dispatches invalidations to handlers. Set in Initialize() and |
| 943 // unset in Shutdown(). | 962 // unset in Shutdown(). |
| 944 scoped_ptr<syncer::InvalidatorRegistrar> invalidator_registrar_; | 963 scoped_ptr<syncer::InvalidatorRegistrar> invalidator_registrar_; |
| 945 // Queues any acknowledgements received while the backend is uninitialized. | 964 // Queues any acknowledgements received while the backend is uninitialized. |
| 946 AckHandleReplayQueue ack_replay_queue_; | 965 AckHandleReplayQueue ack_replay_queue_; |
| 947 | 966 |
| 948 // Sync's internal debug info listener. Used to record datatype configuration | 967 // Sync's internal debug info listener. Used to record datatype configuration |
| 949 // and association information. | 968 // and association information. |
| 950 syncer::WeakHandle<syncer::DataTypeDebugInfoListener> debug_info_listener_; | 969 syncer::WeakHandle<syncer::DataTypeDebugInfoListener> debug_info_listener_; |
| 951 | 970 |
| 971 // ProfileSyncService needs to remember access token in order to invalidate it |
| 972 // with OAuth2TokenService. |
| 973 std::string access_token_; |
| 974 |
| 975 // ProfileSyncService needs to hold reference to access_token_request_ for |
| 976 // the duration of request in order to receive callbacks. |
| 977 scoped_ptr<OAuth2TokenService::Request> access_token_request_; |
| 978 |
| 979 // If RequestAccessToken fails with transient error then retry requesting |
| 980 // access token with exponential backoff. |
| 981 base::OneShotTimer<ProfileSyncService> request_access_token_retry_timer_; |
| 982 net::BackoffEntry request_access_token_backoff_; |
| 983 |
| 952 DISALLOW_COPY_AND_ASSIGN(ProfileSyncService); | 984 DISALLOW_COPY_AND_ASSIGN(ProfileSyncService); |
| 953 }; | 985 }; |
| 954 | 986 |
| 955 bool ShouldShowActionOnUI( | 987 bool ShouldShowActionOnUI( |
| 956 const syncer::SyncProtocolError& error); | 988 const syncer::SyncProtocolError& error); |
| 957 | 989 |
| 958 | 990 |
| 959 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ | 991 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ |
| OLD | NEW |