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