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/auth_attempt_state.h"
9 #include "content/public/browser/browser_thread.h"
10 #include "google_apis/gaia/gaia_auth_consumer.h"
11 #include "google_apis/gaia/gaia_auth_fetcher.h"
13 using content::BrowserThread;
17 AuthAttemptState::AuthAttemptState(const UserContext& user_context,
18 User::UserType user_type,
22 : user_context(user_context),
25 online_complete_(online_complete),
26 online_outcome_(online_complete ? LoginFailure::UNLOCK_FAILED :
28 hosted_policy_(GaiaAuthFetcher::HostedAccountsAllowed),
29 is_first_time_user_(user_is_new),
30 cryptohome_complete_(false),
31 cryptohome_outcome_(false),
32 cryptohome_code_(cryptohome::MOUNT_ERROR_NONE),
33 username_hash_obtained_(true),
34 username_hash_valid_(true) {
37 AuthAttemptState::~AuthAttemptState() {}
39 void AuthAttemptState::RecordOnlineLoginStatus(
40 const LoginFailure& outcome) {
41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
42 online_complete_ = true;
43 online_outcome_ = outcome;
44 // We're either going to not try again, or try again with HOSTED
45 // accounts not allowed, so just set this here.
49 void AuthAttemptState::DisableHosted() {
50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
51 hosted_policy_ = GaiaAuthFetcher::HostedAccountsNotAllowed;
54 void AuthAttemptState::RecordCryptohomeStatus(
55 bool cryptohome_outcome,
56 cryptohome::MountError cryptohome_code) {
57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
58 cryptohome_complete_ = true;
59 cryptohome_outcome_ = cryptohome_outcome;
60 cryptohome_code_ = cryptohome_code;
63 void AuthAttemptState::RecordUsernameHash(const std::string& username_hash) {
64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
65 user_context.SetUserIDHash(username_hash);
66 username_hash_obtained_ = true;
67 username_hash_valid_ = true;
70 void AuthAttemptState::RecordUsernameHashFailed() {
71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
72 username_hash_obtained_ = true;
73 username_hash_valid_ = false;
76 void AuthAttemptState::UsernameHashRequested() {
77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
78 username_hash_obtained_ = false;
81 void AuthAttemptState::ResetCryptohomeStatus() {
82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
83 cryptohome_complete_ = false;
84 cryptohome_outcome_ = false;
85 cryptohome_code_ = cryptohome::MOUNT_ERROR_NONE;
88 bool AuthAttemptState::online_complete() {
89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
90 return online_complete_;
93 const LoginFailure& AuthAttemptState::online_outcome() {
94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
95 return online_outcome_;
98 bool AuthAttemptState::is_first_time_user() {
99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
100 return is_first_time_user_;
103 GaiaAuthFetcher::HostedAccountsSetting AuthAttemptState::hosted_policy() {
104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
105 return hosted_policy_;
108 bool AuthAttemptState::cryptohome_complete() {
109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
110 return cryptohome_complete_;
113 bool AuthAttemptState::cryptohome_outcome() {
114 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
115 return cryptohome_outcome_;
118 cryptohome::MountError AuthAttemptState::cryptohome_code() {
119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
120 return cryptohome_code_;
123 bool AuthAttemptState::username_hash_obtained() {
124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
125 return username_hash_obtained_;
128 bool AuthAttemptState::username_hash_valid() {
129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
130 return username_hash_obtained_;
133 } // namespace chromeos