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. See SigninManagerBase for full description of | 6 // which user is signed in. See SigninManagerBase for full description of |
7 // responsibilities. The class defined in this file provides functionality | 7 // responsibilities. The class defined in this file provides functionality |
8 // required by all platforms except Chrome OS. | 8 // required by all platforms except Chrome OS. |
9 // | 9 // |
10 // When a user is signed in, a ClientLogin request is run on their behalf. | 10 // When a user is signed in, a ClientLogin request is run on their behalf. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 // This is used to distinguish URLs belonging to the special web signin flow | 66 // This is used to distinguish URLs belonging to the special web signin flow |
67 // running in the special signin process from other URLs on the same domain. | 67 // running in the special signin process from other URLs on the same domain. |
68 // We do not grant WebUI privilieges / bindings to this process or to URLs of | 68 // We do not grant WebUI privilieges / bindings to this process or to URLs of |
69 // this scheme; enforcement of privileges is handled separately by | 69 // this scheme; enforcement of privileges is handled separately by |
70 // OneClickSigninHelper. | 70 // OneClickSigninHelper. |
71 static const char* kChromeSigninEffectiveSite; | 71 static const char* kChromeSigninEffectiveSite; |
72 | 72 |
73 explicit SigninManager(scoped_ptr<SigninManagerDelegate> delegate); | 73 explicit SigninManager(scoped_ptr<SigninManagerDelegate> delegate); |
74 virtual ~SigninManager(); | 74 virtual ~SigninManager(); |
75 | 75 |
| 76 // Returns true if the username is allowed based on the policy string. |
| 77 static bool IsUsernameAllowedByPolicy(const std::string& username, |
| 78 const std::string& policy); |
| 79 |
76 // Attempt to sign in this user with ClientLogin. If successful, set a | 80 // Attempt to sign in this user with ClientLogin. If successful, set a |
77 // preference indicating the signed in user and send out a notification, | 81 // preference indicating the signed in user and send out a notification, |
78 // then start fetching tokens for the user. | 82 // then start fetching tokens for the user. |
79 // This is overridden for test subclasses that don't want to issue auth | 83 // This is overridden for test subclasses that don't want to issue auth |
80 // requests. | 84 // requests. |
81 virtual void StartSignIn(const std::string& username, | 85 virtual void StartSignIn(const std::string& username, |
82 const std::string& password, | 86 const std::string& password, |
83 const std::string& login_token, | 87 const std::string& login_token, |
84 const std::string& login_captcha); | 88 const std::string& login_captcha); |
85 | 89 |
(...skipping 17 matching lines...) Expand all Loading... |
103 const std::string& password, | 107 const std::string& password, |
104 const OAuthTokenFetchedCallback& oauth_fetched_callback); | 108 const OAuthTokenFetchedCallback& oauth_fetched_callback); |
105 | 109 |
106 // Copies auth credentials from one SigninManager to this one. This is used | 110 // Copies auth credentials from one SigninManager to this one. This is used |
107 // when creating a new profile during the signin process to transfer the | 111 // when creating a new profile during the signin process to transfer the |
108 // in-progress credentials to the new profile. | 112 // in-progress credentials to the new profile. |
109 virtual void CopyCredentialsFrom(const SigninManager& source); | 113 virtual void CopyCredentialsFrom(const SigninManager& source); |
110 | 114 |
111 // Sign a user out, removing the preference, erasing all keys | 115 // Sign a user out, removing the preference, erasing all keys |
112 // associated with the user, and canceling all auth in progress. | 116 // associated with the user, and canceling all auth in progress. |
113 virtual void SignOut() OVERRIDE; | 117 virtual void SignOut(); |
| 118 |
| 119 // On platforms where SigninManager is responsible for dealing with |
| 120 // invalid username policy updates, we need to check this during |
| 121 // initialization and sign the user out. |
| 122 virtual void Initialize(Profile* profile) OVERRIDE; |
114 | 123 |
115 // Invoked from an OAuthTokenFetchedCallback to complete user signin. | 124 // Invoked from an OAuthTokenFetchedCallback to complete user signin. |
116 virtual void CompletePendingSignin(); | 125 virtual void CompletePendingSignin(); |
117 | 126 |
118 // Returns true if there's a signin in progress. | 127 // Returns true if there's a signin in progress. |
119 virtual bool AuthInProgress() const OVERRIDE; | 128 virtual bool AuthInProgress() const OVERRIDE; |
120 | 129 |
| 130 virtual bool IsSigninAllowed() const OVERRIDE; |
| 131 |
| 132 // Returns true if the passed username is allowed by policy. Virtual for |
| 133 // mocking in tests. |
| 134 virtual bool IsAllowedUsername(const std::string& username) const; |
| 135 |
121 // If an authentication is in progress, return the username being | 136 // If an authentication is in progress, return the username being |
122 // authenticated. Returns an empty string if no auth is in progress. | 137 // authenticated. Returns an empty string if no auth is in progress. |
123 const std::string& GetUsernameForAuthInProgress() const; | 138 const std::string& GetUsernameForAuthInProgress() const; |
124 | 139 |
125 // Handles errors if a required user info key is not returned from the | 140 // Handles errors if a required user info key is not returned from the |
126 // GetUserInfo call. | 141 // GetUserInfo call. |
127 void OnGetUserInfoKeyNotFound(const std::string& key); | 142 void OnGetUserInfoKeyNotFound(const std::string& key); |
128 | 143 |
129 // Set the profile preference to turn off one-click sign-in so that it won't | 144 // Set the profile preference to turn off one-click sign-in so that it won't |
130 // ever show it again in this profile (even if the user tries a new account). | 145 // ever show it again in this profile (even if the user tries a new account). |
(...skipping 22 matching lines...) Expand all Loading... |
153 | 168 |
154 | 169 |
155 // Tells the SigninManager whether to prohibit signout for this profile. | 170 // Tells the SigninManager whether to prohibit signout for this profile. |
156 // If |prohibit_signout| is true, then signout will be prohibited. | 171 // If |prohibit_signout| is true, then signout will be prohibited. |
157 void ProhibitSignout(bool prohibit_signout); | 172 void ProhibitSignout(bool prohibit_signout); |
158 | 173 |
159 // If true, signout is prohibited for this profile (calls to SignOut() are | 174 // If true, signout is prohibited for this profile (calls to SignOut() are |
160 // ignored). | 175 // ignored). |
161 bool IsSignoutProhibited() const; | 176 bool IsSignoutProhibited() const; |
162 | 177 |
| 178 // Checks if signin is allowed for the profile that owns |io_data|. This must |
| 179 // be invoked on the IO thread, and can be used to check if signin is enabled |
| 180 // on that thread. |
| 181 static bool IsSigninAllowedOnIOThread(ProfileIOData* io_data); |
| 182 |
163 // Allows the SigninManager to track the privileged signin process | 183 // Allows the SigninManager to track the privileged signin process |
164 // identified by |process_id| so that we can later ask (via IsSigninProcess) | 184 // identified by |process_id| so that we can later ask (via IsSigninProcess) |
165 // if it is safe to sign the user in from the current context (see | 185 // if it is safe to sign the user in from the current context (see |
166 // OneClickSigninHelper). All of this tracking state is reset once the | 186 // OneClickSigninHelper). All of this tracking state is reset once the |
167 // renderer process terminates. | 187 // renderer process terminates. |
168 void SetSigninProcess(int process_id); | 188 void SetSigninProcess(int process_id); |
169 bool IsSigninProcess(int process_id) const; | 189 bool IsSigninProcess(int process_id) const; |
170 bool HasSigninProcess() const; | 190 bool HasSigninProcess() const; |
171 | 191 |
172 protected: | 192 protected: |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 // Called to handle an error from a GAIA auth fetch. Sets the last error | 236 // Called to handle an error from a GAIA auth fetch. Sets the last error |
217 // to |error|, sends out a notification of login failure, and clears the | 237 // to |error|, sends out a notification of login failure, and clears the |
218 // transient signin data if |clear_transient_data| is true. | 238 // transient signin data if |clear_transient_data| is true. |
219 void HandleAuthError(const GoogleServiceAuthError& error, | 239 void HandleAuthError(const GoogleServiceAuthError& error, |
220 bool clear_transient_data); | 240 bool clear_transient_data); |
221 | 241 |
222 // Called to tell GAIA that we will no longer be using the current refresh | 242 // Called to tell GAIA that we will no longer be using the current refresh |
223 // token. | 243 // token. |
224 void RevokeOAuthLoginToken(); | 244 void RevokeOAuthLoginToken(); |
225 | 245 |
| 246 void OnSigninAllowedPrefChanged(); |
| 247 void OnGoogleServicesUsernamePatternChanged(); |
| 248 |
226 // ClientLogin identity. | 249 // ClientLogin identity. |
227 std::string possibly_invalid_username_; | 250 std::string possibly_invalid_username_; |
228 std::string password_; // This is kept empty whenever possible. | 251 std::string password_; // This is kept empty whenever possible. |
229 bool had_two_factor_error_; | 252 bool had_two_factor_error_; |
230 | 253 |
231 void CleanupNotificationRegistration(); | 254 void CleanupNotificationRegistration(); |
232 | 255 |
233 // Result of the last client login, kept pending the lookup of the | 256 // Result of the last client login, kept pending the lookup of the |
234 // canonical email. | 257 // canonical email. |
235 ClientLoginResult last_result_; | 258 ClientLoginResult last_result_; |
(...skipping 25 matching lines...) Expand all Loading... |
261 // See SetSigninProcess. Tracks the currently active signin process | 284 // See SetSigninProcess. Tracks the currently active signin process |
262 // by ID, if there is one. | 285 // by ID, if there is one. |
263 int signin_process_id_; | 286 int signin_process_id_; |
264 | 287 |
265 // Callback invoked during signin after an OAuth token has been fetched | 288 // Callback invoked during signin after an OAuth token has been fetched |
266 // but before signin is complete. | 289 // but before signin is complete. |
267 OAuthTokenFetchedCallback oauth_token_fetched_callback_; | 290 OAuthTokenFetchedCallback oauth_token_fetched_callback_; |
268 | 291 |
269 scoped_ptr<SigninManagerDelegate> delegate_; | 292 scoped_ptr<SigninManagerDelegate> delegate_; |
270 | 293 |
| 294 // Helper object to listen for changes to signin preferences stored in non- |
| 295 // profile-specific local prefs (like kGoogleServicesUsernamePattern). |
| 296 PrefChangeRegistrar local_state_pref_registrar_; |
| 297 |
| 298 // Helper object to listen for changes to the signin allowed preference. |
| 299 BooleanPrefMember signin_allowed_; |
| 300 |
271 DISALLOW_COPY_AND_ASSIGN(SigninManager); | 301 DISALLOW_COPY_AND_ASSIGN(SigninManager); |
272 }; | 302 }; |
273 | 303 |
274 #endif // !defined(OS_CHROMEOS) | 304 #endif // !defined(OS_CHROMEOS) |
275 | 305 |
276 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_H_ | 306 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_H_ |
OLD | NEW |