Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / chromeos / login / auth_attempt_state.h
blob4b01b3954e16b3a60599d0aa089afe786cb68f13
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.
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_AUTH_ATTEMPT_STATE_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_AUTH_ATTEMPT_STATE_H_
8 #include <string>
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"
16 namespace chromeos {
18 // Tracks the state associated with a single attempt to log in to chromium os.
19 // 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 const std::string& login_token,
26 const std::string& login_captcha,
27 const User::UserType user_type,
28 const bool user_is_new);
30 // Used to initialize for a externally authenticated login.
31 AuthAttemptState(const UserContext& user_context,
32 const bool user_is_new);
34 // Used to initialize for a screen unlock attempt.
35 AuthAttemptState(const std::string& username, const std::string& password);
37 virtual ~AuthAttemptState();
39 // Copy |user_context| and copy |outcome| into this object, so we can have
40 // a copy we're sure to own, and can make available on the UI thread.
41 // Must be called from the UI thread.
42 void RecordOnlineLoginStatus(
43 const LoginFailure& outcome);
45 // Copy |username_hash| into this object, so we can have
46 // a copy we're sure to own, and can make available on the UI thread.
47 // Must be called from the UI thread.
48 void RecordUsernameHash(const std::string& username_hash);
50 // Marks that the username hash request attempt has failed.
51 void RecordUsernameHashFailed();
53 // Marks username hash as being requested so that flow will block till both
54 // requests (Mount/GetUsernameHash) are completed.
55 void UsernameHashRequested();
57 // The next attempt will not allow HOSTED accounts to log in.
58 void DisableHosted();
60 // Copy |cryptohome_code| and |cryptohome_outcome| into this object,
61 // so we can have a copy we're sure to own, and can make available
62 // on the UI thread. Must be called from the UI thread.
63 void RecordCryptohomeStatus(bool cryptohome_outcome,
64 cryptohome::MountError cryptohome_code);
66 // Blow away locally stored cryptohome login status.
67 // Must be called from the UI thread.
68 void ResetCryptohomeStatus();
70 virtual bool online_complete();
71 virtual const LoginFailure& online_outcome();
72 virtual bool is_first_time_user();
73 virtual GaiaAuthFetcher::HostedAccountsSetting hosted_policy();
75 virtual bool cryptohome_complete();
76 virtual bool cryptohome_outcome();
77 virtual cryptohome::MountError cryptohome_code();
79 virtual bool username_hash_obtained();
80 virtual bool username_hash_valid();
82 // Saved so we can retry client login, and also so we know for whom login
83 // has succeeded, in the event of successful completion.
84 UserContext user_context;
86 // These fields are saved so we can retry client login.
87 const std::string login_token;
88 const std::string login_captcha;
90 // The type of the user attempting to log in.
91 const User::UserType user_type;
93 const bool unlock; // True if authenticating to unlock the computer.
95 protected:
96 // Status of our online login attempt.
97 bool online_complete_;
98 LoginFailure online_outcome_;
100 // Whether or not we're accepting HOSTED accounts during the current
101 // online auth attempt.
102 GaiaAuthFetcher::HostedAccountsSetting hosted_policy_;
103 bool is_first_time_user_;
105 // Status of our cryptohome op attempt. Can only have one in flight at a time.
106 bool cryptohome_complete_;
107 bool cryptohome_outcome_;
108 cryptohome::MountError cryptohome_code_;
110 private:
111 // Status of the crypthome GetSanitizedUsername() async call.
112 // This gets initialized as being completed and those callers
113 // that would explicitly request username hash would have to reset this.
114 bool username_hash_obtained_;
116 // After the username hash request is completed, this marks whether
117 // the request was successful.
118 bool username_hash_valid_;
120 DISALLOW_COPY_AND_ASSIGN(AuthAttemptState);
123 } // namespace chromeos
125 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_AUTH_ATTEMPT_STATE_H_