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 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_AUTH_ATTEMPT_STATE_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_AUTH_ATTEMPT_STATE_H_ 7 #pragma once 8 9 #include <string> 10 11 #include "chrome/browser/chromeos/login/login_status_consumer.h" 12 #include "chrome/common/net/gaia/gaia_auth_consumer.h" 13 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" 14 15 namespace chromeos { 16 17 // Tracks the state associated with a single attempt to log in to chromium os. 18 // Enforces that methods are only called on the IO thread. 19 20 class AuthAttemptState { 21 public: 22 // Used to initalize for a login attempt. 23 AuthAttemptState(const std::string& username, 24 const std::string& password, 25 const std::string& ascii_hash, 26 const std::string& login_token, 27 const std::string& login_captcha, 28 const bool user_is_new); 29 30 // Used to initalize for a screen unlock attempt. 31 AuthAttemptState(const std::string& username, const std::string& ascii_hash); 32 33 virtual ~AuthAttemptState(); 34 35 // Copy |credentials| and |outcome| into this object, so we can have 36 // a copy we're sure to own, and can make available on the IO thread. 37 // Must be called from the IO thread. 38 void RecordOnlineLoginStatus( 39 const GaiaAuthConsumer::ClientLoginResult& credentials, 40 const LoginFailure& outcome); 41 42 // The next attempt will not allow HOSTED accounts to log in. 43 void DisableHosted(); 44 45 // Copy |cryptohome_code| and |cryptohome_outcome| into this object, 46 // so we can have a copy we're sure to own, and can make available 47 // on the IO thread. Must be called from the IO thread. 48 void RecordCryptohomeStatus(bool cryptohome_outcome, int cryptohome_code); 49 50 // Blow away locally stored cryptohome login status. 51 // Must be called from the IO thread. 52 void ResetCryptohomeStatus(); 53 54 virtual bool online_complete(); 55 virtual const LoginFailure& online_outcome(); 56 virtual const GaiaAuthConsumer::ClientLoginResult& credentials(); 57 virtual bool is_first_time_user(); 58 virtual GaiaAuthFetcher::HostedAccountsSetting hosted_policy(); 59 60 virtual bool cryptohome_complete(); 61 virtual bool cryptohome_outcome(); 62 virtual int cryptohome_code(); 63 64 // Saved so we can retry client login, and also so we know for whom login 65 // has succeeded, in the event of successful completion. 66 const std::string username; 67 68 // These fields are saved so we can retry client login. 69 const std::string password; 70 const std::string ascii_hash; 71 const std::string login_token; 72 const std::string login_captcha; 73 74 const bool unlock; // True if authenticating to unlock the computer. 75 76 protected: 77 bool try_again_; // True if we're willing to retry the login attempt. 78 79 // Status of our online login attempt. 80 bool online_complete_; 81 LoginFailure online_outcome_; 82 GaiaAuthConsumer::ClientLoginResult credentials_; 83 84 // Whether or not we're accepting HOSTED accounts during the current 85 // online auth attempt. 86 GaiaAuthFetcher::HostedAccountsSetting hosted_policy_; 87 bool is_first_time_user_; 88 89 // Status of our cryptohome op attempt. Can only have one in flight at a time. 90 bool cryptohome_complete_; 91 bool cryptohome_outcome_; 92 int cryptohome_code_; 93 94 private: 95 DISALLOW_COPY_AND_ASSIGN(AuthAttemptState); 96 }; 97 98 } // namespace chromeos 99 100 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_AUTH_ATTEMPT_STATE_H_ 101