| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // The signin manager encapsulates some functionality tracking | 5 // The signin manager encapsulates some functionality tracking |
| 6 // which user is signed in. When a user is signed in, a ClientLogin | 6 // which user is signed in. When a user is signed in, a ClientLogin |
| 7 // request is run on their behalf. Auth tokens are fetched from Google | 7 // request is run on their behalf. Auth tokens are fetched from Google |
| 8 // and the results are stored in the TokenService. | 8 // and the results are stored in the TokenService. |
| 9 // | 9 // |
| 10 // **NOTE** on semantics of SigninManager: | 10 // **NOTE** on semantics of SigninManager: |
| 11 // | 11 // |
| 12 // Once a signin is successful, the username becomes "established" and will not | 12 // Once a signin is successful, the username becomes "established" and will not |
| 13 // be cleared until a SignOut operation is performed (persists across | 13 // be cleared until a SignOut operation is performed (persists across |
| 14 // restarts). Until that happens, the signin manager can still be used to | 14 // restarts). Until that happens, the signin manager can still be used to |
| 15 // refresh credentials, but changing the username is not permitted. | 15 // refresh credentials, but changing the username is not permitted. |
| 16 | 16 |
| 17 #ifndef CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_H_ | 17 #ifndef CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_H_ |
| 18 #define CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_H_ | 18 #define CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_H_ |
| 19 | 19 |
| 20 #include <string> | 20 #include <string> |
| 21 | 21 |
| 22 #include "base/compiler_specific.h" | 22 #include "base/compiler_specific.h" |
| 23 #include "base/gtest_prod_util.h" | 23 #include "base/gtest_prod_util.h" |
| 24 #include "base/logging.h" | 24 #include "base/logging.h" |
| 25 #include "base/memory/scoped_ptr.h" | 25 #include "base/memory/scoped_ptr.h" |
| 26 #include "base/observer_list.h" | 26 #include "base/observer_list.h" |
| 27 #include "base/prefs/public/pref_change_registrar.h" | 27 #include "base/prefs/public/pref_change_registrar.h" |
| 28 #include "base/prefs/public/pref_member.h" |
| 28 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
| 29 #include "chrome/browser/profiles/profile_keyed_service.h" | 30 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 30 #include "chrome/browser/signin/signin_internals_util.h" | 31 #include "chrome/browser/signin/signin_internals_util.h" |
| 31 #include "chrome/browser/signin/ubertoken_fetcher.h" | 32 #include "chrome/browser/signin/ubertoken_fetcher.h" |
| 32 #include "content/public/browser/notification_observer.h" | 33 #include "content/public/browser/notification_observer.h" |
| 33 #include "content/public/browser/notification_registrar.h" | 34 #include "content/public/browser/notification_registrar.h" |
| 34 #include "google_apis/gaia/gaia_auth_consumer.h" | 35 #include "google_apis/gaia/gaia_auth_consumer.h" |
| 35 #include "google_apis/gaia/google_service_auth_error.h" | 36 #include "google_apis/gaia/google_service_auth_error.h" |
| 36 #include "net/cookies/canonical_cookie.h" | 37 #include "net/cookies/canonical_cookie.h" |
| 37 | 38 |
| 38 class CookieSettings; | 39 class CookieSettings; |
| 39 class GaiaAuthFetcher; | 40 class GaiaAuthFetcher; |
| 41 class ProfileIOData; |
| 40 class PrefService; | 42 class PrefService; |
| 41 class SigninGlobalError; | 43 class SigninGlobalError; |
| 42 | 44 |
| 43 namespace policy { | 45 namespace policy { |
| 44 class CloudPolicyClient; | 46 class CloudPolicyClient; |
| 45 } | 47 } |
| 46 | 48 |
| 47 // Details for the Notification type GOOGLE_SIGNIN_SUCCESSFUL. | 49 // Details for the Notification type GOOGLE_SIGNIN_SUCCESSFUL. |
| 48 // A listener might use this to make note of a username / password | 50 // A listener might use this to make note of a username / password |
| 49 // pair for encryption keys. | 51 // pair for encryption keys. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 virtual ~SigninManager(); | 89 virtual ~SigninManager(); |
| 88 | 90 |
| 89 // If user was signed in, load tokens from DB if available. | 91 // If user was signed in, load tokens from DB if available. |
| 90 void Initialize(Profile* profile); | 92 void Initialize(Profile* profile); |
| 91 bool IsInitialized() const; | 93 bool IsInitialized() const; |
| 92 | 94 |
| 93 // Returns true if the passed username is allowed by policy. Virtual for | 95 // Returns true if the passed username is allowed by policy. Virtual for |
| 94 // mocking in tests. | 96 // mocking in tests. |
| 95 virtual bool IsAllowedUsername(const std::string& username) const; | 97 virtual bool IsAllowedUsername(const std::string& username) const; |
| 96 | 98 |
| 99 // Returns true if a signin to Chrome is allowed (by policy or pref). |
| 100 bool IsSigninAllowed() const; |
| 101 |
| 102 // Checks if signin is allowed for the profile that owns |io_data|. This must |
| 103 // be invoked on the IO thread, and can be used to check if signin is enabled |
| 104 // on that thread. |
| 105 static bool IsSigninAllowedOnIOThread(ProfileIOData* io_data); |
| 106 |
| 97 // If a user has previously established a username and SignOut has not been | 107 // If a user has previously established a username and SignOut has not been |
| 98 // called, this will return the username. | 108 // called, this will return the username. |
| 99 // Otherwise, it will return an empty string. | 109 // Otherwise, it will return an empty string. |
| 100 const std::string& GetAuthenticatedUsername() const; | 110 const std::string& GetAuthenticatedUsername() const; |
| 101 | 111 |
| 102 // Sets the user name. Note: |username| should be already authenticated as | 112 // Sets the user name. Note: |username| should be already authenticated as |
| 103 // this is a sticky operation (in contrast to StartSignIn). | 113 // this is a sticky operation (in contrast to StartSignIn). |
| 104 // TODO(tim): Remove this in favor of passing username on construction by | 114 // TODO(tim): Remove this in favor of passing username on construction by |
| 105 // (by platform / depending on StartBehavior). Bug 88109. | 115 // (by platform / depending on StartBehavior). Bug 88109. |
| 106 void SetAuthenticatedUsername(const std::string& username); | 116 void SetAuthenticatedUsername(const std::string& username); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 | 280 |
| 271 // ClientLogin identity. | 281 // ClientLogin identity. |
| 272 std::string possibly_invalid_username_; | 282 std::string possibly_invalid_username_; |
| 273 std::string password_; // This is kept empty whenever possible. | 283 std::string password_; // This is kept empty whenever possible. |
| 274 bool had_two_factor_error_; | 284 bool had_two_factor_error_; |
| 275 | 285 |
| 276 void CleanupNotificationRegistration(); | 286 void CleanupNotificationRegistration(); |
| 277 | 287 |
| 278 void OnGoogleServicesUsernamePatternChanged(); | 288 void OnGoogleServicesUsernamePatternChanged(); |
| 279 | 289 |
| 290 void OnSigninAllowedPrefChanged(); |
| 291 |
| 280 // Helper methods to notify all registered diagnostics observers with. | 292 // Helper methods to notify all registered diagnostics observers with. |
| 281 void NotifyDiagnosticsObservers( | 293 void NotifyDiagnosticsObservers( |
| 282 const signin_internals_util::UntimedSigninStatusField& field, | 294 const signin_internals_util::UntimedSigninStatusField& field, |
| 283 const std::string& value); | 295 const std::string& value); |
| 284 void NotifyDiagnosticsObservers( | 296 void NotifyDiagnosticsObservers( |
| 285 const signin_internals_util::TimedSigninStatusField& field, | 297 const signin_internals_util::TimedSigninStatusField& field, |
| 286 const std::string& value); | 298 const std::string& value); |
| 287 | 299 |
| 288 // Result of the last client login, kept pending the lookup of the | 300 // Result of the last client login, kept pending the lookup of the |
| 289 // canonical email. | 301 // canonical email. |
| 290 ClientLoginResult last_result_; | 302 ClientLoginResult last_result_; |
| 291 | 303 |
| 292 // Actual client login handler. | 304 // Actual client login handler. |
| 293 scoped_ptr<GaiaAuthFetcher> client_login_; | 305 scoped_ptr<GaiaAuthFetcher> client_login_; |
| 294 | 306 |
| 295 // Registrar for notifications from the TokenService. | 307 // Registrar for notifications from the TokenService. |
| 296 content::NotificationRegistrar registrar_; | 308 content::NotificationRegistrar registrar_; |
| 297 | 309 |
| 298 // UbertokenFetcher to login to user to the web property. | 310 // UbertokenFetcher to login to user to the web property. |
| 299 scoped_ptr<UbertokenFetcher> ubertoken_fetcher_; | 311 scoped_ptr<UbertokenFetcher> ubertoken_fetcher_; |
| 300 | 312 |
| 301 // Helper object to listen for changes to signin preferences stored in non- | 313 // Helper object to listen for changes to signin preferences stored in non- |
| 302 // profile-specific local prefs (like kGoogleServicesUsernamePattern). | 314 // profile-specific local prefs (like kGoogleServicesUsernamePattern). |
| 303 PrefChangeRegistrar local_state_pref_registrar_; | 315 PrefChangeRegistrar local_state_pref_registrar_; |
| 304 | 316 |
| 317 // Helper object to listen for changes to the signin allowed preference. |
| 318 BooleanPrefMember signin_allowed_; |
| 319 |
| 305 // Actual username after successful authentication. | 320 // Actual username after successful authentication. |
| 306 std::string authenticated_username_; | 321 std::string authenticated_username_; |
| 307 | 322 |
| 308 // The type of sign being performed. This value is valid only between a call | 323 // The type of sign being performed. This value is valid only between a call |
| 309 // to one of the StartSigninXXX methods and when the sign in is either | 324 // to one of the StartSigninXXX methods and when the sign in is either |
| 310 // successful or not. | 325 // successful or not. |
| 311 SigninType type_; | 326 SigninType type_; |
| 312 | 327 |
| 313 // Temporarily saves the oauth2 refresh and access tokens when signing in | 328 // Temporarily saves the oauth2 refresh and access tokens when signing in |
| 314 // with credentials. These will be passed to TokenService so that it does | 329 // with credentials. These will be passed to TokenService so that it does |
| (...skipping 10 matching lines...) Expand all Loading... |
| 325 #if defined(ENABLE_CONFIGURATION_POLICY) && !defined(OS_CHROMEOS) | 340 #if defined(ENABLE_CONFIGURATION_POLICY) && !defined(OS_CHROMEOS) |
| 326 // CloudPolicyClient reference we keep while determining whether to create | 341 // CloudPolicyClient reference we keep while determining whether to create |
| 327 // a new profile for an enterprise user or not. | 342 // a new profile for an enterprise user or not. |
| 328 scoped_ptr<policy::CloudPolicyClient> policy_client_; | 343 scoped_ptr<policy::CloudPolicyClient> policy_client_; |
| 329 #endif | 344 #endif |
| 330 | 345 |
| 331 DISALLOW_COPY_AND_ASSIGN(SigninManager); | 346 DISALLOW_COPY_AND_ASSIGN(SigninManager); |
| 332 }; | 347 }; |
| 333 | 348 |
| 334 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_H_ | 349 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_H_ |
| OLD | NEW |