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

Side by Side Diff: chrome/browser/signin/signin_manager.h

Issue 12088040: Add a SigninAllowed policy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Some bugfixes. Created 7 years, 10 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) 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_keyed_service.h" 29 #include "chrome/browser/profiles/profile_keyed_service.h"
29 #include "chrome/browser/signin/signin_internals_util.h" 30 #include "chrome/browser/signin/signin_internals_util.h"
31 #include "chrome/browser/signin/signin_pref_observer.h"
30 #include "content/public/browser/notification_observer.h" 32 #include "content/public/browser/notification_observer.h"
31 #include "content/public/browser/notification_registrar.h" 33 #include "content/public/browser/notification_registrar.h"
32 #include "google_apis/gaia/gaia_auth_consumer.h" 34 #include "google_apis/gaia/gaia_auth_consumer.h"
33 #include "google_apis/gaia/google_service_auth_error.h" 35 #include "google_apis/gaia/google_service_auth_error.h"
34 #include "net/cookies/canonical_cookie.h" 36 #include "net/cookies/canonical_cookie.h"
35 37
36 class CookieSettings; 38 class CookieSettings;
37 class GaiaAuthFetcher; 39 class GaiaAuthFetcher;
38 class Profile; 40 class Profile;
41 class ProfileIOData;
39 class PrefService; 42 class PrefService;
40 class SigninGlobalError; 43 class SigninGlobalError;
41 44
42 // Details for the Notification type GOOGLE_SIGNIN_SUCCESSFUL. 45 // Details for the Notification type GOOGLE_SIGNIN_SUCCESSFUL.
43 // A listener might use this to make note of a username / password 46 // A listener might use this to make note of a username / password
44 // pair for encryption keys. 47 // pair for encryption keys.
45 struct GoogleServiceSigninSuccessDetails { 48 struct GoogleServiceSigninSuccessDetails {
46 GoogleServiceSigninSuccessDetails(const std::string& in_username, 49 GoogleServiceSigninSuccessDetails(const std::string& in_username,
47 const std::string& in_password) 50 const std::string& in_password)
48 : username(in_username), 51 : username(in_username),
(...skipping 12 matching lines...) Expand all
61 class SigninManager : public GaiaAuthConsumer, 64 class SigninManager : public GaiaAuthConsumer,
62 public content::NotificationObserver, 65 public content::NotificationObserver,
63 public ProfileKeyedService { 66 public ProfileKeyedService {
64 public: 67 public:
65 // Methods to register or remove SigninDiagnosticObservers 68 // Methods to register or remove SigninDiagnosticObservers
66 void AddSigninDiagnosticsObserver( 69 void AddSigninDiagnosticsObserver(
67 signin_internals_util::SigninDiagnosticsObserver* observer); 70 signin_internals_util::SigninDiagnosticsObserver* observer);
68 void RemoveSigninDiagnosticsObserver( 71 void RemoveSigninDiagnosticsObserver(
69 signin_internals_util::SigninDiagnosticsObserver* observer); 72 signin_internals_util::SigninDiagnosticsObserver* observer);
70 73
74 // Functions for adding and removing SigninPrefObservers.
75 void AddSigninPrefObserver(SigninPrefObserver* signin_pref_observer);
76 void RemoveSigninPrefObserver(SigninPrefObserver* signin_pref_observer);
77
71 // Returns true if the cookie policy for the given profile allows cookies 78 // Returns true if the cookie policy for the given profile allows cookies
72 // for the Google signin domain. 79 // for the Google signin domain.
73 static bool AreSigninCookiesAllowed(Profile* profile); 80 static bool AreSigninCookiesAllowed(Profile* profile);
74 static bool AreSigninCookiesAllowed(CookieSettings* cookie_settings); 81 static bool AreSigninCookiesAllowed(CookieSettings* cookie_settings);
75 82
76 // Returns true if the username is allowed based on the policy string. 83 // Returns true if the username is allowed based on the policy string.
77 static bool IsAllowedUsername(const std::string& username, 84 static bool IsAllowedUsername(const std::string& username,
78 const std::string& policy); 85 const std::string& policy);
79 86
80 SigninManager(); 87 SigninManager();
81 virtual ~SigninManager(); 88 virtual ~SigninManager();
82 89
83 // If user was signed in, load tokens from DB if available. 90 // If user was signed in, load tokens from DB if available.
84 void Initialize(Profile* profile); 91 void Initialize(Profile* profile);
85 bool IsInitialized() const; 92 bool IsInitialized() const;
86 93
87 // Returns true if the passed username is allowed by policy. Virtual for 94 // Returns true if the passed username is allowed by policy. Virtual for
88 // mocking in tests. 95 // mocking in tests.
89 virtual bool IsAllowedUsername(const std::string& username) const; 96 virtual bool IsAllowedUsername(const std::string& username) const;
90 97
98 // Returns true if a signin to Chrome is allowed (by policy or pref).
99 bool IsSigninAllowed() const;
100
101 // Checks if signin is allowed for the profile that owns |io_data|. This must
102 // be invoked on the IO thread, and can be used to check if signin is enabled
103 // on that thread.
104 static bool IsSigninAllowedOnIOThread(ProfileIOData* io_data);
105
91 // If a user has previously established a username and SignOut has not been 106 // If a user has previously established a username and SignOut has not been
92 // called, this will return the username. 107 // called, this will return the username.
93 // Otherwise, it will return an empty string. 108 // Otherwise, it will return an empty string.
94 const std::string& GetAuthenticatedUsername() const; 109 const std::string& GetAuthenticatedUsername() const;
95 110
96 // Sets the user name. Note: |username| should be already authenticated as 111 // Sets the user name. Note: |username| should be already authenticated as
97 // this is a sticky operation (in contrast to StartSignIn). 112 // this is a sticky operation (in contrast to StartSignIn).
98 // TODO(tim): Remove this in favor of passing username on construction by 113 // TODO(tim): Remove this in favor of passing username on construction by
99 // (by platform / depending on StartBehavior). Bug 88109. 114 // (by platform / depending on StartBehavior). Bug 88109.
100 void SetAuthenticatedUsername(const std::string& username); 115 void SetAuthenticatedUsername(const std::string& username);
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 249
235 // ClientLogin identity. 250 // ClientLogin identity.
236 std::string possibly_invalid_username_; 251 std::string possibly_invalid_username_;
237 std::string password_; // This is kept empty whenever possible. 252 std::string password_; // This is kept empty whenever possible.
238 bool had_two_factor_error_; 253 bool had_two_factor_error_;
239 254
240 void CleanupNotificationRegistration(); 255 void CleanupNotificationRegistration();
241 256
242 void OnGoogleServicesUsernamePatternChanged(); 257 void OnGoogleServicesUsernamePatternChanged();
243 258
259 void OnSigninAllowedPrefChanged();
260
244 // Helper methods to notify all registered diagnostics observers with. 261 // Helper methods to notify all registered diagnostics observers with.
245 void NotifyDiagnosticsObservers( 262 void NotifyDiagnosticsObservers(
246 const signin_internals_util::UntimedSigninStatusField& field, 263 const signin_internals_util::UntimedSigninStatusField& field,
247 const std::string& value); 264 const std::string& value);
248 void NotifyDiagnosticsObservers( 265 void NotifyDiagnosticsObservers(
249 const signin_internals_util::TimedSigninStatusField& field, 266 const signin_internals_util::TimedSigninStatusField& field,
250 const std::string& value); 267 const std::string& value);
251 268
252 // Result of the last client login, kept pending the lookup of the 269 // Result of the last client login, kept pending the lookup of the
253 // canonical email. 270 // canonical email.
254 ClientLoginResult last_result_; 271 ClientLoginResult last_result_;
255 272
256 // Actual client login handler. 273 // Actual client login handler.
257 scoped_ptr<GaiaAuthFetcher> client_login_; 274 scoped_ptr<GaiaAuthFetcher> client_login_;
258 275
259 // Registrar for notifications from the TokenService. 276 // Registrar for notifications from the TokenService.
260 content::NotificationRegistrar registrar_; 277 content::NotificationRegistrar registrar_;
261 278
262 // Helper object to listen for changes to signin preferences stored in non- 279 // Helper object to listen for changes to signin preferences stored in non-
263 // profile-specific local prefs (like kGoogleServicesUsernamePattern). 280 // profile-specific local prefs (like kGoogleServicesUsernamePattern).
264 PrefChangeRegistrar local_state_pref_registrar_; 281 PrefChangeRegistrar local_state_pref_registrar_;
265 282
283 // Helper object to listen for changes to the signin allowed preference.
284 BooleanPrefMember signin_allowed_;
285
266 // Actual username after successful authentication. 286 // Actual username after successful authentication.
267 std::string authenticated_username_; 287 std::string authenticated_username_;
268 288
269 // The type of sign being performed. This value is valid only between a call 289 // The type of sign being performed. This value is valid only between a call
270 // to one of the StartSigninXXX methods and when the sign in is either 290 // to one of the StartSigninXXX methods and when the sign in is either
271 // successful or not. 291 // successful or not.
272 SigninType type_; 292 SigninType type_;
273 293
274 // Temporarily saves the oauth2 refresh and access tokens when signing in 294 // Temporarily saves the oauth2 refresh and access tokens when signing in
275 // with credentials. These will be passed to TokenService so that it does 295 // with credentials. These will be passed to TokenService so that it does
276 // not need to mint new ones. 296 // not need to mint new ones.
277 ClientOAuthResult temp_oauth_login_tokens_; 297 ClientOAuthResult temp_oauth_login_tokens_;
278 298
279 // The list of SigninDiagnosticObservers. 299 // The list of SigninDiagnosticObservers.
280 ObserverList<signin_internals_util::SigninDiagnosticsObserver, true> 300 ObserverList<signin_internals_util::SigninDiagnosticsObserver, true>
281 signin_diagnostics_observers_; 301 signin_diagnostics_observers_;
282 302
303 // List of SigninPrefObservers.
304 ObserverList<SigninPrefObserver> signin_pref_observers_;
305
283 base::WeakPtrFactory<SigninManager> weak_pointer_factory_; 306 base::WeakPtrFactory<SigninManager> weak_pointer_factory_;
284 307
285 DISALLOW_COPY_AND_ASSIGN(SigninManager); 308 DISALLOW_COPY_AND_ASSIGN(SigninManager);
286 }; 309 };
287 310
288 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_H_ 311 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698