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