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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/login/auth/online_attempt_host.h"
8 #include "chrome/browser/chromeos/login/auth/online_attempt.h"
9 #include "chromeos/login/auth/auth_attempt_state.h"
10 #include "chromeos/login/auth/user_context.h"
11 #include "components/user_manager/user_type.h"
12 #include "content/public/browser/browser_context.h"
13 #include "content/public/browser/browser_thread.h"
17 OnlineAttemptHost::OnlineAttemptHost(Delegate* delegate)
18 : delegate_(delegate), weak_ptr_factory_(this) {}
20 OnlineAttemptHost::~OnlineAttemptHost() {
24 void OnlineAttemptHost::Check(content::BrowserContext* auth_context,
25 const UserContext& user_context) {
26 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
27 if (user_context != current_attempt_user_context_) {
29 current_attempt_user_context_ = user_context;
31 state_.reset(new AuthAttemptState(user_context,
32 user_manager::USER_TYPE_REGULAR,
34 false, // online_complete
35 false)); // user_is_new
36 online_attempt_.reset(new OnlineAttempt(state_.get(), this));
37 online_attempt_->Initiate(auth_context);
41 void OnlineAttemptHost::Reset() {
42 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
43 online_attempt_.reset(NULL);
44 current_attempt_user_context_ = UserContext();
47 void OnlineAttemptHost::Resolve() {
48 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
49 if (state_->online_complete()) {
50 bool success = state_->online_outcome().reason() == AuthFailure::NONE;
51 content::BrowserThread::PostTask(
52 content::BrowserThread::UI,
54 base::Bind(&OnlineAttemptHost::ResolveOnUIThread,
55 weak_ptr_factory_.GetWeakPtr(),
60 void OnlineAttemptHost::ResolveOnUIThread(bool success) {
61 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
62 delegate_->OnChecked(current_attempt_user_context_.GetUserID(), success);
66 } // namespace chromeos