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

Powered by Google App Engine
This is Rietveld 408576698