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.
5 #ifndef CHROMEOS_LOGIN_AUTH_AUTH_ATTEMPT_STATE_H_
6 #define CHROMEOS_LOGIN_AUTH_AUTH_ATTEMPT_STATE_H_
10 #include "base/memory/weak_ptr.h"
11 #include "chromeos/chromeos_export.h"
12 #include "chromeos/login/auth/auth_status_consumer.h"
13 #include "chromeos/login/auth/user_context.h"
14 #include "google_apis/gaia/gaia_auth_consumer.h"
15 #include "google_apis/gaia/gaia_auth_fetcher.h"
16 #include "third_party/cros_system_api/dbus/service_constants.h"
20 // Tracks the state associated with a single attempt to log in to chromium OS.
21 // Enforces that methods are only called on the UI thread.
22 class CHROMEOS_EXPORT AuthAttemptState
23 : public base::SupportsWeakPtr
<AuthAttemptState
> {
25 // Used to initialize for a login attempt.
26 AuthAttemptState(const UserContext
& user_context
,
31 virtual ~AuthAttemptState();
33 // Copy |user_context| and copy |outcome| into this object, so we can have
34 // a copy we're sure to own, and can make available on the UI thread.
35 // Must be called from the UI thread.
36 void RecordOnlineLoginStatus(const AuthFailure
& outcome
);
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
);
43 // Marks that the username hash request attempt has failed.
44 void RecordUsernameHashFailed();
46 // Marks username hash as being requested so that flow will block till both
47 // requests (Mount/GetUsernameHash) are completed.
48 void UsernameHashRequested();
50 // The next attempt will not allow HOSTED accounts to log in.
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
);
59 // Blow away locally stored cryptohome login status.
60 // Must be called from the UI thread.
61 void ResetCryptohomeStatus();
63 virtual bool online_complete();
64 virtual const AuthFailure
& online_outcome();
65 virtual bool is_first_time_user();
66 virtual GaiaAuthFetcher::HostedAccountsSetting
hosted_policy();
68 virtual bool cryptohome_complete();
69 virtual bool cryptohome_outcome();
70 virtual cryptohome::MountError
cryptohome_code();
72 virtual bool username_hash_obtained();
73 virtual bool username_hash_valid();
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
;
79 // These fields are saved so we can retry client login.
80 const std::string login_token
;
81 const std::string login_captcha
;
83 const bool unlock
; // True if authenticating to unlock the computer.
86 // Status of our online login attempt.
87 bool online_complete_
;
88 AuthFailure online_outcome_
;
90 // Whether or not we're accepting HOSTED accounts during the current
91 // online auth attempt.
92 GaiaAuthFetcher::HostedAccountsSetting hosted_policy_
;
93 bool is_first_time_user_
;
95 // Status of our cryptohome op attempt. Can only have one in flight at a time.
96 bool cryptohome_complete_
;
97 bool cryptohome_outcome_
;
98 cryptohome::MountError cryptohome_code_
;
101 // Status of the crypthome GetSanitizedUsername() async call.
102 // This gets initialized as being completed and those callers
103 // that would explicitly request username hash would have to reset this.
104 bool username_hash_obtained_
;
106 // After the username hash request is completed, this marks whether
107 // the request was successful.
108 bool username_hash_valid_
;
110 DISALLOW_COPY_AND_ASSIGN(AuthAttemptState
);
113 } // namespace chromeos
115 #endif // CHROMEOS_LOGIN_AUTH_AUTH_ATTEMPT_STATE_H_