OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // |
| 10 // **NOTE** on semantics of SigninManager: |
| 11 // |
| 12 // Once a signin is successful, the username becomes "established" and will not |
| 13 // be cleared until a SignOut operation is performed (persists across |
| 14 // restarts). Until that happens, the signin manager can still be used to |
| 15 // refresh credentials, but changing the username is not permitted. |
9 | 16 |
10 #ifndef CHROME_BROWSER_SYNC_SIGNIN_MANAGER_H_ | 17 #ifndef CHROME_BROWSER_SYNC_SIGNIN_MANAGER_H_ |
11 #define CHROME_BROWSER_SYNC_SIGNIN_MANAGER_H_ | 18 #define CHROME_BROWSER_SYNC_SIGNIN_MANAGER_H_ |
12 #pragma once | 19 #pragma once |
13 | 20 |
14 #include <string> | 21 #include <string> |
15 | 22 |
16 #include "base/compiler_specific.h" | 23 #include "base/compiler_specific.h" |
17 #include "base/logging.h" | 24 #include "base/logging.h" |
18 #include "base/memory/scoped_ptr.h" | 25 #include "base/memory/scoped_ptr.h" |
(...skipping 26 matching lines...) Expand all Loading... |
45 SigninManager(); | 52 SigninManager(); |
46 virtual ~SigninManager(); | 53 virtual ~SigninManager(); |
47 | 54 |
48 // Call to register our prefs. | 55 // Call to register our prefs. |
49 static void RegisterUserPrefs(PrefService* user_prefs); | 56 static void RegisterUserPrefs(PrefService* user_prefs); |
50 | 57 |
51 // If user was signed in, load tokens from DB if available. | 58 // If user was signed in, load tokens from DB if available. |
52 void Initialize(Profile* profile); | 59 void Initialize(Profile* profile); |
53 bool IsInitialized() const; | 60 bool IsInitialized() const; |
54 | 61 |
55 // If a user is signed in, this will return their name. | 62 // If a user has previously established a username and SignOut has not been |
| 63 // called, this will return the username. |
56 // Otherwise, it will return an empty string. | 64 // Otherwise, it will return an empty string. |
57 const std::string& GetUsername(); | 65 const std::string& GetAuthenticatedUsername(); |
58 | 66 |
59 // Sets the user name. Used for migrating credentials from previous system. | 67 // Sets the user name. Note: |username| should be already authenticated as |
60 void SetUsername(const std::string& username); | 68 // this is a sticky operation (in contrast to StartSignIn). |
| 69 // TODO(tim): Remove this in favor of passing username on construction by |
| 70 // (by platform / depending on StartBehavior). Bug 88109. |
| 71 void SetAuthenticatedUsername(const std::string& username); |
61 | 72 |
62 // Attempt to sign in this user with OAuth. If successful, set a preference | 73 // Attempt to sign in this user with OAuth. If successful, set a preference |
63 // indicating the signed in user and send out a notification, then start | 74 // indicating the signed in user and send out a notification, then start |
64 // fetching tokens for the user. | 75 // fetching tokens for the user. |
65 virtual void StartOAuthSignIn(const std::string& oauth1_request_token); | 76 virtual void StartOAuthSignIn(const std::string& oauth1_request_token); |
66 | 77 |
67 // Attempt to sign in this user with ClientLogin. If successful, set a | 78 // Attempt to sign in this user with ClientLogin. If successful, set a |
68 // preference indicating the signed in user and send out a notification, | 79 // preference indicating the signed in user and send out a notification, |
69 // then start fetching tokens for the user. | 80 // then start fetching tokens for the user. |
70 // This is overridden for test subclasses that don't want to issue auth | 81 // This is overridden for test subclasses that don't want to issue auth |
71 // requests. | 82 // requests. |
72 virtual void StartSignIn(const std::string& username, | 83 virtual void StartSignIn(const std::string& username, |
73 const std::string& password, | 84 const std::string& password, |
74 const std::string& login_token, | 85 const std::string& login_token, |
75 const std::string& login_captcha); | 86 const std::string& login_captcha); |
76 | 87 |
77 // Used when a second factor access code was required to complete a signin | 88 // Used when a second factor access code was required to complete a signin |
78 // attempt. | 89 // attempt. |
79 void ProvideSecondFactorAccessCode(const std::string& access_code); | 90 void ProvideSecondFactorAccessCode(const std::string& access_code); |
80 | 91 |
81 // Sign a user out, removing the preference, erasing all keys | 92 // Sign a user out, removing the preference, erasing all keys |
82 // associated with the user, and canceling all auth in progress. | 93 // associated with the user, and canceling all auth in progress. |
83 void SignOut(); | 94 void SignOut(); |
84 | 95 |
85 // Called when a new request to re-authenticate a user is in progress. | |
86 // Will clear in memory data but leaves the db as such so when the browser | |
87 // restarts we can use the old token(which might throw a password error). | |
88 void ClearInMemoryData(); | |
89 | |
90 // GaiaAuthConsumer | 96 // GaiaAuthConsumer |
91 virtual void OnClientLoginSuccess(const ClientLoginResult& result) OVERRIDE; | 97 virtual void OnClientLoginSuccess(const ClientLoginResult& result) OVERRIDE; |
92 virtual void OnClientLoginFailure( | 98 virtual void OnClientLoginFailure( |
93 const GoogleServiceAuthError& error) OVERRIDE; | 99 const GoogleServiceAuthError& error) OVERRIDE; |
94 virtual void OnGetUserInfoSuccess(const std::string& key, | 100 virtual void OnGetUserInfoSuccess(const std::string& key, |
95 const std::string& value) OVERRIDE; | 101 const std::string& value) OVERRIDE; |
96 virtual void OnGetUserInfoKeyNotFound(const std::string& key) OVERRIDE; | 102 virtual void OnGetUserInfoKeyNotFound(const std::string& key) OVERRIDE; |
97 virtual void OnGetUserInfoFailure( | 103 virtual void OnGetUserInfoFailure( |
98 const GoogleServiceAuthError& error) OVERRIDE; | 104 const GoogleServiceAuthError& error) OVERRIDE; |
99 virtual void OnTokenAuthFailure(const GoogleServiceAuthError& error) OVERRIDE; | 105 virtual void OnTokenAuthFailure(const GoogleServiceAuthError& error) OVERRIDE; |
(...skipping 11 matching lines...) Expand all Loading... |
111 const GoogleServiceAuthError& error) OVERRIDE; | 117 const GoogleServiceAuthError& error) OVERRIDE; |
112 virtual void OnUserInfoSuccess(const std::string& email) OVERRIDE; | 118 virtual void OnUserInfoSuccess(const std::string& email) OVERRIDE; |
113 virtual void OnUserInfoFailure(const GoogleServiceAuthError& error) OVERRIDE; | 119 virtual void OnUserInfoFailure(const GoogleServiceAuthError& error) OVERRIDE; |
114 | 120 |
115 // content::NotificationObserver | 121 // content::NotificationObserver |
116 virtual void Observe(int type, | 122 virtual void Observe(int type, |
117 const content::NotificationSource& source, | 123 const content::NotificationSource& source, |
118 const content::NotificationDetails& details) OVERRIDE; | 124 const content::NotificationDetails& details) OVERRIDE; |
119 | 125 |
120 private: | 126 private: |
| 127 FRIEND_TEST_ALL_PREFIXES(SigninManagerTest, ClearTransientSigninData); |
| 128 FRIEND_TEST_ALL_PREFIXES(SigninManagerTest, ProvideSecondFactorSuccess); |
| 129 FRIEND_TEST_ALL_PREFIXES(SigninManagerTest, ProvideSecondFactorFailure); |
121 void PrepareForSignin(); | 130 void PrepareForSignin(); |
122 void PrepareForOAuthSignin(); | 131 void PrepareForOAuthSignin(); |
123 | 132 |
| 133 // Called when a new request to re-authenticate a user is in progress. |
| 134 // Will clear in memory data but leaves the db as such so when the browser |
| 135 // restarts we can use the old token(which might throw a password error). |
| 136 void ClearTransientSigninData(); |
| 137 |
124 Profile* profile_; | 138 Profile* profile_; |
125 | 139 |
126 // ClientLogin identity. | 140 // ClientLogin identity. |
127 std::string username_; | 141 std::string possibly_invalid_username_; |
128 std::string password_; // This is kept empty whenever possible. | 142 std::string password_; // This is kept empty whenever possible. |
129 bool had_two_factor_error_; | 143 bool had_two_factor_error_; |
130 | 144 |
131 // OAuth identity. | 145 // OAuth identity. |
132 std::string oauth_username_; | |
133 std::string oauth1_request_token_; | 146 std::string oauth1_request_token_; |
134 | 147 |
135 void CleanupNotificationRegistration(); | 148 void CleanupNotificationRegistration(); |
136 | 149 |
137 // Result of the last client login, kept pending the lookup of the | 150 // Result of the last client login, kept pending the lookup of the |
138 // canonical email. | 151 // canonical email. |
139 ClientLoginResult last_result_; | 152 ClientLoginResult last_result_; |
140 | 153 |
141 // Actual client login handler. | 154 // Actual client login handler. |
142 scoped_ptr<GaiaAuthFetcher> client_login_; | 155 scoped_ptr<GaiaAuthFetcher> client_login_; |
143 | 156 |
144 // Actual OAuth login handler. | 157 // Actual OAuth login handler. |
145 scoped_ptr<GaiaOAuthFetcher> oauth_login_; | 158 scoped_ptr<GaiaOAuthFetcher> oauth_login_; |
146 | 159 |
147 // Register for notifications from the TokenService. | 160 // Register for notifications from the TokenService. |
148 content::NotificationRegistrar registrar_; | 161 content::NotificationRegistrar registrar_; |
149 | 162 |
| 163 std::string authenticated_username_; |
| 164 |
150 DISALLOW_COPY_AND_ASSIGN(SigninManager); | 165 DISALLOW_COPY_AND_ASSIGN(SigninManager); |
151 }; | 166 }; |
152 | 167 |
153 #endif // CHROME_BROWSER_SYNC_SIGNIN_MANAGER_H_ | 168 #endif // CHROME_BROWSER_SYNC_SIGNIN_MANAGER_H_ |
OLD | NEW |