| 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_EXISTING_USER_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_EXISTING_USER_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_EXISTING_USER_CONTROLLER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_EXISTING_USER_CONTROLLER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
| 13 #include "base/task.h" | 13 #include "base/task.h" |
| 14 #include "base/timer.h" | 14 #include "base/timer.h" |
| 15 #include "chrome/browser/chromeos/login/background_view.h" | 15 #include "chrome/browser/chromeos/login/background_view.h" |
| 16 #include "chrome/browser/chromeos/login/captcha_view.h" | 16 #include "chrome/browser/chromeos/login/captcha_view.h" |
| 17 #include "chrome/browser/chromeos/login/login_performer.h" | 17 #include "chrome/browser/chromeos/login/login_performer.h" |
| 18 #include "chrome/browser/chromeos/login/message_bubble.h" | 18 #include "chrome/browser/chromeos/login/message_bubble.h" |
| 19 #include "chrome/browser/chromeos/login/password_changed_view.h" | 19 #include "chrome/browser/chromeos/login/password_changed_view.h" |
| 20 #include "chrome/browser/chromeos/login/user_controller.h" | 20 #include "chrome/browser/chromeos/login/user_controller.h" |
| 21 #include "chrome/browser/chromeos/login/user_manager.h" | 21 #include "chrome/browser/chromeos/login/user_manager.h" |
| 22 #include "chrome/browser/chromeos/wm_message_listener.h" | 22 #include "chrome/browser/chromeos/wm_message_listener.h" |
| 23 #include "gfx/size.h" | 23 #include "gfx/size.h" |
| 24 #include "testing/gtest/include/gtest/gtest_prod.h" |
| 24 | 25 |
| 25 namespace chromeos { | 26 namespace chromeos { |
| 26 | 27 |
| 27 class HelpAppLauncher; | 28 class HelpAppLauncher; |
| 28 class MessageBubble; | 29 class MessageBubble; |
| 29 class UserCrosSettingsProvider; | 30 class UserCrosSettingsProvider; |
| 30 | 31 |
| 31 // ExistingUserController is used to handle login when someone has | 32 // ExistingUserController is used to handle login when someone has |
| 32 // already logged into the machine. When Init is invoked, a | 33 // already logged into the machine. When Init is invoked, a |
| 33 // UserController is created for each of the Users's in the | 34 // UserController is created for each of the Users's in the |
| 34 // UserManager (including one for new user and one for Guest login), | 35 // UserManager (including one for new user and one for Guest login), |
| 35 // and the window manager is then told to show the windows. | 36 // and the window manager is then told to show the windows. |
| 36 // | 37 // |
| 37 // To use ExistingUserController create an instance of it and invoke Init. | 38 // To use ExistingUserController create an instance of it and invoke Init. |
| 38 // | 39 // |
| 39 // ExistingUserController maintains it's own life cycle and deletes itself when | 40 // ExistingUserController maintains it's own life cycle and deletes itself when |
| 40 // the user logs in (or chooses to see other settings). | 41 // the user logs in (or chooses to see other settings). |
| 41 class ExistingUserController : public WmMessageListener::Observer, | 42 class ExistingUserController : public WmMessageListener::Observer, |
| 42 public UserController::Delegate, | 43 public UserController::Delegate, |
| 43 public LoginPerformer::Delegate, | 44 public LoginPerformer::Delegate, |
| 44 public MessageBubbleDelegate, | 45 public MessageBubbleDelegate, |
| 45 public CaptchaView::Delegate, | 46 public CaptchaView::Delegate, |
| 46 public PasswordChangedView::Delegate { | 47 public PasswordChangedView::Delegate { |
| 47 public: | 48 public: |
| 48 // Initializes views for known users. |background_bounds| determines the | 49 // Initializes views for known users. |background_bounds| determines the |
| 49 // bounds of background view. | 50 // bounds of background view. |
| 50 ExistingUserController(const std::vector<UserManager::User>& users, | 51 ExistingUserController(const std::vector<UserManager::User>& users, |
| 51 const gfx::Rect& background_bounds); | 52 const gfx::Rect& background_bounds); |
| 52 | 53 |
| 54 // Returns the current existing user controller if it has been created. |
| 55 static ExistingUserController* current_controller() { |
| 56 return current_controller_; |
| 57 } |
| 58 |
| 53 // Creates and shows the appropriate set of windows. | 59 // Creates and shows the appropriate set of windows. |
| 54 void Init(); | 60 void Init(); |
| 55 | 61 |
| 56 // Takes ownership of the specified background widget and view. | 62 // Takes ownership of the specified background widget and view. |
| 57 void OwnBackground(views::Widget* background_widget, | 63 void OwnBackground(views::Widget* background_widget, |
| 58 chromeos::BackgroundView* background_view); | 64 chromeos::BackgroundView* background_view); |
| 59 | 65 |
| 60 // Tries to login from new user pod with given user login and password. | 66 // Tries to login from new user pod with given user login and password. |
| 61 // Called after creating new account. | 67 // Called after creating new account. |
| 62 void LoginNewUser(const std::string& username, const std::string& password); | 68 void LoginNewUser(const std::string& username, const std::string& password); |
| 63 | 69 |
| 64 // Selects new user pod. | 70 // Selects new user pod. |
| 65 void SelectNewUser(); | 71 void SelectNewUser(); |
| 66 | 72 |
| 67 private: | 73 private: |
| 68 friend class DeleteTask<ExistingUserController>; | 74 friend class DeleteTask<ExistingUserController>; |
| 75 friend class MockLoginPerformerDelegate; |
| 69 | 76 |
| 70 ~ExistingUserController(); | 77 ~ExistingUserController(); |
| 71 | 78 |
| 72 // Cover for invoking the destructor. Used by delete_timer_. | 79 // Cover for invoking the destructor. Used by delete_timer_. |
| 73 void Delete(); | 80 void Delete(); |
| 74 | 81 |
| 75 // WmMessageListener::Observer: | 82 // WmMessageListener::Observer: |
| 76 virtual void ProcessWmMessage(const WmIpc::Message& message, | 83 virtual void ProcessWmMessage(const WmIpc::Message& message, |
| 77 GdkWindow* window); | 84 GdkWindow* window); |
| 78 | 85 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 gfx::NativeWindow GetNativeWindow() const; | 129 gfx::NativeWindow GetNativeWindow() const; |
| 123 | 130 |
| 124 // Show error message. |error_id| error message ID in resources. | 131 // Show error message. |error_id| error message ID in resources. |
| 125 // If |details| string is not empty, it specify additional error text | 132 // If |details| string is not empty, it specify additional error text |
| 126 // provided by authenticator, it is not localized. | 133 // provided by authenticator, it is not localized. |
| 127 void ShowError(int error_id, const std::string& details); | 134 void ShowError(int error_id, const std::string& details); |
| 128 | 135 |
| 129 // Send message to window manager to enable/disable click on other windows. | 136 // Send message to window manager to enable/disable click on other windows. |
| 130 void SendSetLoginState(bool is_login); | 137 void SendSetLoginState(bool is_login); |
| 131 | 138 |
| 139 void set_login_performer_delegate(LoginPerformer::Delegate* d) { |
| 140 login_performer_delegate_.reset(d); |
| 141 } |
| 142 |
| 132 // Bounds of the background window. | 143 // Bounds of the background window. |
| 133 const gfx::Rect background_bounds_; | 144 const gfx::Rect background_bounds_; |
| 134 | 145 |
| 135 // Background window/view. | 146 // Background window/view. |
| 136 views::Widget* background_window_; | 147 views::Widget* background_window_; |
| 137 BackgroundView* background_view_; | 148 BackgroundView* background_view_; |
| 138 | 149 |
| 139 // The set of visible UserControllers. | 150 // The set of visible UserControllers. |
| 140 std::vector<UserController*> controllers_; | 151 std::vector<UserController*> controllers_; |
| 141 | 152 |
| 142 // The set of invisible UserControllers. | 153 // The set of invisible UserControllers. |
| 143 std::vector<UserController*> invisible_controllers_; | 154 std::vector<UserController*> invisible_controllers_; |
| 144 | 155 |
| 145 // Used to execute login operations. | 156 // Used to execute login operations. |
| 146 scoped_ptr<LoginPerformer> login_performer_; | 157 scoped_ptr<LoginPerformer> login_performer_; |
| 147 | 158 |
| 159 // Delegate for login performer to be overridden by tests. |
| 160 // |this| is used if |login_performer_delegate_| is NULL. |
| 161 scoped_ptr<LoginPerformer::Delegate> login_performer_delegate_; |
| 162 |
| 148 // Index of selected view (user). | 163 // Index of selected view (user). |
| 149 size_t selected_view_index_; | 164 size_t selected_view_index_; |
| 150 | 165 |
| 151 // Number of login attempts. Used to show help link when > 1 unsuccessful | 166 // Number of login attempts. Used to show help link when > 1 unsuccessful |
| 152 // logins for the same user. | 167 // logins for the same user. |
| 153 size_t num_login_attempts_; | 168 size_t num_login_attempts_; |
| 154 | 169 |
| 155 // See comment in ProcessWmMessage. | 170 // See comment in ProcessWmMessage. |
| 156 base::OneShotTimer<ExistingUserController> delete_timer_; | 171 base::OneShotTimer<ExistingUserController> delete_timer_; |
| 157 | 172 |
| 158 // Pointer to the instance that was scheduled to be deleted soon or NULL | 173 // Pointer to the current instance of the controller to be used by |
| 159 // if there is no such instance. | 174 // automation tests. |
| 160 static ExistingUserController* delete_scheduled_instance_; | 175 static ExistingUserController* current_controller_; |
| 161 | 176 |
| 162 // Pointer to shown message bubble. We don't need to delete it because | 177 // Pointer to shown message bubble. We don't need to delete it because |
| 163 // it will be deleted on bubble closing. | 178 // it will be deleted on bubble closing. |
| 164 MessageBubble* bubble_; | 179 MessageBubble* bubble_; |
| 165 | 180 |
| 166 // URL that will be opened on browser startup. | 181 // URL that will be opened on browser startup. |
| 167 GURL start_url_; | 182 GURL start_url_; |
| 168 | 183 |
| 169 // Help application used for help dialogs. | 184 // Help application used for help dialogs. |
| 170 scoped_ptr<HelpAppLauncher> help_app_; | 185 scoped_ptr<HelpAppLauncher> help_app_; |
| 171 | 186 |
| 172 // Triggers prefetching of user settings. | 187 // Triggers prefetching of user settings. |
| 173 scoped_ptr<UserCrosSettingsProvider> user_settings_; | 188 scoped_ptr<UserCrosSettingsProvider> user_settings_; |
| 174 | 189 |
| 175 // Factory of callbacks. | 190 // Factory of callbacks. |
| 176 ScopedRunnableMethodFactory<ExistingUserController> method_factory_; | 191 ScopedRunnableMethodFactory<ExistingUserController> method_factory_; |
| 177 | 192 |
| 193 FRIEND_TEST_ALL_PREFIXES(ExistingUserControllerTest, NewUserLogin); |
| 194 |
| 178 DISALLOW_COPY_AND_ASSIGN(ExistingUserController); | 195 DISALLOW_COPY_AND_ASSIGN(ExistingUserController); |
| 179 }; | 196 }; |
| 180 | 197 |
| 181 } // namespace chromeos | 198 } // namespace chromeos |
| 182 | 199 |
| 183 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_EXISTING_USER_CONTROLLER_H_ | 200 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_EXISTING_USER_CONTROLLER_H_ |
| OLD | NEW |