Support for remote enrollment.
[chromium-blink-merge.git] / chrome / browser / chromeos / login / wizard_controller.h
blob235c9248198fd3ab4cd587869cc4c8895eba980c
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_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/containers/hash_tables.h"
13 #include "base/gtest_prod_util.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "base/observer_list.h"
17 #include "base/time/time.h"
18 #include "base/timer/timer.h"
19 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
20 #include "chrome/browser/chromeos/login/screens/screen_observer.h"
22 class PrefRegistrySimple;
23 class PrefService;
25 namespace base {
26 class DictionaryValue;
29 namespace chromeos {
31 class AutoEnrollmentCheckScreen;
32 class ControllerPairingScreen;
33 class EnrollmentScreen;
34 class ErrorScreen;
35 class EulaScreen;
36 struct Geoposition;
37 class HIDDetectionScreen;
38 class HostPairingScreen;
39 class KioskAutolaunchScreen;
40 class KioskEnableScreen;
41 class LoginDisplayHost;
42 class LoginScreenContext;
43 class NetworkScreen;
44 class OobeDisplay;
45 class ResetScreen;
46 class SimpleGeolocationProvider;
47 class SupervisedUserCreationScreen;
48 class TermsOfServiceScreen;
49 class TimeZoneProvider;
50 struct TimeZoneResponseData;
51 class UpdateScreen;
52 class UserImageScreen;
53 class WizardScreen;
54 class WrongHWIDScreen;
56 // Class that manages control flow between wizard screens. Wizard controller
57 // interacts with screen controllers to move the user between screens.
58 class WizardController : public ScreenObserver {
59 public:
60 // Observes screen changes.
61 class Observer {
62 public:
63 // Called before a screen change happens.
64 virtual void OnScreenChanged(WizardScreen* next_screen) = 0;
66 // Called after the browser session has started.
67 virtual void OnSessionStart() = 0;
70 WizardController(LoginDisplayHost* host, OobeDisplay* oobe_display);
71 virtual ~WizardController();
73 // Returns the default wizard controller if it has been created.
74 static WizardController* default_controller() {
75 return default_controller_;
78 // Whether to skip any screens that may normally be shown after login
79 // (registration, Terms of Service, user image selection).
80 static bool skip_post_login_screens() {
81 return skip_post_login_screens_;
84 // Sets delays to zero. MUST be used only for tests.
85 static void SetZeroDelays();
87 // If true zero delays have been enabled (for browser tests).
88 static bool IsZeroDelayEnabled();
90 // Checks whether screen show time should be tracked with UMA.
91 static bool IsOOBEStepToTrack(const std::string& screen_id);
93 // Skips any screens that may normally be shown after login (registration,
94 // Terms of Service, user image selection).
95 static void SkipPostLoginScreensForTesting();
97 // Checks whether OOBE should start enrollment automatically.
98 static bool ShouldAutoStartEnrollment();
100 // Checks whether OOBE should recover enrollment. Note that this flips to
101 // false once device policy has been restored as a part of recovery.
102 static bool ShouldRecoverEnrollment();
104 // Obtains domain the device used to be enrolled to from install attributes.
105 static std::string GetEnrollmentRecoveryDomain();
107 // Shows the first screen defined by |first_screen_name| or by default
108 // if the parameter is empty. Takes ownership of |screen_parameters|.
109 void Init(const std::string& first_screen_name,
110 scoped_ptr<base::DictionaryValue> screen_parameters);
112 // Advances to screen defined by |screen_name| and shows it.
113 void AdvanceToScreen(const std::string& screen_name);
115 // Advances to login screen. Should be used in for testing only.
116 void SkipToLoginForTesting(const LoginScreenContext& context);
118 // Adds and removes an observer.
119 void AddObserver(Observer* observer);
120 void RemoveObserver(Observer* observer);
122 // Called right after the browser session has started.
123 void OnSessionStart();
125 // Skip update, go straight to enrollment after EULA is accepted.
126 void SkipUpdateEnrollAfterEula();
128 // TODO(antrim) : temporary hack. Should be removed once screen system is
129 // reworked at hackaton.
130 void EnableUserImageScreenReturnToPreviousHack();
132 // Lazy initializers and getters for screens.
133 NetworkScreen* GetNetworkScreen();
134 UpdateScreen* GetUpdateScreen();
135 UserImageScreen* GetUserImageScreen();
136 EulaScreen* GetEulaScreen();
137 EnrollmentScreen* GetEnrollmentScreen();
138 ResetScreen* GetResetScreen();
139 KioskAutolaunchScreen* GetKioskAutolaunchScreen();
140 KioskEnableScreen* GetKioskEnableScreen();
141 TermsOfServiceScreen* GetTermsOfServiceScreen();
142 WrongHWIDScreen* GetWrongHWIDScreen();
143 AutoEnrollmentCheckScreen* GetAutoEnrollmentCheckScreen();
144 SupervisedUserCreationScreen* GetSupervisedUserCreationScreen();
145 HIDDetectionScreen* GetHIDDetectionScreen();
146 ControllerPairingScreen* GetControllerPairingScreen();
147 HostPairingScreen* GetHostPairingScreen();
149 // Returns a pointer to the current screen or NULL if there's no such
150 // screen.
151 WizardScreen* current_screen() const { return current_screen_; }
153 // Returns true if the current wizard instance has reached the login screen.
154 bool login_screen_started() const { return login_screen_started_; }
156 static const char kNetworkScreenName[];
157 static const char kLoginScreenName[];
158 static const char kUpdateScreenName[];
159 static const char kUserImageScreenName[];
160 static const char kOutOfBoxScreenName[];
161 static const char kTestNoScreenName[];
162 static const char kEulaScreenName[];
163 static const char kEnrollmentScreenName[];
164 static const char kResetScreenName[];
165 static const char kKioskEnableScreenName[];
166 static const char kKioskAutolaunchScreenName[];
167 static const char kErrorScreenName[];
168 static const char kTermsOfServiceScreenName[];
169 static const char kAutoEnrollmentCheckScreenName[];
170 static const char kWrongHWIDScreenName[];
171 static const char kSupervisedUserCreationScreenName[];
172 static const char kAppLaunchSplashScreenName[];
173 static const char kHIDDetectionScreenName[];
174 static const char kControllerPairingScreenName[];
175 static const char kHostPairingScreenName[];
177 // Volume percent at which spoken feedback is still audible.
178 static const int kMinAudibleOutputVolumePercent;
180 private:
181 // Show specific screen.
182 void ShowNetworkScreen();
183 void ShowUpdateScreen();
184 void ShowUserImageScreen();
185 void ShowEulaScreen();
186 void ShowEnrollmentScreen();
187 void ShowResetScreen();
188 void ShowKioskAutolaunchScreen();
189 void ShowKioskEnableScreen();
190 void ShowTermsOfServiceScreen();
191 void ShowWrongHWIDScreen();
192 void ShowAutoEnrollmentCheckScreen();
193 void ShowSupervisedUserCreationScreen();
194 void ShowHIDDetectionScreen();
195 void ShowControllerPairingScreen();
196 void ShowHostPairingScreen();
198 // Shows images login screen.
199 void ShowLoginScreen(const LoginScreenContext& context);
201 // Resumes a pending login screen.
202 void ResumeLoginScreen();
204 // Invokes corresponding first OOBE screen.
205 void OnHIDScreenNecessityCheck(bool screen_needed);
207 // Exit handlers:
208 void OnHIDDetectionCompleted();
209 void OnNetworkConnected();
210 void OnNetworkOffline();
211 void OnConnectionFailed();
212 void OnUpdateCompleted();
213 void OnEulaAccepted();
214 void OnUpdateErrorCheckingForUpdate();
215 void OnUpdateErrorUpdating();
216 void OnUserImageSelected();
217 void OnUserImageSkipped();
218 void OnEnrollmentDone();
219 void OnAutoEnrollmentDone();
220 void OnResetCanceled();
221 void OnKioskAutolaunchCanceled();
222 void OnKioskAutolaunchConfirmed();
223 void OnKioskEnableCompleted();
224 void OnWrongHWIDWarningSkipped();
225 void OnAutoEnrollmentCheckCompleted();
226 void OnTermsOfServiceDeclined();
227 void OnTermsOfServiceAccepted();
228 void OnControllerPairingFinished();
229 void OnHostPairingFinished();
231 // Loads brand code on I/O enabled thread and stores to Local State.
232 void LoadBrandCodeFromFile();
234 // Called after all post-EULA blocking tasks have been completed.
235 void OnEulaBlockingTasksDone();
237 // Shows update screen and starts update process.
238 void InitiateOOBEUpdate();
240 // Actions that should be done right after EULA is accepted,
241 // before update check.
242 void PerformPostEulaActions();
244 // Actions that should be done right after update stage is finished.
245 void PerformOOBECompletedActions();
247 // Overridden from ScreenObserver:
248 virtual void OnExit(ExitCodes exit_code) OVERRIDE;
249 virtual void ShowCurrentScreen() OVERRIDE;
250 virtual void OnSetUserNamePassword(const std::string& username,
251 const std::string& password) OVERRIDE;
252 virtual void SetUsageStatisticsReporting(bool val) OVERRIDE;
253 virtual bool GetUsageStatisticsReporting() const OVERRIDE;
254 virtual ErrorScreen* GetErrorScreen() OVERRIDE;
255 virtual void ShowErrorScreen() OVERRIDE;
256 virtual void HideErrorScreen(WizardScreen* parent_screen) OVERRIDE;
258 // Notification of a change in the state of an accessibility setting.
259 void OnAccessibilityStatusChanged(
260 const AccessibilityStatusEventDetails& details);
262 // Switches from one screen to another.
263 void SetCurrentScreen(WizardScreen* screen);
265 // Switches from one screen to another with delay before showing. Calling
266 // ShowCurrentScreen directly forces screen to be shown immediately.
267 void SetCurrentScreenSmooth(WizardScreen* screen, bool use_smoothing);
269 // Changes status area visibility.
270 void SetStatusAreaVisible(bool visible);
272 // Logs in the specified user via default login screen.
273 void Login(const std::string& username, const std::string& password);
275 // Launched kiosk app configured for auto-launch.
276 void AutoLaunchKioskApp();
278 // Checks whether the user is allowed to exit enrollment.
279 static bool CanExitEnrollment();
281 // Gets the management domain.
282 static std::string GetForcedEnrollmentDomain();
284 // Called when LocalState is initialized.
285 void OnLocalStateInitialized(bool /* succeeded */);
287 // Returns local state.
288 PrefService* GetLocalState();
290 static void set_local_state_for_testing(PrefService* local_state) {
291 local_state_for_testing_ = local_state;
294 std::string first_screen_name() { return first_screen_name_; }
296 // Called when network is UP.
297 void StartTimezoneResolve();
299 // Creates provider on demand.
300 TimeZoneProvider* GetTimezoneProvider();
302 // TimeZoneRequest::TimeZoneResponseCallback implementation.
303 void OnTimezoneResolved(scoped_ptr<TimeZoneResponseData> timezone,
304 bool server_error);
306 // Called from SimpleGeolocationProvider when location is resolved.
307 void OnLocationResolved(const Geoposition& position,
308 bool server_error,
309 const base::TimeDelta elapsed);
311 // Returns true if callback has been installed.
312 // Returns false if timezone has already been resolved.
313 bool SetOnTimeZoneResolvedForTesting(const base::Closure& callback);
315 // Callback for enrollment auth token.
316 void OnEnrollmentAuthTokenReceived(const std::string& auth_token);
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 // Screens.
325 scoped_ptr<NetworkScreen> network_screen_;
326 scoped_ptr<UpdateScreen> update_screen_;
327 scoped_ptr<UserImageScreen> user_image_screen_;
328 scoped_ptr<EulaScreen> eula_screen_;
329 scoped_ptr<ResetScreen> reset_screen_;
330 scoped_ptr<KioskAutolaunchScreen> autolaunch_screen_;
331 scoped_ptr<KioskEnableScreen> kiosk_enable_screen_;
332 scoped_ptr<EnrollmentScreen> enrollment_screen_;
333 scoped_ptr<ErrorScreen> error_screen_;
334 scoped_ptr<TermsOfServiceScreen> terms_of_service_screen_;
335 scoped_ptr<WrongHWIDScreen> wrong_hwid_screen_;
336 scoped_ptr<AutoEnrollmentCheckScreen> auto_enrollment_check_screen_;
337 scoped_ptr<SupervisedUserCreationScreen> supervised_user_creation_screen_;
338 scoped_ptr<HIDDetectionScreen> hid_detection_screen_;
339 scoped_ptr<ControllerPairingScreen> controller_pairing_screen_;
340 scoped_ptr<HostPairingScreen> host_pairing_screen_;
342 // Screen that's currently active.
343 WizardScreen* current_screen_;
345 // Screen that was active before, or NULL for login screen.
346 WizardScreen* previous_screen_;
348 std::string username_;
349 std::string password_;
350 std::string auth_token_;
352 // True if running official BUILD.
353 bool is_official_build_;
355 // True if full OOBE flow should be shown.
356 bool is_out_of_box_;
358 // Value of the screen name that WizardController was started with.
359 std::string first_screen_name_;
361 // OOBE/login display host.
362 LoginDisplayHost* host_;
364 // Default WizardController.
365 static WizardController* default_controller_;
367 // Parameters for the first screen. May be NULL.
368 scoped_ptr<base::DictionaryValue> screen_parameters_;
370 base::OneShotTimer<WizardController> smooth_show_timer_;
372 OobeDisplay* oobe_display_;
374 // State of Usage stat/error reporting checkbox on EULA screen
375 // during wizard lifetime.
376 bool usage_statistics_reporting_;
378 // If true then update check is cancelled and enrollment is started after
379 // EULA is accepted.
380 bool skip_update_enroll_after_eula_;
382 // Whether enrollment will be or has been recovered in the current wizard
383 // instance.
384 bool enrollment_recovery_;
386 // Time when the EULA was accepted. Used to measure the duration from the EULA
387 // acceptance until the Sign-In screen is displayed.
388 base::Time time_eula_accepted_;
390 // Time when OOBE was started. Used to measure the total time from boot to
391 // user Sign-In completed.
392 base::Time time_oobe_started_;
394 ObserverList<Observer> observer_list_;
396 bool login_screen_started_;
398 // Indicates that once image selection screen finishes we should return to
399 // a previous screen instead of proceeding with usual flow.
400 bool user_image_screen_return_to_previous_hack_;
402 // Non-owning pointer to local state used for testing.
403 static PrefService* local_state_for_testing_;
405 FRIEND_TEST_ALL_PREFIXES(EnrollmentScreenTest, TestCancel);
406 FRIEND_TEST_ALL_PREFIXES(WizardControllerFlowTest, Accelerators);
407 friend class WizardControllerFlowTest;
408 friend class WizardControllerOobeResumeTest;
409 friend class WizardInProcessBrowserTest;
410 friend class WizardControllerBrokenLocalStateTest;
412 scoped_ptr<AccessibilityStatusSubscription> accessibility_subscription_;
414 scoped_ptr<SimpleGeolocationProvider> geolocation_provider_;
415 scoped_ptr<TimeZoneProvider> timezone_provider_;
417 // Maps screen ids to last time of their shows.
418 base::hash_map<std::string, base::Time> screen_show_times_;
420 // Tests check result of timezone resolve.
421 bool timezone_resolved_;
422 base::Closure on_timezone_resolved_for_testing_;
424 base::WeakPtrFactory<WizardController> weak_factory_;
426 DISALLOW_COPY_AND_ASSIGN(WizardController);
429 } // namespace chromeos
431 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WIZARD_CONTROLLER_H_