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 #include "chrome/browser/sync/signin_manager.h" | 5 #include "chrome/browser/sync/signin_manager.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "chrome/browser/net/gaia/token_service.h" | 9 #include "chrome/browser/net/gaia/token_service.h" |
10 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/sync/profile_sync_service.h" | 12 #include "chrome/browser/sync/profile_sync_service.h" |
| 13 #include "chrome/common/chrome_notification_types.h" |
13 #include "chrome/common/net/gaia/gaia_constants.h" | 14 #include "chrome/common/net/gaia/gaia_constants.h" |
14 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
15 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
16 #include "content/common/notification_service.h" | 17 #include "content/common/notification_service.h" |
17 | 18 |
18 const char kGetInfoEmailKey[] = "email"; | 19 const char kGetInfoEmailKey[] = "email"; |
19 | 20 |
20 SigninManager::SigninManager() | 21 SigninManager::SigninManager() |
21 : profile_(NULL), had_two_factor_error_(false) {} | 22 : profile_(NULL), had_two_factor_error_(false) {} |
22 | 23 |
(...skipping 12 matching lines...) Expand all Loading... |
35 profile_->GetTokenService()->Initialize( | 36 profile_->GetTokenService()->Initialize( |
36 GaiaConstants::kChromeSource, profile_); | 37 GaiaConstants::kChromeSource, profile_); |
37 if (!username_.empty()) { | 38 if (!username_.empty()) { |
38 profile_->GetTokenService()->LoadTokensFromDB(); | 39 profile_->GetTokenService()->LoadTokensFromDB(); |
39 } | 40 } |
40 } | 41 } |
41 | 42 |
42 void SigninManager::CleanupNotificationRegistration() { | 43 void SigninManager::CleanupNotificationRegistration() { |
43 #if !defined(OS_CHROMEOS) | 44 #if !defined(OS_CHROMEOS) |
44 if (registrar_.IsRegistered(this, | 45 if (registrar_.IsRegistered(this, |
45 NotificationType::TOKEN_AVAILABLE, | 46 chrome::NOTIFICATION_TOKEN_AVAILABLE, |
46 NotificationService::AllSources())) { | 47 NotificationService::AllSources())) { |
47 registrar_.Remove(this, | 48 registrar_.Remove(this, |
48 NotificationType::TOKEN_AVAILABLE, | 49 chrome::NOTIFICATION_TOKEN_AVAILABLE, |
49 NotificationService::AllSources()); | 50 NotificationService::AllSources()); |
50 } | 51 } |
51 #endif | 52 #endif |
52 } | 53 } |
53 | 54 |
54 // If a username already exists, the user is logged in. | 55 // If a username already exists, the user is logged in. |
55 const std::string& SigninManager::GetUsername() { | 56 const std::string& SigninManager::GetUsername() { |
56 return username_; | 57 return username_; |
57 } | 58 } |
58 | 59 |
(...skipping 26 matching lines...) Expand all Loading... |
85 login_captcha, | 86 login_captcha, |
86 GaiaAuthFetcher::HostedAccountsNotAllowed); | 87 GaiaAuthFetcher::HostedAccountsNotAllowed); |
87 | 88 |
88 // Register for token availability. The signin manager will pre-login the | 89 // Register for token availability. The signin manager will pre-login the |
89 // user when the GAIA service token is ready for use. Only do this if we | 90 // user when the GAIA service token is ready for use. Only do this if we |
90 // are not running in ChomiumOS, since it handles pre-login itself. | 91 // are not running in ChomiumOS, since it handles pre-login itself. |
91 #if !defined(OS_CHROMEOS) | 92 #if !defined(OS_CHROMEOS) |
92 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 93 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
93 switches::kDisableAutoLogin)) { | 94 switches::kDisableAutoLogin)) { |
94 registrar_.Add(this, | 95 registrar_.Add(this, |
95 NotificationType::TOKEN_AVAILABLE, | 96 chrome::NOTIFICATION_TOKEN_AVAILABLE, |
96 NotificationService::AllSources()); | 97 NotificationService::AllSources()); |
97 } | 98 } |
98 #endif | 99 #endif |
99 } | 100 } |
100 | 101 |
101 void SigninManager::ProvideSecondFactorAccessCode( | 102 void SigninManager::ProvideSecondFactorAccessCode( |
102 const std::string& access_code) { | 103 const std::string& access_code) { |
103 DCHECK(!username_.empty() && !password_.empty() && | 104 DCHECK(!username_.empty() && !password_.empty() && |
104 last_result_.data.empty()); | 105 last_result_.data.empty()); |
105 | 106 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 void SigninManager::OnGetUserInfoSuccess(const std::string& key, | 141 void SigninManager::OnGetUserInfoSuccess(const std::string& key, |
141 const std::string& value) { | 142 const std::string& value) { |
142 DCHECK(key == kGetInfoEmailKey); | 143 DCHECK(key == kGetInfoEmailKey); |
143 | 144 |
144 username_ = value; | 145 username_ = value; |
145 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, username_); | 146 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, username_); |
146 profile_->GetPrefs()->ScheduleSavePersistentPrefs(); | 147 profile_->GetPrefs()->ScheduleSavePersistentPrefs(); |
147 | 148 |
148 GoogleServiceSigninSuccessDetails details(username_, password_); | 149 GoogleServiceSigninSuccessDetails details(username_, password_); |
149 NotificationService::current()->Notify( | 150 NotificationService::current()->Notify( |
150 NotificationType::GOOGLE_SIGNIN_SUCCESSFUL, | 151 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, |
151 Source<Profile>(profile_), | 152 Source<Profile>(profile_), |
152 Details<const GoogleServiceSigninSuccessDetails>(&details)); | 153 Details<const GoogleServiceSigninSuccessDetails>(&details)); |
153 | 154 |
154 password_.clear(); // Don't need it anymore. | 155 password_.clear(); // Don't need it anymore. |
155 | 156 |
156 profile_->GetTokenService()->UpdateCredentials(last_result_); | 157 profile_->GetTokenService()->UpdateCredentials(last_result_); |
157 DCHECK(profile_->GetTokenService()->AreCredentialsValid()); | 158 DCHECK(profile_->GetTokenService()->AreCredentialsValid()); |
158 profile_->GetTokenService()->StartFetchingTokens(); | 159 profile_->GetTokenService()->StartFetchingTokens(); |
159 } | 160 } |
160 | 161 |
(...skipping 12 matching lines...) Expand all Loading... |
173 | 174 |
174 void SigninManager::OnTokenAuthFailure(const GoogleServiceAuthError& error) { | 175 void SigninManager::OnTokenAuthFailure(const GoogleServiceAuthError& error) { |
175 #if !defined(OS_CHROMEOS) | 176 #if !defined(OS_CHROMEOS) |
176 LOG(INFO) << "Unable to retreive the token auth."; | 177 LOG(INFO) << "Unable to retreive the token auth."; |
177 CleanupNotificationRegistration(); | 178 CleanupNotificationRegistration(); |
178 #endif | 179 #endif |
179 } | 180 } |
180 | 181 |
181 void SigninManager::OnClientLoginFailure(const GoogleServiceAuthError& error) { | 182 void SigninManager::OnClientLoginFailure(const GoogleServiceAuthError& error) { |
182 NotificationService::current()->Notify( | 183 NotificationService::current()->Notify( |
183 NotificationType::GOOGLE_SIGNIN_FAILED, | 184 chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, |
184 Source<Profile>(profile_), | 185 Source<Profile>(profile_), |
185 Details<const GoogleServiceAuthError>(&error)); | 186 Details<const GoogleServiceAuthError>(&error)); |
186 | 187 |
187 // We don't sign-out if the password was valid and we're just dealing with | 188 // We don't sign-out if the password was valid and we're just dealing with |
188 // a second factor error, and we don't sign out if we're dealing with | 189 // a second factor error, and we don't sign out if we're dealing with |
189 // an invalid access code (again, because the password was valid). | 190 // an invalid access code (again, because the password was valid). |
190 bool invalid_gaia = error.state() == | 191 bool invalid_gaia = error.state() == |
191 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS; | 192 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS; |
192 if (error.state() == GoogleServiceAuthError::TWO_FACTOR || | 193 if (error.state() == GoogleServiceAuthError::TWO_FACTOR || |
193 (had_two_factor_error_ && invalid_gaia)) { | 194 (had_two_factor_error_ && invalid_gaia)) { |
194 had_two_factor_error_ = true; | 195 had_two_factor_error_ = true; |
195 return; | 196 return; |
196 } | 197 } |
197 | 198 |
198 SignOut(); | 199 SignOut(); |
199 } | 200 } |
200 | 201 |
201 void SigninManager::Observe(NotificationType type, | 202 void SigninManager::Observe(int type, |
202 const NotificationSource& source, | 203 const NotificationSource& source, |
203 const NotificationDetails& details) { | 204 const NotificationDetails& details) { |
204 #if !defined(OS_CHROMEOS) | 205 #if !defined(OS_CHROMEOS) |
205 DCHECK(type == NotificationType::TOKEN_AVAILABLE); | 206 DCHECK(type == chrome::NOTIFICATION_TOKEN_AVAILABLE); |
206 TokenService::TokenAvailableDetails* tok_details = | 207 TokenService::TokenAvailableDetails* tok_details = |
207 Details<TokenService::TokenAvailableDetails>(details).ptr(); | 208 Details<TokenService::TokenAvailableDetails>(details).ptr(); |
208 | 209 |
209 // If a GAIA service token has become available, use it to pre-login the | 210 // If a GAIA service token has become available, use it to pre-login the |
210 // user to other services that depend on GAIA credentials. | 211 // user to other services that depend on GAIA credentials. |
211 if (tok_details->service() == GaiaConstants::kGaiaService) { | 212 if (tok_details->service() == GaiaConstants::kGaiaService) { |
212 if (client_login_.get() == NULL) { | 213 if (client_login_.get() == NULL) { |
213 client_login_.reset(new GaiaAuthFetcher(this, | 214 client_login_.reset(new GaiaAuthFetcher(this, |
214 GaiaConstants::kChromeSource, | 215 GaiaConstants::kChromeSource, |
215 profile_->GetRequestContext())); | 216 profile_->GetRequestContext())); |
216 } | 217 } |
217 | 218 |
218 client_login_->StartTokenAuth(tok_details->token()); | 219 client_login_->StartTokenAuth(tok_details->token()); |
219 | 220 |
220 // We only want to do this once per sign-in. | 221 // We only want to do this once per sign-in. |
221 CleanupNotificationRegistration(); | 222 CleanupNotificationRegistration(); |
222 } | 223 } |
223 #endif | 224 #endif |
224 } | 225 } |
OLD | NEW |