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