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 #include "chrome/browser/signin/signin_manager.h" | 5 #include "chrome/browser/signin/signin_manager.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); | 123 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); |
124 if (token_service && !GetAuthenticatedUsername().empty()) | 124 if (token_service && !GetAuthenticatedUsername().empty()) |
125 token_service->LoadTokensFromDB(); | 125 token_service->LoadTokensFromDB(); |
126 } | 126 } |
127 | 127 |
128 std::string SigninManager::SigninTypeToString( | 128 std::string SigninManager::SigninTypeToString( |
129 SigninManager::SigninType type) { | 129 SigninManager::SigninType type) { |
130 switch (type) { | 130 switch (type) { |
131 case SIGNIN_TYPE_NONE: | 131 case SIGNIN_TYPE_NONE: |
132 return "No Signin"; | 132 return "No Signin"; |
133 case SIGNIN_TYPE_CLIENT_LOGIN: | |
134 return "Client Login"; | |
135 case SIGNIN_TYPE_WITH_CREDENTIALS: | 133 case SIGNIN_TYPE_WITH_CREDENTIALS: |
136 return "Signin with credentials"; | 134 return "Signin with credentials"; |
137 } | 135 } |
138 | 136 |
139 NOTREACHED(); | 137 NOTREACHED(); |
140 return std::string(); | 138 return std::string(); |
141 } | 139 } |
142 | 140 |
143 bool SigninManager::PrepareForSignin(SigninType type, | 141 bool SigninManager::PrepareForSignin(SigninType type, |
144 const std::string& username, | 142 const std::string& username, |
(...skipping 16 matching lines...) Expand all Loading... |
161 // restart we don't think sync setup has never completed. | 159 // restart we don't think sync setup has never completed. |
162 RevokeOAuthLoginToken(); | 160 RevokeOAuthLoginToken(); |
163 ClearTransientSigninData(); | 161 ClearTransientSigninData(); |
164 type_ = type; | 162 type_ = type; |
165 possibly_invalid_username_.assign(username); | 163 possibly_invalid_username_.assign(username); |
166 password_.assign(password); | 164 password_.assign(password); |
167 | 165 |
168 client_login_.reset(new GaiaAuthFetcher(this, | 166 client_login_.reset(new GaiaAuthFetcher(this, |
169 GaiaConstants::kChromeSource, | 167 GaiaConstants::kChromeSource, |
170 profile_->GetRequestContext())); | 168 profile_->GetRequestContext())); |
171 | |
172 NotifyDiagnosticsObservers(SIGNIN_TYPE, SigninTypeToString(type)); | 169 NotifyDiagnosticsObservers(SIGNIN_TYPE, SigninTypeToString(type)); |
173 return true; | 170 return true; |
174 } | 171 } |
175 | 172 |
176 // Users must always sign out before they sign in again. | |
177 void SigninManager::StartSignIn(const std::string& username, | |
178 const std::string& password, | |
179 const std::string& login_token, | |
180 const std::string& login_captcha) { | |
181 DCHECK(GetAuthenticatedUsername().empty() || | |
182 gaia::AreEmailsSame(username, GetAuthenticatedUsername())); | |
183 | |
184 if (!PrepareForSignin(SIGNIN_TYPE_CLIENT_LOGIN, username, password)) | |
185 return; | |
186 | |
187 client_login_->StartClientLogin(username, | |
188 password, | |
189 "", | |
190 login_token, | |
191 login_captcha, | |
192 GaiaAuthFetcher::HostedAccountsNotAllowed); | |
193 } | |
194 | |
195 void SigninManager::ProvideSecondFactorAccessCode( | |
196 const std::string& access_code) { | |
197 DCHECK(!possibly_invalid_username_.empty() && !password_.empty() && | |
198 last_result_.data.empty()); | |
199 DCHECK(type_ == SIGNIN_TYPE_CLIENT_LOGIN); | |
200 | |
201 client_login_.reset(new GaiaAuthFetcher(this, | |
202 GaiaConstants::kChromeSource, | |
203 profile_->GetRequestContext())); | |
204 client_login_->StartClientLogin(possibly_invalid_username_, | |
205 access_code, | |
206 "", | |
207 std::string(), | |
208 std::string(), | |
209 GaiaAuthFetcher::HostedAccountsNotAllowed); | |
210 } | |
211 | |
212 void SigninManager::StartSignInWithCredentials( | 173 void SigninManager::StartSignInWithCredentials( |
213 const std::string& session_index, | 174 const std::string& session_index, |
214 const std::string& username, | 175 const std::string& username, |
215 const std::string& password, | 176 const std::string& password, |
216 const OAuthTokenFetchedCallback& callback) { | 177 const OAuthTokenFetchedCallback& callback) { |
217 DCHECK(GetAuthenticatedUsername().empty() || | 178 DCHECK(GetAuthenticatedUsername().empty() || |
218 gaia::AreEmailsSame(username, GetAuthenticatedUsername())); | 179 gaia::AreEmailsSame(username, GetAuthenticatedUsername())); |
219 | 180 |
220 if (!PrepareForSignin(SIGNIN_TYPE_WITH_CREDENTIALS, username, password)) | 181 if (!PrepareForSignin(SIGNIN_TYPE_WITH_CREDENTIALS, username, password)) |
221 return; | 182 return; |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 } | 607 } |
647 } | 608 } |
648 | 609 |
649 void SigninManager::ProhibitSignout(bool prohibit_signout) { | 610 void SigninManager::ProhibitSignout(bool prohibit_signout) { |
650 prohibit_signout_ = prohibit_signout; | 611 prohibit_signout_ = prohibit_signout; |
651 } | 612 } |
652 | 613 |
653 bool SigninManager::IsSignoutProhibited() const { | 614 bool SigninManager::IsSignoutProhibited() const { |
654 return prohibit_signout_; | 615 return prohibit_signout_; |
655 } | 616 } |
OLD | NEW |