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

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: Extract managed user specific stuff into another changelist. 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"
30 #include "chrome/browser/signin/ubertoken_fetcher.h" 31 #include "chrome/browser/signin/ubertoken_fetcher.h"
31 #include "content/public/browser/notification_observer.h" 32 #include "content/public/browser/notification_observer.h"
32 #include "content/public/browser/notification_registrar.h" 33 #include "content/public/browser/notification_registrar.h"
33 #include "google_apis/gaia/gaia_auth_consumer.h" 34 #include "google_apis/gaia/gaia_auth_consumer.h"
34 #include "google_apis/gaia/google_service_auth_error.h" 35 #include "google_apis/gaia/google_service_auth_error.h"
35 #include "net/cookies/canonical_cookie.h" 36 #include "net/cookies/canonical_cookie.h"
36 37
37 class CookieSettings; 38 class CookieSettings;
38 class GaiaAuthFetcher; 39 class GaiaAuthFetcher;
39 class Profile; 40 class Profile;
41 class ProfileIOData;
40 class PrefService; 42 class PrefService;
41 class SigninGlobalError; 43 class SigninGlobalError;
42 44
43 // Details for the Notification type GOOGLE_SIGNIN_SUCCESSFUL. 45 // Details for the Notification type GOOGLE_SIGNIN_SUCCESSFUL.
44 // 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
45 // pair for encryption keys. 47 // pair for encryption keys.
46 struct GoogleServiceSigninSuccessDetails { 48 struct GoogleServiceSigninSuccessDetails {
47 GoogleServiceSigninSuccessDetails(const std::string& in_username, 49 GoogleServiceSigninSuccessDetails(const std::string& in_username,
48 const std::string& in_password) 50 const std::string& in_password)
49 : username(in_username), 51 : username(in_username),
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 virtual ~SigninManager(); 85 virtual ~SigninManager();
84 86
85 // If user was signed in, load tokens from DB if available. 87 // If user was signed in, load tokens from DB if available.
86 void Initialize(Profile* profile); 88 void Initialize(Profile* profile);
87 bool IsInitialized() const; 89 bool IsInitialized() const;
88 90
89 // Returns true if the passed username is allowed by policy. Virtual for 91 // Returns true if the passed username is allowed by policy. Virtual for
90 // mocking in tests. 92 // mocking in tests.
91 virtual bool IsAllowedUsername(const std::string& username) const; 93 virtual bool IsAllowedUsername(const std::string& username) const;
92 94
95 // Returns true if a signin to Chrome is allowed (by policy or pref).
96 bool IsSigninAllowed() const;
97
98 // Checks if signin is allowed for the profile that owns |io_data|. This must
99 // be invoked on the IO thread, and can be used to check if signin is enabled
100 // on that thread.
101 static bool IsSigninAllowedOnIOThread(ProfileIOData* io_data);
102
93 // If a user has previously established a username and SignOut has not been 103 // If a user has previously established a username and SignOut has not been
94 // called, this will return the username. 104 // called, this will return the username.
95 // Otherwise, it will return an empty string. 105 // Otherwise, it will return an empty string.
96 const std::string& GetAuthenticatedUsername() const; 106 const std::string& GetAuthenticatedUsername() const;
97 107
98 // Sets the user name. Note: |username| should be already authenticated as 108 // Sets the user name. Note: |username| should be already authenticated as
99 // this is a sticky operation (in contrast to StartSignIn). 109 // this is a sticky operation (in contrast to StartSignIn).
100 // TODO(tim): Remove this in favor of passing username on construction by 110 // TODO(tim): Remove this in favor of passing username on construction by
101 // (by platform / depending on StartBehavior). Bug 88109. 111 // (by platform / depending on StartBehavior). Bug 88109.
102 void SetAuthenticatedUsername(const std::string& username); 112 void SetAuthenticatedUsername(const std::string& username);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 250
241 // ClientLogin identity. 251 // ClientLogin identity.
242 std::string possibly_invalid_username_; 252 std::string possibly_invalid_username_;
243 std::string password_; // This is kept empty whenever possible. 253 std::string password_; // This is kept empty whenever possible.
244 bool had_two_factor_error_; 254 bool had_two_factor_error_;
245 255
246 void CleanupNotificationRegistration(); 256 void CleanupNotificationRegistration();
247 257
248 void OnGoogleServicesUsernamePatternChanged(); 258 void OnGoogleServicesUsernamePatternChanged();
249 259
260 void OnSigninAllowedPrefChanged();
261
250 // Helper methods to notify all registered diagnostics observers with. 262 // Helper methods to notify all registered diagnostics observers with.
251 void NotifyDiagnosticsObservers( 263 void NotifyDiagnosticsObservers(
252 const signin_internals_util::UntimedSigninStatusField& field, 264 const signin_internals_util::UntimedSigninStatusField& field,
253 const std::string& value); 265 const std::string& value);
254 void NotifyDiagnosticsObservers( 266 void NotifyDiagnosticsObservers(
255 const signin_internals_util::TimedSigninStatusField& field, 267 const signin_internals_util::TimedSigninStatusField& field,
256 const std::string& value); 268 const std::string& value);
257 269
258 // Result of the last client login, kept pending the lookup of the 270 // Result of the last client login, kept pending the lookup of the
259 // canonical email. 271 // canonical email.
260 ClientLoginResult last_result_; 272 ClientLoginResult last_result_;
261 273
262 // Actual client login handler. 274 // Actual client login handler.
263 scoped_ptr<GaiaAuthFetcher> client_login_; 275 scoped_ptr<GaiaAuthFetcher> client_login_;
264 276
265 // Registrar for notifications from the TokenService. 277 // Registrar for notifications from the TokenService.
266 content::NotificationRegistrar registrar_; 278 content::NotificationRegistrar registrar_;
267 279
268 // UbertokenFetcher to login to user to the web property. 280 // UbertokenFetcher to login to user to the web property.
269 scoped_ptr<UbertokenFetcher> ubertoken_fetcher_; 281 scoped_ptr<UbertokenFetcher> ubertoken_fetcher_;
270 282
271 // Helper object to listen for changes to signin preferences stored in non- 283 // Helper object to listen for changes to signin preferences stored in non-
272 // profile-specific local prefs (like kGoogleServicesUsernamePattern). 284 // profile-specific local prefs (like kGoogleServicesUsernamePattern).
273 PrefChangeRegistrar local_state_pref_registrar_; 285 PrefChangeRegistrar local_state_pref_registrar_;
274 286
287 // Helper object to listen for changes to the signin allowed preference.
288 BooleanPrefMember signin_allowed_;
289
275 // Actual username after successful authentication. 290 // Actual username after successful authentication.
276 std::string authenticated_username_; 291 std::string authenticated_username_;
277 292
278 // The type of sign being performed. This value is valid only between a call 293 // The type of sign being performed. This value is valid only between a call
279 // to one of the StartSigninXXX methods and when the sign in is either 294 // to one of the StartSigninXXX methods and when the sign in is either
280 // successful or not. 295 // successful or not.
281 SigninType type_; 296 SigninType type_;
282 297
283 // Temporarily saves the oauth2 refresh and access tokens when signing in 298 // Temporarily saves the oauth2 refresh and access tokens when signing in
284 // with credentials. These will be passed to TokenService so that it does 299 // with credentials. These will be passed to TokenService so that it does
285 // not need to mint new ones. 300 // not need to mint new ones.
286 ClientOAuthResult temp_oauth_login_tokens_; 301 ClientOAuthResult temp_oauth_login_tokens_;
287 302
288 // The list of SigninDiagnosticObservers. 303 // The list of SigninDiagnosticObservers.
289 ObserverList<signin_internals_util::SigninDiagnosticsObserver, true> 304 ObserverList<signin_internals_util::SigninDiagnosticsObserver, true>
290 signin_diagnostics_observers_; 305 signin_diagnostics_observers_;
291 306
292 base::WeakPtrFactory<SigninManager> weak_pointer_factory_; 307 base::WeakPtrFactory<SigninManager> weak_pointer_factory_;
293 308
294 DISALLOW_COPY_AND_ASSIGN(SigninManager); 309 DISALLOW_COPY_AND_ASSIGN(SigninManager);
295 }; 310 };
296 311
297 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_H_ 312 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698