blob: a0e1cb89e3f2917a031115bc9ecaf051d9e0dd87 [file] [log] [blame]
[email protected]ebbbb9f2011-03-09 13:16:141// Copyright (c) 2011 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]3b63f8f42011-03-28 01:54:1513#include "base/memory/scoped_ptr.h"
[email protected]132c85652009-08-05 01:18:2714#include "base/observer_list.h"
[email protected]066146872010-08-05 00:55:0815#include "base/string16.h"
[email protected]a1595962011-04-22 21:56:2416#include "base/task.h"
[email protected]4aea04a2010-02-10 20:13:4317#include "base/time.h"
[email protected]990de362010-10-13 17:55:5018#include "base/timer.h"
[email protected]a1595962011-04-22 21:56:2419#include "base/tracked.h"
[email protected]37858e52010-08-26 00:22:0220#include "chrome/browser/prefs/pref_member.h"
[email protected]a1595962011-04-22 21:56:2421#include "chrome/browser/sync/engine/model_safe_worker.h"
[email protected]72a31b42010-02-17 22:26:3322#include "chrome/browser/sync/glue/data_type_controller.h"
[email protected]132c85652009-08-05 01:18:2723#include "chrome/browser/sync/glue/sync_backend_host.h"
[email protected]f92351d2011-02-01 07:42:1224#include "chrome/browser/sync/js_event_handler_list.h"
[email protected]d3b98c82010-07-14 07:45:5925#include "chrome/browser/sync/profile_sync_service_observer.h"
[email protected]d80033e2009-10-16 10:32:0426#include "chrome/browser/sync/sync_setup_wizard.h"
[email protected]a1595962011-04-22 21:56:2427#include "chrome/browser/sync/syncable/autofill_migration.h"
[email protected]4aea04a2010-02-10 20:13:4328#include "chrome/browser/sync/syncable/model_type.h"
[email protected]eafb2182010-03-03 00:46:3129#include "chrome/browser/sync/unrecoverable_error_handler.h"
[email protected]99074c52010-08-19 18:44:1930#include "chrome/common/net/gaia/google_service_auth_error.h"
[email protected]ebbbb9f2011-03-09 13:16:1431#include "content/common/notification_observer.h"
32#include "content/common/notification_registrar.h"
[email protected]a1595962011-04-22 21:56:2433#include "content/common/notification_type.h"
[email protected]132c85652009-08-05 01:18:2734#include "googleurl/src/gurl.h"
[email protected]a1595962011-04-22 21:56:2435#include "ui/gfx/native_widget_types.h"
[email protected]132c85652009-08-05 01:18:2736
[email protected]c4c672a2010-03-23 21:47:0437class NotificationDetails;
38class NotificationSource;
[email protected]942690b132010-05-11 06:42:1439class Profile;
40class ProfileSyncFactory;
[email protected]a1595962011-04-22 21:56:2441class SigninManager;
[email protected]c4c672a2010-03-23 21:47:0442
[email protected]f92351d2011-02-01 07:42:1243namespace browser_sync {
[email protected]dc556252011-04-20 01:59:3544class BackendMigrator;
[email protected]a1595962011-04-22 21:56:2445class ChangeProcessor;
46class DataTypeManager;
[email protected]f92351d2011-02-01 07:42:1247class JsFrontend;
[email protected]a1595962011-04-22 21:56:2448class SessionModelAssociator;
49namespace sessions { struct SyncSessionSnapshot; }
50}
51
52namespace sync_api {
53class BaseTransaction;
54struct SyncCredentials;
55struct UserShare;
56}
[email protected]f92351d2011-02-01 07:42:1257
[email protected]132c85652009-08-05 01:18:2758// ProfileSyncService is the layer between browser subsystems like bookmarks,
[email protected]a1c2aef62010-04-02 02:58:0559// and the sync backend. Each subsystem is logically thought of as being
60// a sync datatype.
61//
62// Individual datatypes can, at any point, be in a variety of stages of being
63// "enabled". Here are some specific terms for concepts used in this class:
64//
65// 'Registered' (feature suppression for a datatype)
66//
67// When a datatype is registered, the user has the option of syncing it.
68// The sync opt-in UI will show only registered types; a checkbox should
69// never be shown for an unregistered type, and nor should it ever be
70// synced.
71//
72// A datatype is considered registered once RegisterDataTypeController
73// has been called with that datatype's DataTypeController.
74//
75// 'Preferred' (user preferences and opt-out for a datatype)
76//
77// This means the user's opt-in or opt-out preference on a per-datatype
78// basis. The sync service will try to make active exactly these types.
79// If a user has opted out of syncing a particular datatype, it will
80// be registered, but not preferred.
81//
82// This state is controlled by the ConfigurePreferredDataTypes and
83// GetPreferredDataTypes. They are stored in the preferences system,
84// and persist; though if a datatype is not registered, it cannot
85// be a preferred datatype.
86//
87// 'Active' (run-time initialization of sync system for a datatype)
88//
89// An active datatype is a preferred datatype that is actively being
90// synchronized: the syncer has been instructed to querying the server
91// for this datatype, first-time merges have finished, and there is an
92// actively installed ChangeProcessor that listens for changes to this
93// datatype, propagating such changes into and out of the sync backend
94// as necessary.
95//
96// When a datatype is in the process of becoming active, it may be
97// in some intermediate state. Those finer-grained intermediate states
98// are differentiated by the DataTypeController state.
99//
[email protected]4aea04a2010-02-10 20:13:43100class ProfileSyncService : public browser_sync::SyncFrontend,
[email protected]c4c672a2010-03-23 21:47:04101 public browser_sync::UnrecoverableErrorHandler,
102 public NotificationObserver {
[email protected]132c85652009-08-05 01:18:27103 public:
104 typedef ProfileSyncServiceObserver Observer;
105 typedef browser_sync::SyncBackendHost::Status Status;
106
[email protected]1f97a112009-08-11 02:17:06107 enum SyncEventCodes {
108 MIN_SYNC_EVENT_CODE = 0,
109
110 // Events starting the sync service.
111 START_FROM_NTP = 1, // Sync was started from the ad in NTP
112 START_FROM_WRENCH = 2, // Sync was started from the Wrench menu.
113 START_FROM_OPTIONS = 3, // Sync was started from Wrench->Options.
[email protected]b220d13f2009-10-09 04:12:46114 START_FROM_BOOKMARK_MANAGER = 4, // Sync was started from Bookmark manager.
[email protected]29d70252011-04-28 02:16:58115 START_FROM_PROFILE_MENU = 5, // Sync was started from multiprofile menu.
[email protected]1f97a112009-08-11 02:17:06116
[email protected]a7ab8332010-03-31 20:49:04117 // Events regarding cancellation of the signon process of sync.
[email protected]8ac2dc112009-10-01 23:19:13118 CANCEL_FROM_SIGNON_WITHOUT_AUTH = 10, // Cancelled before submitting
[email protected]1f97a112009-08-11 02:17:06119 // username and password.
120 CANCEL_DURING_SIGNON = 11, // Cancelled after auth.
[email protected]c976938f2010-10-12 04:55:44121 CANCEL_DURING_CONFIGURE = 12, // Cancelled before choosing data
[email protected]8c94d632010-06-25 22:38:00122 // types and clicking OK.
[email protected]1f97a112009-08-11 02:17:06123 // Events resulting in the stoppage of sync service.
124 STOP_FROM_OPTIONS = 20, // Sync was stopped from Wrench->Options.
125
126 // Miscellaneous events caused by sync service.
[email protected]1f97a112009-08-11 02:17:06127
128 MAX_SYNC_EVENT_CODE
129 };
130
[email protected]689a7a72010-09-29 19:56:41131 // Keep track of where we are when clearing server data.
132 enum ClearServerDataState {
133 CLEAR_NOT_STARTED = 1,
134 CLEAR_CLEARING = 2,
135 CLEAR_FAILED = 3,
136 CLEAR_SUCCEEDED = 4,
137 };
138
[email protected]f66bcdf2010-05-17 20:31:14139 // Default sync server URL.
140 static const char* kSyncServerUrl;
141 // Sync server URL for dev channel users
142 static const char* kDevServerUrl;
143
[email protected]e3e43d92010-02-26 22:02:38144 ProfileSyncService(ProfileSyncFactory* factory_,
145 Profile* profile,
[email protected]e8234d32010-09-09 20:36:39146 const std::string& cros_user);
[email protected]132c85652009-08-05 01:18:27147 virtual ~ProfileSyncService();
148
149 // Initializes the object. This should be called every time an object of this
150 // class is constructed.
151 void Initialize();
152
[email protected]e8234d32010-09-09 20:36:39153 void RegisterAuthNotifications();
154
155 // Return whether all sync tokens are loaded and
156 // available for the backend to start up.
157 bool AreCredentialsAvailable();
158
[email protected]4aea04a2010-02-10 20:13:43159 // Registers a data type controller with the sync service. This
160 // makes the data type controller available for use, it does not
161 // enable or activate the synchronization of the data type (see
162 // ActivateDataType). Takes ownership of the pointer.
163 void RegisterDataTypeController(
164 browser_sync::DataTypeController* data_type_controller);
165
[email protected]5edb9222010-08-18 00:23:29166 // Returns the session model associator associated with this type, but only if
167 // the associator is running. If it is doing anything else, it will return
168 // null.
169 browser_sync::SessionModelAssociator* GetSessionModelAssociator();
170
[email protected]689a7a72010-09-29 19:56:41171 // Maintain state of where we are in a server clear operation.
172 void ResetClearServerDataState();
173 ClearServerDataState GetClearServerDataState();
174
[email protected]a7ab8332010-03-31 20:49:04175 // Fills state_map with a map of current data types that are possible to
176 // sync, as well as their states.
177 void GetDataTypeControllerStates(
178 browser_sync::DataTypeController::StateMap* state_map) const;
[email protected]4aea04a2010-02-10 20:13:43179
[email protected]e8234d32010-09-09 20:36:39180 // Disables sync for user. Use ShowLoginDialog to enable.
[email protected]132c85652009-08-05 01:18:27181 virtual void DisableForUser();
182
[email protected]1ce52aa2010-09-08 19:07:36183 // Clears all Chromesync data from the server.
184 void ClearServerData();
185
[email protected]132c85652009-08-05 01:18:27186 // Whether sync is enabled by user or not.
[email protected]4772b072010-03-30 17:45:46187 virtual bool HasSyncSetupCompleted() const;
[email protected]2efebbbf2010-10-25 10:31:21188 virtual void SetSyncSetupCompleted();
[email protected]132c85652009-08-05 01:18:27189
[email protected]132c85652009-08-05 01:18:27190 // SyncFrontend implementation.
191 virtual void OnBackendInitialized();
192 virtual void OnSyncCycleCompleted();
193 virtual void OnAuthError();
[email protected]7f8abea2010-07-14 01:31:36194 virtual void OnStopSyncingPermanently();
[email protected]1ce52aa2010-09-08 19:07:36195 virtual void OnClearServerDataFailed();
[email protected]990de362010-10-13 17:55:50196 virtual void OnClearServerDataTimeout();
[email protected]1ce52aa2010-09-08 19:07:36197 virtual void OnClearServerDataSucceeded();
[email protected]43c48fb92011-05-02 19:47:43198 virtual void OnPassphraseRequired(sync_api::PassphraseRequiredReason reason);
[email protected]1a787692011-01-19 22:19:46199 virtual void OnPassphraseAccepted();
[email protected]3fa964af2011-02-24 18:54:39200 virtual void OnEncryptionComplete(
201 const syncable::ModelTypeSet& encrypted_types);
[email protected]dc556252011-04-20 01:59:35202 virtual void OnMigrationNeededForTypes(
203 const syncable::ModelTypeSet& types);
[email protected]132c85652009-08-05 01:18:27204
205 // Called when a user enters credentials through UI.
206 virtual void OnUserSubmittedAuth(const std::string& username,
[email protected]1fc9b3f2009-11-12 21:22:09207 const std::string& password,
[email protected]96209ccd2010-10-11 21:57:27208 const std::string& captcha,
209 const std::string& access_code);
[email protected]132c85652009-08-05 01:18:27210
[email protected]e8234d32010-09-09 20:36:39211 // Update the last auth error and notify observers of error state.
212 void UpdateAuthErrorState(const GoogleServiceAuthError& error);
213
[email protected]af909492010-06-10 18:45:38214 // Called when a user chooses which data types to sync as part of the sync
215 // setup wizard. |sync_everything| represents whether they chose the
[email protected]8c94d632010-06-25 22:38:00216 // "keep everything synced" option; if true, |chosen_types| will be ignored
217 // and all data types will be synced. |sync_everything| means "sync all
218 // current and future data types."
[email protected]af909492010-06-10 18:45:38219 virtual void OnUserChoseDatatypes(bool sync_everything,
[email protected]8c94d632010-06-25 22:38:00220 const syncable::ModelTypeSet& chosen_types);
[email protected]af909492010-06-10 18:45:38221
[email protected]a7ab8332010-03-31 20:49:04222 // Called when a user cancels any setup dialog (login, etc).
[email protected]132c85652009-08-05 01:18:27223 virtual void OnUserCancelledDialog();
224
225 // Get various information for displaying in the user interface.
226 browser_sync::SyncBackendHost::StatusSummary QuerySyncStatusSummary();
[email protected]f1e6e0212010-10-15 20:54:24227 virtual browser_sync::SyncBackendHost::Status QueryDetailedSyncStatus();
[email protected]132c85652009-08-05 01:18:27228
[email protected]712257e2009-11-11 22:57:46229 const GoogleServiceAuthError& GetAuthError() const {
[email protected]132c85652009-08-05 01:18:27230 return last_auth_error_;
231 }
232
233 // Displays a dialog for the user to enter GAIA credentials and attempt
234 // re-authentication, and returns true if it actually opened the dialog.
235 // Returns false if a dialog is already showing, an auth attempt is in
236 // progress, the sync system is already authenticated, or some error
237 // occurred preventing the action. We make it the duty of ProfileSyncService
238 // to open the dialog to easily ensure only one is ever showing.
[email protected]d6885592010-10-11 19:38:24239 virtual bool SetupInProgress() const;
[email protected]44b78f90a2009-10-15 17:32:20240 bool WizardIsVisible() const {
241 return wizard_.IsVisible();
242 }
[email protected]d6885592010-10-11 19:38:24243 virtual void ShowLoginDialog(gfx::NativeWindow parent_window);
[email protected]a1595962011-04-22 21:56:24244 SyncSetupWizard& get_wizard() { return wizard_; }
[email protected]1c738472011-01-19 21:48:01245
246 // This method handles clicks on "sync error" UI, showing the appropriate
247 // dialog for the error condition (relogin / enter passphrase).
248 virtual void ShowErrorUI(gfx::NativeWindow parent_window);
249
[email protected]5d0e7c22011-04-19 23:09:07250 // Shows the configure screen of the Sync setup wizard. If |sync_everything|
251 // is true, shows the corresponding page in the customize screen; otherwise,
252 // displays the page that gives the user the ability to select which data
253 // types to sync.
254 void ShowConfigure(gfx::NativeWindow parent_window, bool sync_everything);
255
[email protected]22d3eff2011-01-08 01:45:18256 void PromptForExistingPassphrase(gfx::NativeWindow parent_window);
[email protected]f0718a392011-01-21 23:52:56257 void SigninForPassphraseMigration(gfx::NativeWindow parent_window);
[email protected]8c94d632010-06-25 22:38:00258
[email protected]132c85652009-08-05 01:18:27259 // Pretty-printed strings for a given StatusSummary.
[email protected]066146872010-08-05 00:55:08260 static std::string BuildSyncStatusSummaryText(
[email protected]132c85652009-08-05 01:18:27261 const browser_sync::SyncBackendHost::StatusSummary& summary);
262
263 // Returns true if the SyncBackendHost has told us it's ready to accept
264 // changes.
[email protected]cd2ec4b2011-01-06 00:09:36265 // [REMARK] - it is safe to call this function only from the ui thread.
266 // because the variable is not thread safe and should only be accessed from
267 // single thread. If we want multiple threads to access this(and there is
268 // currently no need to do so) we need to protect this with a lock.
[email protected]132c85652009-08-05 01:18:27269 // TODO(timsteele): What happens if the bookmark model is loaded, a change
270 // takes place, and the backend isn't initialized yet?
271 bool sync_initialized() const { return backend_initialized_; }
[email protected]ddb1e5a2010-12-13 20:10:45272 virtual bool unrecoverable_error_detected() const;
[email protected]f6ec8b22010-06-08 23:40:06273 const std::string& unrecoverable_error_message() {
274 return unrecoverable_error_message_;
275 }
276 tracked_objects::Location unrecoverable_error_location() {
277 return unrecoverable_error_location_.get() ?
278 *unrecoverable_error_location_.get() : tracked_objects::Location();
279 }
[email protected]132c85652009-08-05 01:18:27280
281 bool UIShouldDepictAuthInProgress() const {
282 return is_auth_in_progress_;
283 }
284
[email protected]43c48fb92011-05-02 19:47:43285 // Returns true if OnPassphraseRequired has been called for any reason.
286 bool ObservedPassphraseRequired() const {
287 return passphrase_required_reason_ !=
288 sync_api::REASON_PASSPHRASE_NOT_REQUIRED;
[email protected]66d81002010-10-18 16:52:09289 }
290
[email protected]43c48fb92011-05-02 19:47:43291 sync_api::PassphraseRequiredReason passphrase_required_reason() const {
292 return passphrase_required_reason_;
[email protected]fc52c422010-11-19 18:59:23293 }
294
[email protected]132c85652009-08-05 01:18:27295 // Returns a user-friendly string form of last synced time (in minutes).
[email protected]f1e6e0212010-10-15 20:54:24296 virtual string16 GetLastSyncedTimeString() const;
[email protected]132c85652009-08-05 01:18:27297
298 // Returns the authenticated username of the sync user, or empty if none
299 // exists. It will only exist if the authentication service provider (e.g
300 // GAIA) has confirmed the username is authentic.
301 virtual string16 GetAuthenticatedUsername() const;
302
303 const std::string& last_attempted_user_email() const {
304 return last_attempted_user_email_;
305 }
306
307 // The profile we are syncing for.
[email protected]c976938f2010-10-12 04:55:44308 Profile* profile() const { return profile_; }
[email protected]132c85652009-08-05 01:18:27309
310 // Adds/removes an observer. ProfileSyncService does not take ownership of
311 // the observer.
[email protected]4772b072010-03-30 17:45:46312 virtual void AddObserver(Observer* observer);
313 virtual void RemoveObserver(Observer* observer);
[email protected]132c85652009-08-05 01:18:27314
[email protected]d1db1c332010-10-13 19:57:00315 // Returns true if |observer| has already been added as an observer.
316 bool HasObserver(Observer* observer) const;
317
[email protected]f92351d2011-02-01 07:42:12318 // Returns a pointer to the service's JsFrontend (which is owned by
319 // the service). Never returns NULL. Overrideable for testing
320 // purposes.
321 virtual browser_sync::JsFrontend* GetJsFrontend();
322
[email protected]1f97a112009-08-11 02:17:06323 // Record stats on various events.
324 static void SyncEvent(SyncEventCodes code);
325
[email protected]eec3bcfa2009-11-12 17:23:43326 // Returns whether sync is enabled. Sync can be enabled/disabled both
327 // at compile time (e.g., on a per-OS basis) or at run time (e.g.,
328 // command-line switches).
329 static bool IsSyncEnabled();
330
[email protected]d1db1c332010-10-13 19:57:00331 // Returns whether sync is managed, i.e. controlled by configuration
[email protected]d3b98c82010-07-14 07:45:59332 // management. If so, the user is not allowed to configure sync.
333 bool IsManaged();
334
[email protected]db1df0f2009-08-18 22:36:05335 // UnrecoverableErrorHandler implementation.
[email protected]f6ec8b22010-06-08 23:40:06336 virtual void OnUnrecoverableError(
337 const tracked_objects::Location& from_here,
338 const std::string& message);
[email protected]db1df0f2009-08-18 22:36:05339
[email protected]420914932011-01-24 23:32:41340 // The functions below (until ActivateDataType()) should only be
341 // called if sync_initialized() is true.
342
343 // TODO(akalin): This is called mostly by ModelAssociators and
344 // tests. Figure out how to pass the handle to the ModelAssociators
345 // directly, figure out how to expose this to tests, and remove this
346 // function.
347 sync_api::UserShare* GetUserShare() const;
348
349 // TODO(akalin): These two functions are used only by
350 // ProfileSyncServiceHarness. Figure out a different way to expose
351 // this info to that class, and remove these functions.
352
[email protected]dc556252011-04-20 01:59:35353 virtual const browser_sync::sessions::SyncSessionSnapshot*
[email protected]420914932011-01-24 23:32:41354 GetLastSessionSnapshot() const;
355
356 // Returns whether or not the underlying sync engine has made any
357 // local changes to items that have not yet been synced with the
358 // server.
359 bool HasUnsyncedItems() const;
360
[email protected]51c84ee2011-04-26 22:07:59361 // Returns whether or not the sync service is reconfiguring due
362 // to server-initiated resynchronization.
363 bool HasPendingBackendMigration() const;
364
[email protected]420914932011-01-24 23:32:41365 // Get the current routing information for all enabled model types.
366 // If a model type is not enabled (that is, if the syncer should not
367 // be trying to sync it), it is not in this map.
368 //
369 // TODO(akalin): This function is used by
370 // sync_ui_util::ConstructAboutInformation() and by some test
371 // classes. Figure out a different way to expose this info and
372 // remove this function.
373 void GetModelSafeRoutingInfo(browser_sync::ModelSafeRoutingInfo* out);
374
375 // TODO(akalin): Remove these four functions once we're done with
376 // autofill migration.
377
378 syncable::AutofillMigrationState
379 GetAutofillMigrationState();
380
381 void SetAutofillMigrationState(
382 syncable::AutofillMigrationState state);
383
384 syncable::AutofillMigrationDebugInfo
385 GetAutofillMigrationDebugInfo();
386
387 void SetAutofillMigrationDebugInfo(
388 syncable::AutofillMigrationDebugInfo::PropertyToSet property_to_set,
389 const syncable::AutofillMigrationDebugInfo& info);
[email protected]db1df0f2009-08-18 22:36:05390
[email protected]4aea04a2010-02-10 20:13:43391 virtual void ActivateDataType(
392 browser_sync::DataTypeController* data_type_controller,
393 browser_sync::ChangeProcessor* change_processor);
394 virtual void DeactivateDataType(
395 browser_sync::DataTypeController* data_type_controller,
396 browser_sync::ChangeProcessor* change_processor);
397
[email protected]c4c672a2010-03-23 21:47:04398 // NotificationObserver implementation.
399 virtual void Observe(NotificationType type,
400 const NotificationSource& source,
401 const NotificationDetails& details);
402
[email protected]a1c2aef62010-04-02 02:58:05403 // Changes which data types we're going to be syncing to |preferred_types|.
404 // If it is running, the DataTypeManager will be instructed to reconfigure
405 // the sync backend so that exactly these datatypes are actively synced. See
406 // class comment for more on what it means for a datatype to be Preferred.
407 virtual void ChangePreferredDataTypes(
408 const syncable::ModelTypeSet& preferred_types);
409
410 // Get the set of currently enabled data types (as chosen or configured by
411 // the user). See class comment for more on what it means for a datatype
412 // to be Preferred.
413 virtual void GetPreferredDataTypes(
414 syncable::ModelTypeSet* preferred_types) const;
415
416 // Gets the set of all data types that could be allowed (the set that
417 // should be advertised to the user). These will typically only change
418 // via a command-line option. See class comment for more on what it means
419 // for a datatype to be Registered.
420 virtual void GetRegisteredDataTypes(
421 syncable::ModelTypeSet* registered_types) const;
[email protected]a7ab8332010-03-31 20:49:04422
[email protected]ff0aa752010-06-10 22:40:52423 // Checks whether the Cryptographer is ready to encrypt and decrypt updates
[email protected]47f6a362011-03-29 19:57:11424 // for sensitive data types. Caller must be holding a
425 // syncapi::BaseTransaction to ensure thread safety.
426 virtual bool IsCryptographerReady(
427 const sync_api::BaseTransaction* trans) const;
[email protected]ff0aa752010-06-10 22:40:52428
[email protected]c976938f2010-10-12 04:55:44429 // Returns true if a secondary passphrase is being used.
430 virtual bool IsUsingSecondaryPassphrase() const;
431
[email protected]ee1adf4b2010-10-11 03:48:48432 // Sets the Cryptographer's passphrase, or caches it until that is possible.
433 // This will check asynchronously whether the passphrase is valid and notify
[email protected]dc39dd1b2010-10-07 18:08:11434 // ProfileSyncServiceObservers via the NotificationService when the outcome
435 // is known.
[email protected]954b1082010-11-10 20:22:50436 // |is_explicit| is true if the call is in response to the user explicitly
437 // setting a passphrase as opposed to implicitly (from the users' perspective)
438 // using their Google Account password. An implicit SetPassphrase will *not*
439 // *not* override an explicit passphrase set previously.
[email protected]2e610e92011-01-13 23:39:45440 // |is_creation| is true if the call is in response to the user setting
441 // up a new passphrase, and false if it's being set in response to a prompt
442 // for an existing passphrase.
443 virtual void SetPassphrase(const std::string& passphrase,
444 bool is_explicit,
445 bool is_creation);
[email protected]bb899b3f2010-06-23 21:35:32446
[email protected]3fa964af2011-02-24 18:54:39447 // Changes the set of datatypes that require encryption. This affects all
448 // machines synced to this account and all data belonging to the specified
449 // types.
450 // Note that this is an asynchronous operation (the encryption of data is
451 // performed on SyncBackendHost's core thread) and may not have an immediate
452 // effect.
453 virtual void EncryptDataTypes(
454 const syncable::ModelTypeSet& encrypted_types);
455
456 // Get the currently encrypted data types.
457 virtual void GetEncryptedDataTypes(
458 syncable::ModelTypeSet* encrypted_types) const;
459
[email protected]5edb9222010-08-18 00:23:29460 // Returns whether processing changes is allowed. Check this before doing
461 // any model-modifying operations.
462 bool ShouldPushChanges();
463
[email protected]9a127f22010-09-17 21:05:16464 const GURL& sync_service_url() const { return sync_service_url_; }
[email protected]bb868b42010-11-18 22:33:00465 SigninManager* signin() { return signin_.get(); }
466 const std::string& cros_user() const { return cros_user_; }
[email protected]9a127f22010-09-17 21:05:16467
[email protected]132c85652009-08-05 01:18:27468 protected:
[email protected]420914932011-01-24 23:32:41469 // Used by test classes that derive from ProfileSyncService.
470 virtual browser_sync::SyncBackendHost* GetBackendForTest();
471
[email protected]7cef1c442010-07-07 17:05:22472 // Helper to install and configure a data type manager.
473 void ConfigureDataTypeManager();
[email protected]132c85652009-08-05 01:18:27474
[email protected]132c85652009-08-05 01:18:27475 // Starts up the backend sync components.
476 void StartUp();
477 // Shuts down the backend sync components.
478 // |sync_disabled| indicates if syncing is being disabled or not.
479 void Shutdown(bool sync_disabled);
480
[email protected]48352c12009-08-15 01:19:11481 // Methods to register and remove preferences.
482 void RegisterPreferences();
483 void ClearPreferences();
484
[email protected]e8234d32010-09-09 20:36:39485 // Return SyncCredentials from the TokenService.
486 sync_api::SyncCredentials GetCredentials();
487
[email protected]18af9a22010-08-11 00:47:19488 // Test need to override this to create backends that allow setting up
489 // initial conditions, such as populating sync nodes.
[email protected]420914932011-01-24 23:32:41490 //
491 // TODO(akalin): Figure out a better way to do this. Ideally, we'd
492 // construct the backend outside this class and pass it in to the
493 // contructor or Initialize().
[email protected]18af9a22010-08-11 00:47:19494 virtual void CreateBackend();
[email protected]132c85652009-08-05 01:18:27495
[email protected]7cef1c442010-07-07 17:05:22496 const browser_sync::DataTypeController::TypeMap& data_type_controllers() {
497 return data_type_controllers_;
498 }
499
[email protected]4b2866b2011-01-26 18:58:44500 // Helper method for managing encryption UI.
501 bool IsEncryptedDatatypeEnabled() const;
502
[email protected]e8234d32010-09-09 20:36:39503 // The wizard will try to read the auth state out of the profile sync
504 // service using this member. Captcha and error state are reflected.
[email protected]712257e2009-11-11 22:57:46505 GoogleServiceAuthError last_auth_error_;
[email protected]132c85652009-08-05 01:18:27506
[email protected]7cef1c442010-07-07 17:05:22507 // Our asynchronous backend to communicate with sync components living on
508 // other threads.
509 scoped_ptr<browser_sync::SyncBackendHost> backend_;
510
[email protected]132c85652009-08-05 01:18:27511 // Cache of the last name the client attempted to authenticate.
512 std::string last_attempted_user_email_;
513
[email protected]fc52c422010-11-19 18:59:23514 // Was the last SYNC_PASSPHRASE_REQUIRED notification sent because it
[email protected]43c48fb92011-05-02 19:47:43515 // was required for encryption, decryption with a cached passphrase, or
516 // because a new passphrase is required?
517 sync_api::PassphraseRequiredReason passphrase_required_reason_;
[email protected]fc52c422010-11-19 18:59:23518
[email protected]f0718a392011-01-21 23:52:56519 // Is the user in a passphrase migration?
520 bool passphrase_migration_in_progress_;
521
[email protected]132c85652009-08-05 01:18:27522 private:
[email protected]4f5732a42010-09-21 22:39:09523 friend class ProfileSyncServicePasswordTest;
[email protected]420914932011-01-24 23:32:41524 friend class TestProfileSyncService;
[email protected]61b694a2010-06-10 10:40:46525 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceTest, InitialState);
[email protected]132c85652009-08-05 01:18:27526
[email protected]18af9a22010-08-11 00:47:19527 // If |delete_sync_data_folder| is true, then this method will delete all
528 // previous "Sync Data" folders. (useful if the folder is partial/corrupt).
529 void InitializeBackend(bool delete_sync_data_folder);
530
[email protected]132c85652009-08-05 01:18:27531 // Initializes the various settings from the command line.
532 void InitSettings();
533
[email protected]132c85652009-08-05 01:18:27534 // Sets the last synced time to the current time.
535 void UpdateLastSyncedTime();
536
[email protected]1a787692011-01-19 22:19:46537 void NotifyObservers();
538
[email protected]57ecc4b2010-08-11 03:02:51539 static const char* GetPrefNameForDataType(syncable::ModelType data_type);
[email protected]a1c2aef62010-04-02 02:58:05540
[email protected]cb4c06e2009-08-22 00:24:39541 // Time at which we begin an attempt a GAIA authorization.
542 base::TimeTicks auth_start_time_;
543
544 // Time at which error UI is presented for the new tab page.
[email protected]1f97a112009-08-11 02:17:06545 base::TimeTicks auth_error_time_;
546
[email protected]e3e43d92010-02-26 22:02:38547 // Factory used to create various dependent objects.
548 ProfileSyncFactory* factory_;
549
[email protected]132c85652009-08-05 01:18:27550 // The profile whose data we are synchronizing.
551 Profile* profile_;
552
[email protected]e8234d32010-09-09 20:36:39553 // Email for the ChromiumOS user, if we're running under ChromiumOS.
554 std::string cros_user_;
[email protected]72a31b42010-02-17 22:26:33555
[email protected]132c85652009-08-05 01:18:27556 // TODO(ncarter): Put this in a profile, once there is UI for it.
557 // This specifies where to find the sync server.
558 GURL sync_service_url_;
559
[email protected]132c85652009-08-05 01:18:27560 // The last time we detected a successful transition from SYNCING state.
561 // Our backend notifies us whenever we should take a new snapshot.
562 base::Time last_synced_time_;
563
[email protected]4aea04a2010-02-10 20:13:43564 // List of available data type controllers.
[email protected]72a31b42010-02-17 22:26:33565 browser_sync::DataTypeController::TypeMap data_type_controllers_;
[email protected]db1df0f2009-08-18 22:36:05566
[email protected]132c85652009-08-05 01:18:27567 // Whether the SyncBackendHost has been initialized.
568 bool backend_initialized_;
569
[email protected]132c85652009-08-05 01:18:27570 // Various pieces of UI query this value to determine if they should show
571 // an "Authenticating.." type of message. We are the only central place
572 // all auth attempts funnel through, so it makes sense to provide this.
573 // As its name suggests, this should NOT be used for anything other than UI.
574 bool is_auth_in_progress_;
575
[email protected]44b78f90a2009-10-15 17:32:20576 SyncSetupWizard wizard_;
577
[email protected]e8234d32010-09-09 20:36:39578 // Encapsulates user signin with TokenService.
[email protected]bb868b42010-11-18 22:33:00579 scoped_ptr<SigninManager> signin_;
[email protected]e8234d32010-09-09 20:36:39580
[email protected]132c85652009-08-05 01:18:27581 // True if an unrecoverable error (e.g. violation of an assumed invariant)
582 // occurred during syncer operation. This value should be checked before
583 // doing any work that might corrupt things further.
584 bool unrecoverable_error_detected_;
585
[email protected]f6ec8b22010-06-08 23:40:06586 // A message sent when an unrecoverable error occurred.
587 std::string unrecoverable_error_message_;
588 scoped_ptr<tracked_objects::Location> unrecoverable_error_location_;
589
[email protected]e3e43d92010-02-26 22:02:38590 // Manages the start and stop of the various data types.
591 scoped_ptr<browser_sync::DataTypeManager> data_type_manager_;
592
[email protected]132c85652009-08-05 01:18:27593 ObserverList<Observer> observers_;
594
[email protected]f92351d2011-02-01 07:42:12595 browser_sync::JsEventHandlerList js_event_handlers_;
596
[email protected]c4c672a2010-03-23 21:47:04597 NotificationRegistrar registrar_;
598
[email protected]2be7bf22010-04-23 21:02:37599 ScopedRunnableMethodFactory<ProfileSyncService>
[email protected]954b1082010-11-10 20:22:50600 scoped_runnable_method_factory_;
[email protected]2be7bf22010-04-23 21:02:37601
[email protected]d3b98c82010-07-14 07:45:59602 // The preference that controls whether sync is under control by configuration
603 // management.
604 BooleanPrefMember pref_sync_managed_;
605
[email protected]a47eeb52010-07-15 17:54:25606 // This allows us to gracefully handle an ABORTED return code from the
607 // DataTypeManager in the event that the server informed us to cease and
608 // desist syncing immediately.
609 bool expect_sync_configuration_aborted_;
610
[email protected]48a98b32010-09-17 20:26:59611 // Sometimes we need to temporarily hold on to a passphrase because we don't
612 // yet have a backend to send it to. This happens during initialization as
613 // we don't StartUp until we have a valid token, which happens after valid
614 // credentials were provided.
[email protected]954b1082010-11-10 20:22:50615 struct CachedPassphrase {
616 std::string value;
617 bool is_explicit;
[email protected]2e610e92011-01-13 23:39:45618 bool is_creation;
619 CachedPassphrase() : is_explicit(false), is_creation(false) {}
[email protected]954b1082010-11-10 20:22:50620 };
621 CachedPassphrase cached_passphrase_;
622
623 // TODO(tim): Remove this once new 'explicit passphrase' code flushes through
624 // dev channel. See bug 62103.
625 // To "migrate" early adopters of password sync on dev channel to the new
626 // model that stores their secondary passphrase preference in the cloud, we
627 // need some extra state since this cloud pref will be empty for all of them
628 // regardless of how they set up sync, and we can't trust
629 // kSyncUsingSecondaryPassphrase due to bugs in that implementation.
630 bool tried_implicit_gaia_remove_when_bug_62103_fixed_;
[email protected]48a98b32010-09-17 20:26:59631
[email protected]689a7a72010-09-29 19:56:41632 // Keep track of where we are in a server clear operation
633 ClearServerDataState clear_server_data_state_;
634
[email protected]990de362010-10-13 17:55:50635 // Timeout for the clear data command. This timeout is a temporary hack
[email protected]954b1082010-11-10 20:22:50636 // and is necessary because the nudge sync framework can drop nudges for
[email protected]990de362010-10-13 17:55:50637 // a wide variety of sync-related conditions (throttling, connections issues,
638 // syncer paused, etc.). It can only be removed correctly when the framework
639 // is reworked to allow one-shot commands like clearing server data.
640 base::OneShotTimer<ProfileSyncService> clear_server_data_timer_;
641
[email protected]3fa964af2011-02-24 18:54:39642 // The set of encrypted types. This is updated whenever datatypes are
643 // encrypted through the OnEncryptionComplete callback of SyncFrontend.
644 syncable::ModelTypeSet encrypted_types_;
645
[email protected]dc556252011-04-20 01:59:35646 scoped_ptr<browser_sync::BackendMigrator> migrator_;
647
[email protected]132c85652009-08-05 01:18:27648 DISALLOW_COPY_AND_ASSIGN(ProfileSyncService);
649};
650
651#endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_