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