Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / chromeos / login / login_display_host_impl.h
blob236e1f812afe0d9b70f89fe388321ac8355283a0
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 "ash/shell_delegate.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "chrome/browser/chromeos/login/app_launch_controller.h"
16 #include "chrome/browser/chromeos/login/auth_prewarmer.h"
17 #include "chrome/browser/chromeos/login/existing_user_controller.h"
18 #include "chrome/browser/chromeos/login/login_display.h"
19 #include "chrome/browser/chromeos/login/login_display_host.h"
20 #include "chrome/browser/chromeos/login/wizard_controller.h"
21 #include "chrome/browser/chromeos/settings/device_settings_service.h"
22 #include "chromeos/audio/cras_audio_handler.h"
23 #include "chromeos/dbus/session_manager_client.h"
24 #include "content/public/browser/notification_observer.h"
25 #include "content/public/browser/notification_registrar.h"
26 #include "content/public/browser/web_contents_observer.h"
27 #include "ui/gfx/rect.h"
28 #include "ui/keyboard/keyboard_controller_observer.h"
30 class PrefService;
32 namespace content {
33 class RenderFrameHost;
34 class WebContents;
37 namespace chromeos {
39 class DemoAppLauncher;
40 class FocusRingController;
41 class KeyboardDrivenOobeKeyHandler;
42 class OobeUI;
43 class WebUILoginDisplay;
44 class WebUILoginView;
46 // An implementation class for OOBE/login WebUI screen host.
47 // It encapsulates controllers, background integration and flow.
48 class LoginDisplayHostImpl : public LoginDisplayHost,
49 public content::NotificationObserver,
50 public content::WebContentsObserver,
51 public chromeos::SessionManagerClient::Observer,
52 public chromeos::CrasAudioHandler::AudioObserver,
53 public ash::VirtualKeyboardStateObserver,
54 public keyboard::KeyboardControllerObserver {
55 public:
56 explicit LoginDisplayHostImpl(const gfx::Rect& background_bounds);
57 virtual ~LoginDisplayHostImpl();
59 // Returns the default LoginDisplayHost instance if it has been created.
60 static LoginDisplayHost* default_host() {
61 return default_host_;
64 // Gets the Gaia auth iframe within a WebContents.
65 static content::RenderFrameHost* GetGaiaAuthIframe(
66 content::WebContents* web_contents);
68 // LoginDisplayHost implementation:
69 virtual LoginDisplay* CreateLoginDisplay(
70 LoginDisplay::Delegate* delegate) OVERRIDE;
71 virtual gfx::NativeWindow GetNativeWindow() const OVERRIDE;
72 virtual WebUILoginView* GetWebUILoginView() const OVERRIDE;
73 virtual void BeforeSessionStart() OVERRIDE;
74 virtual void Finalize() OVERRIDE;
75 virtual void OnCompleteLogin() OVERRIDE;
76 virtual void OpenProxySettings() OVERRIDE;
77 virtual void SetStatusAreaVisible(bool visible) OVERRIDE;
78 virtual AutoEnrollmentController* GetAutoEnrollmentController() OVERRIDE;
79 virtual void StartWizard(
80 const std::string& first_screen_name,
81 scoped_ptr<base::DictionaryValue> screen_parameters) OVERRIDE;
82 virtual WizardController* GetWizardController() OVERRIDE;
83 virtual AppLaunchController* GetAppLaunchController() OVERRIDE;
84 virtual void StartUserAdding(
85 const base::Closure& completion_callback) OVERRIDE;
86 virtual void StartSignInScreen(const LoginScreenContext& context) OVERRIDE;
87 virtual void ResumeSignInScreen() OVERRIDE;
88 virtual void OnPreferencesChanged() OVERRIDE;
89 virtual void PrewarmAuthentication() OVERRIDE;
90 virtual void StartAppLaunch(const std::string& app_id,
91 bool diagnostic_mode) OVERRIDE;
92 virtual void StartDemoAppLaunch() OVERRIDE;
94 // Creates WizardController instance.
95 WizardController* CreateWizardController();
97 // Called when the first browser window is created, but before it's shown.
98 void OnBrowserCreated();
100 // Returns instance of the OOBE WebUI.
101 OobeUI* GetOobeUI() const;
103 const gfx::Rect& background_bounds() const { return background_bounds_; }
105 // Trace id for ShowLoginWebUI event (since there exists at most one login
106 // WebUI at a time).
107 static const int kShowLoginWebUIid;
109 views::Widget* login_window_for_test() { return login_window_; }
111 protected:
112 // content::NotificationObserver implementation:
113 virtual void Observe(int type,
114 const content::NotificationSource& source,
115 const content::NotificationDetails& details) OVERRIDE;
117 // Overridden from content::WebContentsObserver:
118 virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
120 // Overridden from chromeos::SessionManagerClient::Observer:
121 virtual void EmitLoginPromptVisibleCalled() OVERRIDE;
123 // Overridden from chromeos::CrasAudioHandler::AudioObserver:
124 virtual void OnActiveOutputNodeChanged() OVERRIDE;
126 // Overridden from ash::KeyboardStateObserver:
127 virtual void OnVirtualKeyboardStateChanged(bool activated) OVERRIDE;
129 // Overridden from keyboard::KeyboardControllerObserver:
130 virtual void OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) OVERRIDE;
132 private:
133 // Way to restore if renderer have crashed.
134 enum RestorePath {
135 RESTORE_UNKNOWN,
136 RESTORE_WIZARD,
137 RESTORE_SIGN_IN,
138 RESTORE_ADD_USER_INTO_SESSION,
141 // Type of animations to run after the login screen.
142 enum FinalizeAnimationType {
143 ANIMATION_NONE, // No animation.
144 ANIMATION_WORKSPACE, // Use initial workspace animation (drop and
145 // and fade in workspace). Used for user login.
146 ANIMATION_FADE_OUT, // Fade out login screen. Used for app launch.
149 // Marks display host for deletion.
150 // If |post_quit_task| is true also posts Quit task to the MessageLoop.
151 void ShutdownDisplayHost(bool post_quit_task);
153 // Schedules workspace transition animation.
154 void ScheduleWorkspaceAnimation();
156 // Schedules fade out animation.
157 void ScheduleFadeOutAnimation();
159 // Progress callback registered with |auto_enrollment_controller_|.
160 void OnAutoEnrollmentProgress(policy::AutoEnrollmentState state);
162 // Loads given URL. Creates WebUILoginView if needed.
163 void LoadURL(const GURL& url);
165 // Shows OOBE/sign in WebUI that was previously initialized in hidden state.
166 void ShowWebUI();
168 // Starts postponed WebUI (OOBE/sign in) if it was waiting for
169 // wallpaper animation end.
170 void StartPostponedWebUI();
172 // Initializes |login_window_| and |login_view_| fields if needed.
173 void InitLoginWindowAndView();
175 // Closes |login_window_| and resets |login_window_| and |login_view_| fields.
176 void ResetLoginWindowAndView();
178 // Deletes |auth_prewarmer_|.
179 void OnAuthPrewarmDone();
181 // Toggles OOBE progress bar visibility, the bar is hidden by default.
182 void SetOobeProgressBarVisible(bool visible);
184 // Tries to play startup sound. If sound can't be played right now,
185 // for instance, because cras server is not initialized, playback
186 // will be delayed.
187 void TryToPlayStartupSound();
189 // Called when login-prompt-visible signal is caught.
190 void OnLoginPromptVisible();
192 // Used to calculate position of the screens and background.
193 gfx::Rect background_bounds_;
195 content::NotificationRegistrar registrar_;
197 base::WeakPtrFactory<LoginDisplayHostImpl> pointer_factory_;
199 // Default LoginDisplayHost.
200 static LoginDisplayHost* default_host_;
202 // Sign in screen controller.
203 scoped_ptr<ExistingUserController> sign_in_controller_;
205 // OOBE and some screens (camera, recovery) controller.
206 scoped_ptr<WizardController> wizard_controller_;
208 // App launch controller.
209 scoped_ptr<AppLaunchController> app_launch_controller_;
211 // Demo app launcher.
212 scoped_ptr<DemoAppLauncher> demo_app_launcher_;
214 // The controller driving the auto-enrollment check.
215 scoped_ptr<AutoEnrollmentController> auto_enrollment_controller_;
217 // Subscription for progress callbacks from |auto_enrollement_controller_|.
218 scoped_ptr<AutoEnrollmentController::ProgressCallbackList::Subscription>
219 auto_enrollment_progress_subscription_;
221 // Has ShutdownDisplayHost() already been called? Used to avoid posting our
222 // own deletion to the message loop twice if the user logs out while we're
223 // still in the process of cleaning up after login (http://crbug.com/134463).
224 bool shutting_down_;
226 // Whether progress bar is shown on the OOBE page.
227 bool oobe_progress_bar_visible_;
229 // True if session start is in progress.
230 bool session_starting_;
232 // Container of the screen we are displaying.
233 views::Widget* login_window_;
235 // Container of the view we are displaying.
236 WebUILoginView* login_view_;
238 // Login display we are using.
239 WebUILoginDisplay* webui_login_display_;
241 // True if the login display is the current screen.
242 bool is_showing_login_;
244 // True if NOTIFICATION_WALLPAPER_ANIMATION_FINISHED notification has been
245 // received.
246 bool is_wallpaper_loaded_;
248 // Stores status area current visibility to be applied once login WebUI
249 // is shown.
250 bool status_area_saved_visibility_;
252 // If true, WebUI is initialized in a hidden state and shown after the
253 // wallpaper animation is finished (when it is enabled) or the user pods have
254 // been loaded (otherwise).
255 // By default is true. Could be used to tune performance if needed.
256 bool initialize_webui_hidden_;
258 // True if WebUI is initialized in hidden state and we're waiting for
259 // wallpaper load animation to finish.
260 bool waiting_for_wallpaper_load_;
262 // True if WebUI is initialized in hidden state and we're waiting for user
263 // pods to load.
264 bool waiting_for_user_pods_;
266 // How many times renderer has crashed.
267 int crash_count_;
269 // Way to restore if renderer have crashed.
270 RestorePath restore_path_;
272 // Stored parameters for StartWizard, required to restore in case of crash.
273 std::string wizard_first_screen_name_;
274 scoped_ptr<base::DictionaryValue> wizard_screen_parameters_;
276 // Called before host deletion.
277 base::Closure completion_callback_;
279 // Active instance of authentication prewarmer.
280 scoped_ptr<AuthPrewarmer> auth_prewarmer_;
282 // A focus ring controller to draw focus ring around view for keyboard
283 // driven oobe.
284 scoped_ptr<FocusRingController> focus_ring_controller_;
286 // Handles special keys for keyboard driven oobe.
287 scoped_ptr<KeyboardDrivenOobeKeyHandler> keyboard_driven_oobe_key_handler_;
289 FinalizeAnimationType finalize_animation_type_;
291 base::WeakPtrFactory<LoginDisplayHostImpl> animation_weak_ptr_factory_;
293 // Time when login prompt visible signal is received. Used for
294 // calculations of delay before startup sound.
295 base::TimeTicks login_prompt_visible_time_;
297 // True when request to play startup sound was sent to
298 // SoundsManager.
299 bool startup_sound_played_;
301 // When true, startup sound should be played only when spoken
302 // feedback is enabled. Otherwise, startup sound should be played
303 // in any case.
304 bool startup_sound_honors_spoken_feedback_;
306 // True is subscribed as keyboard controller observer.
307 bool is_observing_keyboard_;
309 // The bounds of the virtual keyboard.
310 gfx::Rect keyboard_bounds_;
312 DISALLOW_COPY_AND_ASSIGN(LoginDisplayHostImpl);
315 } // namespace chromeos
317 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_DISPLAY_HOST_IMPL_H_