[email protected] | ebbbb9f | 2011-03-09 13:16:14 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ |
| 6 | #define CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ |
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 8 | |
| 9 | #include <string> |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 10 | |
| 11 | #include "base/basictypes.h" |
[email protected] | fa13487 | 2011-08-02 18:39:55 | [diff] [blame] | 12 | #include "base/compiler_specific.h" |
[email protected] | 61b694a | 2010-06-10 10:40:46 | [diff] [blame] | 13 | #include "base/gtest_prod_util.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 14 | #include "base/memory/scoped_ptr.h" |
[email protected] | fa13487 | 2011-08-02 18:39:55 | [diff] [blame] | 15 | #include "base/memory/weak_ptr.h" |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 16 | #include "base/observer_list.h" |
[email protected] | 06614687 | 2010-08-05 00:55:08 | [diff] [blame] | 17 | #include "base/string16.h" |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 18 | #include "base/task.h" |
[email protected] | 4aea04a | 2010-02-10 20:13:43 | [diff] [blame] | 19 | #include "base/time.h" |
[email protected] | 990de36 | 2010-10-13 17:55:50 | [diff] [blame] | 20 | #include "base/timer.h" |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 21 | #include "base/tracked.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 22 | #include "chrome/browser/prefs/pref_member.h" |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 23 | #include "chrome/browser/sync/engine/model_safe_worker.h" |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 24 | #include "chrome/browser/sync/glue/data_type_controller.h" |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 25 | #include "chrome/browser/sync/glue/sync_backend_host.h" |
[email protected] | 67192b4 | 2011-08-17 23:38:30 | [diff] [blame] | 26 | #include "chrome/browser/sync/internal_api/sync_manager.h" |
[email protected] | d3b98c8 | 2010-07-14 07:45:59 | [diff] [blame] | 27 | #include "chrome/browser/sync/profile_sync_service_observer.h" |
[email protected] | 67192b4 | 2011-08-17 23:38:30 | [diff] [blame] | 28 | #include "chrome/browser/sync/syncable/model_type.h" |
[email protected] | fa13487 | 2011-08-02 18:39:55 | [diff] [blame] | 29 | #include "chrome/browser/sync/sync_js_controller.h" |
[email protected] | d80033e | 2009-10-16 10:32:04 | [diff] [blame] | 30 | #include "chrome/browser/sync/sync_setup_wizard.h" |
[email protected] | eafb218 | 2010-03-03 00:46:31 | [diff] [blame] | 31 | #include "chrome/browser/sync/unrecoverable_error_handler.h" |
[email protected] | 99074c5 | 2010-08-19 18:44:19 | [diff] [blame] | 32 | #include "chrome/common/net/gaia/google_service_auth_error.h" |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 33 | #include "content/common/content_notification_types.h" |
[email protected] | ebbbb9f | 2011-03-09 13:16:14 | [diff] [blame] | 34 | #include "content/common/notification_observer.h" |
| 35 | #include "content/common/notification_registrar.h" |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 36 | #include "googleurl/src/gurl.h" |
| 37 | |
[email protected] | c4c672a | 2010-03-23 21:47:04 | [diff] [blame] | 38 | class NotificationDetails; |
| 39 | class NotificationSource; |
[email protected] | 942690b13 | 2010-05-11 06:42:14 | [diff] [blame] | 40 | class Profile; |
| 41 | class ProfileSyncFactory; |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 42 | class SigninManager; |
[email protected] | 9e11c95 | 2011-06-24 21:31:30 | [diff] [blame] | 43 | struct ChromeCookieDetails; |
[email protected] | c4c672a | 2010-03-23 21:47:04 | [diff] [blame] | 44 | |
[email protected] | f92351d | 2011-02-01 07:42:12 | [diff] [blame] | 45 | namespace browser_sync { |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 46 | class BackendMigrator; |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 47 | class ChangeProcessor; |
| 48 | class DataTypeManager; |
[email protected] | fa13487 | 2011-08-02 18:39:55 | [diff] [blame] | 49 | class JsController; |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 50 | class SessionModelAssociator; |
| 51 | namespace sessions { struct SyncSessionSnapshot; } |
| 52 | } |
| 53 | |
| 54 | namespace sync_api { |
| 55 | class BaseTransaction; |
| 56 | struct SyncCredentials; |
| 57 | struct UserShare; |
| 58 | } |
[email protected] | f92351d | 2011-02-01 07:42:12 | [diff] [blame] | 59 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 60 | // ProfileSyncService is the layer between browser subsystems like bookmarks, |
[email protected] | a1c2aef6 | 2010-04-02 02:58:05 | [diff] [blame] | 61 | // 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] | 4aea04a | 2010-02-10 20:13:43 | [diff] [blame] | 102 | class ProfileSyncService : public browser_sync::SyncFrontend, |
[email protected] | c4c672a | 2010-03-23 21:47:04 | [diff] [blame] | 103 | public browser_sync::UnrecoverableErrorHandler, |
| 104 | public NotificationObserver { |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 105 | public: |
| 106 | typedef ProfileSyncServiceObserver Observer; |
| 107 | typedef browser_sync::SyncBackendHost::Status Status; |
| 108 | |
[email protected] | 1f97a11 | 2009-08-11 02:17:06 | [diff] [blame] | 109 | 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] | b220d13f | 2009-10-09 04:12:46 | [diff] [blame] | 116 | START_FROM_BOOKMARK_MANAGER = 4, // Sync was started from Bookmark manager. |
[email protected] | 29d7025 | 2011-04-28 02:16:58 | [diff] [blame] | 117 | START_FROM_PROFILE_MENU = 5, // Sync was started from multiprofile menu. |
[email protected] | b70651d | 2011-05-26 18:39:12 | [diff] [blame] | 118 | START_FROM_URL = 6, // Sync was started from a typed URL. |
[email protected] | 1f97a11 | 2009-08-11 02:17:06 | [diff] [blame] | 119 | |
[email protected] | a7ab833 | 2010-03-31 20:49:04 | [diff] [blame] | 120 | // Events regarding cancellation of the signon process of sync. |
[email protected] | 8ac2dc11 | 2009-10-01 23:19:13 | [diff] [blame] | 121 | CANCEL_FROM_SIGNON_WITHOUT_AUTH = 10, // Cancelled before submitting |
[email protected] | 1f97a11 | 2009-08-11 02:17:06 | [diff] [blame] | 122 | // username and password. |
| 123 | CANCEL_DURING_SIGNON = 11, // Cancelled after auth. |
[email protected] | c976938f | 2010-10-12 04:55:44 | [diff] [blame] | 124 | CANCEL_DURING_CONFIGURE = 12, // Cancelled before choosing data |
[email protected] | 8c94d63 | 2010-06-25 22:38:00 | [diff] [blame] | 125 | // types and clicking OK. |
[email protected] | 1f97a11 | 2009-08-11 02:17:06 | [diff] [blame] | 126 | // 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] | 1f97a11 | 2009-08-11 02:17:06 | [diff] [blame] | 130 | |
| 131 | MAX_SYNC_EVENT_CODE |
| 132 | }; |
| 133 | |
[email protected] | 689a7a7 | 2010-09-29 19:56:41 | [diff] [blame] | 134 | // 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] | f66bcdf | 2010-05-17 20:31:14 | [diff] [blame] | 142 | // 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] | 62828b1 | 2011-07-21 21:48:16 | [diff] [blame] | 147 | ProfileSyncService(ProfileSyncFactory* factory, |
[email protected] | e3e43d9 | 2010-02-26 22:02:38 | [diff] [blame] | 148 | Profile* profile, |
[email protected] | 62828b1 | 2011-07-21 21:48:16 | [diff] [blame] | 149 | SigninManager* signin, // Service takes ownership. |
[email protected] | e8234d3 | 2010-09-09 20:36:39 | [diff] [blame] | 150 | const std::string& cros_user); |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 151 | 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] | e8234d3 | 2010-09-09 20:36:39 | [diff] [blame] | 157 | 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] | 4aea04a | 2010-02-10 20:13:43 | [diff] [blame] | 163 | // 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] | 5edb922 | 2010-08-18 00:23:29 | [diff] [blame] | 170 | // 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] | 689a7a7 | 2010-09-29 19:56:41 | [diff] [blame] | 175 | // Maintain state of where we are in a server clear operation. |
| 176 | void ResetClearServerDataState(); |
| 177 | ClearServerDataState GetClearServerDataState(); |
| 178 | |
[email protected] | a7ab833 | 2010-03-31 20:49:04 | [diff] [blame] | 179 | // 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] | 4aea04a | 2010-02-10 20:13:43 | [diff] [blame] | 183 | |
[email protected] | e8234d3 | 2010-09-09 20:36:39 | [diff] [blame] | 184 | // Disables sync for user. Use ShowLoginDialog to enable. |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 185 | virtual void DisableForUser(); |
| 186 | |
[email protected] | 1ce52aa | 2010-09-08 19:07:36 | [diff] [blame] | 187 | // Clears all Chromesync data from the server. |
| 188 | void ClearServerData(); |
| 189 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 190 | // Whether sync is enabled by user or not. |
[email protected] | 4772b07 | 2010-03-30 17:45:46 | [diff] [blame] | 191 | virtual bool HasSyncSetupCompleted() const; |
[email protected] | 2efebbbf | 2010-10-25 10:31:21 | [diff] [blame] | 192 | virtual void SetSyncSetupCompleted(); |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 193 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 194 | // SyncFrontend implementation. |
[email protected] | fa13487 | 2011-08-02 18:39:55 | [diff] [blame] | 195 | 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] | 3fa964af | 2011-02-24 18:54:39 | [diff] [blame] | 206 | virtual void OnEncryptionComplete( |
[email protected] | fa13487 | 2011-08-02 18:39:55 | [diff] [blame] | 207 | const syncable::ModelTypeSet& encrypted_types) OVERRIDE; |
[email protected] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 208 | virtual void OnMigrationNeededForTypes( |
[email protected] | fa13487 | 2011-08-02 18:39:55 | [diff] [blame] | 209 | const syncable::ModelTypeSet& types) OVERRIDE; |
[email protected] | 23caf1d | 2011-08-25 22:21:02 | [diff] [blame] | 210 | virtual void OnDataTypesChanged( |
| 211 | const syncable::ModelTypeSet& to_add) OVERRIDE; |
[email protected] | cb5199b | 2011-09-04 01:55:52 | [diff] [blame^] | 212 | virtual void OnActionableError( |
| 213 | const browser_sync::SyncProtocolError& error) OVERRIDE; |
[email protected] | fa13487 | 2011-08-02 18:39:55 | [diff] [blame] | 214 | |
| 215 | void OnClearServerDataTimeout(); |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 216 | |
| 217 | // Called when a user enters credentials through UI. |
| 218 | virtual void OnUserSubmittedAuth(const std::string& username, |
[email protected] | 1fc9b3f | 2009-11-12 21:22:09 | [diff] [blame] | 219 | const std::string& password, |
[email protected] | 96209ccd | 2010-10-11 21:57:27 | [diff] [blame] | 220 | const std::string& captcha, |
| 221 | const std::string& access_code); |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 222 | |
[email protected] | e8234d3 | 2010-09-09 20:36:39 | [diff] [blame] | 223 | // Update the last auth error and notify observers of error state. |
| 224 | void UpdateAuthErrorState(const GoogleServiceAuthError& error); |
| 225 | |
[email protected] | af90949 | 2010-06-10 18:45:38 | [diff] [blame] | 226 | // 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] | 8c94d63 | 2010-06-25 22:38:00 | [diff] [blame] | 228 | // "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] | af90949 | 2010-06-10 18:45:38 | [diff] [blame] | 231 | virtual void OnUserChoseDatatypes(bool sync_everything, |
[email protected] | 8c94d63 | 2010-06-25 22:38:00 | [diff] [blame] | 232 | const syncable::ModelTypeSet& chosen_types); |
[email protected] | af90949 | 2010-06-10 18:45:38 | [diff] [blame] | 233 | |
[email protected] | a7ab833 | 2010-03-31 20:49:04 | [diff] [blame] | 234 | // Called when a user cancels any setup dialog (login, etc). |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 235 | virtual void OnUserCancelledDialog(); |
| 236 | |
| 237 | // Get various information for displaying in the user interface. |
| 238 | browser_sync::SyncBackendHost::StatusSummary QuerySyncStatusSummary(); |
[email protected] | f1e6e021 | 2010-10-15 20:54:24 | [diff] [blame] | 239 | virtual browser_sync::SyncBackendHost::Status QueryDetailedSyncStatus(); |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 240 | |
[email protected] | 712257e | 2009-11-11 22:57:46 | [diff] [blame] | 241 | const GoogleServiceAuthError& GetAuthError() const { |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 242 | 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] | d688559 | 2010-10-11 19:38:24 | [diff] [blame] | 251 | virtual bool SetupInProgress() const; |
[email protected] | 44b78f90a | 2009-10-15 17:32:20 | [diff] [blame] | 252 | bool WizardIsVisible() const { |
| 253 | return wizard_.IsVisible(); |
| 254 | } |
[email protected] | 8b6ede2 | 2011-05-23 23:50:54 | [diff] [blame] | 255 | |
[email protected] | a159596 | 2011-04-22 21:56:24 | [diff] [blame] | 256 | SyncSetupWizard& get_wizard() { return wizard_; } |
[email protected] | 1c73847 | 2011-01-19 21:48:01 | [diff] [blame] | 257 | |
[email protected] | 87d5eb4 | 2011-06-14 01:21:25 | [diff] [blame] | 258 | // Shows the login screen of the Sync setup wizard. |
| 259 | virtual void ShowLoginDialog(); |
[email protected] | 8b6ede2 | 2011-05-23 23:50:54 | [diff] [blame] | 260 | |
[email protected] | 1c73847 | 2011-01-19 21:48:01 | [diff] [blame] | 261 | // This method handles clicks on "sync error" UI, showing the appropriate |
[email protected] | 87d5eb4 | 2011-06-14 01:21:25 | [diff] [blame] | 262 | // dialog for the error condition (relogin / enter passphrase). |
| 263 | virtual void ShowErrorUI(); |
[email protected] | 1c73847 | 2011-01-19 21:48:01 | [diff] [blame] | 264 | |
[email protected] | 5d0e7c2 | 2011-04-19 23:09:07 | [diff] [blame] | 265 | // 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] | 87d5eb4 | 2011-06-14 01:21:25 | [diff] [blame] | 268 | // types to sync. |
| 269 | void ShowConfigure(bool sync_everything); |
[email protected] | 5d0e7c2 | 2011-04-19 23:09:07 | [diff] [blame] | 270 | |
[email protected] | cb5199b | 2011-09-04 01:55:52 | [diff] [blame^] | 271 | void ShowSyncSetup(const std::string& sub_page); |
| 272 | void ShowSyncSetupWithWizard(SyncSetupWizard::State state); |
[email protected] | 68f6ead | 2011-07-20 23:51:39 | [diff] [blame] | 273 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 274 | // Pretty-printed strings for a given StatusSummary. |
[email protected] | 06614687 | 2010-08-05 00:55:08 | [diff] [blame] | 275 | static std::string BuildSyncStatusSummaryText( |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 276 | 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] | cd2ec4b | 2011-01-06 00:09:36 | [diff] [blame] | 280 | // [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] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 284 | // 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] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 287 | virtual bool unrecoverable_error_detected() const; |
[email protected] | f6ec8b2 | 2010-06-08 23:40:06 | [diff] [blame] | 288 | 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] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 295 | |
| 296 | bool UIShouldDepictAuthInProgress() const { |
| 297 | return is_auth_in_progress_; |
| 298 | } |
| 299 | |
[email protected] | 43c48fb9 | 2011-05-02 19:47:43 | [diff] [blame] | 300 | // Returns true if OnPassphraseRequired has been called for any reason. |
[email protected] | 88dee5e | 2011-05-03 18:23:53 | [diff] [blame] | 301 | bool IsPassphraseRequired() const { |
[email protected] | 43c48fb9 | 2011-05-02 19:47:43 | [diff] [blame] | 302 | return passphrase_required_reason_ != |
| 303 | sync_api::REASON_PASSPHRASE_NOT_REQUIRED; |
[email protected] | 66d8100 | 2010-10-18 16:52:09 | [diff] [blame] | 304 | } |
| 305 | |
[email protected] | 88dee5e | 2011-05-03 18:23:53 | [diff] [blame] | 306 | // 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] | 43c48fb9 | 2011-05-02 19:47:43 | [diff] [blame] | 312 | sync_api::PassphraseRequiredReason passphrase_required_reason() const { |
| 313 | return passphrase_required_reason_; |
[email protected] | fc52c42 | 2010-11-19 18:59:23 | [diff] [blame] | 314 | } |
| 315 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 316 | // Returns a user-friendly string form of last synced time (in minutes). |
[email protected] | f1e6e021 | 2010-10-15 20:54:24 | [diff] [blame] | 317 | virtual string16 GetLastSyncedTimeString() const; |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 318 | |
| 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] | c976938f | 2010-10-12 04:55:44 | [diff] [blame] | 329 | Profile* profile() const { return profile_; } |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 330 | |
| 331 | // Adds/removes an observer. ProfileSyncService does not take ownership of |
| 332 | // the observer. |
[email protected] | 4772b07 | 2010-03-30 17:45:46 | [diff] [blame] | 333 | virtual void AddObserver(Observer* observer); |
| 334 | virtual void RemoveObserver(Observer* observer); |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 335 | |
[email protected] | d1db1c33 | 2010-10-13 19:57:00 | [diff] [blame] | 336 | // Returns true if |observer| has already been added as an observer. |
| 337 | bool HasObserver(Observer* observer) const; |
| 338 | |
[email protected] | fa13487 | 2011-08-02 18:39:55 | [diff] [blame] | 339 | // Returns a weak pointer to the service's JsController. |
| 340 | // Overrideable for testing purposes. |
| 341 | virtual base::WeakPtr<browser_sync::JsController> GetJsController(); |
[email protected] | f92351d | 2011-02-01 07:42:12 | [diff] [blame] | 342 | |
[email protected] | 1f97a11 | 2009-08-11 02:17:06 | [diff] [blame] | 343 | // Record stats on various events. |
| 344 | static void SyncEvent(SyncEventCodes code); |
| 345 | |
[email protected] | eec3bcfa | 2009-11-12 17:23:43 | [diff] [blame] | 346 | // 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] | d1db1c33 | 2010-10-13 19:57:00 | [diff] [blame] | 351 | // Returns whether sync is managed, i.e. controlled by configuration |
[email protected] | d3b98c8 | 2010-07-14 07:45:59 | [diff] [blame] | 352 | // management. If so, the user is not allowed to configure sync. |
| 353 | bool IsManaged(); |
| 354 | |
[email protected] | db1df0f | 2009-08-18 22:36:05 | [diff] [blame] | 355 | // UnrecoverableErrorHandler implementation. |
[email protected] | f6ec8b2 | 2010-06-08 23:40:06 | [diff] [blame] | 356 | virtual void OnUnrecoverableError( |
| 357 | const tracked_objects::Location& from_here, |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 358 | const std::string& message) OVERRIDE; |
[email protected] | db1df0f | 2009-08-18 22:36:05 | [diff] [blame] | 359 | |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 360 | // 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] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 373 | virtual const browser_sync::sessions::SyncSessionSnapshot* |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 374 | 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] | 2a3ac6f | 2011-05-04 01:38:52 | [diff] [blame] | 381 | // Logs the current unsynced items in the sync database. Useful for debugging. |
| 382 | void LogUnsyncedItems(int level) const; |
| 383 | |
[email protected] | 1a425fc | 2011-09-01 23:11:59 | [diff] [blame] | 384 | // Used by ProfileSyncServiceHarness. May return NULL. |
| 385 | browser_sync::BackendMigrator* GetBackendMigratorForTest(); |
[email protected] | 51c84ee | 2011-04-26 22:07:59 | [diff] [blame] | 386 | |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 387 | // 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] | e057d76 | 2011-08-23 04:39:05 | [diff] [blame] | 395 | void GetModelSafeRoutingInfo( |
| 396 | browser_sync::ModelSafeRoutingInfo* out) const; |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 397 | |
[email protected] | 418b75e | 2011-08-11 04:58:24 | [diff] [blame] | 398 | // Overridden by tests. |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 399 | // TODO(zea): Remove these and have the dtc's call directly into the SBH. |
[email protected] | 4aea04a | 2010-02-10 20:13:43 | [diff] [blame] | 400 | virtual void ActivateDataType( |
[email protected] | 418b75e | 2011-08-11 04:58:24 | [diff] [blame] | 401 | syncable::ModelType type, browser_sync::ModelSafeGroup group, |
[email protected] | 4aea04a | 2010-02-10 20:13:43 | [diff] [blame] | 402 | browser_sync::ChangeProcessor* change_processor); |
[email protected] | 418b75e | 2011-08-11 04:58:24 | [diff] [blame] | 403 | virtual void DeactivateDataType(syncable::ModelType type); |
[email protected] | 4aea04a | 2010-02-10 20:13:43 | [diff] [blame] | 404 | |
[email protected] | c4c672a | 2010-03-23 21:47:04 | [diff] [blame] | 405 | // NotificationObserver implementation. |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 406 | virtual void Observe(int type, |
[email protected] | c4c672a | 2010-03-23 21:47:04 | [diff] [blame] | 407 | const NotificationSource& source, |
| 408 | const NotificationDetails& details); |
| 409 | |
[email protected] | a1c2aef6 | 2010-04-02 02:58:05 | [diff] [blame] | 410 | // 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] | a7ab833 | 2010-03-31 20:49:04 | [diff] [blame] | 429 | |
[email protected] | ff0aa75 | 2010-06-10 22:40:52 | [diff] [blame] | 430 | // Checks whether the Cryptographer is ready to encrypt and decrypt updates |
[email protected] | 47f6a36 | 2011-03-29 19:57:11 | [diff] [blame] | 431 | // 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] | ff0aa75 | 2010-06-10 22:40:52 | [diff] [blame] | 435 | |
[email protected] | c976938f | 2010-10-12 04:55:44 | [diff] [blame] | 436 | // Returns true if a secondary passphrase is being used. |
| 437 | virtual bool IsUsingSecondaryPassphrase() const; |
| 438 | |
[email protected] | ee1adf4b | 2010-10-11 03:48:48 | [diff] [blame] | 439 | // 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] | dc39dd1b | 2010-10-07 18:08:11 | [diff] [blame] | 441 | // ProfileSyncServiceObservers via the NotificationService when the outcome |
| 442 | // is known. |
[email protected] | 954b108 | 2010-11-10 20:22:50 | [diff] [blame] | 443 | // |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] | d693024 | 2011-09-03 01:52:19 | [diff] [blame] | 445 | // using their Google Account password. An implicit SetPassphrase will |
[email protected] | 954b108 | 2010-11-10 20:22:50 | [diff] [blame] | 446 | // *not* override an explicit passphrase set previously. |
[email protected] | 2e610e9 | 2011-01-13 23:39:45 | [diff] [blame] | 447 | virtual void SetPassphrase(const std::string& passphrase, |
[email protected] | d693024 | 2011-09-03 01:52:19 | [diff] [blame] | 448 | bool is_explicit); |
[email protected] | bb899b3f | 2010-06-23 21:35:32 | [diff] [blame] | 449 | |
[email protected] | cc10e7c | 2011-08-06 00:17:50 | [diff] [blame] | 450 | // 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] | 3fa964af | 2011-02-24 18:54:39 | [diff] [blame] | 456 | const syncable::ModelTypeSet& encrypted_types); |
| 457 | |
| 458 | // Get the currently encrypted data types. |
[email protected] | 59e414e | 2011-05-16 18:38:56 | [diff] [blame] | 459 | // Note: this can include types that this client is not syncing. Passwords |
| 460 | // will always be in this list. |
[email protected] | 3fa964af | 2011-02-24 18:54:39 | [diff] [blame] | 461 | virtual void GetEncryptedDataTypes( |
| 462 | syncable::ModelTypeSet* encrypted_types) const; |
| 463 | |
[email protected] | cc10e7c | 2011-08-06 00:17:50 | [diff] [blame] | 464 | // Returns true if the syncer is waiting for new datatypes to be encrypted. |
| 465 | virtual bool HasPendingEncryptedTypes() const; |
| 466 | |
[email protected] | 5edb922 | 2010-08-18 00:23:29 | [diff] [blame] | 467 | // Returns whether processing changes is allowed. Check this before doing |
| 468 | // any model-modifying operations. |
| 469 | bool ShouldPushChanges(); |
| 470 | |
[email protected] | 9a127f2 | 2010-09-17 21:05:16 | [diff] [blame] | 471 | const GURL& sync_service_url() const { return sync_service_url_; } |
[email protected] | bb868b4 | 2010-11-18 22:33:00 | [diff] [blame] | 472 | SigninManager* signin() { return signin_.get(); } |
| 473 | const std::string& cros_user() const { return cros_user_; } |
[email protected] | 9a127f2 | 2010-09-17 21:05:16 | [diff] [blame] | 474 | |
[email protected] | c3ca8c1 | 2011-08-11 03:39:48 | [diff] [blame] | 475 | // 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] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 483 | protected: |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 484 | // Used by test classes that derive from ProfileSyncService. |
| 485 | virtual browser_sync::SyncBackendHost* GetBackendForTest(); |
| 486 | |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 487 | // Helper to install and configure a data type manager. |
| 488 | void ConfigureDataTypeManager(); |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 489 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 490 | // 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] | 48352c1 | 2009-08-15 01:19:11 | [diff] [blame] | 496 | // Methods to register and remove preferences. |
| 497 | void RegisterPreferences(); |
| 498 | void ClearPreferences(); |
| 499 | |
[email protected] | e8234d3 | 2010-09-09 20:36:39 | [diff] [blame] | 500 | // Return SyncCredentials from the TokenService. |
| 501 | sync_api::SyncCredentials GetCredentials(); |
| 502 | |
[email protected] | 18af9a2 | 2010-08-11 00:47:19 | [diff] [blame] | 503 | // Test need to override this to create backends that allow setting up |
| 504 | // initial conditions, such as populating sync nodes. |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 505 | // |
| 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] | 18af9a2 | 2010-08-11 00:47:19 | [diff] [blame] | 509 | virtual void CreateBackend(); |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 510 | |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 511 | const browser_sync::DataTypeController::TypeMap& data_type_controllers() { |
| 512 | return data_type_controllers_; |
| 513 | } |
| 514 | |
[email protected] | 4b2866b | 2011-01-26 18:58:44 | [diff] [blame] | 515 | // Helper method for managing encryption UI. |
| 516 | bool IsEncryptedDatatypeEnabled() const; |
| 517 | |
[email protected] | e8234d3 | 2010-09-09 20:36:39 | [diff] [blame] | 518 | // 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] | 712257e | 2009-11-11 22:57:46 | [diff] [blame] | 520 | GoogleServiceAuthError last_auth_error_; |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 521 | |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 522 | // Our asynchronous backend to communicate with sync components living on |
| 523 | // other threads. |
| 524 | scoped_ptr<browser_sync::SyncBackendHost> backend_; |
| 525 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 526 | // Cache of the last name the client attempted to authenticate. |
| 527 | std::string last_attempted_user_email_; |
| 528 | |
[email protected] | fc52c42 | 2010-11-19 18:59:23 | [diff] [blame] | 529 | // Was the last SYNC_PASSPHRASE_REQUIRED notification sent because it |
[email protected] | 43c48fb9 | 2011-05-02 19:47:43 | [diff] [blame] | 530 | // 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] | fc52c42 | 2010-11-19 18:59:23 | [diff] [blame] | 533 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 534 | private: |
[email protected] | 4f5732a4 | 2010-09-21 22:39:09 | [diff] [blame] | 535 | friend class ProfileSyncServicePasswordTest; |
[email protected] | 42091493 | 2011-01-24 23:32:41 | [diff] [blame] | 536 | friend class TestProfileSyncService; |
[email protected] | 62828b1 | 2011-07-21 21:48:16 | [diff] [blame] | 537 | friend class ProfileSyncServiceForWizardTest; |
[email protected] | 61b694a | 2010-06-10 10:40:46 | [diff] [blame] | 538 | FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceTest, InitialState); |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 539 | |
[email protected] | 18af9a2 | 2010-08-11 00:47:19 | [diff] [blame] | 540 | // 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] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 544 | // Initializes the various settings from the command line. |
| 545 | void InitSettings(); |
| 546 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 547 | // Sets the last synced time to the current time. |
| 548 | void UpdateLastSyncedTime(); |
| 549 | |
[email protected] | 1a78769 | 2011-01-19 22:19:46 | [diff] [blame] | 550 | void NotifyObservers(); |
| 551 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 552 | static const char* GetPrefNameForDataType(syncable::ModelType data_type); |
[email protected] | a1c2aef6 | 2010-04-02 02:58:05 | [diff] [blame] | 553 | |
[email protected] | 23caf1d | 2011-08-25 22:21:02 | [diff] [blame] | 554 | // 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] | cb4c06e | 2009-08-22 00:24:39 | [diff] [blame] | 562 | // 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] | 1f97a11 | 2009-08-11 02:17:06 | [diff] [blame] | 566 | base::TimeTicks auth_error_time_; |
| 567 | |
[email protected] | e3e43d9 | 2010-02-26 22:02:38 | [diff] [blame] | 568 | // Factory used to create various dependent objects. |
| 569 | ProfileSyncFactory* factory_; |
| 570 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 571 | // The profile whose data we are synchronizing. |
| 572 | Profile* profile_; |
| 573 | |
[email protected] | e8234d3 | 2010-09-09 20:36:39 | [diff] [blame] | 574 | // Email for the ChromiumOS user, if we're running under ChromiumOS. |
| 575 | std::string cros_user_; |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 576 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 577 | // 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] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 581 | // 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] | 4aea04a | 2010-02-10 20:13:43 | [diff] [blame] | 585 | // List of available data type controllers. |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 586 | browser_sync::DataTypeController::TypeMap data_type_controllers_; |
[email protected] | db1df0f | 2009-08-18 22:36:05 | [diff] [blame] | 587 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 588 | // Whether the SyncBackendHost has been initialized. |
| 589 | bool backend_initialized_; |
| 590 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 591 | // 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] | 44b78f90a | 2009-10-15 17:32:20 | [diff] [blame] | 597 | SyncSetupWizard wizard_; |
| 598 | |
[email protected] | e8234d3 | 2010-09-09 20:36:39 | [diff] [blame] | 599 | // Encapsulates user signin with TokenService. |
[email protected] | bb868b4 | 2010-11-18 22:33:00 | [diff] [blame] | 600 | scoped_ptr<SigninManager> signin_; |
[email protected] | e8234d3 | 2010-09-09 20:36:39 | [diff] [blame] | 601 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 602 | // 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] | f6ec8b2 | 2010-06-08 23:40:06 | [diff] [blame] | 607 | // 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] | e3e43d9 | 2010-02-26 22:02:38 | [diff] [blame] | 611 | // Manages the start and stop of the various data types. |
| 612 | scoped_ptr<browser_sync::DataTypeManager> data_type_manager_; |
| 613 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 614 | ObserverList<Observer> observers_; |
| 615 | |
[email protected] | fa13487 | 2011-08-02 18:39:55 | [diff] [blame] | 616 | browser_sync::SyncJsController sync_js_controller_; |
[email protected] | f92351d | 2011-02-01 07:42:12 | [diff] [blame] | 617 | |
[email protected] | c4c672a | 2010-03-23 21:47:04 | [diff] [blame] | 618 | NotificationRegistrar registrar_; |
| 619 | |
[email protected] | 2be7bf2 | 2010-04-23 21:02:37 | [diff] [blame] | 620 | ScopedRunnableMethodFactory<ProfileSyncService> |
[email protected] | 954b108 | 2010-11-10 20:22:50 | [diff] [blame] | 621 | scoped_runnable_method_factory_; |
[email protected] | 2be7bf2 | 2010-04-23 21:02:37 | [diff] [blame] | 622 | |
[email protected] | d3b98c8 | 2010-07-14 07:45:59 | [diff] [blame] | 623 | // The preference that controls whether sync is under control by configuration |
| 624 | // management. |
| 625 | BooleanPrefMember pref_sync_managed_; |
| 626 | |
[email protected] | a47eeb5 | 2010-07-15 17:54:25 | [diff] [blame] | 627 | // 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] | 48a98b3 | 2010-09-17 20:26:59 | [diff] [blame] | 632 | // 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] | d693024 | 2011-09-03 01:52:19 | [diff] [blame] | 636 | struct CachedPassphrases { |
| 637 | std::string explicit_passphrase; |
| 638 | std::string gaia_passphrase; |
[email protected] | 954b108 | 2010-11-10 20:22:50 | [diff] [blame] | 639 | }; |
[email protected] | d693024 | 2011-09-03 01:52:19 | [diff] [blame] | 640 | CachedPassphrases cached_passphrases_; |
[email protected] | 4bc5eee | 2011-05-11 18:36:16 | [diff] [blame] | 641 | |
[email protected] | 689a7a7 | 2010-09-29 19:56:41 | [diff] [blame] | 642 | // Keep track of where we are in a server clear operation |
| 643 | ClearServerDataState clear_server_data_state_; |
| 644 | |
[email protected] | 990de36 | 2010-10-13 17:55:50 | [diff] [blame] | 645 | // Timeout for the clear data command. This timeout is a temporary hack |
[email protected] | 954b108 | 2010-11-10 20:22:50 | [diff] [blame] | 646 | // and is necessary because the nudge sync framework can drop nudges for |
[email protected] | 990de36 | 2010-10-13 17:55:50 | [diff] [blame] | 647 | // 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] | 7bf8dd0 | 2011-06-03 21:58:24 | [diff] [blame] | 652 | // The most recently requested set of types to encrypt. Set by the user, |
[email protected] | cc10e7c | 2011-08-06 00:17:50 | [diff] [blame] | 653 | // and cached until the syncer either finishes encryption |
| 654 | // (OnEncryptionComplete) or the user cancels. |
[email protected] | 7bf8dd0 | 2011-06-03 21:58:24 | [diff] [blame] | 655 | syncable::ModelTypeSet pending_types_for_encryption_; |
[email protected] | 2620b48 | 2011-08-24 08:48:53 | [diff] [blame] | 656 | bool set_backend_encrypted_types_; |
[email protected] | 3fa964af | 2011-02-24 18:54:39 | [diff] [blame] | 657 | |
[email protected] | d693024 | 2011-09-03 01:52:19 | [diff] [blame] | 658 | // 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] | dc55625 | 2011-04-20 01:59:35 | [diff] [blame] | 664 | scoped_ptr<browser_sync::BackendMigrator> migrator_; |
| 665 | |
[email protected] | cb5199b | 2011-09-04 01:55:52 | [diff] [blame^] | 666 | // 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] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 670 | DISALLOW_COPY_AND_ASSIGN(ProfileSyncService); |
| 671 | }; |
| 672 | |
[email protected] | cb5199b | 2011-09-04 01:55:52 | [diff] [blame^] | 673 | bool ShouldShowActionOnUI( |
| 674 | const browser_sync::SyncProtocolError& error); |
| 675 | |
| 676 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 677 | #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ |