1 // Copyright (c) 2010 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 "chrome/common/net/gaia/gaia_auth_consumer.h" 10 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" 11 #include "content/browser/browser_thread.h" 12 #include "third_party/cros/chromeos_cryptohome.h" 13 14 namespace chromeos { 15 16 AuthAttemptState::AuthAttemptState(const std::string& username, 17 const std::string& password, 18 const std::string& ascii_hash, 19 const std::string& login_token, 20 const std::string& login_captcha, 21 const bool user_is_new) 22 : username(username), 23 password(password), 24 ascii_hash(ascii_hash), 25 login_token(login_token), 26 login_captcha(login_captcha), 27 unlock(false), 28 online_complete_(false), 29 online_outcome_(LoginFailure::NONE), 30 hosted_policy_(GaiaAuthFetcher::HostedAccountsAllowed), 31 is_first_time_user_(user_is_new), 32 cryptohome_complete_(false), 33 cryptohome_outcome_(false), 34 cryptohome_code_(kCryptohomeMountErrorNone) { 35 } 36 37 AuthAttemptState::AuthAttemptState(const std::string& username, 38 const std::string& ascii_hash) 39 : username(username), 40 ascii_hash(ascii_hash), 41 unlock(true), 42 online_complete_(true), 43 online_outcome_(LoginFailure::UNLOCK_FAILED), 44 credentials_(GaiaAuthConsumer::ClientLoginResult()), 45 hosted_policy_(GaiaAuthFetcher::HostedAccountsAllowed), 46 is_first_time_user_(false), 47 cryptohome_complete_(false), 48 cryptohome_outcome_(false), 49 cryptohome_code_(kCryptohomeMountErrorNone) { 50 } 51 52 AuthAttemptState::~AuthAttemptState() {} 53 54 void AuthAttemptState::RecordOnlineLoginStatus( 55 const GaiaAuthConsumer::ClientLoginResult& credentials, 56 const LoginFailure& outcome) { 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 58 online_complete_ = true; 59 online_outcome_ = outcome; 60 credentials_ = credentials; 61 // We're either going to not try again, or try again with HOSTED 62 // accounts not allowed, so just set this here. 63 DisableHosted(); 64 } 65 66 void AuthAttemptState::DisableHosted() { 67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 68 hosted_policy_ = GaiaAuthFetcher::HostedAccountsNotAllowed; 69 } 70 71 void AuthAttemptState::RecordCryptohomeStatus(bool cryptohome_outcome, 72 int cryptohome_code) { 73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 74 cryptohome_complete_ = true; 75 cryptohome_outcome_ = cryptohome_outcome; 76 cryptohome_code_ = cryptohome_code; 77 } 78 79 void AuthAttemptState::ResetCryptohomeStatus() { 80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 81 cryptohome_complete_ = false; 82 cryptohome_outcome_ = false; 83 cryptohome_code_ = kCryptohomeMountErrorNone; 84 } 85 86 bool AuthAttemptState::online_complete() { 87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 88 return online_complete_; 89 } 90 91 const LoginFailure& AuthAttemptState::online_outcome() { 92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 93 return online_outcome_; 94 } 95 96 const GaiaAuthConsumer::ClientLoginResult& AuthAttemptState::credentials() { 97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 98 return credentials_; 99 } 100 101 bool AuthAttemptState::is_first_time_user() { 102 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 103 return is_first_time_user_; 104 } 105 106 GaiaAuthFetcher::HostedAccountsSetting AuthAttemptState::hosted_policy() { 107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 108 return hosted_policy_; 109 } 110 111 bool AuthAttemptState::cryptohome_complete() { 112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 113 return cryptohome_complete_; 114 } 115 116 bool AuthAttemptState::cryptohome_outcome() { 117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 118 return cryptohome_outcome_; 119 } 120 121 int AuthAttemptState::cryptohome_code() { 122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 123 return cryptohome_code_; 124 } 125 126 } // namespace chromeos 127