cros: Wait for auto enrollment check before enabling kiosk.
[chromium-blink-merge.git] / chrome / browser / chromeos / login / login_display_host_impl.h
blob858a8cf599ef2c12339342c68b41e85177171d71
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_DISPLAY_HOST_IMPL_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_DISPLAY_HOST_IMPL_H_
8 #include <string>
9 #include <vector>
11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "chrome/browser/chromeos/login/app_launch_controller.h"
15 #include "chrome/browser/chromeos/login/auth_prewarmer.h"
16 #include "chrome/browser/chromeos/login/existing_user_controller.h"
17 #include "chrome/browser/chromeos/login/login_display.h"
18 #include "chrome/browser/chromeos/login/login_display_host.h"
19 #include "chrome/browser/chromeos/login/wizard_controller.h"
20 #include "chrome/browser/chromeos/settings/device_settings_service.h"
21 #include "content/public/browser/notification_observer.h"
22 #include "content/public/browser/notification_registrar.h"
23 #include "content/public/browser/web_contents_observer.h"
24 #include "ui/gfx/rect.h"
26 class PrefService;
28 namespace policy {
29 class AutoEnrollmentClient;
30 } // namespace policy
32 namespace chromeos {
34 class FocusRingController;
35 class OobeUI;
36 class WebUILoginDisplay;
37 class WebUILoginView;
39 // An implementation class for OOBE/login WebUI screen host.
40 // It encapsulates controllers, background integration and flow.
41 class LoginDisplayHostImpl : public LoginDisplayHost,
42 public content::NotificationObserver,
43 public content::WebContentsObserver {
44 public:
45 explicit LoginDisplayHostImpl(const gfx::Rect& background_bounds);
46 virtual ~LoginDisplayHostImpl();
48 // Returns the default LoginDispalyHost instance if it has been created.
49 static LoginDisplayHost* default_host() {
50 return default_host_;
53 // LoginDisplayHost implementation:
54 virtual LoginDisplay* CreateLoginDisplay(
55 LoginDisplay::Delegate* delegate) OVERRIDE;
56 virtual gfx::NativeWindow GetNativeWindow() const OVERRIDE;
57 virtual WebUILoginView* GetWebUILoginView() const OVERRIDE;
58 virtual void BeforeSessionStart() OVERRIDE;
59 virtual void Finalize() OVERRIDE;
60 virtual void OnCompleteLogin() OVERRIDE;
61 virtual void OpenProxySettings() OVERRIDE;
62 virtual void SetStatusAreaVisible(bool visible) OVERRIDE;
63 virtual void CheckForAutoEnrollment() OVERRIDE;
64 virtual void GetAutoEnrollmentCheckResult(
65 const GetAutoEnrollmentCheckResultCallback& callback) OVERRIDE;
66 virtual void StartWizard(
67 const std::string& first_screen_name,
68 scoped_ptr<DictionaryValue> screen_parameters) OVERRIDE;
69 virtual WizardController* GetWizardController() OVERRIDE;
70 virtual AppLaunchController* GetAppLaunchController() OVERRIDE;
71 virtual void StartUserAdding(
72 const base::Closure& completion_callback) OVERRIDE;
73 virtual void StartSignInScreen() OVERRIDE;
74 virtual void ResumeSignInScreen() OVERRIDE;
75 virtual void OnPreferencesChanged() OVERRIDE;
76 virtual void PrewarmAuthentication() OVERRIDE;
77 virtual void StartAppLaunch(const std::string& app_id) OVERRIDE;
79 // Creates WizardController instance.
80 WizardController* CreateWizardController();
82 // Called when the first browser window is created, but before it's shown.
83 void OnBrowserCreated();
85 // Returns instance of the OOBE WebUI.
86 OobeUI* GetOobeUI() const;
88 const gfx::Rect& background_bounds() const { return background_bounds_; }
90 // Trace id for ShowLoginWebUI event (since there exists at most one login
91 // WebUI at a time).
92 static const int kShowLoginWebUIid;
94 views::Widget* login_window_for_test() { return login_window_; }
96 protected:
97 // content::NotificationObserver implementation:
98 virtual void Observe(int type,
99 const content::NotificationSource& source,
100 const content::NotificationDetails& details) OVERRIDE;
102 // Overridden from content::WebContentsObserver:
103 virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
105 private:
106 // Marks display host for deletion.
107 // If |post_quit_task| is true also posts Quit task to the MessageLoop.
108 void ShutdownDisplayHost(bool post_quit_task);
110 // Start sign in transition animation.
111 void StartAnimation();
113 // Callback for the ownership status check.
114 void OnOwnershipStatusCheckDone(
115 DeviceSettingsService::OwnershipStatus status);
117 // Callback for completion of the |auto_enrollment_client_|.
118 void OnAutoEnrollmentClientDone();
120 // Forces auto-enrollment on the appropriate controller.
121 void ForceAutoEnrollment();
123 // Loads given URL. Creates WebUILoginView if needed.
124 void LoadURL(const GURL& url);
126 // Shows OOBE/sign in WebUI that was previously initialized in hidden state.
127 void ShowWebUI();
129 // Starts postponed WebUI (OOBE/sign in) if it was waiting for
130 // wallpaper animation end.
131 void StartPostponedWebUI();
133 // Initializes |login_window_| and |login_view_| fields if needed.
134 void InitLoginWindowAndView();
136 // Closes |login_window_| and resets |login_window_| and |login_view_| fields.
137 void ResetLoginWindowAndView();
139 // Returns true if hosr running UI for adding users into session.
140 bool IsRunningUserAdding();
142 // Deletes |auth_prewarmer_|.
143 void OnAuthPrewarmDone();
145 // Toggles OOBE progress bar visibility, the bar is hidden by default.
146 void SetOobeProgressBarVisible(bool visible);
148 // Notifies the interested parties of the auto enrollment check result.
149 void NotifyAutoEnrollmentCheckResult(bool should_auto_enroll);
151 // Used to calculate position of the screens and background.
152 gfx::Rect background_bounds_;
154 content::NotificationRegistrar registrar_;
156 base::WeakPtrFactory<LoginDisplayHostImpl> pointer_factory_;
158 // Default LoginDisplayHost.
159 static LoginDisplayHost* default_host_;
161 // Sign in screen controller.
162 scoped_ptr<ExistingUserController> sign_in_controller_;
164 // OOBE and some screens (camera, recovery) controller.
165 scoped_ptr<WizardController> wizard_controller_;
167 // App launch controller.
168 scoped_ptr<AppLaunchController> app_launch_controller_;
170 // Client for enterprise auto-enrollment check.
171 scoped_ptr<policy::AutoEnrollmentClient> auto_enrollment_client_;
173 // Has ShutdownDisplayHost() already been called? Used to avoid posting our
174 // own deletion to the message loop twice if the user logs out while we're
175 // still in the process of cleaning up after login (http://crbug.com/134463).
176 bool shutting_down_;
178 // Whether progress bar is shown on the OOBE page.
179 bool oobe_progress_bar_visible_;
181 // True if session start is in progress.
182 bool session_starting_;
184 // Container of the screen we are displaying.
185 views::Widget* login_window_;
187 // Container of the view we are displaying.
188 WebUILoginView* login_view_;
190 // Login display we are using.
191 WebUILoginDisplay* webui_login_display_;
193 // True if the login display is the current screen.
194 bool is_showing_login_;
196 // True if NOTIFICATION_WALLPAPER_ANIMATION_FINISHED notification has been
197 // received.
198 bool is_wallpaper_loaded_;
200 // Stores status area current visibility to be applied once login WebUI
201 // is shown.
202 bool status_area_saved_visibility_;
204 // If true, WebUI is initialized in a hidden state and shown after the
205 // wallpaper animation is finished (when it is enabled) or the user pods have
206 // been loaded (otherwise).
207 // By default is true. Could be used to tune performance if needed.
208 bool initialize_webui_hidden_;
210 // True if WebUI is initialized in hidden state and we're waiting for
211 // wallpaper load animation to finish.
212 bool waiting_for_wallpaper_load_;
214 // True if WebUI is initialized in hidden state and we're waiting for user
215 // pods to load.
216 bool waiting_for_user_pods_;
218 // How many times renderer has crashed.
219 int crash_count_;
221 // Way to restore if renderer have crashed.
222 enum {
223 RESTORE_UNKNOWN,
224 RESTORE_WIZARD,
225 RESTORE_SIGN_IN,
226 RESTORE_ADD_USER_INTO_SESSION,
227 } restore_path_;
229 // Stored parameters for StartWizard, required to restore in case of crash.
230 std::string wizard_first_screen_name_;
231 scoped_ptr<DictionaryValue> wizard_screen_parameters_;
233 // Old value of the ash::internal::kIgnoreSoloWindowFramePainterPolicy
234 // property of the root window for |login_window_|.
235 bool old_ignore_solo_window_frame_painter_policy_value_;
237 // Called before host deletion.
238 base::Closure completion_callback_;
240 // Active instance of authentication prewarmer.
241 scoped_ptr<AuthPrewarmer> auth_prewarmer_;
243 // A focus ring controller to draw focus ring around view for keyboard
244 // driven oobe.
245 scoped_ptr<FocusRingController> focus_ring_controller_;
247 // Whether auto enrollment client has done the check.
248 bool auto_enrollment_check_done_;
250 // Callbacks to notify when auto enrollment client has done the check.
251 std::vector<GetAutoEnrollmentCheckResultCallback>
252 get_auto_enrollment_result_callbacks_;
254 DISALLOW_COPY_AND_ASSIGN(LoginDisplayHostImpl);
257 } // namespace chromeos
259 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_DISPLAY_HOST_IMPL_H_