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_LOGIN_STATUS_CONSUMER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_STATUS_CONSUMER_H_
10 #include "base/logging.h"
11 #include "google_apis/gaia/gaia_auth_consumer.h"
12 #include "google_apis/gaia/google_service_auth_error.h"
13 #include "net/base/net_errors.h"
23 COULD_NOT_MOUNT_CRYPTOHOME
,
24 COULD_NOT_MOUNT_TMPFS
,
25 COULD_NOT_UNMOUNT_CRYPTOHOME
,
26 DATA_REMOVAL_FAILED
, // Could not destroy your old data
29 NETWORK_AUTH_FAILED
, // Could not authenticate against Google
30 OWNER_REQUIRED
, // Only the device owner can log-in.
31 WHITELIST_CHECK_FAILED
, // Login attempt blocked by whitelist. This value is
32 // synthesized by the ExistingUserController and
33 // passed to the login_status_consumer_ in tests
34 // only. It is never generated or seen by any of the
35 // other authenticator classes.
36 TPM_ERROR
, // Critical TPM error encountered.
37 USERNAME_HASH_FAILED
, // Could not get username hash.
38 NUM_FAILURE_REASONS
, // This has to be the last item.
41 explicit LoginFailure(FailureReason reason
)
43 error_(GoogleServiceAuthError::NONE
) {
44 DCHECK(reason
!= NETWORK_AUTH_FAILED
);
47 inline bool operator==(const LoginFailure
&b
) const {
48 if (reason_
!= b
.reason_
) {
51 if (reason_
== NETWORK_AUTH_FAILED
) {
52 return error_
== b
.error_
;
57 static LoginFailure
FromNetworkAuthFailure(
58 const GoogleServiceAuthError
& error
) {
59 return LoginFailure(NETWORK_AUTH_FAILED
, error
);
62 static LoginFailure
LoginFailureNone() {
63 return LoginFailure(NONE
);
66 const std::string
GetErrorString() const {
68 case DATA_REMOVAL_FAILED
:
69 return "Could not destroy your old data.";
70 case COULD_NOT_MOUNT_CRYPTOHOME
:
71 return "Could not mount cryptohome.";
72 case COULD_NOT_UNMOUNT_CRYPTOHOME
:
73 return "Could not unmount cryptohome.";
74 case COULD_NOT_MOUNT_TMPFS
:
75 return "Could not mount tmpfs.";
77 return "Login timed out. Please try again.";
79 return "Unlock failed.";
80 case NETWORK_AUTH_FAILED
:
81 if (error_
.state() == GoogleServiceAuthError::CONNECTION_FAILED
) {
82 return net::ErrorToString(error_
.network_error());
84 return "Google authentication failed.";
86 return "Login is restricted to the owner's account only.";
87 case WHITELIST_CHECK_FAILED
:
88 return "Login attempt blocked by whitelist.";
95 const GoogleServiceAuthError
& error() const { return error_
; }
96 const FailureReason
& reason() const { return reason_
; }
99 LoginFailure(FailureReason reason
, GoogleServiceAuthError error
)
104 FailureReason reason_
;
105 GoogleServiceAuthError error_
;
108 // An interface that defines the callbacks for objects that the
109 // Authenticator class will call to report the success/failure of
110 // authentication for Chromium OS.
111 class LoginStatusConsumer
{
113 virtual ~LoginStatusConsumer() {}
114 // The current login attempt has ended in failure, with error |error|.
115 virtual void OnLoginFailure(const LoginFailure
& error
) = 0;
117 // The current retail mode login attempt has succeeded.
118 // Unless overridden for special processing, this should always call
119 // OnLoginSuccess with the magic |kRetailModeUserEMail| constant.
120 virtual void OnRetailModeLoginSuccess(const UserContext
& user_context
);
121 // The current login attempt has succeeded for |user_context|.
122 virtual void OnLoginSuccess(const UserContext
& user_context
) = 0;
123 // The current guest login attempt has succeeded.
124 virtual void OnOffTheRecordLoginSuccess() {}
125 // The same password didn't work both online and offline.
126 virtual void OnPasswordChangeDetected();
129 } // namespace chromeos
131 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_STATUS_CONSUMER_H_