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

Side by Side Diff: components/signin/core/browser/signin_manager.h

Issue 964563002: Replace SetAuthenticatedUsername with SetAuthenticatedAccountId. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@priv
Patch Set: Fix gaia-id Created 5 years, 8 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 24 matching lines...) Expand all
35 #include "components/signin/core/browser/account_tracker_service.h" 35 #include "components/signin/core/browser/account_tracker_service.h"
36 #include "components/signin/core/browser/signin_internals_util.h" 36 #include "components/signin/core/browser/signin_internals_util.h"
37 #include "components/signin/core/browser/signin_manager_base.h" 37 #include "components/signin/core/browser/signin_manager_base.h"
38 #include "components/signin/core/browser/signin_metrics.h" 38 #include "components/signin/core/browser/signin_metrics.h"
39 #include "net/cookies/canonical_cookie.h" 39 #include "net/cookies/canonical_cookie.h"
40 40
41 class GaiaCookieManagerService; 41 class GaiaCookieManagerService;
42 class GoogleServiceAuthError; 42 class GoogleServiceAuthError;
43 class PrefService; 43 class PrefService;
44 class ProfileOAuth2TokenService; 44 class ProfileOAuth2TokenService;
45 class SigninAccountIdHelper;
46 class SigninClient; 45 class SigninClient;
47 46
48 class SigninManager : public SigninManagerBase, 47 class SigninManager : public SigninManagerBase,
49 public AccountTrackerService::Observer { 48 public AccountTrackerService::Observer {
50 public: 49 public:
51 // The callback invoked once the OAuth token has been fetched during signin, 50 // The callback invoked once the OAuth token has been fetched during signin,
52 // but before the profile transitions to the "signed-in" state. This allows 51 // but before the profile transitions to the "signed-in" state. This allows
53 // callers to load policy and prompt the user appropriately before completing 52 // callers to load policy and prompt the user appropriately before completing
54 // signin. The callback is passed the just-fetched OAuth login refresh token. 53 // signin. The callback is passed the just-fetched OAuth login refresh token.
55 typedef base::Callback<void(const std::string&)> OAuthTokenFetchedCallback; 54 typedef base::Callback<void(const std::string&)> OAuthTokenFetchedCallback;
(...skipping 15 matching lines...) Expand all
71 static bool IsUsernameAllowedByPolicy(const std::string& username, 70 static bool IsUsernameAllowedByPolicy(const std::string& username,
72 const std::string& policy); 71 const std::string& policy);
73 72
74 // Attempt to sign in this user with a refresh token. 73 // Attempt to sign in this user with a refresh token.
75 // If non-null, the passed |oauth_fetched_callback| callback is invoked once 74 // If non-null, the passed |oauth_fetched_callback| callback is invoked once
76 // signin has been completed. 75 // signin has been completed.
77 // The callback should invoke SignOut() or CompletePendingSignin() to either 76 // The callback should invoke SignOut() or CompletePendingSignin() to either
78 // continue or cancel the in-process signin. 77 // continue or cancel the in-process signin.
79 virtual void StartSignInWithRefreshToken( 78 virtual void StartSignInWithRefreshToken(
80 const std::string& refresh_token, 79 const std::string& refresh_token,
80 const std::string& gaia_id,
81 const std::string& username, 81 const std::string& username,
82 const std::string& password, 82 const std::string& password,
83 const OAuthTokenFetchedCallback& oauth_fetched_callback); 83 const OAuthTokenFetchedCallback& oauth_fetched_callback);
84 84
85 // Copies auth credentials from one SigninManager to this one. This is used 85 // Copies auth credentials from one SigninManager to this one. This is used
86 // when creating a new profile during the signin process to transfer the 86 // when creating a new profile during the signin process to transfer the
87 // in-progress credentials to the new profile. 87 // in-progress credentials to the new profile.
88 virtual void CopyCredentialsFrom(const SigninManager& source); 88 virtual void CopyCredentialsFrom(const SigninManager& source);
89 89
90 // Sign a user out, removing the preference, erasing all keys 90 // Sign a user out, removing the preference, erasing all keys
91 // associated with the user, and canceling all auth in progress. 91 // associated with the user, and canceling all auth in progress.
92 virtual void SignOut(signin_metrics::ProfileSignout signout_source_metric); 92 virtual void SignOut(signin_metrics::ProfileSignout signout_source_metric);
93 93
94 // On platforms where SigninManager is responsible for dealing with 94 // On platforms where SigninManager is responsible for dealing with
95 // invalid username policy updates, we need to check this during 95 // invalid username policy updates, we need to check this during
96 // initialization and sign the user out. 96 // initialization and sign the user out.
97 void Initialize(PrefService* local_state) override; 97 void Initialize(PrefService* local_state) override;
98 void Shutdown() override; 98 void Shutdown() override;
99 99
100 // If applicable, merge the signed in account into the cookie jar. 100 // If applicable, merge the signed in account into the cookie jar.
101 void MergeSigninCredentialIntoCookieJar(); 101 void MergeSigninCredentialIntoCookieJar();
102 102
103 // Invoked from an OAuthTokenFetchedCallback to complete user signin. 103 // Invoked from an OAuthTokenFetchedCallback to complete user signin.
104 virtual void CompletePendingSignin(); 104 virtual void CompletePendingSignin();
105 105
106 // Invoked from SigninManagerAndroid to indicate that the sign-in process 106 // Invoked from SigninManagerAndroid to indicate that the sign-in process
107 // has completed for |username|. 107 // has completed for the email |username|. SigninManager assumes that
108 // |username| can be used to look up the corresponding account_id and gaia_id
109 // for this email.
108 void OnExternalSigninCompleted(const std::string& username); 110 void OnExternalSigninCompleted(const std::string& username);
109 111
110 // Returns true if there's a signin in progress. 112 // Returns true if there's a signin in progress.
111 bool AuthInProgress() const override; 113 bool AuthInProgress() const override;
112 114
113 bool IsSigninAllowed() const override; 115 bool IsSigninAllowed() const override;
114 116
115 // Returns true if the passed username is allowed by policy. Virtual for 117 // Returns true if the passed username is allowed by policy. Virtual for
116 // mocking in tests. 118 // mocking in tests.
117 virtual bool IsAllowedUsername(const std::string& username) const; 119 virtual bool IsAllowedUsername(const std::string& username) const;
118 120
121 // If an authentication is in progress, return the account id being
122 // authenticated. Returns an empty string if no auth is in progress.
123 const std::string& GetAccountIdForAuthInProgress() const;
124
119 // If an authentication is in progress, return the username being 125 // If an authentication is in progress, return the username being
120 // authenticated. Returns an empty string if no auth is in progress. 126 // authenticated. Returns an empty string if no auth is in progress.
121 const std::string& GetUsernameForAuthInProgress() const; 127 const std::string& GetUsernameForAuthInProgress() const;
122 128
123 // Set the preference to turn off one-click sign-in so that it won't ever 129 // Set the preference to turn off one-click sign-in so that it won't ever
124 // show it again for the user associated with |prefs| (even if the user tries 130 // show it again for the user associated with |prefs| (even if the user tries
125 // a new account). 131 // a new account).
126 static void DisableOneClickSignIn(PrefService* prefs); 132 static void DisableOneClickSignIn(PrefService* prefs);
127 133
128 // Tells the SigninManager whether to prohibit signout for this profile. 134 // Tells the SigninManager whether to prohibit signout for this profile.
(...skipping 17 matching lines...) Expand all
146 FRIEND_TEST_ALL_PREFIXES(SigninManagerTest, ProvideSecondFactorSuccess); 152 FRIEND_TEST_ALL_PREFIXES(SigninManagerTest, ProvideSecondFactorSuccess);
147 FRIEND_TEST_ALL_PREFIXES(SigninManagerTest, ProvideSecondFactorFailure); 153 FRIEND_TEST_ALL_PREFIXES(SigninManagerTest, ProvideSecondFactorFailure);
148 154
149 // If user was signed in, load tokens from DB if available. 155 // If user was signed in, load tokens from DB if available.
150 void InitTokenService(); 156 void InitTokenService();
151 157
152 // Called to setup the transient signin data during one of the 158 // Called to setup the transient signin data during one of the
153 // StartSigninXXX methods. |type| indicates which of the methods is being 159 // StartSigninXXX methods. |type| indicates which of the methods is being
154 // used to perform the signin while |username| and |password| identify the 160 // used to perform the signin while |username| and |password| identify the
155 // account to be signed in. Returns false and generates an auth error if the 161 // account to be signed in. Returns false and generates an auth error if the
156 // passed |username| is not allowed by policy. 162 // passed |username| is not allowed by policy. |gaia_id| is the obfuscated
163 // gaia id corresponding to |username|.
157 bool PrepareForSignin(SigninType type, 164 bool PrepareForSignin(SigninType type,
165 const std::string& gaia_id,
158 const std::string& username, 166 const std::string& username,
159 const std::string& password); 167 const std::string& password);
160 168
161 // Persists |username| as the currently signed-in account, and triggers 169 // Persists |account_id| as the currently signed-in account, and triggers
162 // a sign-in success notification. 170 // a sign-in success notification.
163 void OnSignedIn(const std::string& username); 171 void OnSignedIn();
164 172
165 // Waits for the AccountTrackerService, then sends GoogleSigninSucceeded to 173 // Waits for the AccountTrackerService, then sends GoogleSigninSucceeded to
166 // the client and clears the local password. 174 // the client and clears the local password.
167 void PostSignedIn(); 175 void PostSignedIn();
168 176
169 // AccountTrackerService::Observer implementation. 177 // AccountTrackerService::Observer implementation.
170 void OnAccountUpdated(const AccountTrackerService::AccountInfo& info) 178 void OnAccountUpdated(const AccountTrackerService::AccountInfo& info)
171 override; 179 override;
172 void OnAccountUpdateFailed(const std::string& account_id) override; 180 void OnAccountUpdateFailed(const std::string& account_id) override;
173 181
174 // Called when a new request to re-authenticate a user is in progress. 182 // Called when a new request to re-authenticate a user is in progress.
175 // Will clear in memory data but leaves the db as such so when the browser 183 // Will clear in memory data but leaves the db as such so when the browser
176 // restarts we can use the old token(which might throw a password error). 184 // restarts we can use the old token(which might throw a password error).
177 void ClearTransientSigninData(); 185 void ClearTransientSigninData();
178 186
179 // Called to handle an error from a GAIA auth fetch. Sets the last error 187 // Called to handle an error from a GAIA auth fetch. Sets the last error
180 // to |error|, sends out a notification of login failure and clears the 188 // to |error|, sends out a notification of login failure and clears the
181 // transient signin data. 189 // transient signin data.
182 void HandleAuthError(const GoogleServiceAuthError& error); 190 void HandleAuthError(const GoogleServiceAuthError& error);
183 191
184 void OnSigninAllowedPrefChanged(); 192 void OnSigninAllowedPrefChanged();
185 void OnGoogleServicesUsernamePatternChanged(); 193 void OnGoogleServicesUsernamePatternChanged();
186 194
187 // ClientLogin identity. 195 std::string possibly_invalid_account_id_;
188 std::string possibly_invalid_username_; 196 std::string possibly_invalid_gaia_id_;
197 std::string possibly_invalid_email_;
189 std::string password_; // This is kept empty whenever possible. 198 std::string password_; // This is kept empty whenever possible.
190 199
191 // Fetcher for the obfuscated user id.
192 scoped_ptr<SigninAccountIdHelper> account_id_helper_;
193
194 // The type of sign being performed. This value is valid only between a call 200 // The type of sign being performed. This value is valid only between a call
195 // to one of the StartSigninXXX methods and when the sign in is either 201 // to one of the StartSigninXXX methods and when the sign in is either
196 // successful or not. 202 // successful or not.
197 SigninType type_; 203 SigninType type_;
198 204
199 // Temporarily saves the oauth2 refresh token. It will be passed to the 205 // Temporarily saves the oauth2 refresh token. It will be passed to the
200 // token service so that it does not need to mint new ones. 206 // token service so that it does not need to mint new ones.
201 std::string temp_refresh_token_; 207 std::string temp_refresh_token_;
202 208
203 // The SigninClient object associated with this object. Must outlive this 209 // The SigninClient object associated with this object. Must outlive this
204 // object. 210 // object.
205 SigninClient* client_; 211 SigninClient* client_;
206 212
207 // The ProfileOAuth2TokenService instance associated with this object. Must 213 // The ProfileOAuth2TokenService instance associated with this object. Must
208 // outlive this object. 214 // outlive this object.
209 ProfileOAuth2TokenService* token_service_; 215 ProfileOAuth2TokenService* token_service_;
210 216
211 // The AccountTrackerService instance associated with this object. Must
212 // outlive this object.
213 AccountTrackerService* account_tracker_service_;
214
215 // Object used to use the token to push a GAIA cookie into the cookie jar. 217 // Object used to use the token to push a GAIA cookie into the cookie jar.
216 GaiaCookieManagerService* cookie_manager_service_; 218 GaiaCookieManagerService* cookie_manager_service_;
217 219
218 // Helper object to listen for changes to signin preferences stored in non- 220 // Helper object to listen for changes to signin preferences stored in non-
219 // profile-specific local prefs (like kGoogleServicesUsernamePattern). 221 // profile-specific local prefs (like kGoogleServicesUsernamePattern).
220 PrefChangeRegistrar local_state_pref_registrar_; 222 PrefChangeRegistrar local_state_pref_registrar_;
221 223
222 // Helper object to listen for changes to the signin allowed preference. 224 // Helper object to listen for changes to the signin allowed preference.
223 BooleanPrefMember signin_allowed_; 225 BooleanPrefMember signin_allowed_;
224 226
225 // Two gate conditions for when PostSignedIn should be called. Verify 227 // Two gate conditions for when PostSignedIn should be called. Verify
226 // that the SigninManager has reached OnSignedIn() and the AccountTracker 228 // that the SigninManager has reached OnSignedIn() and the AccountTracker
227 // has completed calling GetUserInfo. 229 // has completed calling GetUserInfo.
228 bool signin_manager_signed_in_; 230 bool signin_manager_signed_in_;
229 bool user_info_fetched_by_account_tracker_; 231 bool user_info_fetched_by_account_tracker_;
230 232
231 base::WeakPtrFactory<SigninManager> weak_pointer_factory_; 233 base::WeakPtrFactory<SigninManager> weak_pointer_factory_;
232 234
233 DISALLOW_COPY_AND_ASSIGN(SigninManager); 235 DISALLOW_COPY_AND_ASSIGN(SigninManager);
234 }; 236 };
235 237
236 #endif // !defined(OS_CHROMEOS) 238 #endif // !defined(OS_CHROMEOS)
237 239
238 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_MANAGER_H_ 240 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698