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