ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chromeos / login / auth / online_attempt_host.cc
blobd6f58f30d4d946049aad84a9f94e9234e15e9b83
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 "chromeos/login/auth/online_attempt_host.h"
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/message_loop/message_loop_proxy.h"
10 #include "chromeos/login/auth/auth_attempt_state.h"
11 #include "chromeos/login/auth/online_attempt.h"
12 #include "components/user_manager/user_type.h"
14 namespace chromeos {
16 OnlineAttemptHost::OnlineAttemptHost(Delegate* delegate)
17 : message_loop_(base::MessageLoopProxy::current()),
18 delegate_(delegate),
19 weak_ptr_factory_(this) {
22 OnlineAttemptHost::~OnlineAttemptHost() {
23 Reset();
26 void OnlineAttemptHost::Check(net::URLRequestContextGetter* request_context,
27 const UserContext& user_context) {
28 if (user_context != current_attempt_user_context_) {
29 Reset();
30 current_attempt_user_context_ = user_context;
32 state_.reset(new AuthAttemptState(user_context,
33 user_manager::USER_TYPE_REGULAR,
34 false, // unlock
35 false, // online_complete
36 false)); // user_is_new
37 online_attempt_.reset(new OnlineAttempt(state_.get(), this));
38 online_attempt_->Initiate(request_context);
42 void OnlineAttemptHost::Reset() {
43 online_attempt_.reset(NULL);
44 current_attempt_user_context_ = UserContext();
47 void OnlineAttemptHost::Resolve() {
48 if (state_->online_complete()) {
49 bool success = state_->online_outcome().reason() == AuthFailure::NONE;
50 message_loop_->PostTask(FROM_HERE,
51 base::Bind(&OnlineAttemptHost::ResolveOnUIThread,
52 weak_ptr_factory_.GetWeakPtr(),
53 success));
57 void OnlineAttemptHost::ResolveOnUIThread(bool success) {
58 delegate_->OnChecked(current_attempt_user_context_.GetUserID(), success);
59 Reset();
62 } // namespace chromeos