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_WIZARD_CONTROLLER_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_WIZARD_CONTROLLER_H_
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/containers/hash_tables.h"
14 #include "base/gtest_prod_util.h"
15 #include "base/memory/linked_ptr.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/weak_ptr.h"
18 #include "base/observer_list.h"
19 #include "base/time/time.h"
20 #include "base/timer/timer.h"
21 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
22 #include "chrome/browser/chromeos/login/screen_manager.h"
23 #include "chrome/browser/chromeos/login/screens/base_screen_delegate.h"
24 #include "chrome/browser/chromeos/login/screens/controller_pairing_screen.h"
25 #include "chrome/browser/chromeos/login/screens/eula_screen.h"
26 #include "chrome/browser/chromeos/login/screens/hid_detection_screen.h"
27 #include "chrome/browser/chromeos/login/screens/host_pairing_screen.h"
28 #include "chrome/browser/chromeos/login/screens/network_screen.h"
29 #include "chrome/browser/chromeos/login/screens/reset_screen.h"
30 #include "chrome/browser/chromeos/policy/enrollment_config.h"
32 class PrefRegistrySimple
;
35 namespace pairing_chromeos
{
36 class ControllerPairingController
;
37 class HostPairingController
;
38 class SharkConnectionListener
;
43 class AutoEnrollmentCheckScreen
;
44 class EnrollmentScreen
;
47 class LoginDisplayHost
;
48 class LoginScreenContext
;
50 class SimpleGeolocationProvider
;
51 class SupervisedUserCreationScreen
;
52 class TimeZoneProvider
;
53 struct TimeZoneResponseData
;
55 class UserImageScreen
;
57 // Class that manages control flow between wizard screens. Wizard controller
58 // interacts with screen controllers to move the user between screens.
59 class WizardController
: public BaseScreenDelegate
,
61 public EulaScreen::Delegate
,
62 public ControllerPairingScreen::Delegate
,
63 public HostPairingScreen::Delegate
,
64 public NetworkScreen::Delegate
,
65 public HIDDetectionScreen::Delegate
{
67 // Observes screen changes.
70 // Called before a screen change happens.
71 virtual void OnScreenChanged(BaseScreen
* next_screen
) = 0;
73 // Called after the browser session has started.
74 virtual void OnSessionStart() = 0;
77 WizardController(LoginDisplayHost
* host
, OobeDisplay
* oobe_display
);
78 ~WizardController() override
;
80 // Returns the default wizard controller if it has been created.
81 static WizardController
* default_controller() {
82 return default_controller_
;
85 // Whether to skip any screens that may normally be shown after login
86 // (registration, Terms of Service, user image selection).
87 static bool skip_post_login_screens() {
88 return skip_post_login_screens_
;
91 // Sets delays to zero. MUST be used only for tests.
92 static void SetZeroDelays();
94 // If true zero delays have been enabled (for browser tests).
95 static bool IsZeroDelayEnabled();
97 // Checks whether screen show time should be tracked with UMA.
98 static bool IsOOBEStepToTrack(const std::string
& screen_id
);
100 // Skips any screens that may normally be shown after login (registration,
101 // Terms of Service, user image selection).
102 static void SkipPostLoginScreensForTesting();
104 // Shows the first screen defined by |first_screen_name| or by default
105 // if the parameter is empty.
106 void Init(const std::string
& first_screen_name
);
108 // Advances to screen defined by |screen_name| and shows it.
109 void AdvanceToScreen(const std::string
& screen_name
);
111 // Advances to login screen. Should be used in for testing only.
112 void SkipToLoginForTesting(const LoginScreenContext
& context
);
114 // Adds and removes an observer.
115 void AddObserver(Observer
* observer
);
116 void RemoveObserver(Observer
* observer
);
118 // Called right after the browser session has started.
119 void OnSessionStart();
121 // Skip update, go straight to enrollment after EULA is accepted.
122 void SkipUpdateEnrollAfterEula();
124 // TODO(antrim) : temporary hack. Should be removed once screen system is
125 // reworked at hackaton.
126 void EnableUserImageScreenReturnToPreviousHack();
128 // Returns a pointer to the current screen or NULL if there's no such
130 BaseScreen
* current_screen() const { return current_screen_
; }
132 // Returns true if the current wizard instance has reached the login screen.
133 bool login_screen_started() const { return login_screen_started_
; }
135 // ScreenManager implementation.
136 BaseScreen
* CreateScreen(const std::string
& screen_name
) override
;
138 static const char kNetworkScreenName
[];
139 static const char kLoginScreenName
[];
140 static const char kUpdateScreenName
[];
141 static const char kUserImageScreenName
[];
142 static const char kOutOfBoxScreenName
[];
143 static const char kTestNoScreenName
[];
144 static const char kEulaScreenName
[];
145 static const char kEnableDebuggingScreenName
[];
146 static const char kEnrollmentScreenName
[];
147 static const char kResetScreenName
[];
148 static const char kKioskEnableScreenName
[];
149 static const char kKioskAutolaunchScreenName
[];
150 static const char kErrorScreenName
[];
151 static const char kTermsOfServiceScreenName
[];
152 static const char kAutoEnrollmentCheckScreenName
[];
153 static const char kWrongHWIDScreenName
[];
154 static const char kSupervisedUserCreationScreenName
[];
155 static const char kAppLaunchSplashScreenName
[];
156 static const char kHIDDetectionScreenName
[];
157 static const char kControllerPairingScreenName
[];
158 static const char kHostPairingScreenName
[];
159 static const char kDeviceDisabledScreenName
[];
161 // Volume percent at which spoken feedback is still audible.
162 static const int kMinAudibleOutputVolumePercent
;
165 // Show specific screen.
166 void ShowNetworkScreen();
167 void ShowUpdateScreen();
168 void ShowUserImageScreen();
169 void ShowEulaScreen();
170 void ShowEnrollmentScreen();
171 void ShowResetScreen();
172 void ShowKioskAutolaunchScreen();
173 void ShowEnableDebuggingScreen();
174 void ShowKioskEnableScreen();
175 void ShowTermsOfServiceScreen();
176 void ShowWrongHWIDScreen();
177 void ShowAutoEnrollmentCheckScreen();
178 void ShowSupervisedUserCreationScreen();
179 void ShowHIDDetectionScreen();
180 void ShowControllerPairingScreen();
181 void ShowHostPairingScreen();
182 void ShowDeviceDisabledScreen();
184 // Shows images login screen.
185 void ShowLoginScreen(const LoginScreenContext
& context
);
188 void OnHIDDetectionCompleted();
189 void OnNetworkConnected();
190 void OnNetworkOffline();
191 void OnConnectionFailed();
192 void OnUpdateCompleted();
193 void OnEulaAccepted();
194 void OnUpdateErrorCheckingForUpdate();
195 void OnUpdateErrorUpdating();
196 void OnUserImageSelected();
197 void OnUserImageSkipped();
198 void OnEnrollmentDone();
199 void OnAutoEnrollmentDone();
200 void OnDeviceModificationCanceled();
201 void OnKioskAutolaunchCanceled();
202 void OnKioskAutolaunchConfirmed();
203 void OnKioskEnableCompleted();
204 void OnWrongHWIDWarningSkipped();
205 void OnTermsOfServiceDeclined();
206 void OnTermsOfServiceAccepted();
207 void OnControllerPairingFinished();
208 void OnHostPairingFinished();
209 void OnAutoEnrollmentCheckCompleted();
211 // Callback invoked once it has been determined whether the device is disabled
213 void OnDeviceDisabledChecked(bool device_disabled
);
215 // Callback function after setting MetricsReporting.
216 void InitiateMetricsReportingChangeCallback(bool enabled
);
218 // Loads brand code on I/O enabled thread and stores to Local State.
219 void LoadBrandCodeFromFile();
221 // Called after all post-EULA blocking tasks have been completed.
222 void OnEulaBlockingTasksDone();
224 // Shows update screen and starts update process.
225 void InitiateOOBEUpdate();
227 // Actions that should be done right after EULA is accepted,
228 // before update check.
229 void PerformPostEulaActions();
231 // Actions that should be done right after update stage is finished.
232 void PerformOOBECompletedActions();
234 // Overridden from BaseScreenDelegate:
235 void OnExit(BaseScreen
& screen
,
237 const ::login::ScreenContext
* context
) override
;
238 void ShowCurrentScreen() override
;
239 ErrorScreen
* GetErrorScreen() override
;
240 void ShowErrorScreen() override
;
241 void HideErrorScreen(BaseScreen
* parent_screen
) override
;
243 // Overridden from EulaScreen::Delegate:
244 void SetUsageStatisticsReporting(bool val
) override
;
245 bool GetUsageStatisticsReporting() const override
;
247 // Override from ControllerPairingScreen::Delegate:
248 void SetHostConfiguration() override
;
250 // Override from HostPairingScreen::Delegate:
251 void ConfigureHost(bool accepted_eula
,
252 const std::string
& lang
,
253 const std::string
& timezone
,
255 const std::string
& keyboard_layout
) override
;
257 // Override from NetworkScreen::Delegate:
258 void OnEnableDebuggingScreenRequested() override
;
260 // Override from HIDDetectionScreen::Delegate
261 void OnHIDScreenNecessityCheck(bool screen_needed
) override
;
263 // Notification of a change in the state of an accessibility setting.
264 void OnAccessibilityStatusChanged(
265 const AccessibilityStatusEventDetails
& details
);
267 // Switches from one screen to another.
268 void SetCurrentScreen(BaseScreen
* screen
);
270 // Switches from one screen to another with delay before showing. Calling
271 // ShowCurrentScreen directly forces screen to be shown immediately.
272 void SetCurrentScreenSmooth(BaseScreen
* screen
, bool use_smoothing
);
274 // Changes status area visibility.
275 void SetStatusAreaVisible(bool visible
);
277 // Launched kiosk app configured for auto-launch.
278 void AutoLaunchKioskApp();
280 // Called when LocalState is initialized.
281 void OnLocalStateInitialized(bool /* succeeded */);
283 // Returns local state.
284 PrefService
* GetLocalState();
286 static void set_local_state_for_testing(PrefService
* local_state
) {
287 local_state_for_testing_
= local_state
;
290 std::string
first_screen_name() { return first_screen_name_
; }
292 // Called when network is UP.
293 void StartTimezoneResolve();
295 // Creates provider on demand.
296 TimeZoneProvider
* GetTimezoneProvider();
298 // TimeZoneRequest::TimeZoneResponseCallback implementation.
299 void OnTimezoneResolved(scoped_ptr
<TimeZoneResponseData
> timezone
,
302 // Called from SimpleGeolocationProvider when location is resolved.
303 void OnLocationResolved(const Geoposition
& position
,
305 const base::TimeDelta elapsed
);
307 // Returns true if callback has been installed.
308 // Returns false if timezone has already been resolved.
309 bool SetOnTimeZoneResolvedForTesting(const base::Closure
& callback
);
311 // Returns true for pairing remora OOBE.
312 bool IsHostPairingOobe() const;
314 // Starts listening for an incoming shark controller connection, if we are
315 // running remora OOBE.
316 void MaybeStartListeningForSharkConnection();
318 // Called when a connection to controller has been established. Wizard
319 // controller takes the ownership of |pairing_controller| after that call.
320 void OnSharkConnected(
321 scoped_ptr
<pairing_chromeos::HostPairingController
> pairing_controller
);
323 // Start the enrollment screen using the config from
324 // |prescribed_enrollment_config_|.
325 void StartEnrollmentScreen();
327 // Whether to skip any screens that may normally be shown after login
328 // (registration, Terms of Service, user image selection).
329 static bool skip_post_login_screens_
;
331 static bool zero_delay_enabled_
;
333 // Screen that's currently active.
334 BaseScreen
* current_screen_
;
336 // Screen that was active before, or NULL for login screen.
337 BaseScreen
* previous_screen_
;
339 // True if running official BUILD.
340 bool is_official_build_
;
342 // True if full OOBE flow should be shown.
345 // Value of the screen name that WizardController was started with.
346 std::string first_screen_name_
;
348 // OOBE/login display host.
349 LoginDisplayHost
* host_
;
351 // Default WizardController.
352 static WizardController
* default_controller_
;
354 base::OneShotTimer
<WizardController
> smooth_show_timer_
;
356 OobeDisplay
* oobe_display_
;
358 // State of Usage stat/error reporting checkbox on EULA screen
359 // during wizard lifetime.
360 bool usage_statistics_reporting_
;
362 // If true then update check is cancelled and enrollment is started after
364 bool skip_update_enroll_after_eula_
;
366 // The prescribed enrollment configuration for the device.
367 policy::EnrollmentConfig prescribed_enrollment_config_
;
369 // Whether the auto-enrollment check should be retried or the cached result
370 // returned if present.
371 bool retry_auto_enrollment_check_
;
373 // Time when the EULA was accepted. Used to measure the duration from the EULA
374 // acceptance until the Sign-In screen is displayed.
375 base::Time time_eula_accepted_
;
377 // Time when OOBE was started. Used to measure the total time from boot to
378 // user Sign-In completed.
379 base::Time time_oobe_started_
;
381 ObserverList
<Observer
> observer_list_
;
383 bool login_screen_started_
;
385 // Indicates that once image selection screen finishes we should return to
386 // a previous screen instead of proceeding with usual flow.
387 bool user_image_screen_return_to_previous_hack_
;
389 // Non-owning pointer to local state used for testing.
390 static PrefService
* local_state_for_testing_
;
392 FRIEND_TEST_ALL_PREFIXES(EnrollmentScreenTest
, TestCancel
);
393 FRIEND_TEST_ALL_PREFIXES(WizardControllerFlowTest
, Accelerators
);
394 friend class WizardControllerFlowTest
;
395 friend class WizardControllerOobeResumeTest
;
396 friend class WizardInProcessBrowserTest
;
397 friend class WizardControllerBrokenLocalStateTest
;
399 scoped_ptr
<AccessibilityStatusSubscription
> accessibility_subscription_
;
401 scoped_ptr
<SimpleGeolocationProvider
> geolocation_provider_
;
402 scoped_ptr
<TimeZoneProvider
> timezone_provider_
;
404 // Pairing controller for shark devices.
405 scoped_ptr
<pairing_chromeos::ControllerPairingController
> shark_controller_
;
407 // Pairing controller for remora devices.
408 scoped_ptr
<pairing_chromeos::HostPairingController
> remora_controller_
;
410 // Maps screen ids to last time of their shows.
411 base::hash_map
<std::string
, base::Time
> screen_show_times_
;
413 // Tests check result of timezone resolve.
414 bool timezone_resolved_
;
415 base::Closure on_timezone_resolved_for_testing_
;
417 // True if shark device initiated connection to this device.
418 bool shark_controller_detected_
;
420 // Listens for incoming connection from a shark controller if a regular (not
421 // pairing) remora OOBE is active. If connection is established, wizard
422 // conroller swithces to a pairing OOBE.
423 scoped_ptr
<pairing_chromeos::SharkConnectionListener
>
424 shark_connection_listener_
;
426 BaseScreen
* hid_screen_
;
428 base::WeakPtrFactory
<WizardController
> weak_factory_
;
430 DISALLOW_COPY_AND_ASSIGN(WizardController
);
433 } // namespace chromeos
435 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WIZARD_CONTROLLER_H_