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_
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"
22 class PrefRegistrySimple;
26 class DictionaryValue;
31 class EnrollmentScreen;
34 class KioskAutolaunchScreen;
35 class KioskEnableScreen;
36 class LocallyManagedUserCreationScreen;
37 class LoginDisplayHost;
41 class TermsOfServiceScreen;
43 class UserImageScreen;
45 class WrongHWIDScreen;
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 {
51 // Observes screen changes.
54 // Called before a screen change happens.
55 virtual void OnScreenChanged(WizardScreen* next_screen) = 0;
57 // Called after the browser session has started.
58 virtual void OnSessionStart() = 0;
61 WizardController(LoginDisplayHost* host, OobeDisplay* oobe_display);
62 virtual ~WizardController();
64 // Returns the default wizard controller if it has been created.
65 static WizardController* default_controller() {
66 return default_controller_;
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_;
75 // Sets delays to zero. MUST be used only for tests.
76 static void SetZeroDelays();
78 // If true zero delays have been enabled (for browser tests).
79 static bool IsZeroDelayEnabled();
81 // Skips any screens that may normally be shown after login (registration,
82 // Terms of Service, user image selection).
83 static void SkipPostLoginScreensForTesting();
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);
90 // Advances to screen defined by |screen_name| and shows it.
91 void AdvanceToScreen(const std::string& screen_name);
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);
98 // Advances to login screen. Should be used in for testing only.
99 void SkipToLoginForTesting();
101 // Adds and removes an observer.
102 void AddObserver(Observer* observer);
103 void RemoveObserver(Observer* observer);
105 // Called right after the browser session has started.
106 void OnSessionStart();
108 // Skip update, go straight to enrollment after EULA is accepted.
109 void SkipUpdateEnrollAfterEula();
111 // TODO(antrim) : temporary hack. Should be removed once screen system is
112 // reworked at hackaton.
113 void EnableUserImageScreenReturnToPreviousHack();
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();
128 // Returns a pointer to the current screen or NULL if there's no such
130 WizardScreen* current_screen() const { return current_screen_; }
132 // Returns true if the current wizard instance has reached the login screen.
133 bool login_screen_started() const { return login_screen_started_; }
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[];
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();
166 // Shows images login screen.
167 void ShowLoginScreen();
169 // Resumes a pending login screen.
170 void ResumeLoginScreen();
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();
193 // Loads brand code on I/O enabled thread and stores to Local State.
194 void LoadBrandCodeFromFile();
196 // Called after all post-EULA blocking tasks have been completed.
197 void OnEulaBlockingTasksDone();
199 // Shows update screen and starts update process.
200 void InitiateOOBEUpdate();
202 // Actions that should be done right after EULA is accepted,
203 // before update check.
204 void PerformPostEulaActions();
206 // Actions that should be done right after update stage is finished.
207 void PerformPostUpdateActions();
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;
220 // Switches from one screen to another.
221 void SetCurrentScreen(WizardScreen* screen);
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);
227 // Changes status area visibility.
228 void SetStatusAreaVisible(bool visible);
230 // Logs in the specified user via default login screen.
231 void Login(const std::string& username, const std::string& password);
233 // Launched kiosk app configured for auto-launch.
234 void AutoLaunchKioskApp();
236 // Checks whether OOBE should start enrollment automatically.
237 bool ShouldAutoStartEnrollment() const;
239 // Checks whether the user is allowed to exit enrollment.
240 bool CanExitEnrollment() const;
242 // Called when LocalState is initialized.
243 void OnLocalStateInitialized(bool /* succeeded */);
245 // Returns local state.
246 PrefService* GetLocalState();
248 static void set_local_state_for_testing(PrefService* local_state) {
249 local_state_for_testing_ = local_state;
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_;
256 static bool zero_delay_enabled_;
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_;
273 // Screen that's currently active.
274 WizardScreen* current_screen_;
276 // Screen that was active before, or NULL for login screen.
277 WizardScreen* previous_screen_;
279 std::string username_;
280 std::string password_;
282 // True if running official BUILD.
283 bool is_official_build_;
285 // True if full OOBE flow should be shown.
288 // Value of the screen name that WizardController was started with.
289 std::string first_screen_name_;
291 // OOBE/login display host.
292 LoginDisplayHost* host_;
294 // Default WizardController.
295 static WizardController* default_controller_;
297 // Parameters for the first screen. May be NULL.
298 scoped_ptr<base::DictionaryValue> screen_parameters_;
300 base::OneShotTimer<WizardController> smooth_show_timer_;
302 OobeDisplay* oobe_display_;
304 // State of Usage stat/error reporting checkbox on EULA screen
305 // during wizard lifetime.
306 bool usage_statistics_reporting_;
308 // If true then update check is cancelled and enrollment is started after
310 bool skip_update_enroll_after_eula_;
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_;
316 ObserverList<Observer> observer_list_;
318 bool login_screen_started_;
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_;
324 // Non-owning pointer to local state used for testing.
325 static PrefService* local_state_for_testing_;
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;
333 base::WeakPtrFactory<WizardController> weak_factory_;
335 DISALLOW_COPY_AND_ASSIGN(WizardController);
338 } // namespace chromeos
340 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WIZARD_CONTROLLER_H_