Update V8 to version 4.6.55.
[chromium-blink-merge.git] / chromeos / login / auth / auth_status_consumer.h
blobad202a5c8a4bba857b7dc1cc2f72699c0e99ef90
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_STATUS_CONSUMER_H_
6 #define CHROMEOS_LOGIN_AUTH_AUTH_STATUS_CONSUMER_H_
8 #include <string>
10 #include "base/logging.h"
11 #include "chromeos/chromeos_export.h"
12 #include "google_apis/gaia/gaia_auth_consumer.h"
13 #include "google_apis/gaia/google_service_auth_error.h"
14 #include "net/base/net_errors.h"
16 namespace chromeos {
18 class UserContext;
20 class CHROMEOS_EXPORT AuthFailure {
21 public:
22 enum FailureReason {
23 NONE,
24 COULD_NOT_MOUNT_CRYPTOHOME,
25 COULD_NOT_MOUNT_TMPFS,
26 COULD_NOT_UNMOUNT_CRYPTOHOME,
27 DATA_REMOVAL_FAILED, // Could not destroy your old data
28 LOGIN_TIMED_OUT,
29 UNLOCK_FAILED,
30 NETWORK_AUTH_FAILED, // Could not authenticate against Google
31 OWNER_REQUIRED, // Only the device owner can log-in.
32 WHITELIST_CHECK_FAILED, // Login attempt blocked by whitelist. This
33 // value is synthesized by the ExistingUserController and passed to the
34 // login_status_consumer_ in tests only. It is never generated or seen by
35 // any of the other authenticator classes.
36 TPM_ERROR, // Critical TPM error encountered.
37 USERNAME_HASH_FAILED, // Could not get username hash.
38 FAILED_TO_INITIALIZE_TOKEN, // Could not get OAuth2 Token,
39 NUM_FAILURE_REASONS, // This has to be the last item.
42 explicit AuthFailure(FailureReason reason)
43 : reason_(reason), error_(GoogleServiceAuthError::NONE) {
44 DCHECK(reason != NETWORK_AUTH_FAILED);
47 inline bool operator==(const AuthFailure& b) const {
48 if (reason_ != b.reason_) {
49 return false;
51 if (reason_ == NETWORK_AUTH_FAILED) {
52 return error_ == b.error_;
54 return true;
57 static AuthFailure FromNetworkAuthFailure(
58 const GoogleServiceAuthError& error) {
59 return AuthFailure(NETWORK_AUTH_FAILED, error);
62 static AuthFailure AuthFailureNone() { return AuthFailure(NONE); }
64 const std::string GetErrorString() const {
65 switch (reason_) {
66 case DATA_REMOVAL_FAILED:
67 return "Could not destroy your old data.";
68 case COULD_NOT_MOUNT_CRYPTOHOME:
69 return "Could not mount cryptohome.";
70 case COULD_NOT_UNMOUNT_CRYPTOHOME:
71 return "Could not unmount cryptohome.";
72 case COULD_NOT_MOUNT_TMPFS:
73 return "Could not mount tmpfs.";
74 case LOGIN_TIMED_OUT:
75 return "Login timed out. Please try again.";
76 case UNLOCK_FAILED:
77 return "Unlock failed.";
78 case NETWORK_AUTH_FAILED:
79 if (error_.state() == GoogleServiceAuthError::CONNECTION_FAILED) {
80 return net::ErrorToString(error_.network_error());
82 return "Google authentication failed.";
83 case OWNER_REQUIRED:
84 return "Login is restricted to the owner's account only.";
85 case WHITELIST_CHECK_FAILED:
86 return "Login attempt blocked by whitelist.";
87 case FAILED_TO_INITIALIZE_TOKEN:
88 return "OAuth2 token fetch failed.";
89 default:
90 NOTREACHED();
91 return std::string();
95 const GoogleServiceAuthError& error() const { return error_; }
96 const FailureReason& reason() const { return reason_; }
98 private:
99 AuthFailure(FailureReason reason, GoogleServiceAuthError error)
100 : reason_(reason), error_(error) {}
102 FailureReason reason_;
103 GoogleServiceAuthError error_;
106 // An interface that defines the callbacks for objects that the
107 // Authenticator class will call to report the success/failure of
108 // authentication for Chromium OS.
109 class CHROMEOS_EXPORT AuthStatusConsumer {
110 public:
111 virtual ~AuthStatusConsumer() {}
112 // The current login attempt has ended in failure, with error |error|.
113 virtual void OnAuthFailure(const AuthFailure& error) = 0;
115 // The current login attempt has succeeded for |user_context|.
116 virtual void OnAuthSuccess(const UserContext& user_context) = 0;
117 // The current guest login attempt has succeeded.
118 virtual void OnOffTheRecordAuthSuccess() {}
119 // The same password didn't work both online and offline.
120 virtual void OnPasswordChangeDetected();
123 } // namespace chromeos
125 #endif // CHROMEOS_LOGIN_AUTH_AUTH_STATUS_CONSUMER_H_