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