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