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
* GetScreen(const std::string
& screen_name
) override
;
137 BaseScreen
* CreateScreen(const std::string
& screen_name
) override
;
139 static const char kNetworkScreenName
[];
140 static const char kLoginScreenName
[];
141 static const char kUpdateScreenName
[];
142 static const char kUserImageScreenName
[];
143 static const char kOutOfBoxScreenName
[];
144 static const char kTestNoScreenName
[];
145 static const char kEulaScreenName
[];
146 static const char kEnableDebuggingScreenName
[];
147 static const char kEnrollmentScreenName
[];
148 static const char kResetScreenName
[];
149 static const char kKioskEnableScreenName
[];
150 static const char kKioskAutolaunchScreenName
[];
151 static const char kErrorScreenName
[];
152 static const char kTermsOfServiceScreenName
[];
153 static const char kAutoEnrollmentCheckScreenName
[];
154 static const char kWrongHWIDScreenName
[];
155 static const char kSupervisedUserCreationScreenName
[];
156 static const char kAppLaunchSplashScreenName
[];
157 static const char kHIDDetectionScreenName
[];
158 static const char kControllerPairingScreenName
[];
159 static const char kHostPairingScreenName
[];
160 static const char kDeviceDisabledScreenName
[];
162 // Volume percent at which spoken feedback is still audible.
163 static const int kMinAudibleOutputVolumePercent
;
166 // Show specific screen.
167 void ShowNetworkScreen();
168 void ShowUpdateScreen();
169 void ShowUserImageScreen();
170 void ShowEulaScreen();
171 void ShowEnrollmentScreen();
172 void ShowResetScreen();
173 void ShowKioskAutolaunchScreen();
174 void ShowEnableDebuggingScreen();
175 void ShowKioskEnableScreen();
176 void ShowTermsOfServiceScreen();
177 void ShowWrongHWIDScreen();
178 void ShowAutoEnrollmentCheckScreen();
179 void ShowSupervisedUserCreationScreen();
180 void ShowHIDDetectionScreen();
181 void ShowControllerPairingScreen();
182 void ShowHostPairingScreen();
183 void ShowDeviceDisabledScreen();
185 // Shows images login screen.
186 void ShowLoginScreen(const LoginScreenContext
& context
);
189 void OnHIDDetectionCompleted();
190 void OnNetworkConnected();
191 void OnNetworkOffline();
192 void OnConnectionFailed();
193 void OnUpdateCompleted();
194 void OnEulaAccepted();
195 void OnUpdateErrorCheckingForUpdate();
196 void OnUpdateErrorUpdating();
197 void OnUserImageSelected();
198 void OnUserImageSkipped();
199 void OnEnrollmentDone();
200 void OnAutoEnrollmentDone();
201 void OnDeviceModificationCanceled();
202 void OnKioskAutolaunchCanceled();
203 void OnKioskAutolaunchConfirmed();
204 void OnKioskEnableCompleted();
205 void OnWrongHWIDWarningSkipped();
206 void OnTermsOfServiceDeclined();
207 void OnTermsOfServiceAccepted();
208 void OnControllerPairingFinished();
209 void OnHostPairingFinished();
210 void OnAutoEnrollmentCheckCompleted();
212 // Callback invoked once it has been determined whether the device is disabled
214 void OnDeviceDisabledChecked(bool device_disabled
);
216 // Callback function after setting MetricsReporting.
217 void InitiateMetricsReportingChangeCallback(bool enabled
);
219 // Loads brand code on I/O enabled thread and stores to Local State.
220 void LoadBrandCodeFromFile();
222 // Called after all post-EULA blocking tasks have been completed.
223 void OnEulaBlockingTasksDone();
225 // Shows update screen and starts update process.
226 void InitiateOOBEUpdate();
228 // Actions that should be done right after EULA is accepted,
229 // before update check.
230 void PerformPostEulaActions();
232 // Actions that should be done right after update stage is finished.
233 void PerformOOBECompletedActions();
235 // Overridden from BaseScreenDelegate:
236 void OnExit(BaseScreen
& screen
,
238 const ::login::ScreenContext
* context
) override
;
239 void ShowCurrentScreen() override
;
240 ErrorScreen
* GetErrorScreen() override
;
241 void ShowErrorScreen() override
;
242 void HideErrorScreen(BaseScreen
* parent_screen
) override
;
244 // Overridden from EulaScreen::Delegate:
245 void SetUsageStatisticsReporting(bool val
) override
;
246 bool GetUsageStatisticsReporting() const override
;
248 // Override from ControllerPairingScreen::Delegate:
249 void SetHostConfiguration() override
;
251 // Override from HostPairingScreen::Delegate:
252 void ConfigureHostRequested(bool accepted_eula
,
253 const std::string
& lang
,
254 const std::string
& timezone
,
256 const std::string
& keyboard_layout
) override
;
257 void AddNetworkRequested(const std::string
& onc_spec
) override
;
259 // Override from NetworkScreen::Delegate:
260 void OnEnableDebuggingScreenRequested() override
;
262 // Override from HIDDetectionScreen::Delegate
263 void OnHIDScreenNecessityCheck(bool screen_needed
) override
;
265 // Notification of a change in the state of an accessibility setting.
266 void OnAccessibilityStatusChanged(
267 const AccessibilityStatusEventDetails
& details
);
269 // Switches from one screen to another.
270 void SetCurrentScreen(BaseScreen
* screen
);
272 // Switches from one screen to another with delay before showing. Calling
273 // ShowCurrentScreen directly forces screen to be shown immediately.
274 void SetCurrentScreenSmooth(BaseScreen
* screen
, bool use_smoothing
);
276 // Changes status area visibility.
277 void SetStatusAreaVisible(bool visible
);
279 // Launched kiosk app configured for auto-launch.
280 void AutoLaunchKioskApp();
282 // Called when LocalState is initialized.
283 void OnLocalStateInitialized(bool /* succeeded */);
285 // Returns local state.
286 PrefService
* GetLocalState();
288 static void set_local_state_for_testing(PrefService
* local_state
) {
289 local_state_for_testing_
= local_state
;
292 std::string
first_screen_name() { return first_screen_name_
; }
294 // Called when network is UP.
295 void StartTimezoneResolve();
297 // Creates provider on demand.
298 TimeZoneProvider
* GetTimezoneProvider();
300 // TimeZoneRequest::TimeZoneResponseCallback implementation.
301 void OnTimezoneResolved(scoped_ptr
<TimeZoneResponseData
> timezone
,
304 // Called from SimpleGeolocationProvider when location is resolved.
305 void OnLocationResolved(const Geoposition
& position
,
307 const base::TimeDelta elapsed
);
309 // Returns true if callback has been installed.
310 // Returns false if timezone has already been resolved.
311 bool SetOnTimeZoneResolvedForTesting(const base::Closure
& callback
);
313 // Returns true for pairing remora OOBE.
314 bool IsHostPairingOobe() const;
316 // Starts listening for an incoming shark controller connection, if we are
317 // running remora OOBE.
318 void MaybeStartListeningForSharkConnection();
320 // Called when a connection to controller has been established. Wizard
321 // controller takes the ownership of |pairing_controller| after that call.
322 void OnSharkConnected(
323 scoped_ptr
<pairing_chromeos::HostPairingController
> pairing_controller
);
325 // Start the enrollment screen using the config from
326 // |prescribed_enrollment_config_|.
327 void StartEnrollmentScreen();
329 // Whether to skip any screens that may normally be shown after login
330 // (registration, Terms of Service, user image selection).
331 static bool skip_post_login_screens_
;
333 static bool zero_delay_enabled_
;
335 // Screen that's currently active.
336 BaseScreen
* current_screen_
;
338 // Screen that was active before, or NULL for login screen.
339 BaseScreen
* previous_screen_
;
341 // True if running official BUILD.
342 bool is_official_build_
;
344 // True if full OOBE flow should be shown.
347 // Value of the screen name that WizardController was started with.
348 std::string first_screen_name_
;
350 // OOBE/login display host.
351 LoginDisplayHost
* host_
;
353 // Default WizardController.
354 static WizardController
* default_controller_
;
356 base::OneShotTimer
<WizardController
> smooth_show_timer_
;
358 OobeDisplay
* oobe_display_
;
360 // State of Usage stat/error reporting checkbox on EULA screen
361 // during wizard lifetime.
362 bool usage_statistics_reporting_
;
364 // If true then update check is cancelled and enrollment is started after
366 bool skip_update_enroll_after_eula_
;
368 // The prescribed enrollment configuration for the device.
369 policy::EnrollmentConfig prescribed_enrollment_config_
;
371 // Whether the auto-enrollment check should be retried or the cached result
372 // returned if present.
373 bool retry_auto_enrollment_check_
;
375 // Time when the EULA was accepted. Used to measure the duration from the EULA
376 // acceptance until the Sign-In screen is displayed.
377 base::Time time_eula_accepted_
;
379 // Time when OOBE was started. Used to measure the total time from boot to
380 // user Sign-In completed.
381 base::Time time_oobe_started_
;
383 base::ObserverList
<Observer
> observer_list_
;
385 bool login_screen_started_
;
387 // Indicates that once image selection screen finishes we should return to
388 // a previous screen instead of proceeding with usual flow.
389 bool user_image_screen_return_to_previous_hack_
;
391 // Non-owning pointer to local state used for testing.
392 static PrefService
* local_state_for_testing_
;
394 FRIEND_TEST_ALL_PREFIXES(EnrollmentScreenTest
, TestCancel
);
395 FRIEND_TEST_ALL_PREFIXES(WizardControllerFlowTest
, Accelerators
);
396 friend class WizardControllerFlowTest
;
397 friend class WizardControllerOobeResumeTest
;
398 friend class WizardInProcessBrowserTest
;
399 friend class WizardControllerBrokenLocalStateTest
;
401 scoped_ptr
<AccessibilityStatusSubscription
> accessibility_subscription_
;
403 scoped_ptr
<SimpleGeolocationProvider
> geolocation_provider_
;
404 scoped_ptr
<TimeZoneProvider
> timezone_provider_
;
406 // Pairing controller for shark devices.
407 scoped_ptr
<pairing_chromeos::ControllerPairingController
> shark_controller_
;
409 // Pairing controller for remora devices.
410 scoped_ptr
<pairing_chromeos::HostPairingController
> remora_controller_
;
412 // Maps screen ids to last time of their shows.
413 base::hash_map
<std::string
, base::Time
> screen_show_times_
;
415 // Tests check result of timezone resolve.
416 bool timezone_resolved_
;
417 base::Closure on_timezone_resolved_for_testing_
;
419 // True if shark device initiated connection to this device.
420 bool shark_controller_detected_
;
422 // Listens for incoming connection from a shark controller if a regular (not
423 // pairing) remora OOBE is active. If connection is established, wizard
424 // conroller swithces to a pairing OOBE.
425 scoped_ptr
<pairing_chromeos::SharkConnectionListener
>
426 shark_connection_listener_
;
428 BaseScreen
* hid_screen_
;
430 base::WeakPtrFactory
<WizardController
> weak_factory_
;
432 DISALLOW_COPY_AND_ASSIGN(WizardController
);
435 } // namespace chromeos
437 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WIZARD_CONTROLLER_H_