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 21 class PrefRegistrySimple; 22 23 namespace base { 24 class DictionaryValue; 25 } 26 27 namespace chromeos { 28 29 class EnrollmentScreen; 30 class ErrorScreen; 31 class EulaScreen; 32 class KioskAutolaunchScreen; 33 class KioskEnableScreen; 34 class LocallyManagedUserCreationScreen; 35 class LoginDisplayHost; 36 class NetworkScreen; 37 class OobeDisplay; 38 class ResetScreen; 39 class TermsOfServiceScreen; 40 class UpdateScreen; 41 class UserImageScreen; 42 class WizardScreen; 43 class WrongHWIDScreen; 44 45 // Class that manages control flow between wizard screens. Wizard controller 46 // interacts with screen controllers to move the user between screens. 47 class 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 149 private: 150 // Show specific screen. 151 void ShowNetworkScreen(); 152 void ShowUpdateScreen(); 153 void ShowUserImageScreen(); 154 void ShowEulaScreen(); 155 void ShowEnrollmentScreen(); 156 void ShowResetScreen(); 157 void ShowKioskAutolaunchScreen(); 158 void ShowKioskEnableScreen(); 159 void ShowTermsOfServiceScreen(); 160 void ShowWrongHWIDScreen(); 161 void ShowLocallyManagedUserCreationScreen(); 162 163 // Shows images login screen. 164 void ShowLoginScreen(); 165 166 // Resumes a pending login screen. 167 void ResumeLoginScreen(); 168 169 // Exit handlers: 170 void OnNetworkConnected(); 171 void OnNetworkOffline(); 172 void OnConnectionFailed(); 173 void OnUpdateCompleted(); 174 void OnEulaAccepted(); 175 void OnUpdateErrorCheckingForUpdate(); 176 void OnUpdateErrorUpdating(); 177 void OnUserImageSelected(); 178 void OnUserImageSkipped(); 179 void OnEnrollmentDone(); 180 void OnAutoEnrollmentDone(); 181 void OnResetCanceled(); 182 void OnKioskAutolaunchCanceled(); 183 void OnKioskAutolaunchConfirmed(); 184 void OnKioskEnableCompleted(); 185 void OnWrongHWIDWarningSkipped(); 186 void OnOOBECompleted(); 187 void OnTermsOfServiceDeclined(); 188 void OnTermsOfServiceAccepted(); 189 190 // Loads brand code on I/O enabled thread and stores to Local State. 191 void LoadBrandCodeFromFile(); 192 193 // Called after all post-EULA blocking tasks have been completed. 194 void OnEulaBlockingTasksDone(); 195 196 // Shows update screen and starts update process. 197 void InitiateOOBEUpdate(); 198 199 // Actions that should be done right after EULA is accepted, 200 // before update check. 201 void PerformPostEulaActions(); 202 203 // Actions that should be done right after update stage is finished. 204 void PerformPostUpdateActions(); 205 206 // Overridden from ScreenObserver: 207 virtual void OnExit(ExitCodes exit_code) OVERRIDE; 208 virtual void ShowCurrentScreen() OVERRIDE; 209 virtual void OnSetUserNamePassword(const std::string& username, 210 const std::string& password) OVERRIDE; 211 virtual void SetUsageStatisticsReporting(bool val) OVERRIDE; 212 virtual bool GetUsageStatisticsReporting() const OVERRIDE; 213 virtual ErrorScreen* GetErrorScreen() OVERRIDE; 214 virtual void ShowErrorScreen() OVERRIDE; 215 virtual void HideErrorScreen(WizardScreen* parent_screen) OVERRIDE; 216 217 // Switches from one screen to another. 218 void SetCurrentScreen(WizardScreen* screen); 219 220 // Switches from one screen to another with delay before showing. Calling 221 // ShowCurrentScreen directly forces screen to be shown immediately. 222 void SetCurrentScreenSmooth(WizardScreen* screen, bool use_smoothing); 223 224 // Changes status area visibility. 225 void SetStatusAreaVisible(bool visible); 226 227 // Logs in the specified user via default login screen. 228 void Login(const std::string& username, const std::string& password); 229 230 // Launched kiosk app configured for auto-launch. 231 void AutoLaunchKioskApp(); 232 233 // Checks whether OOBE should start enrollment automatically. 234 bool ShouldAutoStartEnrollment() const; 235 236 // Checks whether the user is allowed to exit enrollment. 237 bool CanExitEnrollment() const; 238 239 // Whether to skip any screens that may normally be shown after login 240 // (registration, Terms of Service, user image selection). 241 static bool skip_post_login_screens_; 242 243 static bool zero_delay_enabled_; 244 245 // Screens. 246 scoped_ptr<NetworkScreen> network_screen_; 247 scoped_ptr<UpdateScreen> update_screen_; 248 scoped_ptr<UserImageScreen> user_image_screen_; 249 scoped_ptr<EulaScreen> eula_screen_; 250 scoped_ptr<ResetScreen> reset_screen_; 251 scoped_ptr<KioskAutolaunchScreen> autolaunch_screen_; 252 scoped_ptr<KioskEnableScreen> kiosk_enable_screen_; 253 scoped_ptr<EnrollmentScreen> enrollment_screen_; 254 scoped_ptr<ErrorScreen> error_screen_; 255 scoped_ptr<TermsOfServiceScreen> terms_of_service_screen_; 256 scoped_ptr<WrongHWIDScreen> wrong_hwid_screen_; 257 scoped_ptr<LocallyManagedUserCreationScreen> 258 locally_managed_user_creation_screen_; 259 260 // Screen that's currently active. 261 WizardScreen* current_screen_; 262 263 // Screen that was active before, or NULL for login screen. 264 WizardScreen* previous_screen_; 265 266 std::string username_; 267 std::string password_; 268 269 // True if running official BUILD. 270 bool is_official_build_; 271 272 // True if full OOBE flow should be shown. 273 bool is_out_of_box_; 274 275 // Value of the screen name that WizardController was started with. 276 std::string first_screen_name_; 277 278 // OOBE/login display host. 279 LoginDisplayHost* host_; 280 281 // Default WizardController. 282 static WizardController* default_controller_; 283 284 // Parameters for the first screen. May be NULL. 285 scoped_ptr<base::DictionaryValue> screen_parameters_; 286 287 base::OneShotTimer<WizardController> smooth_show_timer_; 288 289 OobeDisplay* oobe_display_; 290 291 // State of Usage stat/error reporting checkbox on EULA screen 292 // during wizard lifetime. 293 bool usage_statistics_reporting_; 294 295 // If true then update check is cancelled and enrollment is started after 296 // EULA is accepted. 297 bool skip_update_enroll_after_eula_; 298 299 // Time when the EULA was accepted. Used to measure the duration from the EULA 300 // acceptance until the Sign-In screen is displayed. 301 base::Time time_eula_accepted_; 302 303 ObserverList<Observer> observer_list_; 304 305 bool login_screen_started_; 306 307 // Indicates that once image selection screen finishes we should return to 308 // a previous screen instead of proceeding with usual flow. 309 bool user_image_screen_return_to_previous_hack_; 310 311 FRIEND_TEST_ALL_PREFIXES(EnrollmentScreenTest, TestCancel); 312 FRIEND_TEST_ALL_PREFIXES(WizardControllerFlowTest, Accelerators); 313 friend class WizardControllerFlowTest; 314 friend class WizardInProcessBrowserTest; 315 316 DISALLOW_COPY_AND_ASSIGN(WizardController); 317 }; 318 319 } // namespace chromeos 320 321 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_WIZARD_CONTROLLER_H_ 322