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/strings/string16.h" | 19 #include "base/strings/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 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 syncer::InvalidationHandler* handler, | 608 syncer::InvalidationHandler* handler, |
606 const syncer::ObjectIdSet& ids) OVERRIDE; | 609 const syncer::ObjectIdSet& ids) OVERRIDE; |
607 virtual void UnregisterInvalidationHandler( | 610 virtual void UnregisterInvalidationHandler( |
608 syncer::InvalidationHandler* handler) OVERRIDE; | 611 syncer::InvalidationHandler* handler) OVERRIDE; |
609 virtual void AcknowledgeInvalidation( | 612 virtual void AcknowledgeInvalidation( |
610 const invalidation::ObjectId& id, | 613 const invalidation::ObjectId& id, |
611 const syncer::AckHandle& ack_handle) OVERRIDE; | 614 const syncer::AckHandle& ack_handle) OVERRIDE; |
612 | 615 |
613 virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE; | 616 virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE; |
614 | 617 |
| 618 // OAuth2TokenService::Consumer implementation |
| 619 virtual void OnGetTokenSuccess( |
| 620 const OAuth2TokenService::Request* request, |
| 621 const std::string& access_token, |
| 622 const base::Time& expiration_time) OVERRIDE; |
| 623 virtual void OnGetTokenFailure( |
| 624 const OAuth2TokenService::Request* request, |
| 625 const GoogleServiceAuthError& error) OVERRIDE; |
| 626 |
615 // BrowserContextKeyedService implementation. This must be called exactly | 627 // BrowserContextKeyedService implementation. This must be called exactly |
616 // once (before this object is destroyed). | 628 // once (before this object is destroyed). |
617 virtual void Shutdown() OVERRIDE; | 629 virtual void Shutdown() OVERRIDE; |
618 | 630 |
619 // Simulate an incoming notification for the given id and payload. | 631 // Simulate an incoming notification for the given id and payload. |
620 void EmitInvalidationForTest( | 632 void EmitInvalidationForTest( |
621 const invalidation::ObjectId& id, | 633 const invalidation::ObjectId& id, |
622 const std::string& payload); | 634 const std::string& payload); |
623 | 635 |
624 // Called when a datatype (SyncableService) has a need for sync to start | 636 // 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... |
715 // because OnPassphraseAccepted() was called, or because we've gotten a | 727 // because OnPassphraseAccepted() was called, or because we've gotten a |
716 // OnPassphraseRequired() but no data types are enabled). | 728 // OnPassphraseRequired() but no data types are enabled). |
717 void ResolvePassphraseRequired(); | 729 void ResolvePassphraseRequired(); |
718 | 730 |
719 // During initial signin, ProfileSyncService caches the user's signin | 731 // During initial signin, ProfileSyncService caches the user's signin |
720 // passphrase so it can be used to encrypt/decrypt data after sync starts up. | 732 // passphrase so it can be used to encrypt/decrypt data after sync starts up. |
721 // This routine is invoked once the backend has started up to use the | 733 // This routine is invoked once the backend has started up to use the |
722 // cached passphrase and clear it out when it is done. | 734 // cached passphrase and clear it out when it is done. |
723 void ConsumeCachedPassphraseIfPossible(); | 735 void ConsumeCachedPassphraseIfPossible(); |
724 | 736 |
| 737 // RequestAccessToken initiates RPC to request downscoped access token from |
| 738 // refresh token. This happens when TokenService loads OAuth2 login token and |
| 739 // when sync server returns AUTH_ERROR which indicates it is time to refresh |
| 740 // token. |
| 741 virtual void RequestAccessToken(); |
| 742 |
725 // If |delete_sync_data_folder| is true, then this method will delete all | 743 // If |delete_sync_data_folder| is true, then this method will delete all |
726 // previous "Sync Data" folders. (useful if the folder is partial/corrupt). | 744 // previous "Sync Data" folders. (useful if the folder is partial/corrupt). |
727 void InitializeBackend(bool delete_sync_data_folder); | 745 void InitializeBackend(bool delete_sync_data_folder); |
728 | 746 |
729 // Initializes the various settings from the command line. | 747 // Initializes the various settings from the command line. |
730 void InitSettings(); | 748 void InitSettings(); |
731 | 749 |
732 // Sets the last synced time to the current time. | 750 // Sets the last synced time to the current time. |
733 void UpdateLastSyncedTime(); | 751 void UpdateLastSyncedTime(); |
734 | 752 |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 // Dispatches invalidations to handlers. Set in Initialize() and | 951 // Dispatches invalidations to handlers. Set in Initialize() and |
934 // unset in Shutdown(). | 952 // unset in Shutdown(). |
935 scoped_ptr<syncer::InvalidatorRegistrar> invalidator_registrar_; | 953 scoped_ptr<syncer::InvalidatorRegistrar> invalidator_registrar_; |
936 // Queues any acknowledgements received while the backend is uninitialized. | 954 // Queues any acknowledgements received while the backend is uninitialized. |
937 AckHandleReplayQueue ack_replay_queue_; | 955 AckHandleReplayQueue ack_replay_queue_; |
938 | 956 |
939 // Sync's internal debug info listener. Used to record datatype configuration | 957 // Sync's internal debug info listener. Used to record datatype configuration |
940 // and association information. | 958 // and association information. |
941 syncer::WeakHandle<syncer::DataTypeDebugInfoListener> debug_info_listener_; | 959 syncer::WeakHandle<syncer::DataTypeDebugInfoListener> debug_info_listener_; |
942 | 960 |
| 961 // Specifies whenever to use oauth2 access token or ClientLogin token in |
| 962 // communications with sync and xmpp servers. |
| 963 // TODO(pavely): Remove once android is converted to oauth2 tokens. |
| 964 bool use_oauth2_token_; |
| 965 |
| 966 // ProfileSyncService needs to remember access token in order to invalidate it |
| 967 // with OAuth2TokenService. |
| 968 std::string access_token_; |
| 969 |
| 970 // ProfileSyncService needs to hold reference to access_token_request_ for |
| 971 // the duration of request in order to receive callbacks. |
| 972 scoped_ptr<OAuth2TokenService::Request> access_token_request_; |
| 973 |
| 974 // If RequestAccessToken fails with transient error then retry requesting |
| 975 // access token with exponential backoff. |
| 976 base::OneShotTimer<ProfileSyncService> request_access_token_retry_timer_; |
| 977 net::BackoffEntry request_access_token_backoff_; |
| 978 |
943 DISALLOW_COPY_AND_ASSIGN(ProfileSyncService); | 979 DISALLOW_COPY_AND_ASSIGN(ProfileSyncService); |
944 }; | 980 }; |
945 | 981 |
946 bool ShouldShowActionOnUI( | 982 bool ShouldShowActionOnUI( |
947 const syncer::SyncProtocolError& error); | 983 const syncer::SyncProtocolError& error); |
948 | 984 |
949 | 985 |
950 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ | 986 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ |
OLD | NEW |