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