Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / chromeos / login / auth / auth_attempt_state.h
blob04b0cbbb43fe2d7d7ab710cc3807ea536c184b3f
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 "chromeos/chromeos_export.h"
11 #include "chromeos/login/auth/auth_status_consumer.h"
12 #include "chromeos/login/auth/user_context.h"
13 #include "components/user_manager/user_type.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"
18 namespace chromeos {
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:
24 // Used to initialize for a login attempt.
25 AuthAttemptState(const UserContext& user_context,
26 user_manager::UserType user_type,
27 bool unlock,
28 bool online_complete,
29 bool user_is_new);
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.
51 void DisableHosted();
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 // The type of the user attempting to log in.
84 const user_manager::UserType user_type;
86 const bool unlock; // True if authenticating to unlock the computer.
88 protected:
89 // Status of our online login attempt.
90 bool online_complete_;
91 AuthFailure online_outcome_;
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_;
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_;
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_;
109 // After the username hash request is completed, this marks whether
110 // the request was successful.
111 bool username_hash_valid_;
113 DISALLOW_COPY_AND_ASSIGN(AuthAttemptState);
116 } // namespace chromeos
118 #endif // CHROMEOS_LOGIN_AUTH_AUTH_ATTEMPT_STATE_H_