Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(526)

Side by Side Diff: components/sync/driver/sync_service.h

Issue 2376123003: [Sync] Move //components/sync to the syncer namespace. (Closed)
Patch Set: Rebase. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/sync/driver/sync_prefs_unittest.cc ('k') | components/sync/driver/sync_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 COMPONENTS_SYNC_DRIVER_SYNC_SERVICE_H_ 5 #ifndef COMPONENTS_SYNC_DRIVER_SYNC_SERVICE_H_
6 #define COMPONENTS_SYNC_DRIVER_SYNC_SERVICE_H_ 6 #define COMPONENTS_SYNC_DRIVER_SYNC_SERVICE_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "components/sync/base/model_type.h" 16 #include "components/sync/base/model_type.h"
17 #include "components/sync/core/connection_status.h" 17 #include "components/sync/core/connection_status.h"
18 #include "components/sync/driver/data_type_encryption_handler.h" 18 #include "components/sync/driver/data_type_encryption_handler.h"
19 #include "components/sync/driver/sync_service_observer.h" 19 #include "components/sync/driver/sync_service_observer.h"
20 #include "google_apis/gaia/google_service_auth_error.h" 20 #include "google_apis/gaia/google_service_auth_error.h"
21 21
22 class GoogleServiceAuthError; 22 class GoogleServiceAuthError;
23 23
24 namespace browser_sync { 24 namespace sync_sessions {
25 class ProtocolEventObserver; 25 class OpenTabsUIDelegate;
26 } 26 } // namespace sync_sessions
27 27
28 namespace syncer { 28 namespace syncer {
29 29
30 class BaseTransaction; 30 class BaseTransaction;
31 class DataTypeController;
31 class JsController; 32 class JsController;
33 class LocalDeviceInfoProvider;
34 class ProtocolEventObserver;
35 class SyncClient;
32 class SyncCycleSnapshot; 36 class SyncCycleSnapshot;
33 class TypeDebugInfoObserver; 37 class TypeDebugInfoObserver;
34 struct SyncStatus; 38 struct SyncStatus;
35 struct UserShare; 39 struct UserShare;
36 40
37 } // namespace syncer
38
39 namespace sync_sessions {
40 class OpenTabsUIDelegate;
41 } // namespace sync_sessions
42
43 namespace sync_driver {
44
45 class DataTypeController;
46 class LocalDeviceInfoProvider;
47 class SyncClient;
48
49 // UIs that need to prevent Sync startup should hold an instance of this class 41 // UIs that need to prevent Sync startup should hold an instance of this class
50 // until the user has finished modifying sync settings. This is not an inner 42 // until the user has finished modifying sync settings. This is not an inner
51 // class of SyncService to enable forward declarations. 43 // class of SyncService to enable forward declarations.
52 class SyncSetupInProgressHandle { 44 class SyncSetupInProgressHandle {
53 public: 45 public:
54 // UIs should not construct this directly, but instead call 46 // UIs should not construct this directly, but instead call
55 // SyncService::GetSetupInProgress(). 47 // SyncService::GetSetupInProgress().
56 explicit SyncSetupInProgressHandle(base::Closure on_destroy); 48 explicit SyncSetupInProgressHandle(base::Closure on_destroy);
57 49
58 ~SyncSetupInProgressHandle(); 50 ~SyncSetupInProgressHandle();
(...skipping 19 matching lines...) Expand all
78 KEEP_DATA, 70 KEEP_DATA,
79 CLEAR_DATA, 71 CLEAR_DATA,
80 }; 72 };
81 73
82 // Status of sync server connection, sync token and token request. 74 // Status of sync server connection, sync token and token request.
83 struct SyncTokenStatus { 75 struct SyncTokenStatus {
84 SyncTokenStatus(); 76 SyncTokenStatus();
85 77
86 // Sync server connection status reported by sync backend. 78 // Sync server connection status reported by sync backend.
87 base::Time connection_status_update_time; 79 base::Time connection_status_update_time;
88 syncer::ConnectionStatus connection_status; 80 ConnectionStatus connection_status;
89 81
90 // Times when OAuth2 access token is requested and received. 82 // Times when OAuth2 access token is requested and received.
91 base::Time token_request_time; 83 base::Time token_request_time;
92 base::Time token_receive_time; 84 base::Time token_receive_time;
93 85
94 // Error returned by OAuth2TokenService for token request and time when 86 // Error returned by OAuth2TokenService for token request and time when
95 // next request is scheduled. 87 // next request is scheduled.
96 GoogleServiceAuthError last_get_token_error; 88 GoogleServiceAuthError last_get_token_error;
97 base::Time next_token_request_time; 89 base::Time next_token_request_time;
98 }; 90 };
(...skipping 12 matching lines...) Expand all
111 virtual bool IsSyncAllowed() const = 0; 103 virtual bool IsSyncAllowed() const = 0;
112 104
113 // Returns true if sync is fully initialized and active. This implies that 105 // Returns true if sync is fully initialized and active. This implies that
114 // an initial configuration has successfully completed, although there may 106 // an initial configuration has successfully completed, although there may
115 // be datatype specific, auth, or other transient errors. To see which 107 // be datatype specific, auth, or other transient errors. To see which
116 // datetypes are actually syncing, see GetActiveTypes() below. 108 // datetypes are actually syncing, see GetActiveTypes() below.
117 virtual bool IsSyncActive() const = 0; 109 virtual bool IsSyncActive() const = 0;
118 110
119 // Triggers a GetUpdates call for the specified |types|, pulling any new data 111 // Triggers a GetUpdates call for the specified |types|, pulling any new data
120 // from the sync server. 112 // from the sync server.
121 virtual void TriggerRefresh(const syncer::ModelTypeSet& types) = 0; 113 virtual void TriggerRefresh(const ModelTypeSet& types) = 0;
122 114
123 // Get the set of current active data types (those chosen or configured by 115 // Get the set of current active data types (those chosen or configured by
124 // the user which have not also encountered a runtime error). 116 // the user which have not also encountered a runtime error).
125 // Note that if the Sync engine is in the middle of a configuration, this 117 // Note that if the Sync engine is in the middle of a configuration, this
126 // will the the empty set. Once the configuration completes the set will 118 // will the the empty set. Once the configuration completes the set will
127 // be updated. 119 // be updated.
128 virtual syncer::ModelTypeSet GetActiveDataTypes() const = 0; 120 virtual ModelTypeSet GetActiveDataTypes() const = 0;
129 121
130 // Returns the SyncClient instance associated with this service. 122 // Returns the SyncClient instance associated with this service.
131 virtual SyncClient* GetSyncClient() const = 0; 123 virtual SyncClient* GetSyncClient() const = 0;
132 124
133 // Adds/removes an observer. SyncService does not take ownership of the 125 // Adds/removes an observer. SyncService does not take ownership of the
134 // observer. 126 // observer.
135 virtual void AddObserver(SyncServiceObserver* observer) = 0; 127 virtual void AddObserver(SyncServiceObserver* observer) = 0;
136 virtual void RemoveObserver(SyncServiceObserver* observer) = 0; 128 virtual void RemoveObserver(SyncServiceObserver* observer) = 0;
137 129
138 // Returns true if |observer| has already been added as an observer. 130 // Returns true if |observer| has already been added as an observer.
139 virtual bool HasObserver(const SyncServiceObserver* observer) const = 0; 131 virtual bool HasObserver(const SyncServiceObserver* observer) const = 0;
140 132
141 // --------------------------------------------------------------------------- 133 // ---------------------------------------------------------------------------
142 // TODO(sync): The methods below were pulled from ProfileSyncService, and 134 // TODO(sync): The methods below were pulled from ProfileSyncService, and
143 // should be evaluated to see if they should stay. 135 // should be evaluated to see if they should stay.
144 136
145 // Called when a datatype (SyncableService) has a need for sync to start 137 // Called when a datatype (SyncableService) has a need for sync to start
146 // ASAP, presumably because a local change event has occurred but we're 138 // ASAP, presumably because a local change event has occurred but we're
147 // still in deferred start mode, meaning the SyncableService hasn't been 139 // still in deferred start mode, meaning the SyncableService hasn't been
148 // told to MergeDataAndStartSyncing yet. 140 // told to MergeDataAndStartSyncing yet.
149 virtual void OnDataTypeRequestsSyncStartup(syncer::ModelType type) = 0; 141 virtual void OnDataTypeRequestsSyncStartup(ModelType type) = 0;
150 142
151 // Returns true if sync is allowed, requested, and the user is logged in. 143 // Returns true if sync is allowed, requested, and the user is logged in.
152 // (being logged in does not mean that tokens are available - tokens may 144 // (being logged in does not mean that tokens are available - tokens may
153 // be missing because they have not loaded yet, or because they were deleted 145 // be missing because they have not loaded yet, or because they were deleted
154 // due to http://crbug.com/121755). 146 // due to http://crbug.com/121755).
155 virtual bool CanSyncStart() const = 0; 147 virtual bool CanSyncStart() const = 0;
156 148
157 // Stops sync at the user's request. |data_fate| controls whether the sync 149 // Stops sync at the user's request. |data_fate| controls whether the sync
158 // backend should clear its data directory when it shuts down. Generally 150 // backend should clear its data directory when it shuts down. Generally
159 // KEEP_DATA is used when the user just stops sync, and CLEAR_DATA is used 151 // KEEP_DATA is used when the user just stops sync, and CLEAR_DATA is used
160 // when they sign out of the profile entirely. 152 // when they sign out of the profile entirely.
161 virtual void RequestStop(SyncStopDataFate data_fate) = 0; 153 virtual void RequestStop(SyncStopDataFate data_fate) = 0;
162 154
163 // The user requests that sync start. This only actually starts sync if 155 // The user requests that sync start. This only actually starts sync if
164 // IsSyncAllowed is true and the user is signed in. Once sync starts, 156 // IsSyncAllowed is true and the user is signed in. Once sync starts,
165 // other things such as IsFirstSetupComplete being false can still prevent 157 // other things such as IsFirstSetupComplete being false can still prevent
166 // it from moving into the "active" state. 158 // it from moving into the "active" state.
167 virtual void RequestStart() = 0; 159 virtual void RequestStart() = 0;
168 160
169 // Returns the set of types which are preferred for enabling. This is a 161 // Returns the set of types which are preferred for enabling. This is a
170 // superset of the active types (see GetActiveDataTypes()). 162 // superset of the active types (see GetActiveDataTypes()).
171 virtual syncer::ModelTypeSet GetPreferredDataTypes() const = 0; 163 virtual ModelTypeSet GetPreferredDataTypes() const = 0;
172 164
173 // Called when a user chooses which data types to sync. |sync_everything| 165 // Called when a user chooses which data types to sync. |sync_everything|
174 // represents whether they chose the "keep everything synced" option; if 166 // represents whether they chose the "keep everything synced" option; if
175 // true, |chosen_types| will be ignored and all data types will be synced. 167 // true, |chosen_types| will be ignored and all data types will be synced.
176 // |sync_everything| means "sync all current and future data types." 168 // |sync_everything| means "sync all current and future data types."
177 // |chosen_types| must be a subset of syncer::UserSelectableTypes(). 169 // |chosen_types| must be a subset of UserSelectableTypes().
178 virtual void OnUserChoseDatatypes(bool sync_everything, 170 virtual void OnUserChoseDatatypes(bool sync_everything,
179 syncer::ModelTypeSet chosen_types) = 0; 171 ModelTypeSet chosen_types) = 0;
180 172
181 // Called whe Sync has been setup by the user and can be started. 173 // Called whe Sync has been setup by the user and can be started.
182 virtual void SetFirstSetupComplete() = 0; 174 virtual void SetFirstSetupComplete() = 0;
183 175
184 // Returns true if initial sync setup is in progress (does not return true 176 // Returns true if initial sync setup is in progress (does not return true
185 // if the user is customizing sync after already completing setup once). 177 // if the user is customizing sync after already completing setup once).
186 // SyncService uses this to determine if it's OK to start syncing, or if the 178 // SyncService uses this to determine if it's OK to start syncing, or if the
187 // user is still setting up the initial sync configuration. 179 // user is still setting up the initial sync configuration.
188 virtual bool IsFirstSetupInProgress() const = 0; 180 virtual bool IsFirstSetupInProgress() const = 0;
189 181
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 239
248 // Asynchronously decrypts pending keys using |passphrase|. Returns false 240 // Asynchronously decrypts pending keys using |passphrase|. Returns false
249 // immediately if the passphrase could not be used to decrypt a locally cached 241 // immediately if the passphrase could not be used to decrypt a locally cached
250 // copy of encrypted keys; returns true otherwise. 242 // copy of encrypted keys; returns true otherwise.
251 virtual bool SetDecryptionPassphrase(const std::string& passphrase) 243 virtual bool SetDecryptionPassphrase(const std::string& passphrase)
252 WARN_UNUSED_RESULT = 0; 244 WARN_UNUSED_RESULT = 0;
253 245
254 // Checks whether the Cryptographer is ready to encrypt and decrypt updates 246 // Checks whether the Cryptographer is ready to encrypt and decrypt updates
255 // for sensitive data types. Caller must be holding a 247 // for sensitive data types. Caller must be holding a
256 // syncapi::BaseTransaction to ensure thread safety. 248 // syncapi::BaseTransaction to ensure thread safety.
257 virtual bool IsCryptographerReady( 249 virtual bool IsCryptographerReady(const BaseTransaction* trans) const = 0;
258 const syncer::BaseTransaction* trans) const = 0;
259 250
260 // TODO(akalin): This is called mostly by ModelAssociators and 251 // TODO(akalin): This is called mostly by ModelAssociators and
261 // tests. Figure out how to pass the handle to the ModelAssociators 252 // tests. Figure out how to pass the handle to the ModelAssociators
262 // directly, figure out how to expose this to tests, and remove this 253 // directly, figure out how to expose this to tests, and remove this
263 // function. 254 // function.
264 virtual syncer::UserShare* GetUserShare() const = 0; 255 virtual UserShare* GetUserShare() const = 0;
265 256
266 // Returns DeviceInfo provider for the local device. 257 // Returns DeviceInfo provider for the local device.
267 virtual LocalDeviceInfoProvider* GetLocalDeviceInfoProvider() const = 0; 258 virtual LocalDeviceInfoProvider* GetLocalDeviceInfoProvider() const = 0;
268 259
269 // Registers a data type controller with the sync service. This 260 // Registers a data type controller with the sync service. This
270 // makes the data type controller available for use, it does not 261 // makes the data type controller available for use, it does not
271 // enable or activate the synchronization of the data type (see 262 // enable or activate the synchronization of the data type (see
272 // ActivateDataType). Takes ownership of the pointer. 263 // ActivateDataType). Takes ownership of the pointer.
273 virtual void RegisterDataTypeController( 264 virtual void RegisterDataTypeController(
274 std::unique_ptr<DataTypeController> data_type_controller) = 0; 265 std::unique_ptr<DataTypeController> data_type_controller) = 0;
275 266
276 // Called to re-enable a type disabled by DisableDatatype(..). Note, this does 267 // Called to re-enable a type disabled by DisableDatatype(..). Note, this does
277 // not change the preferred state of a datatype, and is not persisted across 268 // not change the preferred state of a datatype, and is not persisted across
278 // restarts. 269 // restarts.
279 virtual void ReenableDatatype(syncer::ModelType type) = 0; 270 virtual void ReenableDatatype(ModelType type) = 0;
280 271
281 // Return sync token status. 272 // Return sync token status.
282 virtual SyncTokenStatus GetSyncTokenStatus() const = 0; 273 virtual SyncTokenStatus GetSyncTokenStatus() const = 0;
283 274
284 // Get a description of the sync status for displaying in the user interface. 275 // Get a description of the sync status for displaying in the user interface.
285 virtual std::string QuerySyncStatusSummaryString() = 0; 276 virtual std::string QuerySyncStatusSummaryString() = 0;
286 277
287 // Initializes a struct of status indicators with data from the backend. 278 // Initializes a struct of status indicators with data from the backend.
288 // Returns false if the backend was not available for querying; in that case 279 // Returns false if the backend was not available for querying; in that case
289 // the struct will be filled with default data. 280 // the struct will be filled with default data.
290 virtual bool QueryDetailedSyncStatus(syncer::SyncStatus* result) = 0; 281 virtual bool QueryDetailedSyncStatus(SyncStatus* result) = 0;
291 282
292 // Returns a user-friendly string form of last synced time (in minutes). 283 // Returns a user-friendly string form of last synced time (in minutes).
293 virtual base::string16 GetLastSyncedTimeString() const = 0; 284 virtual base::string16 GetLastSyncedTimeString() const = 0;
294 285
295 // Returns a human readable string describing backend initialization state. 286 // Returns a human readable string describing backend initialization state.
296 virtual std::string GetBackendInitializationStateString() const = 0; 287 virtual std::string GetBackendInitializationStateString() const = 0;
297 288
298 virtual syncer::SyncCycleSnapshot GetLastCycleSnapshot() const = 0; 289 virtual SyncCycleSnapshot GetLastCycleSnapshot() const = 0;
299 290
300 // Returns a ListValue indicating the status of all registered types. 291 // Returns a ListValue indicating the status of all registered types.
301 // 292 //
302 // The format is: 293 // The format is:
303 // [ {"name": <name>, "value": <value>, "status": <status> }, ... ] 294 // [ {"name": <name>, "value": <value>, "status": <status> }, ... ]
304 // where <name> is a type's name, <value> is a string providing details for 295 // where <name> is a type's name, <value> is a string providing details for
305 // the type's status, and <status> is one of "error", "warning" or "ok" 296 // the type's status, and <status> is one of "error", "warning" or "ok"
306 // depending on the type's current status. 297 // depending on the type's current status.
307 // 298 //
308 // This function is used by about_sync_util.cc to help populate the about:sync 299 // This function is used by about_sync_util.cc to help populate the about:sync
309 // page. It returns a ListValue rather than a DictionaryValue in part to make 300 // page. It returns a ListValue rather than a DictionaryValue in part to make
310 // it easier to iterate over its elements when constructing that page. 301 // it easier to iterate over its elements when constructing that page.
311 virtual base::Value* GetTypeStatusMap() const = 0; 302 virtual base::Value* GetTypeStatusMap() const = 0;
312 303
313 virtual const GURL& sync_service_url() const = 0; 304 virtual const GURL& sync_service_url() const = 0;
314 305
315 virtual std::string unrecoverable_error_message() const = 0; 306 virtual std::string unrecoverable_error_message() const = 0;
316 virtual tracked_objects::Location unrecoverable_error_location() const = 0; 307 virtual tracked_objects::Location unrecoverable_error_location() const = 0;
317 308
318 virtual void AddProtocolEventObserver( 309 virtual void AddProtocolEventObserver(ProtocolEventObserver* observer) = 0;
319 browser_sync::ProtocolEventObserver* observer) = 0; 310 virtual void RemoveProtocolEventObserver(ProtocolEventObserver* observer) = 0;
320 virtual void RemoveProtocolEventObserver(
321 browser_sync::ProtocolEventObserver* observer) = 0;
322 311
323 virtual void AddTypeDebugInfoObserver( 312 virtual void AddTypeDebugInfoObserver(TypeDebugInfoObserver* observer) = 0;
324 syncer::TypeDebugInfoObserver* observer) = 0; 313 virtual void RemoveTypeDebugInfoObserver(TypeDebugInfoObserver* observer) = 0;
325 virtual void RemoveTypeDebugInfoObserver(
326 syncer::TypeDebugInfoObserver* observer) = 0;
327 314
328 // Returns a weak pointer to the service's JsController. 315 // Returns a weak pointer to the service's JsController.
329 virtual base::WeakPtr<syncer::JsController> GetJsController() = 0; 316 virtual base::WeakPtr<JsController> GetJsController() = 0;
330 317
331 // Asynchronously fetches base::Value representations of all sync nodes and 318 // Asynchronously fetches base::Value representations of all sync nodes and
332 // returns them to the specified callback on this thread. 319 // returns them to the specified callback on this thread.
333 // 320 //
334 // These requests can live a long time and return when you least expect it. 321 // These requests can live a long time and return when you least expect it.
335 // For safety, the callback should be bound to some sort of WeakPtr<> or 322 // For safety, the callback should be bound to some sort of WeakPtr<> or
336 // scoped_refptr<>. 323 // scoped_refptr<>.
337 virtual void GetAllNodes( 324 virtual void GetAllNodes(
338 const base::Callback<void(std::unique_ptr<base::ListValue>)>& 325 const base::Callback<void(std::unique_ptr<base::ListValue>)>&
339 callback) = 0; 326 callback) = 0;
340 327
341 protected: 328 protected:
342 SyncService() {} 329 SyncService() {}
343 330
344 private: 331 private:
345 DISALLOW_COPY_AND_ASSIGN(SyncService); 332 DISALLOW_COPY_AND_ASSIGN(SyncService);
346 }; 333 };
347 334
348 } // namespace sync_driver 335 } // namespace syncer
349 336
350 #endif // COMPONENTS_SYNC_DRIVER_SYNC_SERVICE_H_ 337 #endif // COMPONENTS_SYNC_DRIVER_SYNC_SERVICE_H_
OLDNEW
« no previous file with comments | « components/sync/driver/sync_prefs_unittest.cc ('k') | components/sync/driver/sync_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698