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