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 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_AUTH_ATTEMPT_STATE_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_AUTH_ATTEMPT_STATE_H_ 7 8 #include <string> 9 10 #include "chrome/browser/chromeos/login/login_status_consumer.h" 11 #include "chrome/browser/chromeos/login/user.h" 12 #include "google_apis/gaia/gaia_auth_consumer.h" 13 #include "google_apis/gaia/gaia_auth_fetcher.h" 14 #include "third_party/cros_system_api/dbus/service_constants.h" 15 16 namespace chromeos { 17 18 // Tracks the state associated with a single attempt to log in to chromium os. 19 // Enforces that methods are only called on the IO thread. 20 21 class AuthAttemptState { 22 public: 23 // Used to initialize for a login attempt. 24 AuthAttemptState(const UserContext& user_context, 25 const std::string& ascii_hash, 26 const std::string& login_token, 27 const std::string& login_captcha, 28 const User::UserType user_type, 29 const bool user_is_new); 30 31 // Used to initialize for a externally authenticated login. 32 AuthAttemptState(const UserContext& user_context, 33 const std::string& ascii_hash, 34 const bool user_is_new); 35 36 // Used to initialize for a screen unlock attempt. 37 AuthAttemptState(const std::string& username, const std::string& ascii_hash); 38 39 virtual ~AuthAttemptState(); 40 41 // Copy |user_context| and copy |outcome| into this object, so we can have 42 // a copy we're sure to own, and can make available on the IO thread. 43 // Must be called from the IO thread. 44 void RecordOnlineLoginStatus( 45 const LoginFailure& outcome); 46 47 // Copy |username_hash| into this object, so we can have 48 // a copy we're sure to own, and can make available on the IO thread. 49 // Must be called from the IO thread. 50 void RecordUsernameHash(const std::string& username_hash); 51 52 // Marks username hash as being requested so that flow will block till both 53 // requests (Mount/GetUsernameHash) are completed. 54 void UsernameHashRequested(); 55 56 // The next attempt will not allow HOSTED accounts to log in. 57 void DisableHosted(); 58 59 // Copy |cryptohome_code| and |cryptohome_outcome| into this object, 60 // so we can have a copy we're sure to own, and can make available 61 // on the IO thread. Must be called from the IO thread. 62 void RecordCryptohomeStatus(bool cryptohome_outcome, 63 cryptohome::MountError cryptohome_code); 64 65 // Blow away locally stored cryptohome login status. 66 // Must be called from the IO thread. 67 void ResetCryptohomeStatus(); 68 69 virtual bool online_complete(); 70 virtual const LoginFailure& online_outcome(); 71 virtual bool is_first_time_user(); 72 virtual GaiaAuthFetcher::HostedAccountsSetting hosted_policy(); 73 74 virtual bool cryptohome_complete(); 75 virtual bool cryptohome_outcome(); 76 virtual cryptohome::MountError cryptohome_code(); 77 78 virtual bool username_hash_obtained(); 79 80 // Saved so we can retry client login, and also so we know for whom login 81 // has succeeded, in the event of successful completion. 82 UserContext user_context; 83 84 // These fields are saved so we can retry client login. 85 const std::string ascii_hash; 86 const std::string login_token; 87 const std::string login_captcha; 88 89 // The type of the user attempting to log in. 90 const User::UserType user_type; 91 92 const bool unlock; // True if authenticating to unlock the computer. 93 94 protected: 95 // Status of our online login attempt. 96 bool online_complete_; 97 LoginFailure online_outcome_; 98 99 // Whether or not we're accepting HOSTED accounts during the current 100 // online auth attempt. 101 GaiaAuthFetcher::HostedAccountsSetting hosted_policy_; 102 bool is_first_time_user_; 103 104 // Status of our cryptohome op attempt. Can only have one in flight at a time. 105 bool cryptohome_complete_; 106 bool cryptohome_outcome_; 107 cryptohome::MountError cryptohome_code_; 108 109 private: 110 // Status of the crypthome GetSanitizedUsername() async call. 111 // This gets initialized as being completed and those callers 112 // that would explicitly request username hash would have to reset this. 113 bool username_hash_obtained_; 114 115 DISALLOW_COPY_AND_ASSIGN(AuthAttemptState); 116 }; 117 118 } // namespace chromeos 119 120 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_AUTH_ATTEMPT_STATE_H_ 121