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