| 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/chromeos/login/online_attempt_host.h" | 5 #include "chrome/browser/chromeos/login/online_attempt_host.h" |
| 6 | 6 |
| 7 #include "base/bind.h" |
| 7 #include "base/sha1.h" | 8 #include "base/sha1.h" |
| 8 #include "chrome/browser/chromeos/login/auth_attempt_state.h" | 9 #include "chrome/browser/chromeos/login/auth_attempt_state.h" |
| 9 #include "chrome/browser/chromeos/login/authenticator.h" | 10 #include "chrome/browser/chromeos/login/authenticator.h" |
| 10 #include "chrome/browser/chromeos/login/online_attempt.h" | 11 #include "chrome/browser/chromeos/login/online_attempt.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "content/public/browser/browser_thread.h" |
| 12 | 14 |
| 13 namespace chromeos { | 15 namespace chromeos { |
| 14 | 16 |
| 15 OnlineAttemptHost::OnlineAttemptHost(Delegate* delegate) | 17 OnlineAttemptHost::OnlineAttemptHost(Delegate* delegate) |
| 16 : delegate_(delegate) { | 18 : delegate_(delegate) { |
| 17 } | 19 } |
| 18 | 20 |
| 19 OnlineAttemptHost::~OnlineAttemptHost() { | 21 OnlineAttemptHost::~OnlineAttemptHost() { |
| 20 Reset(); | 22 Reset(); |
| 21 } | 23 } |
| 22 | 24 |
| 23 void OnlineAttemptHost::Check(Profile* profile, | 25 void OnlineAttemptHost::Check(Profile* profile, |
| 24 const std::string& username, | 26 const std::string& username, |
| 25 const std::string& password) { | 27 const std::string& password) { |
| 28 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 26 std::string attempt_hash = base::SHA1HashString(username + "\n" + password); | 29 std::string attempt_hash = base::SHA1HashString(username + "\n" + password); |
| 27 if (attempt_hash != current_attempt_hash_) { | 30 if (attempt_hash != current_attempt_hash_) { |
| 28 Reset(); | 31 Reset(); |
| 29 current_attempt_hash_ = attempt_hash; | 32 current_attempt_hash_ = attempt_hash; |
| 30 current_username_ = username; | 33 current_username_ = username; |
| 31 | 34 |
| 32 state_.reset( | 35 state_.reset( |
| 33 new AuthAttemptState( | 36 new AuthAttemptState( |
| 34 Authenticator::Canonicalize(username), | 37 Authenticator::Canonicalize(username), |
| 35 password, | 38 password, |
| 36 std::string(), | 39 std::string(), |
| 37 std::string(), | 40 std::string(), |
| 38 std::string(), | 41 std::string(), |
| 39 false)); // Isn't a new user. | 42 false)); // Isn't a new user. |
| 40 online_attempt_ = new OnlineAttempt(false, // Don't use oauth. | 43 online_attempt_ = new OnlineAttempt(false, // Don't use oauth. |
| 41 state_.get(), | 44 state_.get(), |
| 42 this); | 45 this); |
| 43 online_attempt_->Initiate(profile); | 46 online_attempt_->Initiate(profile); |
| 44 } | 47 } |
| 45 } | 48 } |
| 46 | 49 |
| 47 void OnlineAttemptHost::Reset() { | 50 void OnlineAttemptHost::Reset() { |
| 51 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 48 online_attempt_ = NULL; | 52 online_attempt_ = NULL; |
| 49 current_attempt_hash_.clear(); | 53 current_attempt_hash_.clear(); |
| 50 current_username_.clear(); | 54 current_username_.clear(); |
| 51 } | 55 } |
| 52 | 56 |
| 53 void OnlineAttemptHost::Resolve() { | 57 void OnlineAttemptHost::Resolve() { |
| 58 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 54 if (state_->online_complete()) { | 59 if (state_->online_complete()) { |
| 55 bool success = state_->online_outcome().reason() == LoginFailure::NONE; | 60 bool success = state_->online_outcome().reason() == LoginFailure::NONE; |
| 56 delegate_->OnChecked(current_username_, success); | 61 content::BrowserThread::PostTask( |
| 57 Reset(); | 62 content::BrowserThread::UI, FROM_HERE, |
| 63 base::Bind(&OnlineAttemptHost::ResolveOnUIThread, |
| 64 base::Unretained(this), success)); |
| 58 } | 65 } |
| 59 } | 66 } |
| 60 | 67 |
| 68 void OnlineAttemptHost::ResolveOnUIThread(bool success) { |
| 69 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 70 delegate_->OnChecked(current_username_, success); |
| 71 Reset(); |
| 72 } |
| 73 |
| 61 } // chromeos | 74 } // chromeos |
| OLD | NEW |