blob: 6b90e7b06004bd012665af514f5dad67837d260e [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]fa134872011-08-02 18:39:5512#include "base/compiler_specific.h"
[email protected]61b694a2010-06-10 10:40:4613#include "base/gtest_prod_util.h"
[email protected]3b63f8f42011-03-28 01:54:1514#include "base/memory/scoped_ptr.h"
[email protected]fa134872011-08-02 18:39:5515#include "base/memory/weak_ptr.h"
[email protected]132c85652009-08-05 01:18:2716#include "base/observer_list.h"
[email protected]066146872010-08-05 00:55:0817#include "base/string16.h"
[email protected]a1595962011-04-22 21:56:2418#include "base/task.h"
[email protected]4aea04a2010-02-10 20:13:4319#include "base/time.h"
[email protected]990de362010-10-13 17:55:5020#include "base/timer.h"
[email protected]a1595962011-04-22 21:56:2421#include "base/tracked.h"
[email protected]37858e52010-08-26 00:22:0222#include "chrome/browser/prefs/pref_member.h"
[email protected]a1595962011-04-22 21:56:2423#include "chrome/browser/sync/engine/model_safe_worker.h"
[email protected]72a31b42010-02-17 22:26:3324#include "chrome/browser/sync/glue/data_type_controller.h"
[email protected]132c85652009-08-05 01:18:2725#include "chrome/browser/sync/glue/sync_backend_host.h"
[email protected]67192b42011-08-17 23:38:3026#include "chrome/browser/sync/internal_api/sync_manager.h"
[email protected]d3b98c82010-07-14 07:45:5927#include "chrome/browser/sync/profile_sync_service_observer.h"
[email protected]67192b42011-08-17 23:38:3028#include "chrome/browser/sync/syncable/model_type.h"
[email protected]fa134872011-08-02 18:39:5529#include "chrome/browser/sync/sync_js_controller.h"
[email protected]d80033e2009-10-16 10:32:0430#include "chrome/browser/sync/sync_setup_wizard.h"
[email protected]eafb2182010-03-03 00:46:3131#include "chrome/browser/sync/unrecoverable_error_handler.h"
[email protected]99074c52010-08-19 18:44:1932#include "chrome/common/net/gaia/google_service_auth_error.h"
[email protected]432115822011-07-10 15:52:2733#include "content/common/content_notification_types.h"
[email protected]ebbbb9f2011-03-09 13:16:1434#include "content/common/notification_observer.h"
35#include "content/common/notification_registrar.h"
[email protected]132c85652009-08-05 01:18:2736#include "googleurl/src/gurl.h"
37
[email protected]c4c672a2010-03-23 21:47:0438class NotificationDetails;
39class NotificationSource;
[email protected]942690b132010-05-11 06:42:1440class Profile;
41class ProfileSyncFactory;
[email protected]a1595962011-04-22 21:56:2442class SigninManager;
[email protected]9e11c952011-06-24 21:31:3043struct ChromeCookieDetails;
[email protected]c4c672a2010-03-23 21:47:0444
[email protected]f92351d2011-02-01 07:42:1245namespace browser_sync {
[email protected]dc556252011-04-20 01:59:3546class BackendMigrator;
[email protected]a1595962011-04-22 21:56:2447class ChangeProcessor;
48class DataTypeManager;
[email protected]fa134872011-08-02 18:39:5549class JsController;
[email protected]a1595962011-04-22 21:56:2450class SessionModelAssociator;
51namespace sessions { struct SyncSessionSnapshot; }
52}
53
54namespace sync_api {
55class BaseTransaction;
56struct SyncCredentials;
57struct UserShare;
58}
[email protected]f92351d2011-02-01 07:42:1259
[email protected]132c85652009-08-05 01:18:2760// ProfileSyncService is the layer between browser subsystems like bookmarks,
[email protected]a1c2aef62010-04-02 02:58:0561// and the sync backend. Each subsystem is logically thought of as being
62// a sync datatype.
63//
64// Individual datatypes can, at any point, be in a variety of stages of being
65// "enabled". Here are some specific terms for concepts used in this class:
66//
67// 'Registered' (feature suppression for a datatype)
68//
69// When a datatype is registered, the user has the option of syncing it.
70// The sync opt-in UI will show only registered types; a checkbox should
71// never be shown for an unregistered type, and nor should it ever be
72// synced.
73//
74// A datatype is considered registered once RegisterDataTypeController
75// has been called with that datatype's DataTypeController.
76//
77// 'Preferred' (user preferences and opt-out for a datatype)
78//
79// This means the user's opt-in or opt-out preference on a per-datatype
80// basis. The sync service will try to make active exactly these types.
81// If a user has opted out of syncing a particular datatype, it will
82// be registered, but not preferred.
83//
84// This state is controlled by the ConfigurePreferredDataTypes and
85// GetPreferredDataTypes. They are stored in the preferences system,
86// and persist; though if a datatype is not registered, it cannot
87// be a preferred datatype.
88//
89// 'Active' (run-time initialization of sync system for a datatype)
90//
91// An active datatype is a preferred datatype that is actively being
92// synchronized: the syncer has been instructed to querying the server
93// for this datatype, first-time merges have finished, and there is an
94// actively installed ChangeProcessor that listens for changes to this
95// datatype, propagating such changes into and out of the sync backend
96// as necessary.
97//
98// When a datatype is in the process of becoming active, it may be
99// in some intermediate state. Those finer-grained intermediate states
100// are differentiated by the DataTypeController state.
101//
[email protected]4aea04a2010-02-10 20:13:43102class ProfileSyncService : public browser_sync::SyncFrontend,
[email protected]c4c672a2010-03-23 21:47:04103 public browser_sync::UnrecoverableErrorHandler,
104 public NotificationObserver {
[email protected]132c85652009-08-05 01:18:27105 public:
106 typedef ProfileSyncServiceObserver Observer;
107 typedef browser_sync::SyncBackendHost::Status Status;
108
[email protected]1f97a112009-08-11 02:17:06109 enum SyncEventCodes {
110 MIN_SYNC_EVENT_CODE = 0,
111
112 // Events starting the sync service.
113 START_FROM_NTP = 1, // Sync was started from the ad in NTP
114 START_FROM_WRENCH = 2, // Sync was started from the Wrench menu.
115 START_FROM_OPTIONS = 3, // Sync was started from Wrench->Options.
[email protected]b220d13f2009-10-09 04:12:46116 START_FROM_BOOKMARK_MANAGER = 4, // Sync was started from Bookmark manager.
[email protected]29d70252011-04-28 02:16:58117 START_FROM_PROFILE_MENU = 5, // Sync was started from multiprofile menu.
[email protected]b70651d2011-05-26 18:39:12118 START_FROM_URL = 6, // Sync was started from a typed URL.
[email protected]1f97a112009-08-11 02:17:06119
[email protected]a7ab8332010-03-31 20:49:04120 // Events regarding cancellation of the signon process of sync.
[email protected]8ac2dc112009-10-01 23:19:13121 CANCEL_FROM_SIGNON_WITHOUT_AUTH = 10, // Cancelled before submitting
[email protected]1f97a112009-08-11 02:17:06122 // username and password.
123 CANCEL_DURING_SIGNON = 11, // Cancelled after auth.
[email protected]c976938f2010-10-12 04:55:44124 CANCEL_DURING_CONFIGURE = 12, // Cancelled before choosing data
[email protected]8c94d632010-06-25 22:38:00125 // types and clicking OK.
[email protected]1f97a112009-08-11 02:17:06126 // Events resulting in the stoppage of sync service.
127 STOP_FROM_OPTIONS = 20, // Sync was stopped from Wrench->Options.
128
129 // Miscellaneous events caused by sync service.
[email protected]1f97a112009-08-11 02:17:06130
131 MAX_SYNC_EVENT_CODE
132 };
133
[email protected]689a7a72010-09-29 19:56:41134 // Keep track of where we are when clearing server data.
135 enum ClearServerDataState {
136 CLEAR_NOT_STARTED = 1,
137 CLEAR_CLEARING = 2,
138 CLEAR_FAILED = 3,
139 CLEAR_SUCCEEDED = 4,
140 };
141
[email protected]f66bcdf2010-05-17 20:31:14142 // Default sync server URL.
143 static const char* kSyncServerUrl;
144 // Sync server URL for dev channel users
145 static const char* kDevServerUrl;
146
[email protected]62828b12011-07-21 21:48:16147 ProfileSyncService(ProfileSyncFactory* factory,
[email protected]e3e43d92010-02-26 22:02:38148 Profile* profile,
[email protected]62828b12011-07-21 21:48:16149 SigninManager* signin, // Service takes ownership.
[email protected]e8234d32010-09-09 20:36:39150 const std::string& cros_user);
[email protected]132c85652009-08-05 01:18:27151 virtual ~ProfileSyncService();
152
153 // Initializes the object. This should be called every time an object of this
154 // class is constructed.
155 void Initialize();
156
[email protected]e8234d32010-09-09 20:36:39157 void RegisterAuthNotifications();
158
159 // Return whether all sync tokens are loaded and
160 // available for the backend to start up.
161 bool AreCredentialsAvailable();
162
[email protected]4aea04a2010-02-10 20:13:43163 // Registers a data type controller with the sync service. This
164 // makes the data type controller available for use, it does not
165 // enable or activate the synchronization of the data type (see
166 // ActivateDataType). Takes ownership of the pointer.
167 void RegisterDataTypeController(
168 browser_sync::DataTypeController* data_type_controller);
169
[email protected]5edb9222010-08-18 00:23:29170 // Returns the session model associator associated with this type, but only if
171 // the associator is running. If it is doing anything else, it will return
172 // null.
173 browser_sync::SessionModelAssociator* GetSessionModelAssociator();
174
[email protected]689a7a72010-09-29 19:56:41175 // Maintain state of where we are in a server clear operation.
176 void ResetClearServerDataState();
177 ClearServerDataState GetClearServerDataState();
178
[email protected]a7ab8332010-03-31 20:49:04179 // Fills state_map with a map of current data types that are possible to
180 // sync, as well as their states.
181 void GetDataTypeControllerStates(
182 browser_sync::DataTypeController::StateMap* state_map) const;
[email protected]4aea04a2010-02-10 20:13:43183
[email protected]e8234d32010-09-09 20:36:39184 // Disables sync for user. Use ShowLoginDialog to enable.
[email protected]132c85652009-08-05 01:18:27185 virtual void DisableForUser();
186
[email protected]1ce52aa2010-09-08 19:07:36187 // Clears all Chromesync data from the server.
188 void ClearServerData();
189
[email protected]132c85652009-08-05 01:18:27190 // Whether sync is enabled by user or not.
[email protected]4772b072010-03-30 17:45:46191 virtual bool HasSyncSetupCompleted() const;
[email protected]2efebbbf2010-10-25 10:31:21192 virtual void SetSyncSetupCompleted();
[email protected]132c85652009-08-05 01:18:27193
[email protected]132c85652009-08-05 01:18:27194 // SyncFrontend implementation.
[email protected]fa134872011-08-02 18:39:55195 virtual void OnBackendInitialized(
196 const browser_sync::WeakHandle<browser_sync::JsBackend>& js_backend,
197 bool success) OVERRIDE;
198 virtual void OnSyncCycleCompleted() OVERRIDE;
199 virtual void OnAuthError() OVERRIDE;
200 virtual void OnStopSyncingPermanently() OVERRIDE;
201 virtual void OnClearServerDataFailed() OVERRIDE;
202 virtual void OnClearServerDataSucceeded() OVERRIDE;
203 virtual void OnPassphraseRequired(
204 sync_api::PassphraseRequiredReason reason) OVERRIDE;
205 virtual void OnPassphraseAccepted() OVERRIDE;
[email protected]3fa964af2011-02-24 18:54:39206 virtual void OnEncryptionComplete(
[email protected]fa134872011-08-02 18:39:55207 const syncable::ModelTypeSet& encrypted_types) OVERRIDE;
[email protected]dc556252011-04-20 01:59:35208 virtual void OnMigrationNeededForTypes(
[email protected]fa134872011-08-02 18:39:55209 const syncable::ModelTypeSet& types) OVERRIDE;
[email protected]23caf1d2011-08-25 22:21:02210 virtual void OnDataTypesChanged(
211 const syncable::ModelTypeSet& to_add) OVERRIDE;
[email protected]cb5199b2011-09-04 01:55:52212 virtual void OnActionableError(
213 const browser_sync::SyncProtocolError& error) OVERRIDE;
[email protected]fa134872011-08-02 18:39:55214
215 void OnClearServerDataTimeout();
[email protected]132c85652009-08-05 01:18:27216
217 // Called when a user enters credentials through UI.
218 virtual void OnUserSubmittedAuth(const std::string& username,
[email protected]1fc9b3f2009-11-12 21:22:09219 const std::string& password,
[email protected]96209ccd2010-10-11 21:57:27220 const std::string& captcha,
221 const std::string& access_code);
[email protected]132c85652009-08-05 01:18:27222
[email protected]e8234d32010-09-09 20:36:39223 // Update the last auth error and notify observers of error state.
224 void UpdateAuthErrorState(const GoogleServiceAuthError& error);
225
[email protected]af909492010-06-10 18:45:38226 // Called when a user chooses which data types to sync as part of the sync
227 // setup wizard. |sync_everything| represents whether they chose the
[email protected]8c94d632010-06-25 22:38:00228 // "keep everything synced" option; if true, |chosen_types| will be ignored
229 // and all data types will be synced. |sync_everything| means "sync all
230 // current and future data types."
[email protected]af909492010-06-10 18:45:38231 virtual void OnUserChoseDatatypes(bool sync_everything,
[email protected]8c94d632010-06-25 22:38:00232 const syncable::ModelTypeSet& chosen_types);
[email protected]af909492010-06-10 18:45:38233
[email protected]a7ab8332010-03-31 20:49:04234 // Called when a user cancels any setup dialog (login, etc).
[email protected]132c85652009-08-05 01:18:27235 virtual void OnUserCancelledDialog();
236
237 // Get various information for displaying in the user interface.
238 browser_sync::SyncBackendHost::StatusSummary QuerySyncStatusSummary();
[email protected]f1e6e0212010-10-15 20:54:24239 virtual browser_sync::SyncBackendHost::Status QueryDetailedSyncStatus();
[email protected]132c85652009-08-05 01:18:27240
[email protected]712257e2009-11-11 22:57:46241 const GoogleServiceAuthError& GetAuthError() const {
[email protected]132c85652009-08-05 01:18:27242 return last_auth_error_;
243 }
244
245 // Displays a dialog for the user to enter GAIA credentials and attempt
246 // re-authentication, and returns true if it actually opened the dialog.
247 // Returns false if a dialog is already showing, an auth attempt is in
248 // progress, the sync system is already authenticated, or some error
249 // occurred preventing the action. We make it the duty of ProfileSyncService
250 // to open the dialog to easily ensure only one is ever showing.
[email protected]d6885592010-10-11 19:38:24251 virtual bool SetupInProgress() const;
[email protected]44b78f90a2009-10-15 17:32:20252 bool WizardIsVisible() const {
253 return wizard_.IsVisible();
254 }
[email protected]8b6ede22011-05-23 23:50:54255
[email protected]a1595962011-04-22 21:56:24256 SyncSetupWizard& get_wizard() { return wizard_; }
[email protected]1c738472011-01-19 21:48:01257
[email protected]87d5eb42011-06-14 01:21:25258 // Shows the login screen of the Sync setup wizard.
259 virtual void ShowLoginDialog();
[email protected]8b6ede22011-05-23 23:50:54260
[email protected]1c738472011-01-19 21:48:01261 // This method handles clicks on "sync error" UI, showing the appropriate
[email protected]87d5eb42011-06-14 01:21:25262 // dialog for the error condition (relogin / enter passphrase).
263 virtual void ShowErrorUI();
[email protected]1c738472011-01-19 21:48:01264
[email protected]5d0e7c22011-04-19 23:09:07265 // Shows the configure screen of the Sync setup wizard. If |sync_everything|
266 // is true, shows the corresponding page in the customize screen; otherwise,
267 // displays the page that gives the user the ability to select which data
[email protected]87d5eb42011-06-14 01:21:25268 // types to sync.
269 void ShowConfigure(bool sync_everything);
[email protected]5d0e7c22011-04-19 23:09:07270
[email protected]cb5199b2011-09-04 01:55:52271 void ShowSyncSetup(const std::string& sub_page);
272 void ShowSyncSetupWithWizard(SyncSetupWizard::State state);
[email protected]68f6ead2011-07-20 23:51:39273
[email protected]132c85652009-08-05 01:18:27274 // Pretty-printed strings for a given StatusSummary.
[email protected]066146872010-08-05 00:55:08275 static std::string BuildSyncStatusSummaryText(
[email protected]132c85652009-08-05 01:18:27276 const browser_sync::SyncBackendHost::StatusSummary& summary);
277
278 // Returns true if the SyncBackendHost has told us it's ready to accept
279 // changes.
[email protected]cd2ec4b2011-01-06 00:09:36280 // [REMARK] - it is safe to call this function only from the ui thread.
281 // because the variable is not thread safe and should only be accessed from
282 // single thread. If we want multiple threads to access this(and there is
283 // currently no need to do so) we need to protect this with a lock.
[email protected]132c85652009-08-05 01:18:27284 // TODO(timsteele): What happens if the bookmark model is loaded, a change
285 // takes place, and the backend isn't initialized yet?
286 bool sync_initialized() const { return backend_initialized_; }
[email protected]ddb1e5a2010-12-13 20:10:45287 virtual bool unrecoverable_error_detected() const;
[email protected]f6ec8b22010-06-08 23:40:06288 const std::string& unrecoverable_error_message() {
289 return unrecoverable_error_message_;
290 }
291 tracked_objects::Location unrecoverable_error_location() {
292 return unrecoverable_error_location_.get() ?
293 *unrecoverable_error_location_.get() : tracked_objects::Location();
294 }
[email protected]132c85652009-08-05 01:18:27295
296 bool UIShouldDepictAuthInProgress() const {
297 return is_auth_in_progress_;
298 }
299
[email protected]43c48fb92011-05-02 19:47:43300 // Returns true if OnPassphraseRequired has been called for any reason.
[email protected]88dee5e2011-05-03 18:23:53301 bool IsPassphraseRequired() const {
[email protected]43c48fb92011-05-02 19:47:43302 return passphrase_required_reason_ !=
303 sync_api::REASON_PASSPHRASE_NOT_REQUIRED;
[email protected]66d81002010-10-18 16:52:09304 }
305
[email protected]88dee5e2011-05-03 18:23:53306 // Returns true if OnPassphraseRequired has been called for decryption.
307 bool IsPassphraseRequiredForDecryption() const {
308 return (passphrase_required_reason_ == sync_api::REASON_DECRYPTION ||
309 passphrase_required_reason_ == sync_api::REASON_SET_PASSPHRASE_FAILED);
310 }
311
[email protected]43c48fb92011-05-02 19:47:43312 sync_api::PassphraseRequiredReason passphrase_required_reason() const {
313 return passphrase_required_reason_;
[email protected]fc52c422010-11-19 18:59:23314 }
315
[email protected]132c85652009-08-05 01:18:27316 // Returns a user-friendly string form of last synced time (in minutes).
[email protected]f1e6e0212010-10-15 20:54:24317 virtual string16 GetLastSyncedTimeString() const;
[email protected]132c85652009-08-05 01:18:27318
319 // Returns the authenticated username of the sync user, or empty if none
320 // exists. It will only exist if the authentication service provider (e.g
321 // GAIA) has confirmed the username is authentic.
322 virtual string16 GetAuthenticatedUsername() const;
323
324 const std::string& last_attempted_user_email() const {
325 return last_attempted_user_email_;
326 }
327
328 // The profile we are syncing for.
[email protected]c976938f2010-10-12 04:55:44329 Profile* profile() const { return profile_; }
[email protected]132c85652009-08-05 01:18:27330
331 // Adds/removes an observer. ProfileSyncService does not take ownership of
332 // the observer.
[email protected]4772b072010-03-30 17:45:46333 virtual void AddObserver(Observer* observer);
334 virtual void RemoveObserver(Observer* observer);
[email protected]132c85652009-08-05 01:18:27335
[email protected]d1db1c332010-10-13 19:57:00336 // Returns true if |observer| has already been added as an observer.
337 bool HasObserver(Observer* observer) const;
338
[email protected]fa134872011-08-02 18:39:55339 // Returns a weak pointer to the service's JsController.
340 // Overrideable for testing purposes.
341 virtual base::WeakPtr<browser_sync::JsController> GetJsController();
[email protected]f92351d2011-02-01 07:42:12342
[email protected]1f97a112009-08-11 02:17:06343 // Record stats on various events.
344 static void SyncEvent(SyncEventCodes code);
345
[email protected]eec3bcfa2009-11-12 17:23:43346 // Returns whether sync is enabled. Sync can be enabled/disabled both
347 // at compile time (e.g., on a per-OS basis) or at run time (e.g.,
348 // command-line switches).
349 static bool IsSyncEnabled();
350
[email protected]d1db1c332010-10-13 19:57:00351 // Returns whether sync is managed, i.e. controlled by configuration
[email protected]d3b98c82010-07-14 07:45:59352 // management. If so, the user is not allowed to configure sync.
353 bool IsManaged();
354
[email protected]db1df0f2009-08-18 22:36:05355 // UnrecoverableErrorHandler implementation.
[email protected]f6ec8b22010-06-08 23:40:06356 virtual void OnUnrecoverableError(
357 const tracked_objects::Location& from_here,
[email protected]1a425fc2011-09-01 23:11:59358 const std::string& message) OVERRIDE;
[email protected]db1df0f2009-08-18 22:36:05359
[email protected]420914932011-01-24 23:32:41360 // The functions below (until ActivateDataType()) should only be
361 // called if sync_initialized() is true.
362
363 // TODO(akalin): This is called mostly by ModelAssociators and
364 // tests. Figure out how to pass the handle to the ModelAssociators
365 // directly, figure out how to expose this to tests, and remove this
366 // function.
367 sync_api::UserShare* GetUserShare() const;
368
369 // TODO(akalin): These two functions are used only by
370 // ProfileSyncServiceHarness. Figure out a different way to expose
371 // this info to that class, and remove these functions.
372
[email protected]dc556252011-04-20 01:59:35373 virtual const browser_sync::sessions::SyncSessionSnapshot*
[email protected]420914932011-01-24 23:32:41374 GetLastSessionSnapshot() const;
375
376 // Returns whether or not the underlying sync engine has made any
377 // local changes to items that have not yet been synced with the
378 // server.
379 bool HasUnsyncedItems() const;
380
[email protected]2a3ac6f2011-05-04 01:38:52381 // Logs the current unsynced items in the sync database. Useful for debugging.
382 void LogUnsyncedItems(int level) const;
383
[email protected]1a425fc2011-09-01 23:11:59384 // Used by ProfileSyncServiceHarness. May return NULL.
385 browser_sync::BackendMigrator* GetBackendMigratorForTest();
[email protected]51c84ee2011-04-26 22:07:59386
[email protected]420914932011-01-24 23:32:41387 // Get the current routing information for all enabled model types.
388 // If a model type is not enabled (that is, if the syncer should not
389 // be trying to sync it), it is not in this map.
390 //
391 // TODO(akalin): This function is used by
392 // sync_ui_util::ConstructAboutInformation() and by some test
393 // classes. Figure out a different way to expose this info and
394 // remove this function.
[email protected]e057d762011-08-23 04:39:05395 void GetModelSafeRoutingInfo(
396 browser_sync::ModelSafeRoutingInfo* out) const;
[email protected]420914932011-01-24 23:32:41397
[email protected]418b75e2011-08-11 04:58:24398 // Overridden by tests.
[email protected]d36f941b2011-05-09 06:19:16399 // TODO(zea): Remove these and have the dtc's call directly into the SBH.
[email protected]4aea04a2010-02-10 20:13:43400 virtual void ActivateDataType(
[email protected]418b75e2011-08-11 04:58:24401 syncable::ModelType type, browser_sync::ModelSafeGroup group,
[email protected]4aea04a2010-02-10 20:13:43402 browser_sync::ChangeProcessor* change_processor);
[email protected]418b75e2011-08-11 04:58:24403 virtual void DeactivateDataType(syncable::ModelType type);
[email protected]4aea04a2010-02-10 20:13:43404
[email protected]c4c672a2010-03-23 21:47:04405 // NotificationObserver implementation.
[email protected]432115822011-07-10 15:52:27406 virtual void Observe(int type,
[email protected]c4c672a2010-03-23 21:47:04407 const NotificationSource& source,
408 const NotificationDetails& details);
409
[email protected]a1c2aef62010-04-02 02:58:05410 // Changes which data types we're going to be syncing to |preferred_types|.
411 // If it is running, the DataTypeManager will be instructed to reconfigure
412 // the sync backend so that exactly these datatypes are actively synced. See
413 // class comment for more on what it means for a datatype to be Preferred.
414 virtual void ChangePreferredDataTypes(
415 const syncable::ModelTypeSet& preferred_types);
416
417 // Get the set of currently enabled data types (as chosen or configured by
418 // the user). See class comment for more on what it means for a datatype
419 // to be Preferred.
420 virtual void GetPreferredDataTypes(
421 syncable::ModelTypeSet* preferred_types) const;
422
423 // Gets the set of all data types that could be allowed (the set that
424 // should be advertised to the user). These will typically only change
425 // via a command-line option. See class comment for more on what it means
426 // for a datatype to be Registered.
427 virtual void GetRegisteredDataTypes(
428 syncable::ModelTypeSet* registered_types) const;
[email protected]a7ab8332010-03-31 20:49:04429
[email protected]ff0aa752010-06-10 22:40:52430 // Checks whether the Cryptographer is ready to encrypt and decrypt updates
[email protected]47f6a362011-03-29 19:57:11431 // for sensitive data types. Caller must be holding a
432 // syncapi::BaseTransaction to ensure thread safety.
433 virtual bool IsCryptographerReady(
434 const sync_api::BaseTransaction* trans) const;
[email protected]ff0aa752010-06-10 22:40:52435
[email protected]c976938f2010-10-12 04:55:44436 // Returns true if a secondary passphrase is being used.
437 virtual bool IsUsingSecondaryPassphrase() const;
438
[email protected]ee1adf4b2010-10-11 03:48:48439 // Sets the Cryptographer's passphrase, or caches it until that is possible.
440 // This will check asynchronously whether the passphrase is valid and notify
[email protected]dc39dd1b2010-10-07 18:08:11441 // ProfileSyncServiceObservers via the NotificationService when the outcome
442 // is known.
[email protected]954b1082010-11-10 20:22:50443 // |is_explicit| is true if the call is in response to the user explicitly
444 // setting a passphrase as opposed to implicitly (from the users' perspective)
[email protected]d6930242011-09-03 01:52:19445 // using their Google Account password. An implicit SetPassphrase will
[email protected]954b1082010-11-10 20:22:50446 // *not* override an explicit passphrase set previously.
[email protected]2e610e92011-01-13 23:39:45447 virtual void SetPassphrase(const std::string& passphrase,
[email protected]d6930242011-09-03 01:52:19448 bool is_explicit);
[email protected]bb899b3f2010-06-23 21:35:32449
[email protected]cc10e7c2011-08-06 00:17:50450 // Sets the set of datatypes that are waiting for encryption
451 // (pending_types_for_encryption_).
452 // Note that this does not trigger the actual encryption. The encryption call
453 // is kicked off automatically the next time the datatype manager is
454 // reconfigured.
455 virtual void set_pending_types_for_encryption(
[email protected]3fa964af2011-02-24 18:54:39456 const syncable::ModelTypeSet& encrypted_types);
457
458 // Get the currently encrypted data types.
[email protected]59e414e2011-05-16 18:38:56459 // Note: this can include types that this client is not syncing. Passwords
460 // will always be in this list.
[email protected]3fa964af2011-02-24 18:54:39461 virtual void GetEncryptedDataTypes(
462 syncable::ModelTypeSet* encrypted_types) const;
463
[email protected]cc10e7c2011-08-06 00:17:50464 // Returns true if the syncer is waiting for new datatypes to be encrypted.
465 virtual bool HasPendingEncryptedTypes() const;
466
[email protected]5edb9222010-08-18 00:23:29467 // Returns whether processing changes is allowed. Check this before doing
468 // any model-modifying operations.
469 bool ShouldPushChanges();
470
[email protected]9a127f22010-09-17 21:05:16471 const GURL& sync_service_url() const { return sync_service_url_; }
[email protected]bb868b42010-11-18 22:33:00472 SigninManager* signin() { return signin_.get(); }
473 const std::string& cros_user() const { return cros_user_; }
[email protected]9a127f22010-09-17 21:05:16474
[email protected]c3ca8c12011-08-11 03:39:48475 // Returns the set of unacknowledged types (new data types added since the
476 // last call to AcknowledgedSyncTypes())..
477 syncable::ModelTypeBitSet GetUnacknowledgedTypes() const;
478
479 // Marks all currently registered types as "acknowledged" so we won't prompt
480 // the user about them any more.
481 void AcknowledgeSyncedTypes();
482
[email protected]132c85652009-08-05 01:18:27483 protected:
[email protected]420914932011-01-24 23:32:41484 // Used by test classes that derive from ProfileSyncService.
485 virtual browser_sync::SyncBackendHost* GetBackendForTest();
486
[email protected]7cef1c442010-07-07 17:05:22487 // Helper to install and configure a data type manager.
488 void ConfigureDataTypeManager();
[email protected]132c85652009-08-05 01:18:27489
[email protected]132c85652009-08-05 01:18:27490 // Starts up the backend sync components.
491 void StartUp();
492 // Shuts down the backend sync components.
493 // |sync_disabled| indicates if syncing is being disabled or not.
494 void Shutdown(bool sync_disabled);
495
[email protected]48352c12009-08-15 01:19:11496 // Methods to register and remove preferences.
497 void RegisterPreferences();
498 void ClearPreferences();
499
[email protected]e8234d32010-09-09 20:36:39500 // Return SyncCredentials from the TokenService.
501 sync_api::SyncCredentials GetCredentials();
502
[email protected]18af9a22010-08-11 00:47:19503 // Test need to override this to create backends that allow setting up
504 // initial conditions, such as populating sync nodes.
[email protected]420914932011-01-24 23:32:41505 //
506 // TODO(akalin): Figure out a better way to do this. Ideally, we'd
507 // construct the backend outside this class and pass it in to the
508 // contructor or Initialize().
[email protected]18af9a22010-08-11 00:47:19509 virtual void CreateBackend();
[email protected]132c85652009-08-05 01:18:27510
[email protected]7cef1c442010-07-07 17:05:22511 const browser_sync::DataTypeController::TypeMap& data_type_controllers() {
512 return data_type_controllers_;
513 }
514
[email protected]4b2866b2011-01-26 18:58:44515 // Helper method for managing encryption UI.
516 bool IsEncryptedDatatypeEnabled() const;
517
[email protected]e8234d32010-09-09 20:36:39518 // The wizard will try to read the auth state out of the profile sync
519 // service using this member. Captcha and error state are reflected.
[email protected]712257e2009-11-11 22:57:46520 GoogleServiceAuthError last_auth_error_;
[email protected]132c85652009-08-05 01:18:27521
[email protected]7cef1c442010-07-07 17:05:22522 // Our asynchronous backend to communicate with sync components living on
523 // other threads.
524 scoped_ptr<browser_sync::SyncBackendHost> backend_;
525
[email protected]132c85652009-08-05 01:18:27526 // Cache of the last name the client attempted to authenticate.
527 std::string last_attempted_user_email_;
528
[email protected]fc52c422010-11-19 18:59:23529 // Was the last SYNC_PASSPHRASE_REQUIRED notification sent because it
[email protected]43c48fb92011-05-02 19:47:43530 // was required for encryption, decryption with a cached passphrase, or
531 // because a new passphrase is required?
532 sync_api::PassphraseRequiredReason passphrase_required_reason_;
[email protected]fc52c422010-11-19 18:59:23533
[email protected]132c85652009-08-05 01:18:27534 private:
[email protected]4f5732a42010-09-21 22:39:09535 friend class ProfileSyncServicePasswordTest;
[email protected]420914932011-01-24 23:32:41536 friend class TestProfileSyncService;
[email protected]62828b12011-07-21 21:48:16537 friend class ProfileSyncServiceForWizardTest;
[email protected]61b694a2010-06-10 10:40:46538 FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceTest, InitialState);
[email protected]132c85652009-08-05 01:18:27539
[email protected]18af9a22010-08-11 00:47:19540 // If |delete_sync_data_folder| is true, then this method will delete all
541 // previous "Sync Data" folders. (useful if the folder is partial/corrupt).
542 void InitializeBackend(bool delete_sync_data_folder);
543
[email protected]132c85652009-08-05 01:18:27544 // Initializes the various settings from the command line.
545 void InitSettings();
546
[email protected]132c85652009-08-05 01:18:27547 // Sets the last synced time to the current time.
548 void UpdateLastSyncedTime();
549
[email protected]1a787692011-01-19 22:19:46550 void NotifyObservers();
551
[email protected]57ecc4b2010-08-11 03:02:51552 static const char* GetPrefNameForDataType(syncable::ModelType data_type);
[email protected]a1c2aef62010-04-02 02:58:05553
[email protected]23caf1d2011-08-25 22:21:02554 // About-flags experiment names for datatypes that aren't enabled by default
555 // yet.
556 static std::string GetExperimentNameForDataType(
557 syncable::ModelType data_type);
558
559 // Create and register a new datatype controller.
560 void RegisterNewDataType(syncable::ModelType data_type);
561
[email protected]cb4c06e2009-08-22 00:24:39562 // Time at which we begin an attempt a GAIA authorization.
563 base::TimeTicks auth_start_time_;
564
565 // Time at which error UI is presented for the new tab page.
[email protected]1f97a112009-08-11 02:17:06566 base::TimeTicks auth_error_time_;
567
[email protected]e3e43d92010-02-26 22:02:38568 // Factory used to create various dependent objects.
569 ProfileSyncFactory* factory_;
570
[email protected]132c85652009-08-05 01:18:27571 // The profile whose data we are synchronizing.
572 Profile* profile_;
573
[email protected]e8234d32010-09-09 20:36:39574 // Email for the ChromiumOS user, if we're running under ChromiumOS.
575 std::string cros_user_;
[email protected]72a31b42010-02-17 22:26:33576
[email protected]132c85652009-08-05 01:18:27577 // TODO(ncarter): Put this in a profile, once there is UI for it.
578 // This specifies where to find the sync server.
579 GURL sync_service_url_;
580
[email protected]132c85652009-08-05 01:18:27581 // The last time we detected a successful transition from SYNCING state.
582 // Our backend notifies us whenever we should take a new snapshot.
583 base::Time last_synced_time_;
584
[email protected]4aea04a2010-02-10 20:13:43585 // List of available data type controllers.
[email protected]72a31b42010-02-17 22:26:33586 browser_sync::DataTypeController::TypeMap data_type_controllers_;
[email protected]db1df0f2009-08-18 22:36:05587
[email protected]132c85652009-08-05 01:18:27588 // Whether the SyncBackendHost has been initialized.
589 bool backend_initialized_;
590
[email protected]132c85652009-08-05 01:18:27591 // Various pieces of UI query this value to determine if they should show
592 // an "Authenticating.." type of message. We are the only central place
593 // all auth attempts funnel through, so it makes sense to provide this.
594 // As its name suggests, this should NOT be used for anything other than UI.
595 bool is_auth_in_progress_;
596
[email protected]44b78f90a2009-10-15 17:32:20597 SyncSetupWizard wizard_;
598
[email protected]e8234d32010-09-09 20:36:39599 // Encapsulates user signin with TokenService.
[email protected]bb868b42010-11-18 22:33:00600 scoped_ptr<SigninManager> signin_;
[email protected]e8234d32010-09-09 20:36:39601
[email protected]132c85652009-08-05 01:18:27602 // True if an unrecoverable error (e.g. violation of an assumed invariant)
603 // occurred during syncer operation. This value should be checked before
604 // doing any work that might corrupt things further.
605 bool unrecoverable_error_detected_;
606
[email protected]f6ec8b22010-06-08 23:40:06607 // A message sent when an unrecoverable error occurred.
608 std::string unrecoverable_error_message_;
609 scoped_ptr<tracked_objects::Location> unrecoverable_error_location_;
610
[email protected]e3e43d92010-02-26 22:02:38611 // Manages the start and stop of the various data types.
612 scoped_ptr<browser_sync::DataTypeManager> data_type_manager_;
613
[email protected]132c85652009-08-05 01:18:27614 ObserverList<Observer> observers_;
615
[email protected]fa134872011-08-02 18:39:55616 browser_sync::SyncJsController sync_js_controller_;
[email protected]f92351d2011-02-01 07:42:12617
[email protected]c4c672a2010-03-23 21:47:04618 NotificationRegistrar registrar_;
619
[email protected]2be7bf22010-04-23 21:02:37620 ScopedRunnableMethodFactory<ProfileSyncService>
[email protected]954b1082010-11-10 20:22:50621 scoped_runnable_method_factory_;
[email protected]2be7bf22010-04-23 21:02:37622
[email protected]d3b98c82010-07-14 07:45:59623 // The preference that controls whether sync is under control by configuration
624 // management.
625 BooleanPrefMember pref_sync_managed_;
626
[email protected]a47eeb52010-07-15 17:54:25627 // This allows us to gracefully handle an ABORTED return code from the
628 // DataTypeManager in the event that the server informed us to cease and
629 // desist syncing immediately.
630 bool expect_sync_configuration_aborted_;
631
[email protected]48a98b32010-09-17 20:26:59632 // Sometimes we need to temporarily hold on to a passphrase because we don't
633 // yet have a backend to send it to. This happens during initialization as
634 // we don't StartUp until we have a valid token, which happens after valid
635 // credentials were provided.
[email protected]d6930242011-09-03 01:52:19636 struct CachedPassphrases {
637 std::string explicit_passphrase;
638 std::string gaia_passphrase;
[email protected]954b1082010-11-10 20:22:50639 };
[email protected]d6930242011-09-03 01:52:19640 CachedPassphrases cached_passphrases_;
[email protected]4bc5eee2011-05-11 18:36:16641
[email protected]689a7a72010-09-29 19:56:41642 // Keep track of where we are in a server clear operation
643 ClearServerDataState clear_server_data_state_;
644
[email protected]990de362010-10-13 17:55:50645 // Timeout for the clear data command. This timeout is a temporary hack
[email protected]954b1082010-11-10 20:22:50646 // and is necessary because the nudge sync framework can drop nudges for
[email protected]990de362010-10-13 17:55:50647 // a wide variety of sync-related conditions (throttling, connections issues,
648 // syncer paused, etc.). It can only be removed correctly when the framework
649 // is reworked to allow one-shot commands like clearing server data.
650 base::OneShotTimer<ProfileSyncService> clear_server_data_timer_;
651
[email protected]7bf8dd02011-06-03 21:58:24652 // The most recently requested set of types to encrypt. Set by the user,
[email protected]cc10e7c2011-08-06 00:17:50653 // and cached until the syncer either finishes encryption
654 // (OnEncryptionComplete) or the user cancels.
[email protected]7bf8dd02011-06-03 21:58:24655 syncable::ModelTypeSet pending_types_for_encryption_;
[email protected]2620b482011-08-24 08:48:53656 bool set_backend_encrypted_types_;
[email protected]3fa964af2011-02-24 18:54:39657
[email protected]d6930242011-09-03 01:52:19658 // If true, we want to automatically start sync signin whenever we have
659 // credentials (user doesn't need to go through the startup flow). This is
660 // typically enabled on platforms (like ChromeOS) that have their own
661 // distinct signin flow.
662 bool auto_start_enabled_;
663
[email protected]dc556252011-04-20 01:59:35664 scoped_ptr<browser_sync::BackendMigrator> migrator_;
665
[email protected]cb5199b2011-09-04 01:55:52666 // This is the last |SyncProtocolError| we received from the server that had
667 // an action set on it.
668 browser_sync::SyncProtocolError last_actionable_error_;
669
[email protected]132c85652009-08-05 01:18:27670 DISALLOW_COPY_AND_ASSIGN(ProfileSyncService);
671};
672
[email protected]cb5199b2011-09-04 01:55:52673bool ShouldShowActionOnUI(
674 const browser_sync::SyncProtocolError& error);
675
676
[email protected]132c85652009-08-05 01:18:27677#endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_