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