wizard_controller.h revision a02191e04bc25c4935f804f2c080ae28663d096d
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.
4
5#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_WIZARD_CONTROLLER_H_
6#define CHROME_BROWSER_CHROMEOS_LOGIN_WIZARD_CONTROLLER_H_
7
8#include <string>
9
10#include "base/compiler_specific.h"
11#include "base/gtest_prod_util.h"
12#include "base/memory/scoped_ptr.h"
13#include "base/memory/weak_ptr.h"
14#include "base/observer_list.h"
15#include "base/time/time.h"
16#include "base/timer/timer.h"
17#include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
18#include "chrome/browser/chromeos/login/screens/screen_observer.h"
19#include "chrome/browser/chromeos/login/screens/wizard_screen.h"
20#include "chrome/browser/chromeos/policy/auto_enrollment_client.h"
21#include "content/public/common/geoposition.h"
22#include "ui/gfx/rect.h"
23#include "url/gurl.h"
24
25class PrefRegistrySimple;
26class PrefService;
27
28namespace base {
29class DictionaryValue;
30}
31
32namespace content {
33struct Geoposition;
34}
35
36namespace chromeos {
37
38class AutoEnrollmentCheckStep;
39class EnrollmentScreen;
40class ErrorScreen;
41class EulaScreen;
42class HIDDetectionScreen;
43class KioskAutolaunchScreen;
44class KioskEnableScreen;
45class LocallyManagedUserCreationScreen;
46class LoginDisplayHost;
47class LoginScreenContext;
48class NetworkScreen;
49class OobeDisplay;
50class ResetScreen;
51class TermsOfServiceScreen;
52class TimeZoneProvider;
53struct TimeZoneResponseData;
54class UpdateScreen;
55class UserImageScreen;
56class WizardScreen;
57class WrongHWIDScreen;
58
59// Class that manages control flow between wizard screens. Wizard controller
60// interacts with screen controllers to move the user between screens.
61class WizardController : public ScreenObserver {
62 public:
63  // Observes screen changes.
64  class Observer {
65   public:
66    // Called before a screen change happens.
67    virtual void OnScreenChanged(WizardScreen* next_screen) = 0;
68
69    // Called after the browser session has started.
70    virtual void OnSessionStart() = 0;
71  };
72
73  WizardController(LoginDisplayHost* host, OobeDisplay* oobe_display);
74  virtual ~WizardController();
75
76  // Returns the default wizard controller if it has been created.
77  static WizardController* default_controller() {
78    return default_controller_;
79  }
80
81  // Whether to skip any screens that may normally be shown after login
82  // (registration, Terms of Service, user image selection).
83  static bool skip_post_login_screens() {
84    return skip_post_login_screens_;
85  }
86
87  // Sets delays to zero. MUST be used only for tests.
88  static void SetZeroDelays();
89
90  // If true zero delays have been enabled (for browser tests).
91  static bool IsZeroDelayEnabled();
92
93  // Skips any screens that may normally be shown after login (registration,
94  // Terms of Service, user image selection).
95  static void SkipPostLoginScreensForTesting();
96
97  // Checks whether OOBE should start enrollment automatically.
98  static bool ShouldAutoStartEnrollment();
99
100  // Shows the first screen defined by |first_screen_name| or by default
101  // if the parameter is empty. Takes ownership of |screen_parameters|.
102  void Init(const std::string& first_screen_name,
103            scoped_ptr<base::DictionaryValue> screen_parameters);
104
105  // Advances to screen defined by |screen_name| and shows it.
106  void AdvanceToScreen(const std::string& screen_name);
107
108  // Advances to login screen. Should be used in for testing only.
109  void SkipToLoginForTesting(const LoginScreenContext& context);
110
111  // Adds and removes an observer.
112  void AddObserver(Observer* observer);
113  void RemoveObserver(Observer* observer);
114
115  // Called right after the browser session has started.
116  void OnSessionStart();
117
118  // Skip update, go straight to enrollment after EULA is accepted.
119  void SkipUpdateEnrollAfterEula();
120
121  // TODO(antrim) : temporary hack. Should be removed once screen system is
122  // reworked at hackaton.
123  void EnableUserImageScreenReturnToPreviousHack();
124
125  // Lazy initializers and getters for screens.
126  NetworkScreen* GetNetworkScreen();
127  UpdateScreen* GetUpdateScreen();
128  UserImageScreen* GetUserImageScreen();
129  EulaScreen* GetEulaScreen();
130  EnrollmentScreen* GetEnrollmentScreen();
131  ResetScreen* GetResetScreen();
132  KioskAutolaunchScreen* GetKioskAutolaunchScreen();
133  KioskEnableScreen* GetKioskEnableScreen();
134  TermsOfServiceScreen* GetTermsOfServiceScreen();
135  WrongHWIDScreen* GetWrongHWIDScreen();
136  HIDDetectionScreen* GetHIDDetectionScreen();
137  LocallyManagedUserCreationScreen* GetLocallyManagedUserCreationScreen();
138
139  // Returns a pointer to the current screen or NULL if there's no such
140  // screen.
141  WizardScreen* current_screen() const { return current_screen_; }
142
143  // Returns true if the current wizard instance has reached the login screen.
144  bool login_screen_started() const { return login_screen_started_; }
145
146  static const char kNetworkScreenName[];
147  static const char kLoginScreenName[];
148  static const char kUpdateScreenName[];
149  static const char kUserImageScreenName[];
150  static const char kOutOfBoxScreenName[];
151  static const char kTestNoScreenName[];
152  static const char kEulaScreenName[];
153  static const char kEnrollmentScreenName[];
154  static const char kResetScreenName[];
155  static const char kKioskEnableScreenName[];
156  static const char kKioskAutolaunchScreenName[];
157  static const char kErrorScreenName[];
158  static const char kTermsOfServiceScreenName[];
159  static const char kWrongHWIDScreenName[];
160  static const char kLocallyManagedUserCreationScreenName[];
161  static const char kAppLaunchSplashScreenName[];
162  static const char kHIDDetectionScreenName [];
163
164  // Volume percent at which spoken feedback is still audible.
165  static const int kMinAudibleOutputVolumePercent;
166
167  // Called from LoginLocationMonitor when location is resolved.
168  static void OnLocationUpdated(const content::Geoposition& position,
169                                base::TimeDelta elapsed);
170
171 private:
172  // Show specific screen.
173  void ShowNetworkScreen();
174  void ShowUpdateScreen();
175  void ShowUserImageScreen();
176  void ShowEulaScreen();
177  void ShowEnrollmentScreen();
178  void ShowResetScreen();
179  void ShowKioskAutolaunchScreen();
180  void ShowKioskEnableScreen();
181  void ShowTermsOfServiceScreen();
182  void ShowWrongHWIDScreen();
183  void ShowLocallyManagedUserCreationScreen();
184  void ShowHIDDetectionScreen();
185
186  // Shows images login screen.
187  void ShowLoginScreen(const LoginScreenContext& context);
188
189  // Resumes a pending login screen.
190  void ResumeLoginScreen();
191
192  // Exit handlers:
193  void OnHIDDetectionCompleted();
194  void OnNetworkConnected();
195  void OnNetworkOffline();
196  void OnConnectionFailed();
197  void OnUpdateCompleted();
198  void OnEulaAccepted();
199  void OnUpdateErrorCheckingForUpdate();
200  void OnUpdateErrorUpdating();
201  void OnUserImageSelected();
202  void OnUserImageSkipped();
203  void OnEnrollmentDone();
204  void OnAutoEnrollmentDone();
205  void OnResetCanceled();
206  void OnKioskAutolaunchCanceled();
207  void OnKioskAutolaunchConfirmed();
208  void OnKioskEnableCompleted();
209  void OnWrongHWIDWarningSkipped();
210  void OnOOBECompleted();
211  void OnTermsOfServiceDeclined();
212  void OnTermsOfServiceAccepted();
213
214  // Loads brand code on I/O enabled thread and stores to Local State.
215  void LoadBrandCodeFromFile();
216
217  // Called after all post-EULA blocking tasks have been completed.
218  void OnEulaBlockingTasksDone();
219
220  // Shows update screen and starts update process.
221  void InitiateOOBEUpdate();
222
223  // Actions that should be done right after EULA is accepted,
224  // before update check.
225  void PerformPostEulaActions();
226
227  // Actions that should be done right after update stage is finished.
228  void PerformOOBECompletedActions();
229
230  // Overridden from ScreenObserver:
231  virtual void OnExit(ExitCodes exit_code) OVERRIDE;
232  virtual void ShowCurrentScreen() OVERRIDE;
233  virtual void OnSetUserNamePassword(const std::string& username,
234                                     const std::string& password) OVERRIDE;
235  virtual void SetUsageStatisticsReporting(bool val) OVERRIDE;
236  virtual bool GetUsageStatisticsReporting() const OVERRIDE;
237  virtual ErrorScreen* GetErrorScreen() OVERRIDE;
238  virtual void ShowErrorScreen() OVERRIDE;
239  virtual void HideErrorScreen(WizardScreen* parent_screen) OVERRIDE;
240
241  // Notification of a change in the state of an accessibility setting.
242  void OnAccessibilityStatusChanged(
243      const AccessibilityStatusEventDetails& details);
244
245  // Switches from one screen to another.
246  void SetCurrentScreen(WizardScreen* screen);
247
248  // Switches from one screen to another with delay before showing. Calling
249  // ShowCurrentScreen directly forces screen to be shown immediately.
250  void SetCurrentScreenSmooth(WizardScreen* screen, bool use_smoothing);
251
252  // Changes status area visibility.
253  void SetStatusAreaVisible(bool visible);
254
255  // Logs in the specified user via default login screen.
256  void Login(const std::string& username, const std::string& password);
257
258  // Launched kiosk app configured for auto-launch.
259  void AutoLaunchKioskApp();
260
261  // Checks whether the user is allowed to exit enrollment.
262  static bool CanExitEnrollment();
263
264  // Gets the management domain.
265  static std::string GetForcedEnrollmentDomain();
266
267  // Called when LocalState is initialized.
268  void OnLocalStateInitialized(bool /* succeeded */);
269
270  // Kicks off the auto-enrollment check step. Once it finishes, it'll call
271  // back via ScreenObserver::OnExit().
272  void StartAutoEnrollmentCheck();
273
274  // Returns local state.
275  PrefService* GetLocalState();
276
277  static void set_local_state_for_testing(PrefService* local_state) {
278    local_state_for_testing_ = local_state;
279  }
280
281  // Called when network is UP.
282  void StartTimezoneResolve() const;
283
284  // Creates provider on demand.
285  TimeZoneProvider* GetTimezoneProvider();
286
287  // TimeZoneRequest::TimeZoneResponseCallback implementation.
288  void OnTimezoneResolved(scoped_ptr<TimeZoneResponseData> timezone,
289                          bool server_error);
290
291  // Whether to skip any screens that may normally be shown after login
292  // (registration, Terms of Service, user image selection).
293  static bool skip_post_login_screens_;
294
295  static bool zero_delay_enabled_;
296
297  // Screens.
298  scoped_ptr<NetworkScreen> network_screen_;
299  scoped_ptr<UpdateScreen> update_screen_;
300  scoped_ptr<UserImageScreen> user_image_screen_;
301  scoped_ptr<EulaScreen> eula_screen_;
302  scoped_ptr<ResetScreen> reset_screen_;
303  scoped_ptr<KioskAutolaunchScreen> autolaunch_screen_;
304  scoped_ptr<KioskEnableScreen> kiosk_enable_screen_;
305  scoped_ptr<EnrollmentScreen> enrollment_screen_;
306  scoped_ptr<ErrorScreen> error_screen_;
307  scoped_ptr<TermsOfServiceScreen> terms_of_service_screen_;
308  scoped_ptr<WrongHWIDScreen> wrong_hwid_screen_;
309  scoped_ptr<LocallyManagedUserCreationScreen>
310      locally_managed_user_creation_screen_;
311  scoped_ptr<HIDDetectionScreen> hid_detection_screen_;
312
313  // Screen that's currently active.
314  WizardScreen* current_screen_;
315
316  // Screen that was active before, or NULL for login screen.
317  WizardScreen* previous_screen_;
318
319  std::string username_;
320  std::string password_;
321
322  // True if running official BUILD.
323  bool is_official_build_;
324
325  // True if full OOBE flow should be shown.
326  bool is_out_of_box_;
327
328  // Value of the screen name that WizardController was started with.
329  std::string first_screen_name_;
330
331  // OOBE/login display host.
332  LoginDisplayHost* host_;
333
334  // Default WizardController.
335  static WizardController* default_controller_;
336
337  // The auto-enrollment check step, currently active.
338  scoped_ptr<AutoEnrollmentCheckStep> auto_enrollment_check_step_;
339
340  // Parameters for the first screen. May be NULL.
341  scoped_ptr<base::DictionaryValue> screen_parameters_;
342
343  base::OneShotTimer<WizardController> smooth_show_timer_;
344
345  OobeDisplay* oobe_display_;
346
347  // State of Usage stat/error reporting checkbox on EULA screen
348  // during wizard lifetime.
349  bool usage_statistics_reporting_;
350
351  // If true then update check is cancelled and enrollment is started after
352  // EULA is accepted.
353  bool skip_update_enroll_after_eula_;
354
355  // Time when the EULA was accepted. Used to measure the duration from the EULA
356  // acceptance until the Sign-In screen is displayed.
357  base::Time time_eula_accepted_;
358
359  ObserverList<Observer> observer_list_;
360
361  bool login_screen_started_;
362
363  // Indicates that once image selection screen finishes we should return to
364  // a previous screen instead of proceeding with usual flow.
365  bool user_image_screen_return_to_previous_hack_;
366
367  // Non-owning pointer to local state used for testing.
368  static PrefService* local_state_for_testing_;
369
370  FRIEND_TEST_ALL_PREFIXES(EnrollmentScreenTest, TestCancel);
371  FRIEND_TEST_ALL_PREFIXES(WizardControllerFlowTest, Accelerators);
372  friend class WizardControllerFlowTest;
373  friend class WizardInProcessBrowserTest;
374  friend class WizardControllerBrokenLocalStateTest;
375
376  scoped_ptr<AccessibilityStatusSubscription> accessibility_subscription_;
377
378  base::WeakPtrFactory<WizardController> weak_factory_;
379
380  scoped_ptr<TimeZoneProvider> timezone_provider_;
381
382  DISALLOW_COPY_AND_ASSIGN(WizardController);
383};
384
385}  // namespace chromeos
386
387#endif  // CHROME_BROWSER_CHROMEOS_LOGIN_WIZARD_CONTROLLER_H_
388