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/scoped_vector.h" | 17 #include "base/memory/scoped_vector.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/strings/string16.h" | 20 #include "base/strings/string16.h" |
21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
22 #include "base/timer/timer.h" | 22 #include "base/timer/timer.h" |
23 #include "chrome/browser/sync/backend_unrecoverable_error_handler.h" | 23 #include "chrome/browser/sync/backend_unrecoverable_error_handler.h" |
24 #include "chrome/browser/sync/backup_rollback_controller.h" | 24 #include "chrome/browser/sync/backup_rollback_controller.h" |
25 #include "chrome/browser/sync/glue/local_device_info_provider.h" | |
26 #include "chrome/browser/sync/glue/sync_backend_host.h" | 25 #include "chrome/browser/sync/glue/sync_backend_host.h" |
27 #include "chrome/browser/sync/glue/synced_device_tracker.h" | 26 #include "chrome/browser/sync/glue/synced_device_tracker.h" |
28 #include "chrome/browser/sync/profile_sync_service_base.h" | 27 #include "chrome/browser/sync/profile_sync_service_base.h" |
29 #include "chrome/browser/sync/profile_sync_service_observer.h" | 28 #include "chrome/browser/sync/profile_sync_service_observer.h" |
30 #include "chrome/browser/sync/protocol_event_observer.h" | 29 #include "chrome/browser/sync/protocol_event_observer.h" |
31 #include "chrome/browser/sync/sessions/sessions_sync_manager.h" | 30 #include "chrome/browser/sync/sessions/sessions_sync_manager.h" |
32 #include "chrome/browser/sync/startup_controller.h" | 31 #include "chrome/browser/sync/startup_controller.h" |
33 #include "components/keyed_service/core/keyed_service.h" | 32 #include "components/keyed_service/core/keyed_service.h" |
34 #include "components/signin/core/browser/signin_manager_base.h" | 33 #include "components/signin/core/browser/signin_manager_base.h" |
35 #include "components/sync_driver/data_type_controller.h" | 34 #include "components/sync_driver/data_type_controller.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 struct StatusCounters; | 81 struct StatusCounters; |
83 struct SyncCredentials; | 82 struct SyncCredentials; |
84 struct UpdateCounters; | 83 struct UpdateCounters; |
85 struct UserShare; | 84 struct UserShare; |
86 } // namespace syncer | 85 } // namespace syncer |
87 | 86 |
88 namespace sync_pb { | 87 namespace sync_pb { |
89 class EncryptedData; | 88 class EncryptedData; |
90 } // namespace sync_pb | 89 } // namespace sync_pb |
91 | 90 |
92 using browser_sync::LocalDeviceInfoProvider; | |
93 using browser_sync::SessionsSyncManager; | 91 using browser_sync::SessionsSyncManager; |
94 | 92 |
95 // ProfileSyncService is the layer between browser subsystems like bookmarks, | 93 // ProfileSyncService is the layer between browser subsystems like bookmarks, |
96 // and the sync backend. Each subsystem is logically thought of as being | 94 // and the sync backend. Each subsystem is logically thought of as being |
97 // a sync datatype. | 95 // a sync datatype. |
98 // | 96 // |
99 // Individual datatypes can, at any point, be in a variety of stages of being | 97 // Individual datatypes can, at any point, be in a variety of stages of being |
100 // "enabled". Here are some specific terms for concepts used in this class: | 98 // "enabled". Here are some specific terms for concepts used in this class: |
101 // | 99 // |
102 // 'Registered' (feature suppression for a datatype) | 100 // 'Registered' (feature suppression for a datatype) |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 // | 175 // |
178 class ProfileSyncService : public ProfileSyncServiceBase, | 176 class ProfileSyncService : public ProfileSyncServiceBase, |
179 public browser_sync::SyncFrontend, | 177 public browser_sync::SyncFrontend, |
180 public sync_driver::SyncPrefObserver, | 178 public sync_driver::SyncPrefObserver, |
181 public browser_sync::DataTypeManagerObserver, | 179 public browser_sync::DataTypeManagerObserver, |
182 public syncer::UnrecoverableErrorHandler, | 180 public syncer::UnrecoverableErrorHandler, |
183 public KeyedService, | 181 public KeyedService, |
184 public browser_sync::DataTypeEncryptionHandler, | 182 public browser_sync::DataTypeEncryptionHandler, |
185 public OAuth2TokenService::Consumer, | 183 public OAuth2TokenService::Consumer, |
186 public OAuth2TokenService::Observer, | 184 public OAuth2TokenService::Observer, |
| 185 public SessionsSyncManager::SyncInternalApiDelegate, |
187 public SigninManagerBase::Observer { | 186 public SigninManagerBase::Observer { |
188 public: | 187 public: |
189 typedef browser_sync::SyncBackendHost::Status Status; | 188 typedef browser_sync::SyncBackendHost::Status Status; |
190 | 189 |
191 // Status of sync server connection, sync token and token request. | 190 // Status of sync server connection, sync token and token request. |
192 struct SyncTokenStatus { | 191 struct SyncTokenStatus { |
193 SyncTokenStatus(); | 192 SyncTokenStatus(); |
194 ~SyncTokenStatus(); | 193 ~SyncTokenStatus(); |
195 | 194 |
196 // Sync server connection status reported by sync backend. | 195 // Sync server connection status reported by sync backend. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 ROLLBACK // Backend for rollback. | 258 ROLLBACK // Backend for rollback. |
260 }; | 259 }; |
261 | 260 |
262 // Default sync server URL. | 261 // Default sync server URL. |
263 static const char* kSyncServerUrl; | 262 static const char* kSyncServerUrl; |
264 // Sync server URL for dev channel users | 263 // Sync server URL for dev channel users |
265 static const char* kDevServerUrl; | 264 static const char* kDevServerUrl; |
266 | 265 |
267 // Takes ownership of |factory| and |signin_wrapper|. | 266 // Takes ownership of |factory| and |signin_wrapper|. |
268 ProfileSyncService( | 267 ProfileSyncService( |
269 scoped_ptr<ProfileSyncComponentsFactory> factory, | 268 ProfileSyncComponentsFactory* factory, |
270 Profile* profile, | 269 Profile* profile, |
271 scoped_ptr<SupervisedUserSigninManagerWrapper> signin_wrapper, | 270 scoped_ptr<SupervisedUserSigninManagerWrapper> signin_wrapper, |
272 ProfileOAuth2TokenService* oauth2_token_service, | 271 ProfileOAuth2TokenService* oauth2_token_service, |
273 browser_sync::ProfileSyncServiceStartBehavior start_behavior); | 272 browser_sync::ProfileSyncServiceStartBehavior start_behavior); |
274 virtual ~ProfileSyncService(); | 273 virtual ~ProfileSyncService(); |
275 | 274 |
276 // Initializes the object. This must be called at most once, and | 275 // Initializes the object. This must be called at most once, and |
277 // immediately after an object of this class is constructed. | 276 // immediately after an object of this class is constructed. |
278 void Initialize(); | 277 void Initialize(); |
279 | 278 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 // in a message that allows the component to delete its local sync state. | 344 // in a message that allows the component to delete its local sync state. |
346 void InitializeNonBlockingType( | 345 void InitializeNonBlockingType( |
347 syncer::ModelType type, | 346 syncer::ModelType type, |
348 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | 347 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
349 const base::WeakPtr<syncer::ModelTypeSyncProxyImpl>& proxy); | 348 const base::WeakPtr<syncer::ModelTypeSyncProxyImpl>& proxy); |
350 | 349 |
351 // Return the active OpenTabsUIDelegate. If sessions is not enabled or not | 350 // Return the active OpenTabsUIDelegate. If sessions is not enabled or not |
352 // currently syncing, returns NULL. | 351 // currently syncing, returns NULL. |
353 virtual browser_sync::OpenTabsUIDelegate* GetOpenTabsUIDelegate(); | 352 virtual browser_sync::OpenTabsUIDelegate* GetOpenTabsUIDelegate(); |
354 | 353 |
355 // Returns the SyncedWindowDelegatesGetter from the embedded sessions manager. | |
356 virtual browser_sync::SyncedWindowDelegatesGetter* | |
357 GetSyncedWindowDelegatesGetter() const; | |
358 | |
359 // Returns the SyncableService for syncer::SESSIONS. | 354 // Returns the SyncableService for syncer::SESSIONS. |
360 virtual syncer::SyncableService* GetSessionsSyncableService(); | 355 virtual syncer::SyncableService* GetSessionsSyncableService(); |
361 | 356 |
362 // Returns DeviceInfo provider for the local device. | 357 // SyncInternalApiDelegate implementation. |
363 virtual browser_sync::LocalDeviceInfoProvider* GetLocalDeviceInfoProvider(); | 358 // |
| 359 // Returns sync's representation of the local device info. |
| 360 // Return value is an empty scoped_ptr if the device info is unavailable. |
| 361 virtual scoped_ptr<browser_sync::DeviceInfo> GetLocalDeviceInfo() |
| 362 const OVERRIDE; |
| 363 |
| 364 // Gets the guid for the local device. Can be used by other layers to |
| 365 // to distinguish sync data that belongs to the local device vs data |
| 366 // that belongs to remote devices. Returns empty string if sync is not |
| 367 // initialized. The GUID is not persistent across Chrome signout/signin. |
| 368 // If you sign out of Chrome and sign in, a new GUID is generated. |
| 369 virtual std::string GetLocalSyncCacheGUID() const OVERRIDE; |
364 | 370 |
365 // Returns sync's representation of the device info for a client identified | 371 // Returns sync's representation of the device info for a client identified |
366 // by |client_id|. Return value is an empty scoped ptr if the device info | 372 // by |client_id|. Return value is an empty scoped ptr if the device info |
367 // is unavailable. | 373 // is unavailable. |
368 virtual scoped_ptr<browser_sync::DeviceInfo> GetDeviceInfo( | 374 virtual scoped_ptr<browser_sync::DeviceInfo> GetDeviceInfo( |
369 const std::string& client_id) const; | 375 const std::string& client_id) const; |
370 | 376 |
371 // Gets the device info for all devices signed into the account associated | 377 // Gets the device info for all devices signed into the account associated |
372 // with this profile. | 378 // with this profile. |
373 virtual ScopedVector<browser_sync::DeviceInfo> GetAllSignedInDevices() const; | 379 virtual ScopedVector<browser_sync::DeviceInfo> GetAllSignedInDevices() const; |
(...skipping 15 matching lines...) Expand all Loading... |
389 virtual void DisableForUser(); | 395 virtual void DisableForUser(); |
390 | 396 |
391 // Disables sync for the user and prevents it from starting on next restart. | 397 // Disables sync for the user and prevents it from starting on next restart. |
392 virtual void StopSyncingPermanently(); | 398 virtual void StopSyncingPermanently(); |
393 | 399 |
394 // SyncFrontend implementation. | 400 // SyncFrontend implementation. |
395 virtual void OnBackendInitialized( | 401 virtual void OnBackendInitialized( |
396 const syncer::WeakHandle<syncer::JsBackend>& js_backend, | 402 const syncer::WeakHandle<syncer::JsBackend>& js_backend, |
397 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& | 403 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& |
398 debug_info_listener, | 404 debug_info_listener, |
399 const std::string& cache_guid, | |
400 bool success) OVERRIDE; | 405 bool success) OVERRIDE; |
401 virtual void OnSyncCycleCompleted() OVERRIDE; | 406 virtual void OnSyncCycleCompleted() OVERRIDE; |
402 virtual void OnProtocolEvent(const syncer::ProtocolEvent& event) OVERRIDE; | 407 virtual void OnProtocolEvent(const syncer::ProtocolEvent& event) OVERRIDE; |
403 virtual void OnDirectoryTypeCommitCounterUpdated( | 408 virtual void OnDirectoryTypeCommitCounterUpdated( |
404 syncer::ModelType type, | 409 syncer::ModelType type, |
405 const syncer::CommitCounters& counters) OVERRIDE; | 410 const syncer::CommitCounters& counters) OVERRIDE; |
406 virtual void OnDirectoryTypeUpdateCounterUpdated( | 411 virtual void OnDirectoryTypeUpdateCounterUpdated( |
407 syncer::ModelType type, | 412 syncer::ModelType type, |
408 const syncer::UpdateCounters& counters) OVERRIDE; | 413 const syncer::UpdateCounters& counters) OVERRIDE; |
409 virtual void OnDirectoryTypeStatusCounterUpdated( | 414 virtual void OnDirectoryTypeStatusCounterUpdated( |
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1094 base::WeakPtrFactory<ProfileSyncService> startup_controller_weak_factory_; | 1099 base::WeakPtrFactory<ProfileSyncService> startup_controller_weak_factory_; |
1095 | 1100 |
1096 // States related to sync token and connection. | 1101 // States related to sync token and connection. |
1097 base::Time connection_status_update_time_; | 1102 base::Time connection_status_update_time_; |
1098 syncer::ConnectionStatus connection_status_; | 1103 syncer::ConnectionStatus connection_status_; |
1099 base::Time token_request_time_; | 1104 base::Time token_request_time_; |
1100 base::Time token_receive_time_; | 1105 base::Time token_receive_time_; |
1101 GoogleServiceAuthError last_get_token_error_; | 1106 GoogleServiceAuthError last_get_token_error_; |
1102 base::Time next_token_request_time_; | 1107 base::Time next_token_request_time_; |
1103 | 1108 |
1104 scoped_ptr<LocalDeviceInfoProvider> local_device_; | |
1105 | |
1106 // Locally owned SyncableService implementations. | 1109 // Locally owned SyncableService implementations. |
1107 scoped_ptr<SessionsSyncManager> sessions_sync_manager_; | 1110 scoped_ptr<SessionsSyncManager> sessions_sync_manager_; |
1108 | 1111 |
1109 scoped_ptr<syncer::NetworkResources> network_resources_; | 1112 scoped_ptr<syncer::NetworkResources> network_resources_; |
1110 | 1113 |
1111 browser_sync::StartupController startup_controller_; | 1114 browser_sync::StartupController startup_controller_; |
1112 | 1115 |
1113 browser_sync::BackupRollbackController backup_rollback_controller_; | 1116 browser_sync::BackupRollbackController backup_rollback_controller_; |
1114 | 1117 |
1115 // Mode of current backend. | 1118 // Mode of current backend. |
1116 BackendMode backend_mode_; | 1119 BackendMode backend_mode_; |
1117 | 1120 |
1118 // When browser starts, delay sync backup/rollback backend start for this | 1121 // When browser starts, delay sync backup/rollback backend start for this |
1119 // time. | 1122 // time. |
1120 base::TimeDelta backup_start_delay_; | 1123 base::TimeDelta backup_start_delay_; |
1121 | 1124 |
1122 base::Callback<void(Profile*, base::Time, base::Time)> clear_browsing_data_; | 1125 base::Callback<void(Profile*, base::Time, base::Time)> clear_browsing_data_; |
1123 | 1126 |
1124 DISALLOW_COPY_AND_ASSIGN(ProfileSyncService); | 1127 DISALLOW_COPY_AND_ASSIGN(ProfileSyncService); |
1125 }; | 1128 }; |
1126 | 1129 |
1127 bool ShouldShowActionOnUI( | 1130 bool ShouldShowActionOnUI( |
1128 const syncer::SyncProtocolError& error); | 1131 const syncer::SyncProtocolError& error); |
1129 | 1132 |
1130 | 1133 |
1131 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ | 1134 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ |
OLD | NEW |