OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_PERFORMER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_PERFORMER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_PERFORMER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_PERFORMER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
13 #include "chrome/browser/chromeos/login/authenticator.h" | 13 #include "chrome/browser/chromeos/login/authenticator.h" |
14 #include "chrome/browser/chromeos/login/login_status_consumer.h" | 14 #include "chrome/browser/chromeos/login/login_status_consumer.h" |
15 #include "chrome/browser/chromeos/login/signed_settings_helper.h" | 15 #include "chrome/browser/chromeos/login/signed_settings_helper.h" |
16 #include "chrome/common/net/gaia/google_service_auth_error.h" | 16 #include "chrome/common/net/gaia/google_service_auth_error.h" |
| 17 #include "chrome/common/notification_observer.h" |
| 18 #include "chrome/common/notification_registrar.h" |
17 | 19 |
18 namespace chromeos { | 20 namespace chromeos { |
19 | 21 |
20 // This class encapsulates sign in operations. | 22 // This class encapsulates sign in operations. |
21 // Sign in is performed in a way that offline login is executed first. | 23 // Sign in is performed in a way that offline auth is executed first. |
22 // Once it's successful user homedir is mounted, UI is launched. | 24 // Once offline auth is OK - user homedir is mounted, UI is launched. |
23 // If concurrent online login operation would fail that means: | 25 // At this point LoginPerformer |delegate_| is destroyed and LP instance |
24 // - User password has changed. Ask user for the new password. | 26 // ownership is released. It waits for online login result. |
25 // - User password has changed & CAPTCHA input is required. | 27 // If it succeeded, cookie fetcher is executed, LP instance deletes itself. |
26 // If |delegate_| is not NULL it will handle | 28 // If online login operation fails that means: |
27 // password changed and CAPTCHA dialogs. | 29 // (1) User password has changed. Ask user for the new password. |
| 30 // (2) User password has changed and/or CAPTCHA input is required. |
| 31 // (3) User account is deleted/disabled/not signed up. |
| 32 // (4) Timeout/service unavailable/connection failed. |
| 33 // Actions: |
| 34 // (1)-(3): Request screen lock. |
| 35 // (1) Ask for new user password. |
| 36 // (2) Ask for new user password and/or CAPTCHA. |
| 37 // (3) Display error message and allow "Sign Out" as the only action. |
| 38 // (4) Delete LP instance since offline auth was OK. |
| 39 // If |delegate_| is not NULL it will handle error messages, |
| 40 // CAPTCHA dialog, password input. |
28 // If |delegate_| is NULL that does mean that LoginPerformer instance | 41 // If |delegate_| is NULL that does mean that LoginPerformer instance |
29 // is waiting for online login operation. | 42 // is waiting for successful online login or blocked on online login failure. |
30 // In case of failure use ScreenLock and ask for a new password. | 43 // In case of failure password/captcha |
| 44 // input & error messages display is dedicated to ScreenLocker instance. |
31 class LoginPerformer : public LoginStatusConsumer, | 45 class LoginPerformer : public LoginStatusConsumer, |
32 public SignedSettingsHelper::Callback { | 46 public SignedSettingsHelper::Callback, |
| 47 public NotificationObserver { |
33 public: | 48 public: |
34 // Delegate class to get notifications from the LoginPerformer. | 49 // Delegate class to get notifications from the LoginPerformer. |
35 class Delegate : public LoginStatusConsumer { | 50 class Delegate : public LoginStatusConsumer { |
36 public: | 51 public: |
37 virtual ~Delegate() {} | 52 virtual ~Delegate() {} |
38 virtual void WhiteListCheckFailed(const std::string& email) = 0; | 53 virtual void WhiteListCheckFailed(const std::string& email) = 0; |
39 }; | 54 }; |
40 | 55 |
41 explicit LoginPerformer(Delegate* delegate); | 56 explicit LoginPerformer(Delegate* delegate); |
| 57 ~LoginPerformer(); |
| 58 |
| 59 // Returns the default instance if it has been created. |
| 60 // This instance is owned by delegate_ till it's destroyed. |
| 61 // When LP instance lives by itself it's used by ScreenLocker instance. |
| 62 static LoginPerformer* default_performer() { |
| 63 return default_performer_; |
| 64 } |
42 | 65 |
43 // LoginStatusConsumer implementation: | 66 // LoginStatusConsumer implementation: |
44 virtual void OnLoginFailure(const LoginFailure& error); | 67 virtual void OnLoginFailure(const LoginFailure& error); |
45 virtual void OnLoginSuccess( | 68 virtual void OnLoginSuccess( |
46 const std::string& username, | 69 const std::string& username, |
47 const std::string& password, | 70 const std::string& password, |
48 const GaiaAuthConsumer::ClientLoginResult& credentials, | 71 const GaiaAuthConsumer::ClientLoginResult& credentials, |
49 bool pending_requests); | 72 bool pending_requests); |
50 virtual void OnOffTheRecordLoginSuccess(); | 73 virtual void OnOffTheRecordLoginSuccess(); |
51 virtual void OnPasswordChangeDetected( | 74 virtual void OnPasswordChangeDetected( |
52 const GaiaAuthConsumer::ClientLoginResult& credentials); | 75 const GaiaAuthConsumer::ClientLoginResult& credentials); |
53 | 76 |
54 // SignedSettingsHelper::Callback | 77 // SignedSettingsHelper::Callback implementation: |
55 virtual void OnCheckWhiteListCompleted(bool success, | 78 virtual void OnCheckWhiteListCompleted(bool success, |
56 const std::string& email); | 79 const std::string& email); |
57 | 80 |
| 81 // NotificationObserver implementation: |
| 82 virtual void Observe(NotificationType type, |
| 83 const NotificationSource& source, |
| 84 const NotificationDetails& details); |
| 85 |
58 // Performs login with the |username| and |password| specified. | 86 // Performs login with the |username| and |password| specified. |
59 void Login(const std::string& username, const std::string& password); | 87 void Login(const std::string& username, const std::string& password); |
60 | 88 |
61 // Performs actions to prepare Guest mode login. | 89 // Performs actions to prepare Guest mode login. |
62 void LoginOffTheRecord(); | 90 void LoginOffTheRecord(); |
63 | 91 |
64 // Migrates cryptohome using |old_password| specified. | 92 // Migrates cryptohome using |old_password| specified. |
65 void RecoverEncryptedData(const std::string& old_password); | 93 void RecoverEncryptedData(const std::string& old_password); |
66 | 94 |
67 // Reinitializes cryptohome with the new password. | 95 // Reinitializes cryptohome with the new password. |
68 void ResyncEncryptedData(); | 96 void ResyncEncryptedData(); |
69 | 97 |
70 // Returns latest auth error. | 98 // Returns latest auth error. |
71 const GoogleServiceAuthError& error() const { | 99 const GoogleServiceAuthError& error() const { |
72 return last_login_failure_.error(); | 100 return last_login_failure_.error(); |
73 } | 101 } |
74 | 102 |
75 // True if last login operation has timed out. | 103 // True if last login operation has timed out. |
76 bool login_timed_out() { | 104 bool login_timed_out() { |
77 return last_login_failure_.reason() == LoginFailure::LOGIN_TIMED_OUT; | 105 return last_login_failure_.reason() == LoginFailure::LOGIN_TIMED_OUT; |
78 } | 106 } |
79 | 107 |
80 void set_captcha(const std::string& captcha) { captcha_ = captcha; } | 108 void set_captcha(const std::string& captcha) { captcha_ = captcha; } |
81 void set_delegate(Delegate* delegate) { delegate_ = delegate; } | 109 void set_delegate(Delegate* delegate) { delegate_ = delegate; } |
82 | 110 |
83 private: | 111 private: |
| 112 // Requests screen lock and subscribes to screen lock notifications. |
| 113 void RequestScreenLock(); |
| 114 |
| 115 // Requests screen unlock. |
| 116 void RequestScreenUnlock(); |
| 117 |
| 118 // Resolves initial LoginFailure::NETWORK_AUTH_FAILED error i.e. |
| 119 // when screen is not locked yet. |
| 120 void ResolveInitialNetworkAuthFailure(); |
| 121 |
| 122 // Resolves LoginFailure when screen is locked. |
| 123 void ResolveLockLoginFailure(); |
| 124 |
| 125 // Resolves LoginFailure::NETWORK_AUTH_FAILED error when screen is locked. |
| 126 // Uses ScreenLocker to show error message based on |last_login_failure_|. |
| 127 void ResolveLockNetworkAuthFailure(); |
| 128 |
| 129 // Resolve ScreenLock changed state. |
| 130 void ResolveScreenLocked(); |
| 131 void ResolveScreenUnlocked(); |
| 132 |
84 // Starts authentication. | 133 // Starts authentication. |
85 void StartAuthentication(); | 134 void StartAuthentication(); |
86 | 135 |
| 136 // Default performer. Will be used by ScreenLocker. |
| 137 static LoginPerformer* default_performer_; |
| 138 |
87 // Used for logging in. | 139 // Used for logging in. |
88 scoped_refptr<Authenticator> authenticator_; | 140 scoped_refptr<Authenticator> authenticator_; |
89 | 141 |
90 // Represents last login failure that was encountered when communicating to | 142 // Represents last login failure that was encountered when communicating to |
91 // sign-in server. LoginFailure.None() by default. | 143 // sign-in server. LoginFailure.None() by default. |
92 LoginFailure last_login_failure_; | 144 LoginFailure last_login_failure_; |
93 | 145 |
94 // String entered by the user as an answer to a CAPTCHA challenge. | 146 // String entered by the user as an answer to a CAPTCHA challenge. |
95 std::string captcha_; | 147 std::string captcha_; |
96 | 148 |
97 // Token representing the specific CAPTCHA challenge. | 149 // Token representing the specific CAPTCHA challenge. |
98 std::string captcha_token_; | 150 std::string captcha_token_; |
99 | 151 |
100 // Cached credentials data when password change is detected. | 152 // Cached credentials data when password change is detected. |
101 GaiaAuthConsumer::ClientLoginResult cached_credentials_; | 153 GaiaAuthConsumer::ClientLoginResult cached_credentials_; |
102 | 154 |
103 // Username and password for the current login attempt. | 155 // Username and password for the current login attempt. |
104 std::string username_; | 156 std::string username_; |
105 std::string password_; | 157 std::string password_; |
106 | 158 |
107 // Notifications receiver. | 159 // Notifications receiver. |
108 Delegate* delegate_; | 160 Delegate* delegate_; |
109 | 161 |
| 162 // True if password change has been detected. |
| 163 // Once correct password is entered homedir migration is executed. |
| 164 bool password_changed_; |
| 165 |
| 166 NotificationRegistrar registrar_; |
| 167 |
110 DISALLOW_COPY_AND_ASSIGN(LoginPerformer); | 168 DISALLOW_COPY_AND_ASSIGN(LoginPerformer); |
111 }; | 169 }; |
112 | 170 |
113 } // namespace chromeos | 171 } // namespace chromeos |
114 | 172 |
115 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_PERFORMER_H_ | 173 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_PERFORMER_H_ |
OLD | NEW |