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 "chromeos/login/auth/auth_attempt_state.h" 6 7#include <string> 8 9#include "google_apis/gaia/gaia_auth_consumer.h" 10#include "google_apis/gaia/gaia_auth_fetcher.h" 11 12namespace chromeos { 13 14AuthAttemptState::AuthAttemptState(const UserContext& user_context, 15 user_manager::UserType user_type, 16 bool unlock, 17 bool online_complete, 18 bool user_is_new) 19 : user_context(user_context), 20 user_type(user_type), 21 unlock(unlock), 22 online_complete_(online_complete), 23 online_outcome_(online_complete ? AuthFailure::UNLOCK_FAILED 24 : AuthFailure::NONE), 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) { 32} 33 34AuthAttemptState::~AuthAttemptState() { 35} 36 37void 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. 42 DisableHosted(); 43} 44 45void AuthAttemptState::DisableHosted() { 46 hosted_policy_ = GaiaAuthFetcher::HostedAccountsNotAllowed; 47} 48 49void 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; 55} 56 57void AuthAttemptState::RecordUsernameHash(const std::string& username_hash) { 58 user_context.SetUserIDHash(username_hash); 59 username_hash_obtained_ = true; 60 username_hash_valid_ = true; 61} 62 63void AuthAttemptState::RecordUsernameHashFailed() { 64 username_hash_obtained_ = true; 65 username_hash_valid_ = false; 66} 67 68void AuthAttemptState::UsernameHashRequested() { 69 username_hash_obtained_ = false; 70} 71 72void AuthAttemptState::ResetCryptohomeStatus() { 73 cryptohome_complete_ = false; 74 cryptohome_outcome_ = false; 75 cryptohome_code_ = cryptohome::MOUNT_ERROR_NONE; 76} 77 78bool AuthAttemptState::online_complete() { 79 return online_complete_; 80} 81 82const AuthFailure& AuthAttemptState::online_outcome() { 83 return online_outcome_; 84} 85 86bool AuthAttemptState::is_first_time_user() { 87 return is_first_time_user_; 88} 89 90GaiaAuthFetcher::HostedAccountsSetting AuthAttemptState::hosted_policy() { 91 return hosted_policy_; 92} 93 94bool AuthAttemptState::cryptohome_complete() { 95 return cryptohome_complete_; 96} 97 98bool AuthAttemptState::cryptohome_outcome() { 99 return cryptohome_outcome_; 100} 101 102cryptohome::MountError AuthAttemptState::cryptohome_code() { 103 return cryptohome_code_; 104} 105 106bool AuthAttemptState::username_hash_obtained() { 107 return username_hash_obtained_; 108} 109 110bool AuthAttemptState::username_hash_valid() { 111 return username_hash_obtained_; 112} 113 114} // namespace chromeos 115