[email protected] | 66761b95 | 2010-06-25 21:30:38 | [diff] [blame] | 1 | // Copyright (c) 2010 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] | 61b694a | 2010-06-10 10:40:46 | [diff] [blame] | 12 | #include "base/gtest_prod_util.h" |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 13 | #include "base/observer_list.h" |
| 14 | #include "base/scoped_ptr.h" |
[email protected] | 06614687 | 2010-08-05 00:55:08 | [diff] [blame] | 15 | #include "base/string16.h" |
[email protected] | 4aea04a | 2010-02-10 20:13:43 | [diff] [blame] | 16 | #include "base/time.h" |
[email protected] | 990de36 | 2010-10-13 17:55:50 | [diff] [blame] | 17 | #include "base/timer.h" |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 18 | #include "chrome/browser/prefs/pref_member.h" |
[email protected] | e8234d3 | 2010-09-09 20:36:39 | [diff] [blame] | 19 | #include "chrome/browser/sync/engine/syncapi.h" |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 20 | #include "chrome/browser/sync/glue/data_type_controller.h" |
[email protected] | e3e43d9 | 2010-02-26 22:02:38 | [diff] [blame] | 21 | #include "chrome/browser/sync/glue/data_type_manager.h" |
[email protected] | 5edb922 | 2010-08-18 00:23:29 | [diff] [blame] | 22 | #include "chrome/browser/sync/glue/session_model_associator.h" |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 23 | #include "chrome/browser/sync/glue/sync_backend_host.h" |
[email protected] | d3b98c8 | 2010-07-14 07:45:59 | [diff] [blame] | 24 | #include "chrome/browser/sync/profile_sync_service_observer.h" |
[email protected] | e8234d3 | 2010-09-09 20:36:39 | [diff] [blame] | 25 | #include "chrome/browser/sync/signin_manager.h" |
[email protected] | d80033e | 2009-10-16 10:32:04 | [diff] [blame] | 26 | #include "chrome/browser/sync/sync_setup_wizard.h" |
[email protected] | 4aea04a | 2010-02-10 20:13:43 | [diff] [blame] | 27 | #include "chrome/browser/sync/syncable/model_type.h" |
[email protected] | eafb218 | 2010-03-03 00:46:31 | [diff] [blame] | 28 | #include "chrome/browser/sync/unrecoverable_error_handler.h" |
[email protected] | 99074c5 | 2010-08-19 18:44:19 | [diff] [blame] | 29 | #include "chrome/common/net/gaia/google_service_auth_error.h" |
[email protected] | c4c672a | 2010-03-23 21:47:04 | [diff] [blame] | 30 | #include "chrome/common/notification_observer.h" |
| 31 | #include "chrome/common/notification_registrar.h" |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 32 | #include "googleurl/src/gurl.h" |
[email protected] | 33cd004 | 2010-09-08 19:25:28 | [diff] [blame] | 33 | #include "jingle/notifier/base/notifier_options.h" |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 34 | |
[email protected] | c4c672a | 2010-03-23 21:47:04 | [diff] [blame] | 35 | class NotificationDetails; |
| 36 | class NotificationSource; |
| 37 | class NotificationType; |
[email protected] | 942690b13 | 2010-05-11 06:42:14 | [diff] [blame] | 38 | class Profile; |
| 39 | class ProfileSyncFactory; |
[email protected] | e8234d3 | 2010-09-09 20:36:39 | [diff] [blame] | 40 | class TokenMigrator; |
[email protected] | c4c672a | 2010-03-23 21:47:04 | [diff] [blame] | 41 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 42 | // ProfileSyncService is the layer between browser subsystems like bookmarks, |
[email protected] | a1c2aef6 | 2010-04-02 02:58:05 | [diff] [blame] | 43 | // and the sync backend. Each subsystem is logically thought of as being |
| 44 | // a sync datatype. |
| 45 | // |
| 46 | // Individual datatypes can, at any point, be in a variety of stages of being |
| 47 | // "enabled". Here are some specific terms for concepts used in this class: |
| 48 | // |
| 49 | // 'Registered' (feature suppression for a datatype) |
| 50 | // |
| 51 | // When a datatype is registered, the user has the option of syncing it. |
| 52 | // The sync opt-in UI will show only registered types; a checkbox should |
| 53 | // never be shown for an unregistered type, and nor should it ever be |
| 54 | // synced. |
| 55 | // |
| 56 | // A datatype is considered registered once RegisterDataTypeController |
| 57 | // has been called with that datatype's DataTypeController. |
| 58 | // |
| 59 | // 'Preferred' (user preferences and opt-out for a datatype) |
| 60 | // |
| 61 | // This means the user's opt-in or opt-out preference on a per-datatype |
| 62 | // basis. The sync service will try to make active exactly these types. |
| 63 | // If a user has opted out of syncing a particular datatype, it will |
| 64 | // be registered, but not preferred. |
| 65 | // |
| 66 | // This state is controlled by the ConfigurePreferredDataTypes and |
| 67 | // GetPreferredDataTypes. They are stored in the preferences system, |
| 68 | // and persist; though if a datatype is not registered, it cannot |
| 69 | // be a preferred datatype. |
| 70 | // |
| 71 | // 'Active' (run-time initialization of sync system for a datatype) |
| 72 | // |
| 73 | // An active datatype is a preferred datatype that is actively being |
| 74 | // synchronized: the syncer has been instructed to querying the server |
| 75 | // for this datatype, first-time merges have finished, and there is an |
| 76 | // actively installed ChangeProcessor that listens for changes to this |
| 77 | // datatype, propagating such changes into and out of the sync backend |
| 78 | // as necessary. |
| 79 | // |
| 80 | // When a datatype is in the process of becoming active, it may be |
| 81 | // in some intermediate state. Those finer-grained intermediate states |
| 82 | // are differentiated by the DataTypeController state. |
| 83 | // |
[email protected] | 4aea04a | 2010-02-10 20:13:43 | [diff] [blame] | 84 | class ProfileSyncService : public browser_sync::SyncFrontend, |
[email protected] | c4c672a | 2010-03-23 21:47:04 | [diff] [blame] | 85 | public browser_sync::UnrecoverableErrorHandler, |
| 86 | public NotificationObserver { |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 87 | public: |
| 88 | typedef ProfileSyncServiceObserver Observer; |
| 89 | typedef browser_sync::SyncBackendHost::Status Status; |
| 90 | |
[email protected] | 1f97a11 | 2009-08-11 02:17:06 | [diff] [blame] | 91 | enum SyncEventCodes { |
| 92 | MIN_SYNC_EVENT_CODE = 0, |
| 93 | |
| 94 | // Events starting the sync service. |
| 95 | START_FROM_NTP = 1, // Sync was started from the ad in NTP |
| 96 | START_FROM_WRENCH = 2, // Sync was started from the Wrench menu. |
| 97 | START_FROM_OPTIONS = 3, // Sync was started from Wrench->Options. |
[email protected] | b220d13f | 2009-10-09 04:12:46 | [diff] [blame] | 98 | START_FROM_BOOKMARK_MANAGER = 4, // Sync was started from Bookmark manager. |
[email protected] | 1f97a11 | 2009-08-11 02:17:06 | [diff] [blame] | 99 | |
[email protected] | a7ab833 | 2010-03-31 20:49:04 | [diff] [blame] | 100 | // Events regarding cancellation of the signon process of sync. |
[email protected] | 8ac2dc11 | 2009-10-01 23:19:13 | [diff] [blame] | 101 | CANCEL_FROM_SIGNON_WITHOUT_AUTH = 10, // Cancelled before submitting |
[email protected] | 1f97a11 | 2009-08-11 02:17:06 | [diff] [blame] | 102 | // username and password. |
| 103 | CANCEL_DURING_SIGNON = 11, // Cancelled after auth. |
[email protected] | c976938f | 2010-10-12 04:55:44 | [diff] [blame] | 104 | CANCEL_DURING_CONFIGURE = 12, // Cancelled before choosing data |
[email protected] | 8c94d63 | 2010-06-25 22:38:00 | [diff] [blame] | 105 | // types and clicking OK. |
[email protected] | 1f97a11 | 2009-08-11 02:17:06 | [diff] [blame] | 106 | // Events resulting in the stoppage of sync service. |
| 107 | STOP_FROM_OPTIONS = 20, // Sync was stopped from Wrench->Options. |
| 108 | |
| 109 | // Miscellaneous events caused by sync service. |
[email protected] | 1f97a11 | 2009-08-11 02:17:06 | [diff] [blame] | 110 | |
| 111 | MAX_SYNC_EVENT_CODE |
| 112 | }; |
| 113 | |
[email protected] | 689a7a7 | 2010-09-29 19:56:41 | [diff] [blame] | 114 | // Keep track of where we are when clearing server data. |
| 115 | enum ClearServerDataState { |
| 116 | CLEAR_NOT_STARTED = 1, |
| 117 | CLEAR_CLEARING = 2, |
| 118 | CLEAR_FAILED = 3, |
| 119 | CLEAR_SUCCEEDED = 4, |
| 120 | }; |
| 121 | |
[email protected] | f66bcdf | 2010-05-17 20:31:14 | [diff] [blame] | 122 | // Default sync server URL. |
| 123 | static const char* kSyncServerUrl; |
| 124 | // Sync server URL for dev channel users |
| 125 | static const char* kDevServerUrl; |
| 126 | |
[email protected] | e3e43d9 | 2010-02-26 22:02:38 | [diff] [blame] | 127 | ProfileSyncService(ProfileSyncFactory* factory_, |
| 128 | Profile* profile, |
[email protected] | e8234d3 | 2010-09-09 20:36:39 | [diff] [blame] | 129 | const std::string& cros_user); |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 130 | virtual ~ProfileSyncService(); |
| 131 | |
| 132 | // Initializes the object. This should be called every time an object of this |
| 133 | // class is constructed. |
| 134 | void Initialize(); |
| 135 | |
[email protected] | e8234d3 | 2010-09-09 20:36:39 | [diff] [blame] | 136 | void RegisterAuthNotifications(); |
| 137 | |
| 138 | // Return whether all sync tokens are loaded and |
| 139 | // available for the backend to start up. |
| 140 | bool AreCredentialsAvailable(); |
| 141 | |
| 142 | // Loads credentials migrated from the old user settings db. |
| 143 | void LoadMigratedCredentials(const std::string& username, |
| 144 | const std::string& token); |
| 145 | |
[email protected] | 4aea04a | 2010-02-10 20:13:43 | [diff] [blame] | 146 | // Registers a data type controller with the sync service. This |
| 147 | // makes the data type controller available for use, it does not |
| 148 | // enable or activate the synchronization of the data type (see |
| 149 | // ActivateDataType). Takes ownership of the pointer. |
| 150 | void RegisterDataTypeController( |
| 151 | browser_sync::DataTypeController* data_type_controller); |
| 152 | |
[email protected] | 5edb922 | 2010-08-18 00:23:29 | [diff] [blame] | 153 | // Returns the session model associator associated with this type, but only if |
| 154 | // the associator is running. If it is doing anything else, it will return |
| 155 | // null. |
| 156 | browser_sync::SessionModelAssociator* GetSessionModelAssociator(); |
| 157 | |
[email protected] | 689a7a7 | 2010-09-29 19:56:41 | [diff] [blame] | 158 | // Maintain state of where we are in a server clear operation. |
| 159 | void ResetClearServerDataState(); |
| 160 | ClearServerDataState GetClearServerDataState(); |
| 161 | |
[email protected] | a7ab833 | 2010-03-31 20:49:04 | [diff] [blame] | 162 | // Fills state_map with a map of current data types that are possible to |
| 163 | // sync, as well as their states. |
| 164 | void GetDataTypeControllerStates( |
| 165 | browser_sync::DataTypeController::StateMap* state_map) const; |
[email protected] | 4aea04a | 2010-02-10 20:13:43 | [diff] [blame] | 166 | |
[email protected] | e8234d3 | 2010-09-09 20:36:39 | [diff] [blame] | 167 | // Disables sync for user. Use ShowLoginDialog to enable. |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 168 | virtual void DisableForUser(); |
| 169 | |
[email protected] | 1ce52aa | 2010-09-08 19:07:36 | [diff] [blame] | 170 | // Clears all Chromesync data from the server. |
| 171 | void ClearServerData(); |
| 172 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 173 | // Whether sync is enabled by user or not. |
[email protected] | 4772b07 | 2010-03-30 17:45:46 | [diff] [blame] | 174 | virtual bool HasSyncSetupCompleted() const; |
[email protected] | 2efebbbf | 2010-10-25 10:31:21 | [diff] [blame] | 175 | virtual void SetSyncSetupCompleted(); |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 176 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 177 | // SyncFrontend implementation. |
| 178 | virtual void OnBackendInitialized(); |
| 179 | virtual void OnSyncCycleCompleted(); |
| 180 | virtual void OnAuthError(); |
[email protected] | 7f8abea | 2010-07-14 01:31:36 | [diff] [blame] | 181 | virtual void OnStopSyncingPermanently(); |
[email protected] | 1ce52aa | 2010-09-08 19:07:36 | [diff] [blame] | 182 | virtual void OnClearServerDataFailed(); |
[email protected] | 990de36 | 2010-10-13 17:55:50 | [diff] [blame] | 183 | virtual void OnClearServerDataTimeout(); |
[email protected] | 1ce52aa | 2010-09-08 19:07:36 | [diff] [blame] | 184 | virtual void OnClearServerDataSucceeded(); |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 185 | |
| 186 | // Called when a user enters credentials through UI. |
| 187 | virtual void OnUserSubmittedAuth(const std::string& username, |
[email protected] | 1fc9b3f | 2009-11-12 21:22:09 | [diff] [blame] | 188 | const std::string& password, |
[email protected] | 96209ccd | 2010-10-11 21:57:27 | [diff] [blame] | 189 | const std::string& captcha, |
| 190 | const std::string& access_code); |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 191 | |
[email protected] | e8234d3 | 2010-09-09 20:36:39 | [diff] [blame] | 192 | // Update the last auth error and notify observers of error state. |
| 193 | void UpdateAuthErrorState(const GoogleServiceAuthError& error); |
| 194 | |
[email protected] | af90949 | 2010-06-10 18:45:38 | [diff] [blame] | 195 | // Called when a user chooses which data types to sync as part of the sync |
| 196 | // setup wizard. |sync_everything| represents whether they chose the |
[email protected] | 8c94d63 | 2010-06-25 22:38:00 | [diff] [blame] | 197 | // "keep everything synced" option; if true, |chosen_types| will be ignored |
| 198 | // and all data types will be synced. |sync_everything| means "sync all |
| 199 | // current and future data types." |
[email protected] | af90949 | 2010-06-10 18:45:38 | [diff] [blame] | 200 | virtual void OnUserChoseDatatypes(bool sync_everything, |
[email protected] | 8c94d63 | 2010-06-25 22:38:00 | [diff] [blame] | 201 | const syncable::ModelTypeSet& chosen_types); |
[email protected] | af90949 | 2010-06-10 18:45:38 | [diff] [blame] | 202 | |
[email protected] | a7ab833 | 2010-03-31 20:49:04 | [diff] [blame] | 203 | // Called when a user cancels any setup dialog (login, etc). |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 204 | virtual void OnUserCancelledDialog(); |
| 205 | |
| 206 | // Get various information for displaying in the user interface. |
| 207 | browser_sync::SyncBackendHost::StatusSummary QuerySyncStatusSummary(); |
[email protected] | f1e6e021 | 2010-10-15 20:54:24 | [diff] [blame] | 208 | virtual browser_sync::SyncBackendHost::Status QueryDetailedSyncStatus(); |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 209 | |
[email protected] | 712257e | 2009-11-11 22:57:46 | [diff] [blame] | 210 | const GoogleServiceAuthError& GetAuthError() const { |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 211 | return last_auth_error_; |
| 212 | } |
| 213 | |
| 214 | // Displays a dialog for the user to enter GAIA credentials and attempt |
| 215 | // re-authentication, and returns true if it actually opened the dialog. |
| 216 | // Returns false if a dialog is already showing, an auth attempt is in |
| 217 | // progress, the sync system is already authenticated, or some error |
| 218 | // occurred preventing the action. We make it the duty of ProfileSyncService |
| 219 | // to open the dialog to easily ensure only one is ever showing. |
[email protected] | d688559 | 2010-10-11 19:38:24 | [diff] [blame] | 220 | virtual bool SetupInProgress() const; |
[email protected] | 44b78f90a | 2009-10-15 17:32:20 | [diff] [blame] | 221 | bool WizardIsVisible() const { |
| 222 | return wizard_.IsVisible(); |
| 223 | } |
[email protected] | d688559 | 2010-10-11 19:38:24 | [diff] [blame] | 224 | virtual void ShowLoginDialog(gfx::NativeWindow parent_window); |
[email protected] | 66d8100 | 2010-10-18 16:52:09 | [diff] [blame] | 225 | void ShowConfigure(gfx::NativeWindow parent_window); |
[email protected] | 8c94d63 | 2010-06-25 22:38:00 | [diff] [blame] | 226 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 227 | // Pretty-printed strings for a given StatusSummary. |
[email protected] | 06614687 | 2010-08-05 00:55:08 | [diff] [blame] | 228 | static std::string BuildSyncStatusSummaryText( |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 229 | const browser_sync::SyncBackendHost::StatusSummary& summary); |
| 230 | |
| 231 | // Returns true if the SyncBackendHost has told us it's ready to accept |
| 232 | // changes. |
| 233 | // TODO(timsteele): What happens if the bookmark model is loaded, a change |
| 234 | // takes place, and the backend isn't initialized yet? |
| 235 | bool sync_initialized() const { return backend_initialized_; } |
[email protected] | f1e6e021 | 2010-10-15 20:54:24 | [diff] [blame] | 236 | virtual bool unrecoverable_error_detected() const { |
[email protected] | fb42c98 | 2009-09-16 22:33:33 | [diff] [blame] | 237 | return unrecoverable_error_detected_; |
| 238 | } |
[email protected] | f6ec8b2 | 2010-06-08 23:40:06 | [diff] [blame] | 239 | const std::string& unrecoverable_error_message() { |
| 240 | return unrecoverable_error_message_; |
| 241 | } |
| 242 | tracked_objects::Location unrecoverable_error_location() { |
| 243 | return unrecoverable_error_location_.get() ? |
| 244 | *unrecoverable_error_location_.get() : tracked_objects::Location(); |
| 245 | } |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 246 | |
| 247 | bool UIShouldDepictAuthInProgress() const { |
| 248 | return is_auth_in_progress_; |
| 249 | } |
| 250 | |
[email protected] | 66d8100 | 2010-10-18 16:52:09 | [diff] [blame] | 251 | bool observed_passphrase_required() const { |
| 252 | return observed_passphrase_required_; |
| 253 | } |
| 254 | |
[email protected] | fc52c42 | 2010-11-19 18:59:23 | [diff] [blame^] | 255 | bool passphrase_required_for_decryption() const { |
| 256 | return passphrase_required_for_decryption_; |
| 257 | } |
| 258 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 259 | // A timestamp marking the last time the service observed a transition from |
| 260 | // the SYNCING state to the READY state. Note that this does not reflect the |
| 261 | // last time we polled the server to see if there were any changes; the |
| 262 | // timestamp is only snapped when syncing takes place and we download or |
| 263 | // upload some bookmark entity. |
| 264 | const base::Time& last_synced_time() const { return last_synced_time_; } |
| 265 | |
| 266 | // Returns a user-friendly string form of last synced time (in minutes). |
[email protected] | f1e6e021 | 2010-10-15 20:54:24 | [diff] [blame] | 267 | virtual string16 GetLastSyncedTimeString() const; |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 268 | |
| 269 | // Returns the authenticated username of the sync user, or empty if none |
| 270 | // exists. It will only exist if the authentication service provider (e.g |
| 271 | // GAIA) has confirmed the username is authentic. |
| 272 | virtual string16 GetAuthenticatedUsername() const; |
| 273 | |
| 274 | const std::string& last_attempted_user_email() const { |
| 275 | return last_attempted_user_email_; |
| 276 | } |
| 277 | |
| 278 | // The profile we are syncing for. |
[email protected] | c976938f | 2010-10-12 04:55:44 | [diff] [blame] | 279 | Profile* profile() const { return profile_; } |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 280 | |
| 281 | // Adds/removes an observer. ProfileSyncService does not take ownership of |
| 282 | // the observer. |
[email protected] | 4772b07 | 2010-03-30 17:45:46 | [diff] [blame] | 283 | virtual void AddObserver(Observer* observer); |
| 284 | virtual void RemoveObserver(Observer* observer); |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 285 | |
[email protected] | d1db1c33 | 2010-10-13 19:57:00 | [diff] [blame] | 286 | // Returns true if |observer| has already been added as an observer. |
| 287 | bool HasObserver(Observer* observer) const; |
| 288 | |
[email protected] | 1f97a11 | 2009-08-11 02:17:06 | [diff] [blame] | 289 | // Record stats on various events. |
| 290 | static void SyncEvent(SyncEventCodes code); |
| 291 | |
[email protected] | eec3bcfa | 2009-11-12 17:23:43 | [diff] [blame] | 292 | // Returns whether sync is enabled. Sync can be enabled/disabled both |
| 293 | // at compile time (e.g., on a per-OS basis) or at run time (e.g., |
| 294 | // command-line switches). |
| 295 | static bool IsSyncEnabled(); |
| 296 | |
[email protected] | d1db1c33 | 2010-10-13 19:57:00 | [diff] [blame] | 297 | // Returns whether sync is managed, i.e. controlled by configuration |
[email protected] | d3b98c8 | 2010-07-14 07:45:59 | [diff] [blame] | 298 | // management. If so, the user is not allowed to configure sync. |
| 299 | bool IsManaged(); |
| 300 | |
[email protected] | db1df0f | 2009-08-18 22:36:05 | [diff] [blame] | 301 | // UnrecoverableErrorHandler implementation. |
[email protected] | f6ec8b2 | 2010-06-08 23:40:06 | [diff] [blame] | 302 | virtual void OnUnrecoverableError( |
| 303 | const tracked_objects::Location& from_here, |
| 304 | const std::string& message); |
[email protected] | db1df0f | 2009-08-18 22:36:05 | [diff] [blame] | 305 | |
| 306 | browser_sync::SyncBackendHost* backend() { return backend_.get(); } |
| 307 | |
[email protected] | 4aea04a | 2010-02-10 20:13:43 | [diff] [blame] | 308 | virtual void ActivateDataType( |
| 309 | browser_sync::DataTypeController* data_type_controller, |
| 310 | browser_sync::ChangeProcessor* change_processor); |
| 311 | virtual void DeactivateDataType( |
| 312 | browser_sync::DataTypeController* data_type_controller, |
| 313 | browser_sync::ChangeProcessor* change_processor); |
| 314 | |
[email protected] | c4c672a | 2010-03-23 21:47:04 | [diff] [blame] | 315 | // NotificationObserver implementation. |
| 316 | virtual void Observe(NotificationType type, |
| 317 | const NotificationSource& source, |
| 318 | const NotificationDetails& details); |
| 319 | |
[email protected] | a1c2aef6 | 2010-04-02 02:58:05 | [diff] [blame] | 320 | // Changes which data types we're going to be syncing to |preferred_types|. |
| 321 | // If it is running, the DataTypeManager will be instructed to reconfigure |
| 322 | // the sync backend so that exactly these datatypes are actively synced. See |
| 323 | // class comment for more on what it means for a datatype to be Preferred. |
| 324 | virtual void ChangePreferredDataTypes( |
| 325 | const syncable::ModelTypeSet& preferred_types); |
| 326 | |
| 327 | // Get the set of currently enabled data types (as chosen or configured by |
| 328 | // the user). See class comment for more on what it means for a datatype |
| 329 | // to be Preferred. |
| 330 | virtual void GetPreferredDataTypes( |
| 331 | syncable::ModelTypeSet* preferred_types) const; |
| 332 | |
| 333 | // Gets the set of all data types that could be allowed (the set that |
| 334 | // should be advertised to the user). These will typically only change |
| 335 | // via a command-line option. See class comment for more on what it means |
| 336 | // for a datatype to be Registered. |
| 337 | virtual void GetRegisteredDataTypes( |
| 338 | syncable::ModelTypeSet* registered_types) const; |
[email protected] | a7ab833 | 2010-03-31 20:49:04 | [diff] [blame] | 339 | |
[email protected] | ff0aa75 | 2010-06-10 22:40:52 | [diff] [blame] | 340 | // Checks whether the Cryptographer is ready to encrypt and decrypt updates |
| 341 | // for sensitive data types. |
| 342 | virtual bool IsCryptographerReady() const; |
| 343 | |
[email protected] | c976938f | 2010-10-12 04:55:44 | [diff] [blame] | 344 | // Returns true if a secondary passphrase is being used. |
| 345 | virtual bool IsUsingSecondaryPassphrase() const; |
| 346 | |
[email protected] | ee1adf4b | 2010-10-11 03:48:48 | [diff] [blame] | 347 | // Sets the Cryptographer's passphrase, or caches it until that is possible. |
| 348 | // This will check asynchronously whether the passphrase is valid and notify |
[email protected] | dc39dd1b | 2010-10-07 18:08:11 | [diff] [blame] | 349 | // ProfileSyncServiceObservers via the NotificationService when the outcome |
| 350 | // is known. |
[email protected] | 954b108 | 2010-11-10 20:22:50 | [diff] [blame] | 351 | // |is_explicit| is true if the call is in response to the user explicitly |
| 352 | // setting a passphrase as opposed to implicitly (from the users' perspective) |
| 353 | // using their Google Account password. An implicit SetPassphrase will *not* |
| 354 | // *not* override an explicit passphrase set previously. |
| 355 | virtual void SetPassphrase(const std::string& passphrase, bool is_explicit); |
[email protected] | bb899b3f | 2010-06-23 21:35:32 | [diff] [blame] | 356 | |
[email protected] | 5edb922 | 2010-08-18 00:23:29 | [diff] [blame] | 357 | // Returns whether processing changes is allowed. Check this before doing |
| 358 | // any model-modifying operations. |
| 359 | bool ShouldPushChanges(); |
| 360 | |
[email protected] | 9a127f2 | 2010-09-17 21:05:16 | [diff] [blame] | 361 | const GURL& sync_service_url() const { return sync_service_url_; } |
[email protected] | bb868b4 | 2010-11-18 22:33:00 | [diff] [blame] | 362 | SigninManager* signin() { return signin_.get(); } |
| 363 | const std::string& cros_user() const { return cros_user_; } |
[email protected] | 9a127f2 | 2010-09-17 21:05:16 | [diff] [blame] | 364 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 365 | protected: |
[email protected] | 82d9d295 | 2010-05-15 00:36:16 | [diff] [blame] | 366 | // Used by ProfileSyncServiceMock only. |
| 367 | // |
| 368 | // TODO(akalin): Separate this class out into an abstract |
| 369 | // ProfileSyncService interface and a ProfileSyncServiceImpl class |
| 370 | // so we don't need this hack anymore. |
| 371 | ProfileSyncService(); |
| 372 | |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 373 | // Helper to install and configure a data type manager. |
| 374 | void ConfigureDataTypeManager(); |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 375 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 376 | // Starts up the backend sync components. |
| 377 | void StartUp(); |
| 378 | // Shuts down the backend sync components. |
| 379 | // |sync_disabled| indicates if syncing is being disabled or not. |
| 380 | void Shutdown(bool sync_disabled); |
| 381 | |
[email protected] | 48352c1 | 2009-08-15 01:19:11 | [diff] [blame] | 382 | // Methods to register and remove preferences. |
| 383 | void RegisterPreferences(); |
| 384 | void ClearPreferences(); |
| 385 | |
[email protected] | e8234d3 | 2010-09-09 20:36:39 | [diff] [blame] | 386 | // Return SyncCredentials from the TokenService. |
| 387 | sync_api::SyncCredentials GetCredentials(); |
| 388 | |
[email protected] | 18af9a2 | 2010-08-11 00:47:19 | [diff] [blame] | 389 | // Test need to override this to create backends that allow setting up |
| 390 | // initial conditions, such as populating sync nodes. |
| 391 | virtual void CreateBackend(); |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 392 | |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 393 | const browser_sync::DataTypeController::TypeMap& data_type_controllers() { |
| 394 | return data_type_controllers_; |
| 395 | } |
| 396 | |
[email protected] | e8234d3 | 2010-09-09 20:36:39 | [diff] [blame] | 397 | // The wizard will try to read the auth state out of the profile sync |
| 398 | // service using this member. Captcha and error state are reflected. |
[email protected] | 712257e | 2009-11-11 22:57:46 | [diff] [blame] | 399 | GoogleServiceAuthError last_auth_error_; |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 400 | |
[email protected] | 7cef1c44 | 2010-07-07 17:05:22 | [diff] [blame] | 401 | // Our asynchronous backend to communicate with sync components living on |
| 402 | // other threads. |
| 403 | scoped_ptr<browser_sync::SyncBackendHost> backend_; |
| 404 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 405 | // Cache of the last name the client attempted to authenticate. |
| 406 | std::string last_attempted_user_email_; |
| 407 | |
[email protected] | 66d8100 | 2010-10-18 16:52:09 | [diff] [blame] | 408 | // Whether we have seen a SYNC_PASSPHRASE_REQUIRED since initializing the |
| 409 | // backend, telling us that it is safe to send a passphrase down ASAP. |
| 410 | bool observed_passphrase_required_; |
| 411 | |
[email protected] | fc52c42 | 2010-11-19 18:59:23 | [diff] [blame^] | 412 | // Was the last SYNC_PASSPHRASE_REQUIRED notification sent because it |
| 413 | // was required for decryption? |
| 414 | bool passphrase_required_for_decryption_; |
| 415 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 416 | private: |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 417 | friend class ProfileSyncServiceTest; |
[email protected] | 4f5732a4 | 2010-09-21 22:39:09 | [diff] [blame] | 418 | friend class ProfileSyncServicePasswordTest; |
[email protected] | 65b3aa1 | 2010-02-22 22:49:00 | [diff] [blame] | 419 | friend class ProfileSyncServicePreferenceTest; |
[email protected] | 5edb922 | 2010-08-18 00:23:29 | [diff] [blame] | 420 | friend class ProfileSyncServiceSessionTest; |
[email protected] | 61b694a | 2010-06-10 10:40:46 | [diff] [blame] | 421 | FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceTest, InitialState); |
| 422 | FRIEND_TEST_ALL_PREFIXES(ProfileSyncServiceTest, |
| 423 | UnrecoverableErrorSuspendsService); |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 424 | |
[email protected] | 18af9a2 | 2010-08-11 00:47:19 | [diff] [blame] | 425 | // If |delete_sync_data_folder| is true, then this method will delete all |
| 426 | // previous "Sync Data" folders. (useful if the folder is partial/corrupt). |
| 427 | void InitializeBackend(bool delete_sync_data_folder); |
| 428 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 429 | // Initializes the various settings from the command line. |
| 430 | void InitSettings(); |
| 431 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 432 | // Sets the last synced time to the current time. |
| 433 | void UpdateLastSyncedTime(); |
| 434 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 435 | static const char* GetPrefNameForDataType(syncable::ModelType data_type); |
[email protected] | a1c2aef6 | 2010-04-02 02:58:05 | [diff] [blame] | 436 | |
[email protected] | cb4c06e | 2009-08-22 00:24:39 | [diff] [blame] | 437 | // Time at which we begin an attempt a GAIA authorization. |
| 438 | base::TimeTicks auth_start_time_; |
| 439 | |
| 440 | // Time at which error UI is presented for the new tab page. |
[email protected] | 1f97a11 | 2009-08-11 02:17:06 | [diff] [blame] | 441 | base::TimeTicks auth_error_time_; |
| 442 | |
[email protected] | e3e43d9 | 2010-02-26 22:02:38 | [diff] [blame] | 443 | // Factory used to create various dependent objects. |
| 444 | ProfileSyncFactory* factory_; |
| 445 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 446 | // The profile whose data we are synchronizing. |
| 447 | Profile* profile_; |
| 448 | |
[email protected] | e8234d3 | 2010-09-09 20:36:39 | [diff] [blame] | 449 | // Email for the ChromiumOS user, if we're running under ChromiumOS. |
| 450 | std::string cros_user_; |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 451 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 452 | // TODO(ncarter): Put this in a profile, once there is UI for it. |
| 453 | // This specifies where to find the sync server. |
| 454 | GURL sync_service_url_; |
| 455 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 456 | // The last time we detected a successful transition from SYNCING state. |
| 457 | // Our backend notifies us whenever we should take a new snapshot. |
| 458 | base::Time last_synced_time_; |
| 459 | |
[email protected] | 4aea04a | 2010-02-10 20:13:43 | [diff] [blame] | 460 | // List of available data type controllers. |
[email protected] | 72a31b4 | 2010-02-17 22:26:33 | [diff] [blame] | 461 | browser_sync::DataTypeController::TypeMap data_type_controllers_; |
[email protected] | db1df0f | 2009-08-18 22:36:05 | [diff] [blame] | 462 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 463 | // Whether the SyncBackendHost has been initialized. |
| 464 | bool backend_initialized_; |
| 465 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 466 | // Various pieces of UI query this value to determine if they should show |
| 467 | // an "Authenticating.." type of message. We are the only central place |
| 468 | // all auth attempts funnel through, so it makes sense to provide this. |
| 469 | // As its name suggests, this should NOT be used for anything other than UI. |
| 470 | bool is_auth_in_progress_; |
| 471 | |
[email protected] | 44b78f90a | 2009-10-15 17:32:20 | [diff] [blame] | 472 | SyncSetupWizard wizard_; |
| 473 | |
[email protected] | e8234d3 | 2010-09-09 20:36:39 | [diff] [blame] | 474 | // Encapsulates user signin with TokenService. |
[email protected] | bb868b4 | 2010-11-18 22:33:00 | [diff] [blame] | 475 | scoped_ptr<SigninManager> signin_; |
[email protected] | e8234d3 | 2010-09-09 20:36:39 | [diff] [blame] | 476 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 477 | // True if an unrecoverable error (e.g. violation of an assumed invariant) |
| 478 | // occurred during syncer operation. This value should be checked before |
| 479 | // doing any work that might corrupt things further. |
| 480 | bool unrecoverable_error_detected_; |
| 481 | |
[email protected] | f6ec8b2 | 2010-06-08 23:40:06 | [diff] [blame] | 482 | // A message sent when an unrecoverable error occurred. |
| 483 | std::string unrecoverable_error_message_; |
| 484 | scoped_ptr<tracked_objects::Location> unrecoverable_error_location_; |
| 485 | |
[email protected] | 33cd004 | 2010-09-08 19:25:28 | [diff] [blame] | 486 | // Contains options specific to how sync clients send and listen to |
| 487 | // notifications. |
| 488 | notifier::NotifierOptions notifier_options_; |
[email protected] | 93d960ce | 2010-02-11 04:27:00 | [diff] [blame] | 489 | |
[email protected] | e3e43d9 | 2010-02-26 22:02:38 | [diff] [blame] | 490 | // Manages the start and stop of the various data types. |
| 491 | scoped_ptr<browser_sync::DataTypeManager> data_type_manager_; |
| 492 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 493 | ObserverList<Observer> observers_; |
| 494 | |
[email protected] | c4c672a | 2010-03-23 21:47:04 | [diff] [blame] | 495 | NotificationRegistrar registrar_; |
| 496 | |
[email protected] | 2be7bf2 | 2010-04-23 21:02:37 | [diff] [blame] | 497 | ScopedRunnableMethodFactory<ProfileSyncService> |
[email protected] | 954b108 | 2010-11-10 20:22:50 | [diff] [blame] | 498 | scoped_runnable_method_factory_; |
[email protected] | 2be7bf2 | 2010-04-23 21:02:37 | [diff] [blame] | 499 | |
[email protected] | d3b98c8 | 2010-07-14 07:45:59 | [diff] [blame] | 500 | // The preference that controls whether sync is under control by configuration |
| 501 | // management. |
| 502 | BooleanPrefMember pref_sync_managed_; |
| 503 | |
[email protected] | a47eeb5 | 2010-07-15 17:54:25 | [diff] [blame] | 504 | // This allows us to gracefully handle an ABORTED return code from the |
| 505 | // DataTypeManager in the event that the server informed us to cease and |
| 506 | // desist syncing immediately. |
| 507 | bool expect_sync_configuration_aborted_; |
| 508 | |
[email protected] | e8234d3 | 2010-09-09 20:36:39 | [diff] [blame] | 509 | scoped_ptr<TokenMigrator> token_migrator_; |
| 510 | |
[email protected] | 48a98b3 | 2010-09-17 20:26:59 | [diff] [blame] | 511 | // Sometimes we need to temporarily hold on to a passphrase because we don't |
| 512 | // yet have a backend to send it to. This happens during initialization as |
| 513 | // we don't StartUp until we have a valid token, which happens after valid |
| 514 | // credentials were provided. |
[email protected] | 954b108 | 2010-11-10 20:22:50 | [diff] [blame] | 515 | struct CachedPassphrase { |
| 516 | std::string value; |
| 517 | bool is_explicit; |
| 518 | CachedPassphrase() : is_explicit(false) {} |
| 519 | }; |
| 520 | CachedPassphrase cached_passphrase_; |
| 521 | |
| 522 | // TODO(tim): Remove this once new 'explicit passphrase' code flushes through |
| 523 | // dev channel. See bug 62103. |
| 524 | // To "migrate" early adopters of password sync on dev channel to the new |
| 525 | // model that stores their secondary passphrase preference in the cloud, we |
| 526 | // need some extra state since this cloud pref will be empty for all of them |
| 527 | // regardless of how they set up sync, and we can't trust |
| 528 | // kSyncUsingSecondaryPassphrase due to bugs in that implementation. |
| 529 | bool tried_implicit_gaia_remove_when_bug_62103_fixed_; |
[email protected] | 48a98b3 | 2010-09-17 20:26:59 | [diff] [blame] | 530 | |
[email protected] | 689a7a7 | 2010-09-29 19:56:41 | [diff] [blame] | 531 | // Keep track of where we are in a server clear operation |
| 532 | ClearServerDataState clear_server_data_state_; |
| 533 | |
[email protected] | 990de36 | 2010-10-13 17:55:50 | [diff] [blame] | 534 | // Timeout for the clear data command. This timeout is a temporary hack |
[email protected] | 954b108 | 2010-11-10 20:22:50 | [diff] [blame] | 535 | // and is necessary because the nudge sync framework can drop nudges for |
[email protected] | 990de36 | 2010-10-13 17:55:50 | [diff] [blame] | 536 | // a wide variety of sync-related conditions (throttling, connections issues, |
| 537 | // syncer paused, etc.). It can only be removed correctly when the framework |
| 538 | // is reworked to allow one-shot commands like clearing server data. |
| 539 | base::OneShotTimer<ProfileSyncService> clear_server_data_timer_; |
| 540 | |
[email protected] | 132c8565 | 2009-08-05 01:18:27 | [diff] [blame] | 541 | DISALLOW_COPY_AND_ASSIGN(ProfileSyncService); |
| 542 | }; |
| 543 | |
| 544 | #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ |