1 // Copyright (c) 2012 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_attempt_state.h" 6 7 #include <string> 8 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" 12 13 using content::BrowserThread; 14 15 namespace chromeos { 16 17 AuthAttemptState::AuthAttemptState(const UserContext& user_context, 18 const std::string& ascii_hash, 19 const std::string& login_token, 20 const std::string& login_captcha, 21 const User::UserType user_type, 22 const bool user_is_new) 23 : user_context(user_context), 24 ascii_hash(ascii_hash), 25 login_token(login_token), 26 login_captcha(login_captcha), 27 user_type(user_type), 28 unlock(false), 29 online_complete_(false), 30 online_outcome_(LoginFailure::NONE), 31 hosted_policy_(GaiaAuthFetcher::HostedAccountsAllowed), 32 is_first_time_user_(user_is_new), 33 cryptohome_complete_(false), 34 cryptohome_outcome_(false), 35 cryptohome_code_(cryptohome::MOUNT_ERROR_NONE), 36 username_hash_obtained_(true) { 37 } 38 39 AuthAttemptState::AuthAttemptState(const std::string& username, 40 const std::string& ascii_hash) 41 : user_context(username, "", ""), 42 ascii_hash(ascii_hash), 43 user_type(User::USER_TYPE_REGULAR), 44 unlock(true), 45 online_complete_(true), 46 online_outcome_(LoginFailure::UNLOCK_FAILED), 47 hosted_policy_(GaiaAuthFetcher::HostedAccountsAllowed), 48 is_first_time_user_(false), 49 cryptohome_complete_(false), 50 cryptohome_outcome_(false), 51 cryptohome_code_(cryptohome::MOUNT_ERROR_NONE), 52 username_hash_obtained_(true) { 53 } 54 55 AuthAttemptState::AuthAttemptState(const UserContext& user_context, 56 const std::string& ascii_hash, 57 const bool user_is_new) 58 : user_context(user_context), 59 ascii_hash(ascii_hash), 60 user_type(User::USER_TYPE_REGULAR), 61 unlock(true), 62 online_complete_(false), 63 online_outcome_(LoginFailure::NONE), 64 hosted_policy_(GaiaAuthFetcher::HostedAccountsAllowed), 65 is_first_time_user_(user_is_new), 66 cryptohome_complete_(false), 67 cryptohome_outcome_(false), 68 cryptohome_code_(cryptohome::MOUNT_ERROR_NONE), 69 username_hash_obtained_(true) { 70 } 71 72 AuthAttemptState::~AuthAttemptState() {} 73 74 void AuthAttemptState::RecordOnlineLoginStatus( 75 const LoginFailure& outcome) { 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 77 online_complete_ = true; 78 online_outcome_ = outcome; 79 // We're either going to not try again, or try again with HOSTED 80 // accounts not allowed, so just set this here. 81 DisableHosted(); 82 } 83 84 void AuthAttemptState::DisableHosted() { 85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 86 hosted_policy_ = GaiaAuthFetcher::HostedAccountsNotAllowed; 87 } 88 89 void AuthAttemptState::RecordCryptohomeStatus( 90 bool cryptohome_outcome, 91 cryptohome::MountError cryptohome_code) { 92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 93 cryptohome_complete_ = true; 94 cryptohome_outcome_ = cryptohome_outcome; 95 cryptohome_code_ = cryptohome_code; 96 } 97 98 void AuthAttemptState::RecordUsernameHash(const std::string& username_hash) { 99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 100 user_context.username_hash = username_hash; 101 username_hash_obtained_ = true; 102 } 103 104 void AuthAttemptState::UsernameHashRequested() { 105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 106 username_hash_obtained_ = false; 107 } 108 109 void AuthAttemptState::ResetCryptohomeStatus() { 110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 111 cryptohome_complete_ = false; 112 cryptohome_outcome_ = false; 113 cryptohome_code_ = cryptohome::MOUNT_ERROR_NONE; 114 } 115 116 bool AuthAttemptState::online_complete() { 117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 118 return online_complete_; 119 } 120 121 const LoginFailure& AuthAttemptState::online_outcome() { 122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 123 return online_outcome_; 124 } 125 126 bool AuthAttemptState::is_first_time_user() { 127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 128 return is_first_time_user_; 129 } 130 131 GaiaAuthFetcher::HostedAccountsSetting AuthAttemptState::hosted_policy() { 132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 133 return hosted_policy_; 134 } 135 136 bool AuthAttemptState::cryptohome_complete() { 137 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 138 return cryptohome_complete_; 139 } 140 141 bool AuthAttemptState::cryptohome_outcome() { 142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 143 return cryptohome_outcome_; 144 } 145 146 cryptohome::MountError AuthAttemptState::cryptohome_code() { 147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 148 return cryptohome_code_; 149 } 150 151 bool AuthAttemptState::username_hash_obtained() { 152 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 153 return username_hash_obtained_; 154 } 155 156 } // namespace chromeos 157