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