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/auth_attempt_state.h"
9 #include "google_apis/gaia/gaia_auth_consumer.h"
10 #include "google_apis/gaia/gaia_auth_fetcher.h"
14 AuthAttemptState::AuthAttemptState(const UserContext
& user_context
,
15 user_manager::UserType user_type
,
19 : user_context(user_context
),
22 online_complete_(online_complete
),
23 online_outcome_(online_complete
? AuthFailure::UNLOCK_FAILED
25 hosted_policy_(GaiaAuthFetcher::HostedAccountsAllowed
),
26 is_first_time_user_(user_is_new
),
27 cryptohome_complete_(false),
28 cryptohome_outcome_(false),
29 cryptohome_code_(cryptohome::MOUNT_ERROR_NONE
),
30 username_hash_obtained_(true),
31 username_hash_valid_(true) {
34 AuthAttemptState::~AuthAttemptState() {
37 void AuthAttemptState::RecordOnlineLoginStatus(const AuthFailure
& outcome
) {
38 online_complete_
= true;
39 online_outcome_
= outcome
;
40 // We're either going to not try again, or try again with HOSTED
41 // accounts not allowed, so just set this here.
45 void AuthAttemptState::DisableHosted() {
46 hosted_policy_
= GaiaAuthFetcher::HostedAccountsNotAllowed
;
49 void AuthAttemptState::RecordCryptohomeStatus(
50 bool cryptohome_outcome
,
51 cryptohome::MountError cryptohome_code
) {
52 cryptohome_complete_
= true;
53 cryptohome_outcome_
= cryptohome_outcome
;
54 cryptohome_code_
= cryptohome_code
;
57 void AuthAttemptState::RecordUsernameHash(const std::string
& username_hash
) {
58 user_context
.SetUserIDHash(username_hash
);
59 username_hash_obtained_
= true;
60 username_hash_valid_
= true;
63 void AuthAttemptState::RecordUsernameHashFailed() {
64 username_hash_obtained_
= true;
65 username_hash_valid_
= false;
68 void AuthAttemptState::UsernameHashRequested() {
69 username_hash_obtained_
= false;
72 void AuthAttemptState::ResetCryptohomeStatus() {
73 cryptohome_complete_
= false;
74 cryptohome_outcome_
= false;
75 cryptohome_code_
= cryptohome::MOUNT_ERROR_NONE
;
78 bool AuthAttemptState::online_complete() {
79 return online_complete_
;
82 const AuthFailure
& AuthAttemptState::online_outcome() {
83 return online_outcome_
;
86 bool AuthAttemptState::is_first_time_user() {
87 return is_first_time_user_
;
90 GaiaAuthFetcher::HostedAccountsSetting
AuthAttemptState::hosted_policy() {
91 return hosted_policy_
;
94 bool AuthAttemptState::cryptohome_complete() {
95 return cryptohome_complete_
;
98 bool AuthAttemptState::cryptohome_outcome() {
99 return cryptohome_outcome_
;
102 cryptohome::MountError
AuthAttemptState::cryptohome_code() {
103 return cryptohome_code_
;
106 bool AuthAttemptState::username_hash_obtained() {
107 return username_hash_obtained_
;
110 bool AuthAttemptState::username_hash_valid() {
111 return username_hash_obtained_
;
114 } // namespace chromeos