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