OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "chrome/browser/chromeos/login/auth/online_attempt_host.h" | |
6 | |
7 #include "base/bind.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" | |
14 | |
15 namespace chromeos { | |
16 | |
17 OnlineAttemptHost::OnlineAttemptHost(Delegate* delegate) | |
18 : delegate_(delegate), weak_ptr_factory_(this) {} | |
19 | |
20 OnlineAttemptHost::~OnlineAttemptHost() { | |
21 Reset(); | |
22 } | |
23 | |
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_) { | |
28 Reset(); | |
29 current_attempt_user_context_ = user_context; | |
30 | |
31 state_.reset(new AuthAttemptState(user_context, | |
32 user_manager::USER_TYPE_REGULAR, | |
33 false, // unlock | |
34 false, // online_complete | |
35 false)); // user_is_new | |
36 online_attempt_.reset(new OnlineAttempt(state_.get(), this)); | |
37 online_attempt_->Initiate(auth_context); | |
38 } | |
39 } | |
40 | |
41 void OnlineAttemptHost::Reset() { | |
42 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
43 online_attempt_.reset(NULL); | |
44 current_attempt_user_context_ = UserContext(); | |
45 } | |
46 | |
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, | |
53 FROM_HERE, | |
54 base::Bind(&OnlineAttemptHost::ResolveOnUIThread, | |
55 weak_ptr_factory_.GetWeakPtr(), | |
56 success)); | |
57 } | |
58 } | |
59 | |
60 void OnlineAttemptHost::ResolveOnUIThread(bool success) { | |
61 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
62 delegate_->OnChecked(current_attempt_user_context_.GetUserID(), success); | |
63 Reset(); | |
64 } | |
65 | |
66 } // namespace chromeos | |
OLD | NEW |