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