Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(608)

Side by Side Diff: chrome/browser/sync/profile_sync_service.h

Issue 3305003: New authorization framework for sync. ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ 5 #ifndef CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_
6 #define CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ 6 #define CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/observer_list.h" 13 #include "base/observer_list.h"
14 #include "base/scoped_ptr.h" 14 #include "base/scoped_ptr.h"
15 #include "base/string16.h" 15 #include "base/string16.h"
16 #include "base/time.h" 16 #include "base/time.h"
17 #include "chrome/browser/prefs/pref_member.h" 17 #include "chrome/browser/prefs/pref_member.h"
18 #include "chrome/browser/sync/engine/syncapi.h"
18 #include "chrome/browser/sync/glue/data_type_controller.h" 19 #include "chrome/browser/sync/glue/data_type_controller.h"
19 #include "chrome/browser/sync/glue/data_type_manager.h" 20 #include "chrome/browser/sync/glue/data_type_manager.h"
20 #include "chrome/browser/sync/glue/session_model_associator.h" 21 #include "chrome/browser/sync/glue/session_model_associator.h"
21 #include "chrome/browser/sync/glue/sync_backend_host.h" 22 #include "chrome/browser/sync/glue/sync_backend_host.h"
22 #include "chrome/browser/sync/notification_method.h" 23 #include "chrome/browser/sync/notification_method.h"
23 #include "chrome/browser/sync/profile_sync_service_observer.h" 24 #include "chrome/browser/sync/profile_sync_service_observer.h"
25 #include "chrome/browser/sync/signin_manager.h"
24 #include "chrome/browser/sync/sync_setup_wizard.h" 26 #include "chrome/browser/sync/sync_setup_wizard.h"
25 #include "chrome/browser/sync/syncable/model_type.h" 27 #include "chrome/browser/sync/syncable/model_type.h"
26 #include "chrome/browser/sync/unrecoverable_error_handler.h" 28 #include "chrome/browser/sync/unrecoverable_error_handler.h"
27 #include "chrome/common/net/gaia/google_service_auth_error.h" 29 #include "chrome/common/net/gaia/google_service_auth_error.h"
28 #include "chrome/common/notification_observer.h" 30 #include "chrome/common/notification_observer.h"
29 #include "chrome/common/notification_registrar.h" 31 #include "chrome/common/notification_registrar.h"
30 #include "googleurl/src/gurl.h" 32 #include "googleurl/src/gurl.h"
31 33
32 class NotificationDetails; 34 class NotificationDetails;
33 class NotificationSource; 35 class NotificationSource;
34 class NotificationType; 36 class NotificationType;
35 class Profile; 37 class Profile;
36 class ProfileSyncFactory; 38 class ProfileSyncFactory;
39 class TokenMigrator;
37 40
38 // ProfileSyncService is the layer between browser subsystems like bookmarks, 41 // ProfileSyncService is the layer between browser subsystems like bookmarks,
39 // and the sync backend. Each subsystem is logically thought of as being 42 // and the sync backend. Each subsystem is logically thought of as being
40 // a sync datatype. 43 // a sync datatype.
41 // 44 //
42 // Individual datatypes can, at any point, be in a variety of stages of being 45 // Individual datatypes can, at any point, be in a variety of stages of being
43 // "enabled". Here are some specific terms for concepts used in this class: 46 // "enabled". Here are some specific terms for concepts used in this class:
44 // 47 //
45 // 'Registered' (feature suppression for a datatype) 48 // 'Registered' (feature suppression for a datatype)
46 // 49 //
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 MAX_SYNC_EVENT_CODE 110 MAX_SYNC_EVENT_CODE
108 }; 111 };
109 112
110 // Default sync server URL. 113 // Default sync server URL.
111 static const char* kSyncServerUrl; 114 static const char* kSyncServerUrl;
112 // Sync server URL for dev channel users 115 // Sync server URL for dev channel users
113 static const char* kDevServerUrl; 116 static const char* kDevServerUrl;
114 117
115 ProfileSyncService(ProfileSyncFactory* factory_, 118 ProfileSyncService(ProfileSyncFactory* factory_,
116 Profile* profile, 119 Profile* profile,
117 bool bootstrap_sync_authentication); 120 const std::string& cros_user);
118 virtual ~ProfileSyncService(); 121 virtual ~ProfileSyncService();
119 122
120 // Initializes the object. This should be called every time an object of this 123 // Initializes the object. This should be called every time an object of this
121 // class is constructed. 124 // class is constructed.
122 void Initialize(); 125 void Initialize();
123 126
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
124 // Registers a data type controller with the sync service. This 137 // Registers a data type controller with the sync service. This
125 // makes the data type controller available for use, it does not 138 // makes the data type controller available for use, it does not
126 // enable or activate the synchronization of the data type (see 139 // enable or activate the synchronization of the data type (see
127 // ActivateDataType). Takes ownership of the pointer. 140 // ActivateDataType). Takes ownership of the pointer.
128 void RegisterDataTypeController( 141 void RegisterDataTypeController(
129 browser_sync::DataTypeController* data_type_controller); 142 browser_sync::DataTypeController* data_type_controller);
130 143
131 // Returns the session model associator associated with this type, but only if 144 // Returns the session model associator associated with this type, but only if
132 // the associator is running. If it is doing anything else, it will return 145 // the associator is running. If it is doing anything else, it will return
133 // null. 146 // null.
134 browser_sync::SessionModelAssociator* GetSessionModelAssociator(); 147 browser_sync::SessionModelAssociator* GetSessionModelAssociator();
135 148
136 // Fills state_map with a map of current data types that are possible to 149 // Fills state_map with a map of current data types that are possible to
137 // sync, as well as their states. 150 // sync, as well as their states.
138 void GetDataTypeControllerStates( 151 void GetDataTypeControllerStates(
139 browser_sync::DataTypeController::StateMap* state_map) const; 152 browser_sync::DataTypeController::StateMap* state_map) const;
140 153
141 // Enables/disables sync for user. 154 // Disables sync for user. Use ShowLoginDialog to enable.
142 virtual void EnableForUser(gfx::NativeWindow parent_window);
143 virtual void DisableForUser(); 155 virtual void DisableForUser();
144 156
145 // Whether sync is enabled by user or not. 157 // Whether sync is enabled by user or not.
146 virtual bool HasSyncSetupCompleted() const; 158 virtual bool HasSyncSetupCompleted() const;
147 void SetSyncSetupCompleted(); 159 void SetSyncSetupCompleted();
148 160
149 // SyncFrontend implementation. 161 // SyncFrontend implementation.
150 virtual void OnBackendInitialized(); 162 virtual void OnBackendInitialized();
151 virtual void OnSyncCycleCompleted(); 163 virtual void OnSyncCycleCompleted();
152 virtual void OnAuthError(); 164 virtual void OnAuthError();
153 virtual void OnStopSyncingPermanently(); 165 virtual void OnStopSyncingPermanently();
154 166
155 // Called when a user enters credentials through UI. 167 // Called when a user enters credentials through UI.
156 virtual void OnUserSubmittedAuth(const std::string& username, 168 virtual void OnUserSubmittedAuth(const std::string& username,
157 const std::string& password, 169 const std::string& password,
158 const std::string& captcha); 170 const std::string& captcha);
159 171
172 // Update the last auth error and notify observers of error state.
173 void UpdateAuthErrorState(const GoogleServiceAuthError& error);
174
160 // Called when a user chooses which data types to sync as part of the sync 175 // Called when a user chooses which data types to sync as part of the sync
161 // setup wizard. |sync_everything| represents whether they chose the 176 // setup wizard. |sync_everything| represents whether they chose the
162 // "keep everything synced" option; if true, |chosen_types| will be ignored 177 // "keep everything synced" option; if true, |chosen_types| will be ignored
163 // and all data types will be synced. |sync_everything| means "sync all 178 // and all data types will be synced. |sync_everything| means "sync all
164 // current and future data types." 179 // current and future data types."
165 virtual void OnUserChoseDatatypes(bool sync_everything, 180 virtual void OnUserChoseDatatypes(bool sync_everything,
166 const syncable::ModelTypeSet& chosen_types); 181 const syncable::ModelTypeSet& chosen_types);
167 182
168 // Called when a user cancels any setup dialog (login, etc). 183 // Called when a user cancels any setup dialog (login, etc).
169 virtual void OnUserCancelledDialog(); 184 virtual void OnUserCancelledDialog();
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 // Starts up the backend sync components. 334 // Starts up the backend sync components.
320 void StartUp(); 335 void StartUp();
321 // Shuts down the backend sync components. 336 // Shuts down the backend sync components.
322 // |sync_disabled| indicates if syncing is being disabled or not. 337 // |sync_disabled| indicates if syncing is being disabled or not.
323 void Shutdown(bool sync_disabled); 338 void Shutdown(bool sync_disabled);
324 339
325 // Methods to register and remove preferences. 340 // Methods to register and remove preferences.
326 void RegisterPreferences(); 341 void RegisterPreferences();
327 void ClearPreferences(); 342 void ClearPreferences();
328 343
344 // Return SyncCredentials from the TokenService.
345 sync_api::SyncCredentials GetCredentials();
346
329 // Test need to override this to create backends that allow setting up 347 // Test need to override this to create backends that allow setting up
330 // initial conditions, such as populating sync nodes. 348 // initial conditions, such as populating sync nodes.
331 virtual void CreateBackend(); 349 virtual void CreateBackend();
332 350
333 const browser_sync::DataTypeController::TypeMap& data_type_controllers() { 351 const browser_sync::DataTypeController::TypeMap& data_type_controllers() {
334 return data_type_controllers_; 352 return data_type_controllers_;
335 } 353 }
336 354
337 // We keep track of the last auth error observed so we can cover up the first 355 // The wizard will try to read the auth state out of the profile sync
338 // "expected" auth failure from observers. 356 // service using this member. Captcha and error state are reflected.
339 // TODO(timsteele): Same as expecting_first_run_auth_needed_event_. Remove
340 // this!
341 GoogleServiceAuthError last_auth_error_; 357 GoogleServiceAuthError last_auth_error_;
342 358
343 // Our asynchronous backend to communicate with sync components living on 359 // Our asynchronous backend to communicate with sync components living on
344 // other threads. 360 // other threads.
345 scoped_ptr<browser_sync::SyncBackendHost> backend_; 361 scoped_ptr<browser_sync::SyncBackendHost> backend_;
346 362
347 // Cache of the last name the client attempted to authenticate. 363 // Cache of the last name the client attempted to authenticate.
348 std::string last_attempted_user_email_; 364 std::string last_attempted_user_email_;
349 365
350 private: 366 private:
(...skipping 22 matching lines...) Expand all
373 389
374 // Time at which error UI is presented for the new tab page. 390 // Time at which error UI is presented for the new tab page.
375 base::TimeTicks auth_error_time_; 391 base::TimeTicks auth_error_time_;
376 392
377 // Factory used to create various dependent objects. 393 // Factory used to create various dependent objects.
378 ProfileSyncFactory* factory_; 394 ProfileSyncFactory* factory_;
379 395
380 // The profile whose data we are synchronizing. 396 // The profile whose data we are synchronizing.
381 Profile* profile_; 397 Profile* profile_;
382 398
383 // True if the profile sync service should attempt to use an LSID 399 // Email for the ChromiumOS user, if we're running under ChromiumOS.
384 // cookie for authentication. This is typically set to true in 400 std::string cros_user_;
385 // ChromiumOS since we want to use the system level authentication
386 // for sync.
387 bool bootstrap_sync_authentication_;
388 401
389 // TODO(ncarter): Put this in a profile, once there is UI for it. 402 // TODO(ncarter): Put this in a profile, once there is UI for it.
390 // This specifies where to find the sync server. 403 // This specifies where to find the sync server.
391 GURL sync_service_url_; 404 GURL sync_service_url_;
392 405
393 // The last time we detected a successful transition from SYNCING state. 406 // The last time we detected a successful transition from SYNCING state.
394 // Our backend notifies us whenever we should take a new snapshot. 407 // Our backend notifies us whenever we should take a new snapshot.
395 base::Time last_synced_time_; 408 base::Time last_synced_time_;
396 409
397 // List of available data type controllers. 410 // List of available data type controllers.
398 browser_sync::DataTypeController::TypeMap data_type_controllers_; 411 browser_sync::DataTypeController::TypeMap data_type_controllers_;
399 412
400 // Whether the SyncBackendHost has been initialized. 413 // Whether the SyncBackendHost has been initialized.
401 bool backend_initialized_; 414 bool backend_initialized_;
402 415
403 // Set to true when the user first enables sync, and we are waiting for
404 // syncapi to give us the green light on providing credentials for the first
405 // time. It is set back to false as soon as we get this message, and is
406 // false all other times so we don't have to persist this value as it will
407 // get initialized to false.
408 // TODO(timsteele): Remove this by way of starting the wizard when enabling
409 // sync *before* initializing the backend. syncapi will need to change, but
410 // it means we don't have to wait for the first AuthError; if we ever get
411 // one, it is actually an error and this bool isn't needed.
412 bool expecting_first_run_auth_needed_event_;
413
414 // Various pieces of UI query this value to determine if they should show 416 // Various pieces of UI query this value to determine if they should show
415 // an "Authenticating.." type of message. We are the only central place 417 // an "Authenticating.." type of message. We are the only central place
416 // all auth attempts funnel through, so it makes sense to provide this. 418 // all auth attempts funnel through, so it makes sense to provide this.
417 // As its name suggests, this should NOT be used for anything other than UI. 419 // As its name suggests, this should NOT be used for anything other than UI.
418 bool is_auth_in_progress_; 420 bool is_auth_in_progress_;
419 421
420 SyncSetupWizard wizard_; 422 SyncSetupWizard wizard_;
421 423
424 // Encapsulates user signin with TokenService.
425 SigninManager signin_;
426
422 // True if an unrecoverable error (e.g. violation of an assumed invariant) 427 // True if an unrecoverable error (e.g. violation of an assumed invariant)
423 // occurred during syncer operation. This value should be checked before 428 // occurred during syncer operation. This value should be checked before
424 // doing any work that might corrupt things further. 429 // doing any work that might corrupt things further.
425 bool unrecoverable_error_detected_; 430 bool unrecoverable_error_detected_;
426 431
427 // A message sent when an unrecoverable error occurred. 432 // A message sent when an unrecoverable error occurred.
428 std::string unrecoverable_error_message_; 433 std::string unrecoverable_error_message_;
429 scoped_ptr<tracked_objects::Location> unrecoverable_error_location_; 434 scoped_ptr<tracked_objects::Location> unrecoverable_error_location_;
430 435
431 // Whether to use the (new, untested) Chrome-socket-based 436 // Whether to use the (new, untested) Chrome-socket-based
(...skipping 15 matching lines...) Expand all
447 452
448 // The preference that controls whether sync is under control by configuration 453 // The preference that controls whether sync is under control by configuration
449 // management. 454 // management.
450 BooleanPrefMember pref_sync_managed_; 455 BooleanPrefMember pref_sync_managed_;
451 456
452 // This allows us to gracefully handle an ABORTED return code from the 457 // This allows us to gracefully handle an ABORTED return code from the
453 // DataTypeManager in the event that the server informed us to cease and 458 // DataTypeManager in the event that the server informed us to cease and
454 // desist syncing immediately. 459 // desist syncing immediately.
455 bool expect_sync_configuration_aborted_; 460 bool expect_sync_configuration_aborted_;
456 461
462 scoped_ptr<TokenMigrator> token_migrator_;
463
457 DISALLOW_COPY_AND_ASSIGN(ProfileSyncService); 464 DISALLOW_COPY_AND_ASSIGN(ProfileSyncService);
458 }; 465 };
459 466
460 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_ 467 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698