| OLD | NEW |
| 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 #include "chrome/browser/chromeos/login/auth/online_attempt.h" | 5 #include "chromeos/login/auth/online_attempt.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "chromeos/login/auth/auth_attempt_state.h" | 13 #include "chromeos/login/auth/auth_attempt_state.h" |
| 14 #include "chromeos/login/auth/auth_attempt_state_resolver.h" | 14 #include "chromeos/login/auth/auth_attempt_state_resolver.h" |
| 15 #include "chromeos/login/auth/key.h" | 15 #include "chromeos/login/auth/key.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 41 } | 41 } |
| 42 | 42 |
| 43 OnlineAttempt::~OnlineAttempt() { | 43 OnlineAttempt::~OnlineAttempt() { |
| 44 // Just to be sure. | 44 // Just to be sure. |
| 45 if (client_fetcher_.get()) | 45 if (client_fetcher_.get()) |
| 46 client_fetcher_->CancelRequest(); | 46 client_fetcher_->CancelRequest(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void OnlineAttempt::Initiate(content::BrowserContext* auth_context) { | 49 void OnlineAttempt::Initiate(content::BrowserContext* auth_context) { |
| 50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 51 client_fetcher_.reset( | 51 client_fetcher_.reset(new GaiaAuthFetcher( |
| 52 new GaiaAuthFetcher(this, GaiaConstants::kChromeOSSource, | 52 this, GaiaConstants::kChromeOSSource, auth_context->GetRequestContext())); |
| 53 auth_context->GetRequestContext())); | |
| 54 BrowserThread::PostTask( | 53 BrowserThread::PostTask( |
| 55 BrowserThread::UI, FROM_HERE, | 54 BrowserThread::UI, |
| 55 FROM_HERE, |
| 56 base::Bind(&OnlineAttempt::TryClientLogin, weak_factory_.GetWeakPtr())); | 56 base::Bind(&OnlineAttempt::TryClientLogin, weak_factory_.GetWeakPtr())); |
| 57 } | 57 } |
| 58 | 58 |
| 59 void OnlineAttempt::OnClientLoginSuccess( | 59 void OnlineAttempt::OnClientLoginSuccess( |
| 60 const GaiaAuthConsumer::ClientLoginResult& unused) { | 60 const GaiaAuthConsumer::ClientLoginResult& unused) { |
| 61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 62 VLOG(1) << "Online login successful!"; | 62 VLOG(1) << "Online login successful!"; |
| 63 | 63 |
| 64 weak_factory_.InvalidateWeakPtrs(); | 64 weak_factory_.InvalidateWeakPtrs(); |
| 65 | 65 |
| 66 if (attempt_->hosted_policy() == GaiaAuthFetcher::HostedAccountsAllowed && | 66 if (attempt_->hosted_policy() == GaiaAuthFetcher::HostedAccountsAllowed && |
| 67 attempt_->is_first_time_user()) { | 67 attempt_->is_first_time_user()) { |
| 68 // First time user, and we don't know if the account is HOSTED or not. | 68 // First time user, and we don't know if the account is HOSTED or not. |
| 69 // Since we don't allow HOSTED accounts to log in, we need to try | 69 // Since we don't allow HOSTED accounts to log in, we need to try |
| 70 // again, without allowing HOSTED accounts. | 70 // again, without allowing HOSTED accounts. |
| 71 // | 71 // |
| 72 // NOTE: we used to do this in the opposite order, so that we'd only | 72 // NOTE: we used to do this in the opposite order, so that we'd only |
| 73 // try the HOSTED pathway if GOOGLE-only failed. This breaks CAPTCHA | 73 // try the HOSTED pathway if GOOGLE-only failed. This breaks CAPTCHA |
| 74 // handling, though. | 74 // handling, though. |
| 75 attempt_->DisableHosted(); | 75 attempt_->DisableHosted(); |
| 76 TryClientLogin(); | 76 TryClientLogin(); |
| 77 return; | 77 return; |
| 78 } | 78 } |
| 79 TriggerResolve(AuthFailure::AuthFailureNone()); | 79 TriggerResolve(AuthFailure::AuthFailureNone()); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void OnlineAttempt::OnClientLoginFailure( | 82 void OnlineAttempt::OnClientLoginFailure(const GoogleServiceAuthError& error) { |
| 83 const GoogleServiceAuthError& error) { | |
| 84 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 85 | 84 |
| 86 weak_factory_.InvalidateWeakPtrs(); | 85 weak_factory_.InvalidateWeakPtrs(); |
| 87 | 86 |
| 88 if (error.state() == GoogleServiceAuthError::REQUEST_CANCELED) { | 87 if (error.state() == GoogleServiceAuthError::REQUEST_CANCELED) { |
| 89 if (try_again_) { | 88 if (try_again_) { |
| 90 try_again_ = false; | 89 try_again_ = false; |
| 91 // TODO(cmasone): add UMA tracking for this to see if we can remove it. | 90 // TODO(cmasone): add UMA tracking for this to see if we can remove it. |
| 92 LOG(ERROR) << "Login attempt canceled!?!? Trying again."; | 91 LOG(ERROR) << "Login attempt canceled!?!? Trying again."; |
| 93 TryClientLogin(); | 92 TryClientLogin(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 115 return; | 114 return; |
| 116 } | 115 } |
| 117 VLOG(2) << "ClientLogin attempt failed with " << error.state(); | 116 VLOG(2) << "ClientLogin attempt failed with " << error.state(); |
| 118 TriggerResolve(AuthFailure::FromNetworkAuthFailure(error)); | 117 TriggerResolve(AuthFailure::FromNetworkAuthFailure(error)); |
| 119 } | 118 } |
| 120 | 119 |
| 121 void OnlineAttempt::TryClientLogin() { | 120 void OnlineAttempt::TryClientLogin() { |
| 122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 123 | 122 |
| 124 BrowserThread::PostDelayedTask( | 123 BrowserThread::PostDelayedTask( |
| 125 BrowserThread::UI, FROM_HERE, | 124 BrowserThread::UI, |
| 125 FROM_HERE, |
| 126 base::Bind(&OnlineAttempt::CancelClientLogin, weak_factory_.GetWeakPtr()), | 126 base::Bind(&OnlineAttempt::CancelClientLogin, weak_factory_.GetWeakPtr()), |
| 127 base::TimeDelta::FromMilliseconds(kClientLoginTimeoutMs)); | 127 base::TimeDelta::FromMilliseconds(kClientLoginTimeoutMs)); |
| 128 | 128 |
| 129 client_fetcher_->StartClientLogin( | 129 client_fetcher_->StartClientLogin( |
| 130 attempt_->user_context.GetUserID(), | 130 attempt_->user_context.GetUserID(), |
| 131 attempt_->user_context.GetKey()->GetSecret(), | 131 attempt_->user_context.GetKey()->GetSecret(), |
| 132 GaiaConstants::kSyncService, | 132 GaiaConstants::kSyncService, |
| 133 attempt_->login_token, | 133 attempt_->login_token, |
| 134 attempt_->login_captcha, | 134 attempt_->login_captcha, |
| 135 attempt_->hosted_policy()); | 135 attempt_->hosted_policy()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 153 } | 153 } |
| 154 } | 154 } |
| 155 | 155 |
| 156 void OnlineAttempt::TriggerResolve(const AuthFailure& outcome) { | 156 void OnlineAttempt::TriggerResolve(const AuthFailure& outcome) { |
| 157 attempt_->RecordOnlineLoginStatus(outcome); | 157 attempt_->RecordOnlineLoginStatus(outcome); |
| 158 client_fetcher_.reset(NULL); | 158 client_fetcher_.reset(NULL); |
| 159 resolver_->Resolve(); | 159 resolver_->Resolve(); |
| 160 } | 160 } |
| 161 | 161 |
| 162 } // namespace chromeos | 162 } // namespace chromeos |
| OLD | NEW |