• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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.
4 
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_EXISTING_USER_CONTROLLER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_EXISTING_USER_CONTROLLER_H_
7 #pragma once
8 
9 #include <string>
10 
11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/string16.h"
14 #include "base/task.h"
15 #include "base/timer.h"
16 #include "chrome/browser/chromeos/login/captcha_view.h"
17 #include "chrome/browser/chromeos/login/login_display.h"
18 #include "chrome/browser/chromeos/login/login_performer.h"
19 #include "chrome/browser/chromeos/login/login_utils.h"
20 #include "chrome/browser/chromeos/login/ownership_status_checker.h"
21 #include "chrome/browser/chromeos/login/password_changed_view.h"
22 #include "chrome/browser/chromeos/login/user_manager.h"
23 #include "chrome/browser/chromeos/wm_message_listener.h"
24 #include "content/common/notification_observer.h"
25 #include "content/common/notification_registrar.h"
26 #include "googleurl/src/gurl.h"
27 #include "testing/gtest/include/gtest/gtest_prod.h"
28 #include "ui/gfx/rect.h"
29 
30 namespace chromeos {
31 
32 class LoginDisplayHost;
33 class UserCrosSettingsProvider;
34 
35 // ExistingUserController is used to handle login when someone has
36 // already logged into the machine.
37 // To use ExistingUserController create an instance of it and invoke Init.
38 // When Init is called it creates LoginDisplay instance which encapsulates
39 // all login UI implementation.
40 // ExistingUserController maintains it's own life cycle and deletes itself when
41 // the user logs in (or chooses to see other settings).
42 class ExistingUserController : public LoginDisplay::Delegate,
43                                public NotificationObserver,
44                                public LoginPerformer::Delegate,
45                                public LoginUtils::Delegate,
46                                public CaptchaView::Delegate,
47                                public PasswordChangedView::Delegate {
48  public:
49   // All UI initialization is deferred till Init() call.
50   explicit ExistingUserController(LoginDisplayHost* host);
51   ~ExistingUserController();
52 
53   // Returns the current existing user controller if it has been created.
current_controller()54   static ExistingUserController* current_controller() {
55     return current_controller_;
56   }
57 
58   // Creates and shows login UI for known users.
59   void Init(const UserVector& users);
60 
61   // LoginDisplay::Delegate: implementation
62   virtual void CreateAccount() OVERRIDE;
63   virtual string16 GetConnectedNetworkName() OVERRIDE;
64   virtual void FixCaptivePortal() OVERRIDE;
65   virtual void Login(const std::string& username,
66                      const std::string& password) OVERRIDE;
67   virtual void LoginAsGuest() OVERRIDE;
68   virtual void OnUserSelected(const std::string& username) OVERRIDE;
69   virtual void OnStartEnterpriseEnrollment() OVERRIDE;
70 
71   // NotificationObserver implementation.
72   virtual void Observe(NotificationType type,
73                        const NotificationSource& source,
74                        const NotificationDetails& details);
75 
76  private:
77   friend class ExistingUserControllerTest;
78   friend class MockLoginPerformerDelegate;
79 
80   // LoginPerformer::Delegate implementation:
81   virtual void OnLoginFailure(const LoginFailure& error);
82   virtual void OnLoginSuccess(
83       const std::string& username,
84       const std::string& password,
85       const GaiaAuthConsumer::ClientLoginResult& credentials,
86       bool pending_requests);
87   virtual void OnOffTheRecordLoginSuccess();
88   virtual void OnPasswordChangeDetected(
89       const GaiaAuthConsumer::ClientLoginResult& credentials);
90   virtual void WhiteListCheckFailed(const std::string& email);
91 
92   // LoginUtils::Delegate implementation:
93   virtual void OnProfilePrepared(Profile* profile);
94 
95   // CaptchaView::Delegate:
96   virtual void OnCaptchaEntered(const std::string& captcha);
97 
98   // PasswordChangedView::Delegate:
99   virtual void RecoverEncryptedData(const std::string& old_password);
100   virtual void ResyncEncryptedData();
101 
102   // Starts WizardController with the specified screen.
103   void ActivateWizard(const std::string& screen_name);
104 
105   // Returns corresponding native window.
106   gfx::NativeWindow GetNativeWindow() const;
107 
108   // Changes state of the status area. During login operation it's disabled.
109   void SetStatusAreaEnabled(bool enable);
110 
111   // Show error message. |error_id| error message ID in resources.
112   // If |details| string is not empty, it specify additional error text
113   // provided by authenticator, it is not localized.
114   void ShowError(int error_id, const std::string& details);
115 
116   // Handles result of ownership check and starts enterprise enrollment if
117   // applicable.
118   void OnEnrollmentOwnershipCheckCompleted(OwnershipService::Status status);
119 
set_login_performer_delegate(LoginPerformer::Delegate * d)120   void set_login_performer_delegate(LoginPerformer::Delegate* d) {
121     login_performer_delegate_.reset(d);
122   }
123 
124   // Used to execute login operations.
125   scoped_ptr<LoginPerformer> login_performer_;
126 
127   // Login UI implementation instance.
128   LoginDisplay* login_display_;
129 
130   // Delegate for login performer to be overridden by tests.
131   // |this| is used if |login_performer_delegate_| is NULL.
132   scoped_ptr<LoginPerformer::Delegate> login_performer_delegate_;
133 
134   // Username of the last login attempt.
135   std::string last_login_attempt_username_;
136 
137   // OOBE/login display host.
138   LoginDisplayHost* host_;
139 
140   // Number of login attempts. Used to show help link when > 1 unsuccessful
141   // logins for the same user.
142   size_t num_login_attempts_;
143 
144   // Pointer to the current instance of the controller to be used by
145   // automation tests.
146   static ExistingUserController* current_controller_;
147 
148   // Triggers prefetching of user settings.
149   scoped_ptr<UserCrosSettingsProvider> user_settings_;
150 
151   // URL to append to start Guest mode with.
152   GURL guest_mode_url_;
153 
154   // Used for user image changed notifications.
155   NotificationRegistrar registrar_;
156 
157   // Factory of callbacks.
158   ScopedRunnableMethodFactory<ExistingUserController> method_factory_;
159 
160   // Whether everything is ready to launch the browser.
161   bool ready_for_browser_launch_;
162 
163   // Whether two factor credentials were used.
164   bool two_factor_credentials_;
165 
166   // Used to verify ownership before starting enterprise enrollment.
167   scoped_ptr<OwnershipStatusChecker> ownership_checker_;
168 
169   FRIEND_TEST_ALL_PREFIXES(ExistingUserControllerTest, NewUserLogin);
170 
171   DISALLOW_COPY_AND_ASSIGN(ExistingUserController);
172 };
173 
174 }  // namespace chromeos
175 
176 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_EXISTING_USER_CONTROLLER_H_
177