blob: c4d8efd63f5e233dca62d1fbe3009c8ac381c74e [file] [log] [blame]
[email protected]66761b952010-06-25 21:30:381// Copyright (c) 2010 The Chromium Authors. All rights reserved.
[email protected]132c85652009-08-05 01:18:272// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]132c85652009-08-05 01:18:275#ifndef CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_
6#define CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]132c85652009-08-05 01:18:278
9#include <string>
[email protected]132c85652009-08-05 01:18:2710
11#include "base/basictypes.h"
[email protected]61b694a2010-06-10 10:40:4612#include "base/gtest_prod_util.h"
[email protected]132c85652009-08-05 01:18:2713#include "base/observer_list.h"
14#include "base/scoped_ptr.h"
[email protected]066146872010-08-05 00:55:0815#include "base/string16.h"
[email protected]4aea04a2010-02-10 20:13:4316#include "base/time.h"
[email protected]990de362010-10-13 17:55:5017#include "base/timer.h"
[email protected]37858e52010-08-26 00:22:0218#include "chrome/browser/prefs/pref_member.h"
[email protected]e8234d32010-09-09 20:36:3919#include "chrome/browser/sync/engine/syncapi.h"
[email protected]72a31b42010-02-17 22:26:3320#include "chrome/browser/sync/glue/data_type_controller.h"
[email protected]e3e43d92010-02-26 22:02:3821#include "chrome/browser/sync/glue/data_type_manager.h"
[email protected]5edb9222010-08-18 00:23:2922#include "chrome/browser/sync/glue/session_model_associator.h"
[email protected]132c85652009-08-05 01:18:2723#include "chrome/browser/sync/glue/sync_backend_host.h"
[email protected]d3b98c82010-07-14 07:45:5924#include "chrome/browser/sync/profile_sync_service_observer.h"
[email protected]e8234d32010-09-09 20:36:3925#include "chrome/browser/sync/signin_manager.h"
[email protected]d80033e2009-10-16 10:32:0426#include "chrome/browser/sync/sync_setup_wizard.h"
[email protected]4aea04a2010-02-10 20:13:4327#include "chrome/browser/sync/syncable/model_type.h"
[email protected]eafb2182010-03-03 00:46:3128#include "chrome/browser/sync/unrecoverable_error_handler.h"
[email protected]99074c52010-08-19 18:44:1929#include "chrome/common/net/gaia/google_service_auth_error.h"
[email protected]c4c672a2010-03-23 21:47:0430#include "chrome/common/notification_observer.h"
31#include "chrome/common/notification_registrar.h"
[email protected]132c85652009-08-05 01:18:2732#include "googleurl/src/gurl.h"
[email protected]33cd0042010-09-08 19:25:2833#include "jingle/notifier/base/notifier_options.h"
[email protected]132c85652009-08-05 01:18:2734
[email protected]c4c672a2010-03-23 21:47:0435class NotificationDetails;
36class NotificationSource;
37class NotificationType;
[email protected]942690b132010-05-11 06:42:1438class Profile;
39class ProfileSyncFactory;
[email protected]e8234d32010-09-09 20:36:3940class TokenMigrator;
[email protected]c4c672a2010-03-23 21:47:0441
[email protected]132c85652009-08-05 01:18:2742// ProfileSyncService is the layer between browser subsystems like bookmarks,
[email protected]a1c2aef62010-04-02 02:58:0543// and the sync backend. Each subsystem is logically thought of as being
44// a sync datatype.
45//
46// Individual datatypes can, at any point, be in a variety of stages of being
47// "enabled". Here are some specific terms for concepts used in this class:
48//
49// 'Registered' (feature suppression for a datatype)
50//
51// When a datatype is registered, the user has the option of syncing it.
52// The sync opt-in UI will show only registered types; a checkbox should
53// never be shown for an unregistered type, and nor should it ever be
54// synced.
55//
56// A datatype is considered registered once RegisterDataTypeController
57// has been called with that datatype's DataTypeController.
58//
59// 'Preferred' (user preferences and opt-out for a datatype)
60//
61// This means the user's opt-in or opt-out preference on a per-datatype
62// basis. The sync service will try to make active exactly these types.
63// If a user has opted out of syncing a particular datatype, it will
64// be registered, but not preferred.
65//
66// This state is controlled by the ConfigurePreferredDataTypes and
67// GetPreferredDataTypes. They are stored in the preferences system,
68// and persist; though if a datatype is not registered, it cannot
69// be a preferred datatype.
70//
71// 'Active' (run-time initialization of sync system for a datatype)
72//
73// An active datatype is a preferred datatype that is actively being
74// synchronized: the syncer has been instructed to querying the server
75// for this datatype, first-time merges have finished, and there is an
76// actively installed ChangeProcessor that listens for changes to this
77// datatype, propagating such changes into and out of the sync backend
78// as necessary.
79//
80// When a datatype is in the process of becoming active, it may be
81// in some intermediate state. Those finer-grained intermediate states
82// are differentiated by the DataTypeController state.
83//
[email protected]4aea04a2010-02-10 20:13:4384class ProfileSyncService : public browser_sync::SyncFrontend,
[email protected]c4c672a2010-03-23 21:47:0485 public browser_sync::UnrecoverableErrorHandler,
86 public NotificationObserver {
[email protected]132c85652009-08-05 01:18:2787 public:
88 typedef ProfileSyncServiceObserver Observer;
89 typedef browser_sync::SyncBackendHost::Status Status;
90
[email protected]1f97a112009-08-11 02:17:0691 enum SyncEventCodes {
92 MIN_SYNC_EVENT_CODE = 0,
93
94 // Events starting the sync service.
95 START_FROM_NTP = 1, // Sync was started from the ad in NTP
96 START_FROM_WRENCH = 2, // Sync was started from the Wrench menu.
97 START_FROM_OPTIONS = 3, // Sync was started from Wrench->Options.
[email protected]b220d13f2009-10-09 04:12:4698 START_FROM_BOOKMARK_MANAGER = 4, // Sync was started from Bookmark manager.
[email protected]1f97a112009-08-11 02:17:0699
[email protected]a7ab8332010-03-31 20:49:04100 // Events regarding cancellation of the signon process of sync.
[email protected]8ac2dc112009-10-01 23:19:13101 CANCEL_FROM_SIGNON_WITHOUT_AUTH = 10, // Cancelled before submitting
[email protected]1f97a112009-08-11 02:17:06102 // username and password.
103 CANCEL_DURING_SIGNON = 11, // Cancelled after auth.
[email protected]c976938f2010-10-12 04:55:44104 CANCEL_DURING_CONFIGURE = 12, // Cancelled before choosing data
[email protected]8c94d632010-06-25 22:38:00105 // types and clicking OK.
[email protected]1f97a112009-08-11 02:17:06106 // Events resulting in the stoppage of sync service.
107 STOP_FROM_OPTIONS = 20, // Sync was stopped from Wrench->Options.
108
109 // Miscellaneous events caused by sync service.
[email protected]1f97a112009-08-11 02:17:06110
111 MAX_SYNC_EVENT_CODE
112 };
113
[email protected]689a7a72010-09-29 19:56:41114 // Keep track of where we are when clearing server data.
115 enum ClearServerDataState {
116 CLEAR_NOT_STARTED = 1,
117 CLEAR_CLEARING = 2,
118 CLEAR_FAILED = 3,
119 CLEAR_SUCCEEDED = 4,
120 };
121
[email protected]f66bcdf2010-05-17 20:31:14122 // Default sync server URL.
123 static const char* kSyncServerUrl;
124 // Sync server URL for dev channel users
125 static const char* kDevServerUrl;
126
[email protected]e3e43d92010-02-26 22:02:38127 ProfileSyncService(ProfileSyncFactory* factory_,
128 Profile* profile,
[email protected]e8234d32010-09-09 20:36:39129 const std::string& cros_user);
[email protected]132c85652009-08-05 01:18:27130 virtual ~ProfileSyncService();
131
132 // Initializes the object. This should be called every time an object of this
133 // class is constructed.
134 void Initialize();
135
[email protected]e8234d32010-09-09 20:36:39136 void RegisterAuthNotifications();
137
138 // Return whether all sync tokens are loaded and
139 // available for the backend to start up.
140 bool AreCredentialsAvailable();
141
142 // Loads credentials migrated from the old user settings db.
143 void LoadMigratedCredentials(const std::string& username,
144 const std::string& token);
145
[email protected]4aea04a2010-02-10 20:13:43146 // Registers a data type controller with the sync service. This
147 // makes the data type controller available for use, it does not
148 // enable or activate the synchronization of the data type (see
149 // ActivateDataType). Takes ownership of the pointer.
150 void RegisterDataTypeController(
151 browser_sync::DataTypeController* data_type_controller);
152
[email protected]5edb9222010-08-18 00:23:29153 // Returns the session model associator associated with this type, but only if
154 // the associator is running. If it is doing anything else, it will return
155 // null.
156 browser_sync::SessionModelAssociator* GetSessionModelAssociator();
157
[email protected]689a7a72010-09-29 19:56:41158 // Maintain state of where we are in a server clear operation.
159 void ResetClearServerDataState();
160 ClearServerDataState GetClearServerDataState();
161
[email protected]a7ab8332010-03-31 20:49:04162 // Fills state_map with a map of current data types that are possible to
163 // sync, as well as their states.
164 void GetDataTypeControllerStates(
165 browser_sync::DataTypeController::StateMap* state_map) const;
[email protected]4aea04a2010-02-10 20:13:43166
[email protected]e8234d32010-09-09 20:36:39167 // Disables sync for user. Use ShowLoginDialog to enable.
[email protected]132c85652009-08-05 01:18:27168 virtual void DisableForUser();
169
[email protected]1ce52aa2010-09-08 19:07:36170 // Clears all Chromesync data from the server.
171 void ClearServerData();
172
[email protected]132c85652009-08-05 01:18:27173 // Whether sync is enabled by user or not.
[email protected]4772b072010-03-30 17:45:46174 virtual bool HasSyncSetupCompleted() const;
[email protected]2efebbbf2010-10-25 10:31:21175 virtual void SetSyncSetupCompleted();
[email protected]132c85652009-08-05 01:18:27176
[email protected]132c85652009-08-05 01:18:27177 // SyncFrontend implementation.
178 virtual void OnBackendInitialized();
179 virtual void OnSyncCycleCompleted();
180 virtual void OnAuthError();
[email protected]7f8abea2010-07-14 01:31:36181 virtual void OnStopSyncingPermanently();
[email protected]1ce52aa2010-09-08 19:07:36182 virtual void OnClearServerDataFailed();
[email protected]990de362010-10-13 17:55:50183 virtual void OnClearServerDataTimeout();
[email protected]1ce52aa2010-09-08 19:07:36184 virtual void OnClearServerDataSucceeded();
[email protected]132c85652009-08-05 01:18:27185
186 // Called when a user enters credentials through UI.
187 virtual void OnUserSubmittedAuth(const std::string& username,
[email protected]1fc9b3f2009-11-12 21:22:09188 const std::string& password,
[email protected]96209ccd2010-10-11 21:57:27189 const std::string& captcha,
190 const std::string& access_code);
[email protected]132c85652009-08-05 01:18:27191
[email protected]e8234d32010-09-09 20:36:39192 // Update the last auth error and notify observers of error state.
193 void UpdateAuthErrorState(const GoogleServiceAuthError& error);
194
[email protected]af909492010-06-10 18:45:38195 // Called when a user chooses which data types to sync as part of the sync
196 // setup wizard. |sync_everything| represents whether they chose the
[email protected]8c94d632010-06-25 22:38:00197 // "keep everything synced" option; if true, |chosen_types| will be ignored
198 // and all data types will be synced. |sync_everything| means "sync all
199 // current and future data types."
[email protected]af909492010-06-10 18:45:38200 virtual void OnUserChoseDatatypes(bool sync_everything,
[email protected]8c94d632010-06-25 22:38:00201 const syncable::ModelTypeSet& chosen_types);
[email protected]af909492010-06-10 18:45:38202
[email protected]a7ab8332010-03-31 20:49:04203 // Called when a user cancels any setup dialog (login, etc).
[email protected]132c85652009-08-05 01:18:27204 virtual void OnUserCancelledDialog();
205
206 // Get various information for displaying in the user interface.
207 browser_sync::SyncBackendHost::StatusSummary QuerySyncStatusSummary();
[email protected]f1e6e0212010-10-15 20:54:24208 virtual browser_sync::SyncBackendHost::Status QueryDetailedSyncStatus();
[email protected]132c85652009-08-05 01:18:27209
[email protected]712257e2009-11-11 22:57:46210 const GoogleServiceAuthError& GetAuthError() const {
[email protected]132c85652009-08-05 01:18:27211 return last_auth_error_;
212 }
213
214 // Displays a dialog for the user to enter GAIA credentials and attempt
215 // re-authentication, and returns true if it actually opened the dialog.
216 // Returns false if a dialog is already showing, an auth attempt is in
217 // progress, the sync system is already authenticated, or some error
218 // occurred preventing the action. We make it the duty of ProfileSyncService
219 // to open the dialog to easily ensure only one is ever showing.
[email protected]d6885592010-10-11 19:38:24220 virtual bool SetupInProgress() const;
[email protected]44b78f90a2009-10-15 17:32:20221 bool WizardIsVisible() const {
222 return wizard_.IsVisible();
223 }
[email protected]d6885592010-10-11 19:38:24224 virtual void ShowLoginDialog(gfx::NativeWindow parent_window);
[email protected]66d81002010-10-18 16:52:09225 void ShowConfigure(gfx::NativeWindow parent_window);
[email protected]8c94d632010-06-25 22:38:00226
[email protected]132c85652009-08-05 01:18:27227 // Pretty-printed strings for a given StatusSummary.
[email protected]066146872010-08-05 00:55:08228 static std::string BuildSyncStatusSummaryText(
[email protected]132c85652009-08-05 01:18:27229 const browser_sync::SyncBackendHost::StatusSummary& summary);
230
231 // Returns true if the SyncBackendHost has told us it's ready to accept
232 // changes.
233 // TODO(timsteele): What happens if the bookmark model is loaded, a change
234 // takes place, and the backend isn't initialized yet?
235 bool sync_initialized() const { return backend_initialized_; }
[email protected]f1e6e0212010-10-15 20:54:24236 virtual bool unrecoverable_error_detected() const {
[email protected]fb42c982009-09-16 22:33:33237 return unrecoverable_error_detected_;
238 }
[email protected]f6ec8b22010-06-08 23:40:06239 const std::string& unrecoverable_error_message() {
240 return unrecoverable_error_message_;
241 }
242 tracked_objects::Location unrecoverable_error_location() {
243 return unrecoverable_error_location_.get() ?
244 *unrecoverable_error_location_.get() : tracked_objects::Location();
245 }
[email protected]132c85652009-08-05 01:18:27246
247 bool UIShouldDepictAuthInProgress() const {
248 return is_auth_in_progress_;
249 }
250
[email protected]66d81002010-10-18 16:52:09251 bool observed_passphrase_required() const {
252 return observed_passphrase_required_;
253 }
254
[email protected]fc52c422010-11-19 18:59:23255 bool passphrase_required_for_decryption() const {
256 return passphrase_required_for_decryption_;
257 }
258
[email protected]132c85652009-08-05 01:18:27259 // A timestamp marking the last time the service observed a transition from
260 // the SYNCING state to the READY state. Note that this does not reflect the
261 // last time we polled the server to see if there were any changes; the
262 // timestamp is only snapped when syncing takes place and we download or
263 // upload some bookmark entity.
264 const base::Time& last_synced_time() const { return last_synced_time_; }
265
266 // Returns a user-friendly string form of last synced time (in minutes).
[email protected]f1e6e0212010-10-15 20:54:24267 virtual string16 GetLastSyncedTimeString() const;
[email protected]132c85652009-08-05 01:18:27268
269 // Returns the authenticated username of the sync user, or empty if none
270 // exists. It will only exist if the authentication service provider (e.g
271 // GAIA) has confirmed the username is authentic.
272 virtual string16 GetAuthenticatedUsername() const;
273
274 const std::string& last_attempted_user_email() const {
275 return last_attempted_user_email_;
276 }
277
278 // The profile we are syncing for.
[email protected]c976938f2010-10-12 04:55:44279 Profile* profile() const { return profile_; }
[email protected]132c85652009-08-05 01:18:27280
281 // Adds/removes an observer. ProfileSyncService does not take ownership of
282 // the observer.
[email protected]4772b072010-03-30 17:45:46283 virtual void AddObserver(Observer* observer);
284 virtual void RemoveObserver(Observer* observer);
[email protected]132c85652009-08-05 01:18:27285
[email protected]d1db1c332010-10-13 19:57:00286 // Returns true if |observer| has already been added as an observer.
287 bool HasObserver(Observer* observer) const;
288
[email protected]1f97a112009-08-11 02:17:06289 // Record stats on various events.
290 static void SyncEvent(SyncEventCodes code);
291
[email protected]eec3bcfa2009-11-12 17:23:43292 // Returns whether sync is enabled. Sync can be enabled/disabled both
293 // at compile time (e.g., on a per-OS basis) or at run time (e.g.,
294 // command-line switches).
295 static bool IsSyncEnabled();
296
[email protected]d1db1c332010-10-13 19:57:00297 // Returns whether sync is managed, i.e. controlled by configuration
[email protected]d3b98c82010-07-14 07:45:59298 // management. If so, the user is not allowed to configure sync.
299 bool IsManaged();
300
[email protected]db1df0f2009-08-18 22:36:05301 // UnrecoverableErrorHandler implementation.
[email protected]f6ec8b22010-06-08 23:40:06302 virtual void OnUnrecoverableError(
303 const tracked_objects::Location& from_here,
304 const std::string& message);
[email protected]db1df0f2009-08-18 22:36:05305
306 browser_sync::SyncBackendHost* backend() { return backend_.get(); }
307
[email protected]4aea04a2010-02-10 20:13:43308 virtual void ActivateDataType(
309 browser_sync::DataTypeController* data_type_controller,
310 browser_sync::ChangeProcessor* change_processor);
311 virtual void DeactivateDataType(
312 browser_sync::DataTypeController* data_type_controller,
313 browser_sync::ChangeProcessor* change_processor);
314
[email protected]c4c672a2010-03-23 21:47:04315 // NotificationObserver implementation.
316 virtual void Observe(NotificationType type,
317 const NotificationSource& source,
318 const NotificationDetails& details);
319
[email protected]a1c2aef62010-04-02 02:58:05320 // Changes which data types we're going to be syncing to |preferred_types|.
321 // If it is running, the DataTypeManager will be instructed to reconfigure
322 // the sync backend so that exactly these datatypes are actively synced. See
323 // class comment for more on what it means for a datatype to be Preferred.
324 virtual void ChangePreferredDataTypes(
325 const syncable::ModelTypeSet& preferred_types);
326
327 // Get the set of currently enabled data types (as chosen or configured by
328 // the user). See class comment for more on what it means for a datatype
329 // to be Preferred.
330 virtual void GetPreferredDataTypes(
331 syncable::ModelTypeSet* preferred_types) const;
332
333 // Gets the set of all data types that could be allowed (the set that
334 // should be advertised to the user). These will typically only change
335 // via a command-line option. See class comment for more on what it means
336 // for a datatype to be Registered.
337 virtual void GetRegisteredDataTypes(
338 syncable::ModelTypeSet* registered_types) const;
[email protected]a7ab8332010-03-31 20:49:04339
[email protected]ff0aa752010-06-10 22:40:52340 // Checks whether the Cryptographer is ready to encrypt and decrypt updates
341 // for sensitive data types.
342 virtual bool IsCryptographerReady() const;
343
[email protected]c976938f2010-10-12 04:55:44344 // Returns true if a secondary passphrase is being used.
345 virtual bool IsUsingSecondaryPassphrase() const;
346
[email protected]ee1adf4b2010-10-11 03:48:48347 // Sets the Cryptographer's passphrase, or caches it until that is possible.
348 // This will check asynchronously whether the passphrase is valid and notify
[email protected]dc39dd1b2010-10-07 18:08:11349 // ProfileSyncServiceObservers via the NotificationService when the outcome
350 // is known.
[email protected]954b1082010-11-10 20:22:50351 // |is_explicit| is true if the call is in response to the user explicitly
352 // setting a passphrase as opposed to implicitly (from the users' perspective)
353 // using their Google Account password. An implicit SetPassphrase will *not*
354 // *not* override an explicit passphrase set previously.
355 virtual void SetPassphrase(const std::string& passphrase, bool is_explicit);
[email protected]bb899b3f2010-06-23 21:35:32356
[email protected]5edb9222010-08-18 00:23:29357 // Returns whether processing changes is allowed. Check this before doing
358 // any model-modifying operations.
359 bool ShouldPushChanges();
360
[email protected]9a127f22010-09-17 21:05:16361 const GURL& sync_service_url() const { return sync_service_url_; }
[email protected]bb868b42010-11-18 22:33:00362 SigninManager* signin() { return signin_.get(); }
363 const std::string& cros_user() const { return cros_user_; }
[email protected]9a127f22010-09-17 21:05:16364
[email protected]132c85652009-08-05 01:18:27365 protected:
[email protected]82d9d2952010-05-15 00:36:16366 // Used by ProfileSyncServiceMock only.
367 //
368 // TODO(akalin): Separate this class out into an abstract
369 // ProfileSyncService interface and a ProfileSyncServiceImpl class
370 // so we don't need this hack anymore.
371 ProfileSyncService();
372
[email protected]7cef1c442010-07-07 17:05:22373 // Helper to install and configure a data type manager.
374 void ConfigureDataTypeManager();
[email protected]132c85652009-08-05 01:18:27375
[email protected]132c85652009-08-05 01:18:27376 // Starts up the backend sync components.
377 void StartUp();
378 // Shuts down the backend sync components.
379 // |sync_disabled| indicates if syncing is being disabled or not.
380 void Shutdown(bool sync_disabled);
381
[email protected]48352c12009-08-15 01:19:11382 // Methods to register and remove preferences.
383 void RegisterPreferences();
384 void ClearPreferences();
385
[email protected]e8234d32010-09-09 20:36:39386 // Return SyncCredentials from the TokenService.
387 sync_api::SyncCredentials GetCredentials();
388
[email protected]18af9a22010-08-11 00:47:19389 // Test need to override this to create backends that allow setting up
390 // initial conditions, such as populating sync nodes.
391 virtual void CreateBackend();
[email protected]132c85652009-08-05 01:18:27392
[email protected]7cef1c442010-07-07 17:05:22393 const browser_sync::DataTypeController::TypeMap& data_type_controllers() {
394 return data_type_controllers_;
395 }
396
[email protected]e8234d32010-09-09 20:36:39397 // The wizard will try to read the auth state out of the profile sync
398 // service using this member. Captcha and error state are reflected.
[email protected]712257e2009-11-11 22:57:46399 GoogleServiceAuthError last_auth_error_;
[email protected]132c85652009-08-05 01:18:27400
[email protected]7cef1c442010-07-07 17:05:22401 // Our asynchronous backend to communicate with sync components living on
402 // other threads.
403 scoped_ptr<browser_sync::SyncBackendHost> backend_;
404
[email protected]132c85652009-08-05 01:18:27405 // Cache of the last name the client attempted to authenticate.
406 std::string last_attempted_user_email_;
407
[email protected]66d81002010-10-18 16:52:09408 // Whether we have seen a SYNC_PASSPHRASE_REQUIRED since initializing the
409 // backend, telling us that it is safe to send a passphrase down ASAP.
410 bool observed_passphrase_required_;
411
[email protected]fc52c422010-11-19 18:59:23412 // Was the last SYNC_PASSPHRASE_REQUIRED notification sent because it
413 // was required for decryption?
414 bool passphrase_required_for_decryption_;
415
[email protected]132c85652009-08-05 01:18:27416 private:
[email protected]132c85652009-08-05 01:18:27417 friend class ProfileSyncServiceTest;
[email protected]4f5732a42010-09-21 22:39:09418 friend class ProfileSyncServicePasswordTest;
[email protected]65b3aa12010-02-22 22:49:00419 friend class ProfileSyncServicePreferenceTest;
[email protected]5edb9222010-08-18 00:23:29420 friend class ProfileSyncServiceSessionTest;
[email protected]61b694a2010-06-10 10:40:46421 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceTest, InitialState);
422 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceTest,
423 UnrecoverableErrorSuspendsService);
[email protected]132c85652009-08-05 01:18:27424
[email protected]18af9a22010-08-11 00:47:19425 // If |delete_sync_data_folder| is true, then this method will delete all
426 // previous "Sync Data" folders. (useful if the folder is partial/corrupt).
427 void InitializeBackend(bool delete_sync_data_folder);
428
[email protected]132c85652009-08-05 01:18:27429 // Initializes the various settings from the command line.
430 void InitSettings();
431
[email protected]132c85652009-08-05 01:18:27432 // Sets the last synced time to the current time.
433 void UpdateLastSyncedTime();
434
[email protected]57ecc4b2010-08-11 03:02:51435 static const char* GetPrefNameForDataType(syncable::ModelType data_type);
[email protected]a1c2aef62010-04-02 02:58:05436
[email protected]cb4c06e2009-08-22 00:24:39437 // Time at which we begin an attempt a GAIA authorization.
438 base::TimeTicks auth_start_time_;
439
440 // Time at which error UI is presented for the new tab page.
[email protected]1f97a112009-08-11 02:17:06441 base::TimeTicks auth_error_time_;
442
[email protected]e3e43d92010-02-26 22:02:38443 // Factory used to create various dependent objects.
444 ProfileSyncFactory* factory_;
445
[email protected]132c85652009-08-05 01:18:27446 // The profile whose data we are synchronizing.
447 Profile* profile_;
448
[email protected]e8234d32010-09-09 20:36:39449 // Email for the ChromiumOS user, if we're running under ChromiumOS.
450 std::string cros_user_;
[email protected]72a31b42010-02-17 22:26:33451
[email protected]132c85652009-08-05 01:18:27452 // TODO(ncarter): Put this in a profile, once there is UI for it.
453 // This specifies where to find the sync server.
454 GURL sync_service_url_;
455
[email protected]132c85652009-08-05 01:18:27456 // The last time we detected a successful transition from SYNCING state.
457 // Our backend notifies us whenever we should take a new snapshot.
458 base::Time last_synced_time_;
459
[email protected]4aea04a2010-02-10 20:13:43460 // List of available data type controllers.
[email protected]72a31b42010-02-17 22:26:33461 browser_sync::DataTypeController::TypeMap data_type_controllers_;
[email protected]db1df0f2009-08-18 22:36:05462
[email protected]132c85652009-08-05 01:18:27463 // Whether the SyncBackendHost has been initialized.
464 bool backend_initialized_;
465
[email protected]132c85652009-08-05 01:18:27466 // Various pieces of UI query this value to determine if they should show
467 // an "Authenticating.." type of message. We are the only central place
468 // all auth attempts funnel through, so it makes sense to provide this.
469 // As its name suggests, this should NOT be used for anything other than UI.
470 bool is_auth_in_progress_;
471
[email protected]44b78f90a2009-10-15 17:32:20472 SyncSetupWizard wizard_;
473
[email protected]e8234d32010-09-09 20:36:39474 // Encapsulates user signin with TokenService.
[email protected]bb868b42010-11-18 22:33:00475 scoped_ptr<SigninManager> signin_;
[email protected]e8234d32010-09-09 20:36:39476
[email protected]132c85652009-08-05 01:18:27477 // True if an unrecoverable error (e.g. violation of an assumed invariant)
478 // occurred during syncer operation. This value should be checked before
479 // doing any work that might corrupt things further.
480 bool unrecoverable_error_detected_;
481
[email protected]f6ec8b22010-06-08 23:40:06482 // A message sent when an unrecoverable error occurred.
483 std::string unrecoverable_error_message_;
484 scoped_ptr<tracked_objects::Location> unrecoverable_error_location_;
485
[email protected]33cd0042010-09-08 19:25:28486 // Contains options specific to how sync clients send and listen to
487 // notifications.
488 notifier::NotifierOptions notifier_options_;
[email protected]93d960ce2010-02-11 04:27:00489
[email protected]e3e43d92010-02-26 22:02:38490 // Manages the start and stop of the various data types.
491 scoped_ptr<browser_sync::DataTypeManager> data_type_manager_;
492
[email protected]132c85652009-08-05 01:18:27493 ObserverList<Observer> observers_;
494
[email protected]c4c672a2010-03-23 21:47:04495 NotificationRegistrar registrar_;
496
[email protected]2be7bf22010-04-23 21:02:37497 ScopedRunnableMethodFactory<ProfileSyncService>
[email protected]954b1082010-11-10 20:22:50498 scoped_runnable_method_factory_;
[email protected]2be7bf22010-04-23 21:02:37499
[email protected]d3b98c82010-07-14 07:45:59500 // The preference that controls whether sync is under control by configuration
501 // management.
502 BooleanPrefMember pref_sync_managed_;
503
[email protected]a47eeb52010-07-15 17:54:25504 // This allows us to gracefully handle an ABORTED return code from the
505 // DataTypeManager in the event that the server informed us to cease and
506 // desist syncing immediately.
507 bool expect_sync_configuration_aborted_;
508
[email protected]e8234d32010-09-09 20:36:39509 scoped_ptr<TokenMigrator> token_migrator_;
510
[email protected]48a98b32010-09-17 20:26:59511 // Sometimes we need to temporarily hold on to a passphrase because we don't
512 // yet have a backend to send it to. This happens during initialization as
513 // we don't StartUp until we have a valid token, which happens after valid
514 // credentials were provided.
[email protected]954b1082010-11-10 20:22:50515 struct CachedPassphrase {
516 std::string value;
517 bool is_explicit;
518 CachedPassphrase() : is_explicit(false) {}
519 };
520 CachedPassphrase cached_passphrase_;
521
522 // TODO(tim): Remove this once new 'explicit passphrase' code flushes through
523 // dev channel. See bug 62103.
524 // To "migrate" early adopters of password sync on dev channel to the new
525 // model that stores their secondary passphrase preference in the cloud, we
526 // need some extra state since this cloud pref will be empty for all of them
527 // regardless of how they set up sync, and we can't trust
528 // kSyncUsingSecondaryPassphrase due to bugs in that implementation.
529 bool tried_implicit_gaia_remove_when_bug_62103_fixed_;
[email protected]48a98b32010-09-17 20:26:59530
[email protected]689a7a72010-09-29 19:56:41531 // Keep track of where we are in a server clear operation
532 ClearServerDataState clear_server_data_state_;
533
[email protected]990de362010-10-13 17:55:50534 // Timeout for the clear data command. This timeout is a temporary hack
[email protected]954b1082010-11-10 20:22:50535 // and is necessary because the nudge sync framework can drop nudges for
[email protected]990de362010-10-13 17:55:50536 // a wide variety of sync-related conditions (throttling, connections issues,
537 // syncer paused, etc.). It can only be removed correctly when the framework
538 // is reworked to allow one-shot commands like clearing server data.
539 base::OneShotTimer<ProfileSyncService> clear_server_data_timer_;
540
[email protected]132c85652009-08-05 01:18:27541 DISALLOW_COPY_AND_ASSIGN(ProfileSyncService);
542};
543
544#endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_