blob: 5a808116808f3b5e9f18ffaa39939b7170a9183c [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]22d3eff2011-01-08 01:45:1840class TabContents;
[email protected]e8234d32010-09-09 20:36:3941class TokenMigrator;
[email protected]c4c672a2010-03-23 21:47:0442
[email protected]132c85652009-08-05 01:18:2743// ProfileSyncService is the layer between browser subsystems like bookmarks,
[email protected]a1c2aef62010-04-02 02:58:0544// and the sync backend. Each subsystem is logically thought of as being
45// a sync datatype.
46//
47// Individual datatypes can, at any point, be in a variety of stages of being
48// "enabled". Here are some specific terms for concepts used in this class:
49//
50// 'Registered' (feature suppression for a datatype)
51//
52// When a datatype is registered, the user has the option of syncing it.
53// The sync opt-in UI will show only registered types; a checkbox should
54// never be shown for an unregistered type, and nor should it ever be
55// synced.
56//
57// A datatype is considered registered once RegisterDataTypeController
58// has been called with that datatype's DataTypeController.
59//
60// 'Preferred' (user preferences and opt-out for a datatype)
61//
62// This means the user's opt-in or opt-out preference on a per-datatype
63// basis. The sync service will try to make active exactly these types.
64// If a user has opted out of syncing a particular datatype, it will
65// be registered, but not preferred.
66//
67// This state is controlled by the ConfigurePreferredDataTypes and
68// GetPreferredDataTypes. They are stored in the preferences system,
69// and persist; though if a datatype is not registered, it cannot
70// be a preferred datatype.
71//
72// 'Active' (run-time initialization of sync system for a datatype)
73//
74// An active datatype is a preferred datatype that is actively being
75// synchronized: the syncer has been instructed to querying the server
76// for this datatype, first-time merges have finished, and there is an
77// actively installed ChangeProcessor that listens for changes to this
78// datatype, propagating such changes into and out of the sync backend
79// as necessary.
80//
81// When a datatype is in the process of becoming active, it may be
82// in some intermediate state. Those finer-grained intermediate states
83// are differentiated by the DataTypeController state.
84//
[email protected]4aea04a2010-02-10 20:13:4385class ProfileSyncService : public browser_sync::SyncFrontend,
[email protected]c4c672a2010-03-23 21:47:0486 public browser_sync::UnrecoverableErrorHandler,
87 public NotificationObserver {
[email protected]132c85652009-08-05 01:18:2788 public:
89 typedef ProfileSyncServiceObserver Observer;
90 typedef browser_sync::SyncBackendHost::Status Status;
91
[email protected]1f97a112009-08-11 02:17:0692 enum SyncEventCodes {
93 MIN_SYNC_EVENT_CODE = 0,
94
95 // Events starting the sync service.
96 START_FROM_NTP = 1, // Sync was started from the ad in NTP
97 START_FROM_WRENCH = 2, // Sync was started from the Wrench menu.
98 START_FROM_OPTIONS = 3, // Sync was started from Wrench->Options.
[email protected]b220d13f2009-10-09 04:12:4699 START_FROM_BOOKMARK_MANAGER = 4, // Sync was started from Bookmark manager.
[email protected]1f97a112009-08-11 02:17:06100
[email protected]a7ab8332010-03-31 20:49:04101 // Events regarding cancellation of the signon process of sync.
[email protected]8ac2dc112009-10-01 23:19:13102 CANCEL_FROM_SIGNON_WITHOUT_AUTH = 10, // Cancelled before submitting
[email protected]1f97a112009-08-11 02:17:06103 // username and password.
104 CANCEL_DURING_SIGNON = 11, // Cancelled after auth.
[email protected]c976938f2010-10-12 04:55:44105 CANCEL_DURING_CONFIGURE = 12, // Cancelled before choosing data
[email protected]8c94d632010-06-25 22:38:00106 // types and clicking OK.
[email protected]1f97a112009-08-11 02:17:06107 // Events resulting in the stoppage of sync service.
108 STOP_FROM_OPTIONS = 20, // Sync was stopped from Wrench->Options.
109
110 // Miscellaneous events caused by sync service.
[email protected]1f97a112009-08-11 02:17:06111
112 MAX_SYNC_EVENT_CODE
113 };
114
[email protected]689a7a72010-09-29 19:56:41115 // Keep track of where we are when clearing server data.
116 enum ClearServerDataState {
117 CLEAR_NOT_STARTED = 1,
118 CLEAR_CLEARING = 2,
119 CLEAR_FAILED = 3,
120 CLEAR_SUCCEEDED = 4,
121 };
122
[email protected]f66bcdf2010-05-17 20:31:14123 // Default sync server URL.
124 static const char* kSyncServerUrl;
125 // Sync server URL for dev channel users
126 static const char* kDevServerUrl;
127
[email protected]e3e43d92010-02-26 22:02:38128 ProfileSyncService(ProfileSyncFactory* factory_,
129 Profile* profile,
[email protected]e8234d32010-09-09 20:36:39130 const std::string& cros_user);
[email protected]132c85652009-08-05 01:18:27131 virtual ~ProfileSyncService();
132
133 // Initializes the object. This should be called every time an object of this
134 // class is constructed.
135 void Initialize();
136
[email protected]e8234d32010-09-09 20:36:39137 void RegisterAuthNotifications();
138
139 // Return whether all sync tokens are loaded and
140 // available for the backend to start up.
141 bool AreCredentialsAvailable();
142
143 // Loads credentials migrated from the old user settings db.
144 void LoadMigratedCredentials(const std::string& username,
145 const std::string& token);
146
[email protected]4aea04a2010-02-10 20:13:43147 // Registers a data type controller with the sync service. This
148 // makes the data type controller available for use, it does not
149 // enable or activate the synchronization of the data type (see
150 // ActivateDataType). Takes ownership of the pointer.
151 void RegisterDataTypeController(
152 browser_sync::DataTypeController* data_type_controller);
153
[email protected]5edb9222010-08-18 00:23:29154 // Returns the session model associator associated with this type, but only if
155 // the associator is running. If it is doing anything else, it will return
156 // null.
157 browser_sync::SessionModelAssociator* GetSessionModelAssociator();
158
[email protected]689a7a72010-09-29 19:56:41159 // Maintain state of where we are in a server clear operation.
160 void ResetClearServerDataState();
161 ClearServerDataState GetClearServerDataState();
162
[email protected]a7ab8332010-03-31 20:49:04163 // Fills state_map with a map of current data types that are possible to
164 // sync, as well as their states.
165 void GetDataTypeControllerStates(
166 browser_sync::DataTypeController::StateMap* state_map) const;
[email protected]4aea04a2010-02-10 20:13:43167
[email protected]e8234d32010-09-09 20:36:39168 // Disables sync for user. Use ShowLoginDialog to enable.
[email protected]132c85652009-08-05 01:18:27169 virtual void DisableForUser();
170
[email protected]1ce52aa2010-09-08 19:07:36171 // Clears all Chromesync data from the server.
172 void ClearServerData();
173
[email protected]132c85652009-08-05 01:18:27174 // Whether sync is enabled by user or not.
[email protected]4772b072010-03-30 17:45:46175 virtual bool HasSyncSetupCompleted() const;
[email protected]2efebbbf2010-10-25 10:31:21176 virtual void SetSyncSetupCompleted();
[email protected]132c85652009-08-05 01:18:27177
[email protected]132c85652009-08-05 01:18:27178 // SyncFrontend implementation.
179 virtual void OnBackendInitialized();
180 virtual void OnSyncCycleCompleted();
181 virtual void OnAuthError();
[email protected]7f8abea2010-07-14 01:31:36182 virtual void OnStopSyncingPermanently();
[email protected]1ce52aa2010-09-08 19:07:36183 virtual void OnClearServerDataFailed();
[email protected]990de362010-10-13 17:55:50184 virtual void OnClearServerDataTimeout();
[email protected]1ce52aa2010-09-08 19:07:36185 virtual void OnClearServerDataSucceeded();
[email protected]1a787692011-01-19 22:19:46186 virtual void OnPassphraseRequired(bool for_decryption);
187 virtual void OnPassphraseAccepted();
[email protected]132c85652009-08-05 01:18:27188
189 // Called when a user enters credentials through UI.
190 virtual void OnUserSubmittedAuth(const std::string& username,
[email protected]1fc9b3f2009-11-12 21:22:09191 const std::string& password,
[email protected]96209ccd2010-10-11 21:57:27192 const std::string& captcha,
193 const std::string& access_code);
[email protected]132c85652009-08-05 01:18:27194
[email protected]e8234d32010-09-09 20:36:39195 // Update the last auth error and notify observers of error state.
196 void UpdateAuthErrorState(const GoogleServiceAuthError& error);
197
[email protected]af909492010-06-10 18:45:38198 // Called when a user chooses which data types to sync as part of the sync
199 // setup wizard. |sync_everything| represents whether they chose the
[email protected]8c94d632010-06-25 22:38:00200 // "keep everything synced" option; if true, |chosen_types| will be ignored
201 // and all data types will be synced. |sync_everything| means "sync all
202 // current and future data types."
[email protected]af909492010-06-10 18:45:38203 virtual void OnUserChoseDatatypes(bool sync_everything,
[email protected]8c94d632010-06-25 22:38:00204 const syncable::ModelTypeSet& chosen_types);
[email protected]af909492010-06-10 18:45:38205
[email protected]a7ab8332010-03-31 20:49:04206 // Called when a user cancels any setup dialog (login, etc).
[email protected]132c85652009-08-05 01:18:27207 virtual void OnUserCancelledDialog();
208
209 // Get various information for displaying in the user interface.
210 browser_sync::SyncBackendHost::StatusSummary QuerySyncStatusSummary();
[email protected]f1e6e0212010-10-15 20:54:24211 virtual browser_sync::SyncBackendHost::Status QueryDetailedSyncStatus();
[email protected]132c85652009-08-05 01:18:27212
[email protected]712257e2009-11-11 22:57:46213 const GoogleServiceAuthError& GetAuthError() const {
[email protected]132c85652009-08-05 01:18:27214 return last_auth_error_;
215 }
216
217 // Displays a dialog for the user to enter GAIA credentials and attempt
218 // re-authentication, and returns true if it actually opened the dialog.
219 // Returns false if a dialog is already showing, an auth attempt is in
220 // progress, the sync system is already authenticated, or some error
221 // occurred preventing the action. We make it the duty of ProfileSyncService
222 // to open the dialog to easily ensure only one is ever showing.
[email protected]d6885592010-10-11 19:38:24223 virtual bool SetupInProgress() const;
[email protected]44b78f90a2009-10-15 17:32:20224 bool WizardIsVisible() const {
225 return wizard_.IsVisible();
226 }
[email protected]d6885592010-10-11 19:38:24227 virtual void ShowLoginDialog(gfx::NativeWindow parent_window);
[email protected]1c738472011-01-19 21:48:01228
229 // This method handles clicks on "sync error" UI, showing the appropriate
230 // dialog for the error condition (relogin / enter passphrase).
231 virtual void ShowErrorUI(gfx::NativeWindow parent_window);
232
[email protected]66d81002010-10-18 16:52:09233 void ShowConfigure(gfx::NativeWindow parent_window);
[email protected]22d3eff2011-01-08 01:45:18234 void PromptForExistingPassphrase(gfx::NativeWindow parent_window);
[email protected]f0718a392011-01-21 23:52:56235 void SigninForPassphraseMigration(gfx::NativeWindow parent_window);
[email protected]8c94d632010-06-25 22:38:00236
[email protected]132c85652009-08-05 01:18:27237 // Pretty-printed strings for a given StatusSummary.
[email protected]066146872010-08-05 00:55:08238 static std::string BuildSyncStatusSummaryText(
[email protected]132c85652009-08-05 01:18:27239 const browser_sync::SyncBackendHost::StatusSummary& summary);
240
241 // Returns true if the SyncBackendHost has told us it's ready to accept
242 // changes.
[email protected]cd2ec4b2011-01-06 00:09:36243 // [REMARK] - it is safe to call this function only from the ui thread.
244 // because the variable is not thread safe and should only be accessed from
245 // single thread. If we want multiple threads to access this(and there is
246 // currently no need to do so) we need to protect this with a lock.
[email protected]132c85652009-08-05 01:18:27247 // TODO(timsteele): What happens if the bookmark model is loaded, a change
248 // takes place, and the backend isn't initialized yet?
249 bool sync_initialized() const { return backend_initialized_; }
[email protected]ddb1e5a2010-12-13 20:10:45250 virtual bool unrecoverable_error_detected() const;
[email protected]f6ec8b22010-06-08 23:40:06251 const std::string& unrecoverable_error_message() {
252 return unrecoverable_error_message_;
253 }
254 tracked_objects::Location unrecoverable_error_location() {
255 return unrecoverable_error_location_.get() ?
256 *unrecoverable_error_location_.get() : tracked_objects::Location();
257 }
[email protected]132c85652009-08-05 01:18:27258
259 bool UIShouldDepictAuthInProgress() const {
260 return is_auth_in_progress_;
261 }
262
[email protected]2e610e92011-01-13 23:39:45263 bool tried_creating_explicit_passphrase() const {
264 return tried_creating_explicit_passphrase_;
265 }
266
267 bool tried_setting_explicit_passphrase() const {
268 return tried_setting_explicit_passphrase_;
269 }
270
[email protected]66d81002010-10-18 16:52:09271 bool observed_passphrase_required() const {
272 return observed_passphrase_required_;
273 }
274
[email protected]fc52c422010-11-19 18:59:23275 bool passphrase_required_for_decryption() const {
276 return passphrase_required_for_decryption_;
277 }
278
[email protected]132c85652009-08-05 01:18:27279 // A timestamp marking the last time the service observed a transition from
280 // the SYNCING state to the READY state. Note that this does not reflect the
281 // last time we polled the server to see if there were any changes; the
282 // timestamp is only snapped when syncing takes place and we download or
283 // upload some bookmark entity.
284 const base::Time& last_synced_time() const { return last_synced_time_; }
285
286 // Returns a user-friendly string form of last synced time (in minutes).
[email protected]f1e6e0212010-10-15 20:54:24287 virtual string16 GetLastSyncedTimeString() const;
[email protected]132c85652009-08-05 01:18:27288
289 // Returns the authenticated username of the sync user, or empty if none
290 // exists. It will only exist if the authentication service provider (e.g
291 // GAIA) has confirmed the username is authentic.
292 virtual string16 GetAuthenticatedUsername() const;
293
294 const std::string& last_attempted_user_email() const {
295 return last_attempted_user_email_;
296 }
297
298 // The profile we are syncing for.
[email protected]c976938f2010-10-12 04:55:44299 Profile* profile() const { return profile_; }
[email protected]132c85652009-08-05 01:18:27300
301 // Adds/removes an observer. ProfileSyncService does not take ownership of
302 // the observer.
[email protected]4772b072010-03-30 17:45:46303 virtual void AddObserver(Observer* observer);
304 virtual void RemoveObserver(Observer* observer);
[email protected]132c85652009-08-05 01:18:27305
[email protected]d1db1c332010-10-13 19:57:00306 // Returns true if |observer| has already been added as an observer.
307 bool HasObserver(Observer* observer) const;
308
[email protected]1f97a112009-08-11 02:17:06309 // Record stats on various events.
310 static void SyncEvent(SyncEventCodes code);
311
[email protected]eec3bcfa2009-11-12 17:23:43312 // Returns whether sync is enabled. Sync can be enabled/disabled both
313 // at compile time (e.g., on a per-OS basis) or at run time (e.g.,
314 // command-line switches).
315 static bool IsSyncEnabled();
316
[email protected]d1db1c332010-10-13 19:57:00317 // Returns whether sync is managed, i.e. controlled by configuration
[email protected]d3b98c82010-07-14 07:45:59318 // management. If so, the user is not allowed to configure sync.
319 bool IsManaged();
320
[email protected]db1df0f2009-08-18 22:36:05321 // UnrecoverableErrorHandler implementation.
[email protected]f6ec8b22010-06-08 23:40:06322 virtual void OnUnrecoverableError(
323 const tracked_objects::Location& from_here,
324 const std::string& message);
[email protected]db1df0f2009-08-18 22:36:05325
[email protected]420914932011-01-24 23:32:41326 // The functions below (until ActivateDataType()) should only be
327 // called if sync_initialized() is true.
328
329 // TODO(akalin): This is called mostly by ModelAssociators and
330 // tests. Figure out how to pass the handle to the ModelAssociators
331 // directly, figure out how to expose this to tests, and remove this
332 // function.
333 sync_api::UserShare* GetUserShare() const;
334
335 // TODO(akalin): These two functions are used only by
336 // ProfileSyncServiceHarness. Figure out a different way to expose
337 // this info to that class, and remove these functions.
338
339 const browser_sync::sessions::SyncSessionSnapshot*
340 GetLastSessionSnapshot() const;
341
342 // Returns whether or not the underlying sync engine has made any
343 // local changes to items that have not yet been synced with the
344 // server.
345 bool HasUnsyncedItems() const;
346
347 // Get the current routing information for all enabled model types.
348 // If a model type is not enabled (that is, if the syncer should not
349 // be trying to sync it), it is not in this map.
350 //
351 // TODO(akalin): This function is used by
352 // sync_ui_util::ConstructAboutInformation() and by some test
353 // classes. Figure out a different way to expose this info and
354 // remove this function.
355 void GetModelSafeRoutingInfo(browser_sync::ModelSafeRoutingInfo* out);
356
357 // TODO(akalin): Remove these four functions once we're done with
358 // autofill migration.
359
360 syncable::AutofillMigrationState
361 GetAutofillMigrationState();
362
363 void SetAutofillMigrationState(
364 syncable::AutofillMigrationState state);
365
366 syncable::AutofillMigrationDebugInfo
367 GetAutofillMigrationDebugInfo();
368
369 void SetAutofillMigrationDebugInfo(
370 syncable::AutofillMigrationDebugInfo::PropertyToSet property_to_set,
371 const syncable::AutofillMigrationDebugInfo& info);
[email protected]db1df0f2009-08-18 22:36:05372
[email protected]4aea04a2010-02-10 20:13:43373 virtual void ActivateDataType(
374 browser_sync::DataTypeController* data_type_controller,
375 browser_sync::ChangeProcessor* change_processor);
376 virtual void DeactivateDataType(
377 browser_sync::DataTypeController* data_type_controller,
378 browser_sync::ChangeProcessor* change_processor);
379
[email protected]c4c672a2010-03-23 21:47:04380 // NotificationObserver implementation.
381 virtual void Observe(NotificationType type,
382 const NotificationSource& source,
383 const NotificationDetails& details);
384
[email protected]a1c2aef62010-04-02 02:58:05385 // Changes which data types we're going to be syncing to |preferred_types|.
386 // If it is running, the DataTypeManager will be instructed to reconfigure
387 // the sync backend so that exactly these datatypes are actively synced. See
388 // class comment for more on what it means for a datatype to be Preferred.
389 virtual void ChangePreferredDataTypes(
390 const syncable::ModelTypeSet& preferred_types);
391
392 // Get the set of currently enabled data types (as chosen or configured by
393 // the user). See class comment for more on what it means for a datatype
394 // to be Preferred.
395 virtual void GetPreferredDataTypes(
396 syncable::ModelTypeSet* preferred_types) const;
397
398 // Gets the set of all data types that could be allowed (the set that
399 // should be advertised to the user). These will typically only change
400 // via a command-line option. See class comment for more on what it means
401 // for a datatype to be Registered.
402 virtual void GetRegisteredDataTypes(
403 syncable::ModelTypeSet* registered_types) const;
[email protected]a7ab8332010-03-31 20:49:04404
[email protected]ff0aa752010-06-10 22:40:52405 // Checks whether the Cryptographer is ready to encrypt and decrypt updates
406 // for sensitive data types.
407 virtual bool IsCryptographerReady() const;
408
[email protected]c976938f2010-10-12 04:55:44409 // Returns true if a secondary passphrase is being used.
410 virtual bool IsUsingSecondaryPassphrase() const;
411
[email protected]ee1adf4b2010-10-11 03:48:48412 // Sets the Cryptographer's passphrase, or caches it until that is possible.
413 // This will check asynchronously whether the passphrase is valid and notify
[email protected]dc39dd1b2010-10-07 18:08:11414 // ProfileSyncServiceObservers via the NotificationService when the outcome
415 // is known.
[email protected]954b1082010-11-10 20:22:50416 // |is_explicit| is true if the call is in response to the user explicitly
417 // setting a passphrase as opposed to implicitly (from the users' perspective)
418 // using their Google Account password. An implicit SetPassphrase will *not*
419 // *not* override an explicit passphrase set previously.
[email protected]2e610e92011-01-13 23:39:45420 // |is_creation| is true if the call is in response to the user setting
421 // up a new passphrase, and false if it's being set in response to a prompt
422 // for an existing passphrase.
423 virtual void SetPassphrase(const std::string& passphrase,
424 bool is_explicit,
425 bool is_creation);
[email protected]bb899b3f2010-06-23 21:35:32426
[email protected]5edb9222010-08-18 00:23:29427 // Returns whether processing changes is allowed. Check this before doing
428 // any model-modifying operations.
429 bool ShouldPushChanges();
430
[email protected]9a127f22010-09-17 21:05:16431 const GURL& sync_service_url() const { return sync_service_url_; }
[email protected]bb868b42010-11-18 22:33:00432 SigninManager* signin() { return signin_.get(); }
433 const std::string& cros_user() const { return cros_user_; }
[email protected]9a127f22010-09-17 21:05:16434
[email protected]132c85652009-08-05 01:18:27435 protected:
[email protected]82d9d2952010-05-15 00:36:16436 // Used by ProfileSyncServiceMock only.
437 //
438 // TODO(akalin): Separate this class out into an abstract
439 // ProfileSyncService interface and a ProfileSyncServiceImpl class
440 // so we don't need this hack anymore.
441 ProfileSyncService();
442
[email protected]420914932011-01-24 23:32:41443 // Used by test classes that derive from ProfileSyncService.
444 virtual browser_sync::SyncBackendHost* GetBackendForTest();
445
[email protected]7cef1c442010-07-07 17:05:22446 // Helper to install and configure a data type manager.
447 void ConfigureDataTypeManager();
[email protected]132c85652009-08-05 01:18:27448
[email protected]132c85652009-08-05 01:18:27449 // Starts up the backend sync components.
450 void StartUp();
451 // Shuts down the backend sync components.
452 // |sync_disabled| indicates if syncing is being disabled or not.
453 void Shutdown(bool sync_disabled);
454
[email protected]48352c12009-08-15 01:19:11455 // Methods to register and remove preferences.
456 void RegisterPreferences();
457 void ClearPreferences();
458
[email protected]e8234d32010-09-09 20:36:39459 // Return SyncCredentials from the TokenService.
460 sync_api::SyncCredentials GetCredentials();
461
[email protected]18af9a22010-08-11 00:47:19462 // Test need to override this to create backends that allow setting up
463 // initial conditions, such as populating sync nodes.
[email protected]420914932011-01-24 23:32:41464 //
465 // TODO(akalin): Figure out a better way to do this. Ideally, we'd
466 // construct the backend outside this class and pass it in to the
467 // contructor or Initialize().
[email protected]18af9a22010-08-11 00:47:19468 virtual void CreateBackend();
[email protected]132c85652009-08-05 01:18:27469
[email protected]7cef1c442010-07-07 17:05:22470 const browser_sync::DataTypeController::TypeMap& data_type_controllers() {
471 return data_type_controllers_;
472 }
473
[email protected]e8234d32010-09-09 20:36:39474 // The wizard will try to read the auth state out of the profile sync
475 // service using this member. Captcha and error state are reflected.
[email protected]712257e2009-11-11 22:57:46476 GoogleServiceAuthError last_auth_error_;
[email protected]132c85652009-08-05 01:18:27477
[email protected]7cef1c442010-07-07 17:05:22478 // Our asynchronous backend to communicate with sync components living on
479 // other threads.
480 scoped_ptr<browser_sync::SyncBackendHost> backend_;
481
[email protected]132c85652009-08-05 01:18:27482 // Cache of the last name the client attempted to authenticate.
483 std::string last_attempted_user_email_;
484
[email protected]2e610e92011-01-13 23:39:45485 // Whether the user has tried creating an explicit passphrase on this
486 // machine.
487 bool tried_creating_explicit_passphrase_;
488
489 // Whether the user has tried setting an explicit passphrase on this
490 // machine.
491 bool tried_setting_explicit_passphrase_;
492
[email protected]66d81002010-10-18 16:52:09493 // Whether we have seen a SYNC_PASSPHRASE_REQUIRED since initializing the
494 // backend, telling us that it is safe to send a passphrase down ASAP.
495 bool observed_passphrase_required_;
496
[email protected]fc52c422010-11-19 18:59:23497 // Was the last SYNC_PASSPHRASE_REQUIRED notification sent because it
498 // was required for decryption?
499 bool passphrase_required_for_decryption_;
500
[email protected]f0718a392011-01-21 23:52:56501 // Is the user in a passphrase migration?
502 bool passphrase_migration_in_progress_;
503
[email protected]132c85652009-08-05 01:18:27504 private:
[email protected]4f5732a42010-09-21 22:39:09505 friend class ProfileSyncServicePasswordTest;
[email protected]420914932011-01-24 23:32:41506 friend class TestProfileSyncService;
[email protected]61b694a2010-06-10 10:40:46507 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceTest, InitialState);
[email protected]132c85652009-08-05 01:18:27508
[email protected]18af9a22010-08-11 00:47:19509 // If |delete_sync_data_folder| is true, then this method will delete all
510 // previous "Sync Data" folders. (useful if the folder is partial/corrupt).
511 void InitializeBackend(bool delete_sync_data_folder);
512
[email protected]132c85652009-08-05 01:18:27513 // Initializes the various settings from the command line.
514 void InitSettings();
515
[email protected]132c85652009-08-05 01:18:27516 // Sets the last synced time to the current time.
517 void UpdateLastSyncedTime();
518
[email protected]1a787692011-01-19 22:19:46519 void NotifyObservers();
520
[email protected]57ecc4b2010-08-11 03:02:51521 static const char* GetPrefNameForDataType(syncable::ModelType data_type);
[email protected]a1c2aef62010-04-02 02:58:05522
[email protected]cb4c06e2009-08-22 00:24:39523 // Time at which we begin an attempt a GAIA authorization.
524 base::TimeTicks auth_start_time_;
525
526 // Time at which error UI is presented for the new tab page.
[email protected]1f97a112009-08-11 02:17:06527 base::TimeTicks auth_error_time_;
528
[email protected]e3e43d92010-02-26 22:02:38529 // Factory used to create various dependent objects.
530 ProfileSyncFactory* factory_;
531
[email protected]132c85652009-08-05 01:18:27532 // The profile whose data we are synchronizing.
533 Profile* profile_;
534
[email protected]e8234d32010-09-09 20:36:39535 // Email for the ChromiumOS user, if we're running under ChromiumOS.
536 std::string cros_user_;
[email protected]72a31b42010-02-17 22:26:33537
[email protected]132c85652009-08-05 01:18:27538 // TODO(ncarter): Put this in a profile, once there is UI for it.
539 // This specifies where to find the sync server.
540 GURL sync_service_url_;
541
[email protected]132c85652009-08-05 01:18:27542 // The last time we detected a successful transition from SYNCING state.
543 // Our backend notifies us whenever we should take a new snapshot.
544 base::Time last_synced_time_;
545
[email protected]4aea04a2010-02-10 20:13:43546 // List of available data type controllers.
[email protected]72a31b42010-02-17 22:26:33547 browser_sync::DataTypeController::TypeMap data_type_controllers_;
[email protected]db1df0f2009-08-18 22:36:05548
[email protected]132c85652009-08-05 01:18:27549 // Whether the SyncBackendHost has been initialized.
550 bool backend_initialized_;
551
[email protected]132c85652009-08-05 01:18:27552 // Various pieces of UI query this value to determine if they should show
553 // an "Authenticating.." type of message. We are the only central place
554 // all auth attempts funnel through, so it makes sense to provide this.
555 // As its name suggests, this should NOT be used for anything other than UI.
556 bool is_auth_in_progress_;
557
[email protected]44b78f90a2009-10-15 17:32:20558 SyncSetupWizard wizard_;
559
[email protected]e8234d32010-09-09 20:36:39560 // Encapsulates user signin with TokenService.
[email protected]bb868b42010-11-18 22:33:00561 scoped_ptr<SigninManager> signin_;
[email protected]e8234d32010-09-09 20:36:39562
[email protected]132c85652009-08-05 01:18:27563 // True if an unrecoverable error (e.g. violation of an assumed invariant)
564 // occurred during syncer operation. This value should be checked before
565 // doing any work that might corrupt things further.
566 bool unrecoverable_error_detected_;
567
[email protected]f6ec8b22010-06-08 23:40:06568 // A message sent when an unrecoverable error occurred.
569 std::string unrecoverable_error_message_;
570 scoped_ptr<tracked_objects::Location> unrecoverable_error_location_;
571
[email protected]33cd0042010-09-08 19:25:28572 // Contains options specific to how sync clients send and listen to
573 // notifications.
574 notifier::NotifierOptions notifier_options_;
[email protected]93d960ce2010-02-11 04:27:00575
[email protected]e3e43d92010-02-26 22:02:38576 // Manages the start and stop of the various data types.
577 scoped_ptr<browser_sync::DataTypeManager> data_type_manager_;
578
[email protected]132c85652009-08-05 01:18:27579 ObserverList<Observer> observers_;
580
[email protected]c4c672a2010-03-23 21:47:04581 NotificationRegistrar registrar_;
582
[email protected]2be7bf22010-04-23 21:02:37583 ScopedRunnableMethodFactory<ProfileSyncService>
[email protected]954b1082010-11-10 20:22:50584 scoped_runnable_method_factory_;
[email protected]2be7bf22010-04-23 21:02:37585
[email protected]d3b98c82010-07-14 07:45:59586 // The preference that controls whether sync is under control by configuration
587 // management.
588 BooleanPrefMember pref_sync_managed_;
589
[email protected]a47eeb52010-07-15 17:54:25590 // This allows us to gracefully handle an ABORTED return code from the
591 // DataTypeManager in the event that the server informed us to cease and
592 // desist syncing immediately.
593 bool expect_sync_configuration_aborted_;
594
[email protected]e8234d32010-09-09 20:36:39595 scoped_ptr<TokenMigrator> token_migrator_;
596
[email protected]48a98b32010-09-17 20:26:59597 // Sometimes we need to temporarily hold on to a passphrase because we don't
598 // yet have a backend to send it to. This happens during initialization as
599 // we don't StartUp until we have a valid token, which happens after valid
600 // credentials were provided.
[email protected]954b1082010-11-10 20:22:50601 struct CachedPassphrase {
602 std::string value;
603 bool is_explicit;
[email protected]2e610e92011-01-13 23:39:45604 bool is_creation;
605 CachedPassphrase() : is_explicit(false), is_creation(false) {}
[email protected]954b1082010-11-10 20:22:50606 };
607 CachedPassphrase cached_passphrase_;
608
609 // TODO(tim): Remove this once new 'explicit passphrase' code flushes through
610 // dev channel. See bug 62103.
611 // To "migrate" early adopters of password sync on dev channel to the new
612 // model that stores their secondary passphrase preference in the cloud, we
613 // need some extra state since this cloud pref will be empty for all of them
614 // regardless of how they set up sync, and we can't trust
615 // kSyncUsingSecondaryPassphrase due to bugs in that implementation.
616 bool tried_implicit_gaia_remove_when_bug_62103_fixed_;
[email protected]48a98b32010-09-17 20:26:59617
[email protected]689a7a72010-09-29 19:56:41618 // Keep track of where we are in a server clear operation
619 ClearServerDataState clear_server_data_state_;
620
[email protected]990de362010-10-13 17:55:50621 // Timeout for the clear data command. This timeout is a temporary hack
[email protected]954b1082010-11-10 20:22:50622 // and is necessary because the nudge sync framework can drop nudges for
[email protected]990de362010-10-13 17:55:50623 // a wide variety of sync-related conditions (throttling, connections issues,
624 // syncer paused, etc.). It can only be removed correctly when the framework
625 // is reworked to allow one-shot commands like clearing server data.
626 base::OneShotTimer<ProfileSyncService> clear_server_data_timer_;
627
[email protected]132c85652009-08-05 01:18:27628 DISALLOW_COPY_AND_ASSIGN(ProfileSyncService);
629};
630
631#endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_