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