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

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

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