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/screen_observer.h"
25 class PrefRegistrySimple;
29 class DictionaryValue;
32 namespace pairing_chromeos {
33 class SharkConnectionListener;
34 class ControllerPairingController;
35 class HostPairingController;
40 class AutoEnrollmentCheckScreen;
41 class EnrollmentScreen;
44 class LoginDisplayHost;
45 class LoginScreenContext;
48 class SimpleGeolocationProvider;
49 class SupervisedUserCreationScreen;
50 class TimeZoneProvider;
51 struct TimeZoneResponseData;
53 class UserImageScreen;
55 // Class that manages control flow between wizard screens. Wizard controller
56 // interacts with screen controllers to move the user between screens.
57 class WizardController : public ScreenObserver, public ScreenManager {
59 // Observes screen changes.
62 // Called before a screen change happens.
63 virtual void OnScreenChanged(WizardScreen* next_screen) = 0;
65 // Called after the browser session has started.
66 virtual void OnSessionStart() = 0;
69 WizardController(LoginDisplayHost* host, OobeDisplay* oobe_display);
70 virtual ~WizardController();
72 // Returns the default wizard controller if it has been created.
73 static WizardController* default_controller() {
74 return default_controller_;
77 // Whether to skip any screens that may normally be shown after login
78 // (registration, Terms of Service, user image selection).
79 static bool skip_post_login_screens() {
80 return skip_post_login_screens_;
83 // Sets delays to zero. MUST be used only for tests.
84 static void SetZeroDelays();
86 // If true zero delays have been enabled (for browser tests).
87 static bool IsZeroDelayEnabled();
89 // Checks whether screen show time should be tracked with UMA.
90 static bool IsOOBEStepToTrack(const std::string& screen_id);
92 // Skips any screens that may normally be shown after login (registration,
93 // Terms of Service, user image selection).
94 static void SkipPostLoginScreensForTesting();
96 // Checks whether OOBE should start enrollment automatically.
97 static bool ShouldAutoStartEnrollment();
99 // Checks whether OOBE should recover enrollment. Note that this flips to
100 // false once device policy has been restored as a part of recovery.
101 static bool ShouldRecoverEnrollment();
103 // Obtains domain the device used to be enrolled to from install attributes.
104 static std::string GetEnrollmentRecoveryDomain();
106 // Shows the first screen defined by |first_screen_name| or by default
107 // if the parameter is empty. Takes ownership of |screen_parameters|.
108 void Init(const std::string& first_screen_name,
109 scoped_ptr<base::DictionaryValue> screen_parameters);
111 // Advances to screen defined by |screen_name| and shows it.
112 void AdvanceToScreen(const std::string& screen_name);
114 // Advances to login screen. Should be used in for testing only.
115 void SkipToLoginForTesting(const LoginScreenContext& context);
117 // Adds and removes an observer.
118 void AddObserver(Observer* observer);
119 void RemoveObserver(Observer* observer);
121 // Called right after the browser session has started.
122 void OnSessionStart();
124 // Skip update, go straight to enrollment after EULA is accepted.
125 void SkipUpdateEnrollAfterEula();
127 // TODO(antrim) : temporary hack. Should be removed once screen system is
128 // reworked at hackaton.
129 void EnableUserImageScreenReturnToPreviousHack();
131 // Callback for enrollment auth token.
132 void OnEnrollmentAuthTokenReceived(const std::string& auth_token);
134 // Returns a pointer to the current screen or NULL if there's no such
136 WizardScreen* current_screen() const { return current_screen_; }
138 // Returns true if the current wizard instance has reached the login screen.
139 bool login_screen_started() const { return login_screen_started_; }
141 // ScreenManager implementation.
142 virtual WizardScreen* CreateScreen(const std::string& screen_name) OVERRIDE;
144 static const char kNetworkScreenName[];
145 static const char kLoginScreenName[];
146 static const char kUpdateScreenName[];
147 static const char kUserImageScreenName[];
148 static const char kOutOfBoxScreenName[];
149 static const char kTestNoScreenName[];
150 static const char kEulaScreenName[];
151 static const char kEnrollmentScreenName[];
152 static const char kResetScreenName[];
153 static const char kKioskEnableScreenName[];
154 static const char kKioskAutolaunchScreenName[];
155 static const char kErrorScreenName[];
156 static const char kTermsOfServiceScreenName[];
157 static const char kAutoEnrollmentCheckScreenName[];
158 static const char kWrongHWIDScreenName[];
159 static const char kSupervisedUserCreationScreenName[];
160 static const char kAppLaunchSplashScreenName[];
161 static const char kHIDDetectionScreenName[];
162 static const char kControllerPairingScreenName[];
163 static const char kHostPairingScreenName[];
165 // Volume percent at which spoken feedback is still audible.
166 static const int kMinAudibleOutputVolumePercent;
169 // Show specific screen.
170 void ShowNetworkScreen();
171 void ShowUpdateScreen();
172 void ShowUserImageScreen();
173 void ShowEulaScreen();
174 void ShowEnrollmentScreen();
175 void ShowResetScreen();
176 void ShowKioskAutolaunchScreen();
177 void ShowKioskEnableScreen();
178 void ShowTermsOfServiceScreen();
179 void ShowWrongHWIDScreen();
180 void ShowAutoEnrollmentCheckScreen();
181 void ShowSupervisedUserCreationScreen();
182 void ShowHIDDetectionScreen();
183 void ShowControllerPairingScreen();
184 void ShowHostPairingScreen();
186 // Shows images login screen.
187 void ShowLoginScreen(const LoginScreenContext& context);
189 // Resumes a pending login screen.
190 void ResumeLoginScreen();
192 // Invokes corresponding first OOBE screen.
193 void OnHIDScreenNecessityCheck(bool screen_needed);
196 void OnHIDDetectionCompleted();
197 void OnNetworkConnected();
198 void OnNetworkOffline();
199 void OnConnectionFailed();
200 void OnUpdateCompleted();
201 void OnEulaAccepted();
202 void OnUpdateErrorCheckingForUpdate();
203 void OnUpdateErrorUpdating();
204 void OnUserImageSelected();
205 void OnUserImageSkipped();
206 void OnEnrollmentDone();
207 void OnAutoEnrollmentDone();
208 void OnResetCanceled();
209 void OnKioskAutolaunchCanceled();
210 void OnKioskAutolaunchConfirmed();
211 void OnKioskEnableCompleted();
212 void OnWrongHWIDWarningSkipped();
213 void OnAutoEnrollmentCheckCompleted();
214 void OnTermsOfServiceDeclined();
215 void OnTermsOfServiceAccepted();
216 void OnControllerPairingFinished();
217 void OnHostPairingFinished();
219 // Callback function after setting MetricsReporting.
220 void InitiateMetricsReportingChangeCallback(bool enabled);
222 // Loads brand code on I/O enabled thread and stores to Local State.
223 void LoadBrandCodeFromFile();
225 // Called after all post-EULA blocking tasks have been completed.
226 void OnEulaBlockingTasksDone();
228 // Shows update screen and starts update process.
229 void InitiateOOBEUpdate();
231 // Actions that should be done right after EULA is accepted,
232 // before update check.
233 void PerformPostEulaActions();
235 // Actions that should be done right after update stage is finished.
236 void PerformOOBECompletedActions();
238 // Overridden from ScreenObserver:
239 virtual void OnExit(ExitCodes exit_code) OVERRIDE;
240 virtual void ShowCurrentScreen() OVERRIDE;
241 virtual void OnSetUserNamePassword(const std::string& username,
242 const std::string& password) OVERRIDE;
243 virtual void SetUsageStatisticsReporting(bool val) OVERRIDE;
244 virtual bool GetUsageStatisticsReporting() const OVERRIDE;
245 virtual ErrorScreen* GetErrorScreen() OVERRIDE;
246 virtual void ShowErrorScreen() OVERRIDE;
247 virtual void HideErrorScreen(WizardScreen* parent_screen) OVERRIDE;
249 // Notification of a change in the state of an accessibility setting.
250 void OnAccessibilityStatusChanged(
251 const AccessibilityStatusEventDetails& details);
253 // Switches from one screen to another.
254 void SetCurrentScreen(WizardScreen* screen);
256 // Switches from one screen to another with delay before showing. Calling
257 // ShowCurrentScreen directly forces screen to be shown immediately.
258 void SetCurrentScreenSmooth(WizardScreen* screen, bool use_smoothing);
260 // Changes status area visibility.
261 void SetStatusAreaVisible(bool visible);
263 // Logs in the specified user via default login screen.
264 void Login(const std::string& username, const std::string& password);
266 // Launched kiosk app configured for auto-launch.
267 void AutoLaunchKioskApp();
269 // Checks whether the user is allowed to exit enrollment.
270 static bool CanExitEnrollment();
272 // Gets the management domain.
273 static std::string GetForcedEnrollmentDomain();
275 // Called when LocalState is initialized.
276 void OnLocalStateInitialized(bool /* succeeded */);
278 // Returns local state.
279 PrefService* GetLocalState();
281 static void set_local_state_for_testing(PrefService* local_state) {
282 local_state_for_testing_ = local_state;
285 std::string first_screen_name() { return first_screen_name_; }
287 // Called when network is UP.
288 void StartTimezoneResolve();
290 // Creates provider on demand.
291 TimeZoneProvider* GetTimezoneProvider();
293 // TimeZoneRequest::TimeZoneResponseCallback implementation.
294 void OnTimezoneResolved(scoped_ptr<TimeZoneResponseData> timezone,
297 // Called from SimpleGeolocationProvider when location is resolved.
298 void OnLocationResolved(const Geoposition& position,
300 const base::TimeDelta elapsed);
302 // Returns true if callback has been installed.
303 // Returns false if timezone has already been resolved.
304 bool SetOnTimeZoneResolvedForTesting(const base::Closure& callback);
306 // Returns true for pairing remora OOBE.
307 bool IsHostPairingOobe() const;
309 // Starts listening for an incoming shark controller connection, if we are
310 // running remora OOBE.
311 void MaybeStartListeningForSharkConnection();
313 // Called when a connection to controller has been established. Wizard
314 // controller takes the ownership of |pairing_controller| after that call.
315 void OnSharkConnected(
316 scoped_ptr<pairing_chromeos::HostPairingController> pairing_controller);
318 // Whether to skip any screens that may normally be shown after login
319 // (registration, Terms of Service, user image selection).
320 static bool skip_post_login_screens_;
322 static bool zero_delay_enabled_;
324 // Screen that's currently active.
325 WizardScreen* current_screen_;
327 // Screen that was active before, or NULL for login screen.
328 WizardScreen* previous_screen_;
330 std::string username_;
331 std::string password_;
332 std::string auth_token_;
334 // True if running official BUILD.
335 bool is_official_build_;
337 // True if full OOBE flow should be shown.
340 // Value of the screen name that WizardController was started with.
341 std::string first_screen_name_;
343 // OOBE/login display host.
344 LoginDisplayHost* host_;
346 // Default WizardController.
347 static WizardController* default_controller_;
349 // Parameters for the first screen. May be NULL.
350 scoped_ptr<base::DictionaryValue> screen_parameters_;
352 base::OneShotTimer<WizardController> smooth_show_timer_;
354 OobeDisplay* oobe_display_;
356 // State of Usage stat/error reporting checkbox on EULA screen
357 // during wizard lifetime.
358 bool usage_statistics_reporting_;
360 // If true then update check is cancelled and enrollment is started after
362 bool skip_update_enroll_after_eula_;
364 // Whether enrollment will be or has been recovered in the current wizard
366 bool enrollment_recovery_;
368 // Time when the EULA was accepted. Used to measure the duration from the EULA
369 // acceptance until the Sign-In screen is displayed.
370 base::Time time_eula_accepted_;
372 // Time when OOBE was started. Used to measure the total time from boot to
373 // user Sign-In completed.
374 base::Time time_oobe_started_;
376 ObserverList<Observer> observer_list_;
378 bool login_screen_started_;
380 // Indicates that once image selection screen finishes we should return to
381 // a previous screen instead of proceeding with usual flow.
382 bool user_image_screen_return_to_previous_hack_;
384 // Non-owning pointer to local state used for testing.
385 static PrefService* local_state_for_testing_;
387 FRIEND_TEST_ALL_PREFIXES(EnrollmentScreenTest, TestCancel);
388 FRIEND_TEST_ALL_PREFIXES(WizardControllerFlowTest, Accelerators);
389 friend class WizardControllerFlowTest;
390 friend class WizardControllerOobeResumeTest;
391 friend class WizardInProcessBrowserTest;
392 friend class WizardControllerBrokenLocalStateTest;
394 scoped_ptr<AccessibilityStatusSubscription> accessibility_subscription_;
396 scoped_ptr<SimpleGeolocationProvider> geolocation_provider_;
397 scoped_ptr<TimeZoneProvider> timezone_provider_;
399 // Pairing controller for shark devices.
400 scoped_ptr<pairing_chromeos::ControllerPairingController>
401 controller_pairing_controller_;
403 // Pairing controller for remora devices.
404 scoped_ptr<pairing_chromeos::HostPairingController> host_pairing_controller_;
406 // Maps screen ids to last time of their shows.
407 base::hash_map<std::string, base::Time> screen_show_times_;
409 // Tests check result of timezone resolve.
410 bool timezone_resolved_;
411 base::Closure on_timezone_resolved_for_testing_;
413 // True if shark device initiated connection to this device.
414 bool shark_controller_detected_;
416 // Listens for incoming connection from a shark controller if a regular (not
417 // pairing) remora OOBE is active. If connection is established, wizard
418 // conroller swithces to a pairing OOBE.
419 scoped_ptr<pairing_chromeos::SharkConnectionListener>
420 shark_connection_listener_;
422 base::WeakPtrFactory<WizardController> weak_factory_;
424 DISALLOW_COPY_AND_ASSIGN(WizardController);
427 } // namespace chromeos
429 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WIZARD_CONTROLLER_H_