Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / login / wizard_controller.cc
blob4c58fd75b885c5bd5650f40a364e184e8fdbe235
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 #include "chrome/browser/chromeos/login/wizard_controller.h"
7 #include <signal.h>
8 #include <stdlib.h>
9 #include <sys/types.h>
11 #include <string>
12 #include <vector>
14 #include "base/bind.h"
15 #include "base/command_line.h"
16 #include "base/logging.h"
17 #include "base/metrics/histogram.h"
18 #include "base/prefs/pref_registry_simple.h"
19 #include "base/prefs/pref_service.h"
20 #include "base/threading/thread_restrictions.h"
21 #include "base/values.h"
22 #include "chrome/browser/browser_process.h"
23 #include "chrome/browser/chrome_notification_types.h"
24 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
25 #include "chrome/browser/chromeos/customization_document.h"
26 #include "chrome/browser/chromeos/login/enrollment/enrollment_screen.h"
27 #include "chrome/browser/chromeos/login/existing_user_controller.h"
28 #include "chrome/browser/chromeos/login/helper.h"
29 #include "chrome/browser/chromeos/login/hwid_checker.h"
30 #include "chrome/browser/chromeos/login/login_display_host.h"
31 #include "chrome/browser/chromeos/login/login_utils.h"
32 #include "chrome/browser/chromeos/login/managed/locally_managed_user_creation_screen.h"
33 #include "chrome/browser/chromeos/login/oobe_display.h"
34 #include "chrome/browser/chromeos/login/screens/error_screen.h"
35 #include "chrome/browser/chromeos/login/screens/eula_screen.h"
36 #include "chrome/browser/chromeos/login/screens/kiosk_autolaunch_screen.h"
37 #include "chrome/browser/chromeos/login/screens/kiosk_enable_screen.h"
38 #include "chrome/browser/chromeos/login/screens/network_screen.h"
39 #include "chrome/browser/chromeos/login/screens/reset_screen.h"
40 #include "chrome/browser/chromeos/login/screens/terms_of_service_screen.h"
41 #include "chrome/browser/chromeos/login/screens/update_screen.h"
42 #include "chrome/browser/chromeos/login/screens/user_image_screen.h"
43 #include "chrome/browser/chromeos/login/screens/wrong_hwid_screen.h"
44 #include "chrome/browser/chromeos/login/startup_utils.h"
45 #include "chrome/browser/chromeos/login/user_manager.h"
46 #include "chrome/browser/chromeos/net/network_portal_detector.h"
47 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
48 #include "chrome/browser/chromeos/settings/cros_settings.h"
49 #include "chrome/browser/policy/browser_policy_connector.h"
50 #include "chrome/browser/profiles/profile.h"
51 #include "chrome/browser/profiles/profile_manager.h"
52 #include "chrome/browser/ui/options/options_util.h"
53 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
54 #include "chrome/common/chrome_constants.h"
55 #include "chrome/common/pref_names.h"
56 #include "chromeos/chromeos_constants.h"
57 #include "chromeos/dbus/dbus_thread_manager.h"
58 #include "chromeos/dbus/session_manager_client.h"
59 #include "chromeos/network/network_state_handler.h"
60 #include "chromeos/settings/cros_settings_names.h"
61 #include "components/breakpad/app/breakpad_linux.h"
62 #include "content/public/browser/browser_thread.h"
63 #include "ui/base/accelerators/accelerator.h"
64 #include "ui/base/l10n/l10n_util.h"
66 using content::BrowserThread;
68 // If reboot didn't happen, ask user to reboot device manually.
69 const int kWaitForRebootTimeSec = 3;
71 // Interval in ms which is used for smooth screen showing.
72 static int kShowDelayMs = 400;
74 namespace chromeos {
76 const char WizardController::kNetworkScreenName[] = "network";
77 const char WizardController::kLoginScreenName[] = "login";
78 const char WizardController::kUpdateScreenName[] = "update";
79 const char WizardController::kUserImageScreenName[] = "image";
80 const char WizardController::kEulaScreenName[] = "eula";
81 const char WizardController::kEnrollmentScreenName[] = "enroll";
82 const char WizardController::kResetScreenName[] = "reset";
83 const char WizardController::kKioskEnableScreenName[] = "kiosk-enable";
84 const char WizardController::kKioskAutolaunchScreenName[] = "autolaunch";
85 const char WizardController::kErrorScreenName[] = "error-message";
86 const char WizardController::kTermsOfServiceScreenName[] = "tos";
87 const char WizardController::kWrongHWIDScreenName[] = "wrong-hwid";
88 const char WizardController::kLocallyManagedUserCreationScreenName[] =
89 "locally-managed-user-creation-flow";
90 const char WizardController::kAppLaunchSplashScreenName[] =
91 "app-launch-splash";
93 // Passing this parameter as a "first screen" initiates full OOBE flow.
94 const char WizardController::kOutOfBoxScreenName[] = "oobe";
96 // Special test value that commands not to create any window yet.
97 const char WizardController::kTestNoScreenName[] = "test:nowindow";
99 // Initialize default controller.
100 // static
101 WizardController* WizardController::default_controller_ = NULL;
103 // static
104 bool WizardController::skip_post_login_screens_ = false;
106 // static
107 bool WizardController::zero_delay_enabled_ = false;
109 ///////////////////////////////////////////////////////////////////////////////
110 // WizardController, public:
112 PrefService* WizardController::local_state_for_testing_ = NULL;
114 WizardController::WizardController(chromeos::LoginDisplayHost* host,
115 chromeos::OobeDisplay* oobe_display)
116 : current_screen_(NULL),
117 previous_screen_(NULL),
118 #if defined(GOOGLE_CHROME_BUILD)
119 is_official_build_(true),
120 #else
121 is_official_build_(false),
122 #endif
123 is_out_of_box_(false),
124 host_(host),
125 oobe_display_(oobe_display),
126 usage_statistics_reporting_(true),
127 skip_update_enroll_after_eula_(false),
128 login_screen_started_(false),
129 user_image_screen_return_to_previous_hack_(false),
130 weak_factory_(this) {
131 DCHECK(default_controller_ == NULL);
132 default_controller_ = this;
135 WizardController::~WizardController() {
136 if (default_controller_ == this) {
137 default_controller_ = NULL;
138 } else {
139 NOTREACHED() << "More than one controller are alive.";
143 void WizardController::Init(
144 const std::string& first_screen_name,
145 scoped_ptr<base::DictionaryValue> screen_parameters) {
146 VLOG(1) << "Starting OOBE wizard with screen: " << first_screen_name;
147 first_screen_name_ = first_screen_name;
148 screen_parameters_ = screen_parameters.Pass();
150 bool oobe_complete = StartupUtils::IsOobeCompleted();
151 if (!oobe_complete || first_screen_name == kOutOfBoxScreenName)
152 is_out_of_box_ = true;
154 // This is a hacky way to check for local state corruption, because
155 // it depends on the fact that the local state is loaded
156 // synchroniously and at the first demand. IsEnterpriseManaged()
157 // check is required because currently powerwash is disabled for
158 // enterprise-entrolled devices.
160 // TODO (ygorshenin@): implement handling of the local state
161 // corruption in the case of asynchronious loading.
163 // TODO (ygorshenin@): remove IsEnterpriseManaged() check once
164 // crbug.com/241313 will be fixed.
165 if (!g_browser_process->browser_policy_connector()->IsEnterpriseManaged()) {
166 const PrefService::PrefInitializationStatus status =
167 GetLocalState()->GetInitializationStatus();
168 if (status == PrefService::INITIALIZATION_STATUS_ERROR) {
169 OnLocalStateInitialized(false);
170 return;
171 } else if (status == PrefService::INITIALIZATION_STATUS_WAITING) {
172 GetLocalState()->AddPrefInitObserver(
173 base::Bind(&WizardController::OnLocalStateInitialized,
174 weak_factory_.GetWeakPtr()));
178 AdvanceToScreen(first_screen_name);
179 if (!IsMachineHWIDCorrect() && !StartupUtils::IsDeviceRegistered() &&
180 first_screen_name.empty())
181 ShowWrongHWIDScreen();
184 chromeos::NetworkScreen* WizardController::GetNetworkScreen() {
185 if (!network_screen_.get())
186 network_screen_.reset(new chromeos::NetworkScreen(
187 this, oobe_display_->GetNetworkScreenActor()));
188 return network_screen_.get();
191 chromeos::UpdateScreen* WizardController::GetUpdateScreen() {
192 if (!update_screen_.get()) {
193 update_screen_.reset(new chromeos::UpdateScreen(
194 this, oobe_display_->GetUpdateScreenActor()));
195 update_screen_->SetRebootCheckDelay(kWaitForRebootTimeSec);
197 return update_screen_.get();
200 chromeos::UserImageScreen* WizardController::GetUserImageScreen() {
201 if (!user_image_screen_.get())
202 user_image_screen_.reset(
203 new chromeos::UserImageScreen(
204 this, oobe_display_->GetUserImageScreenActor()));
205 return user_image_screen_.get();
208 chromeos::EulaScreen* WizardController::GetEulaScreen() {
209 if (!eula_screen_.get())
210 eula_screen_.reset(new chromeos::EulaScreen(
211 this, oobe_display_->GetEulaScreenActor()));
212 return eula_screen_.get();
215 chromeos::EnrollmentScreen*
216 WizardController::GetEnrollmentScreen() {
217 if (!enrollment_screen_.get()) {
218 enrollment_screen_.reset(
219 new chromeos::EnrollmentScreen(
220 this, oobe_display_->GetEnrollmentScreenActor()));
222 return enrollment_screen_.get();
225 chromeos::ResetScreen* WizardController::GetResetScreen() {
226 if (!reset_screen_.get()) {
227 reset_screen_.reset(
228 new chromeos::ResetScreen(this, oobe_display_->GetResetScreenActor()));
230 return reset_screen_.get();
233 chromeos::KioskEnableScreen* WizardController::GetKioskEnableScreen() {
234 if (!kiosk_enable_screen_.get()) {
235 kiosk_enable_screen_.reset(
236 new chromeos::KioskEnableScreen(
237 this,
238 oobe_display_->GetKioskEnableScreenActor()));
240 return kiosk_enable_screen_.get();
243 chromeos::KioskAutolaunchScreen* WizardController::GetKioskAutolaunchScreen() {
244 if (!autolaunch_screen_.get()) {
245 autolaunch_screen_.reset(
246 new chromeos::KioskAutolaunchScreen(
247 this, oobe_display_->GetKioskAutolaunchScreenActor()));
249 return autolaunch_screen_.get();
252 chromeos::TermsOfServiceScreen* WizardController::GetTermsOfServiceScreen() {
253 if (!terms_of_service_screen_.get()) {
254 terms_of_service_screen_.reset(
255 new chromeos::TermsOfServiceScreen(
256 this, oobe_display_->GetTermsOfServiceScreenActor()));
258 return terms_of_service_screen_.get();
261 chromeos::WrongHWIDScreen* WizardController::GetWrongHWIDScreen() {
262 if (!wrong_hwid_screen_.get()) {
263 wrong_hwid_screen_.reset(
264 new chromeos::WrongHWIDScreen(
265 this, oobe_display_->GetWrongHWIDScreenActor()));
267 return wrong_hwid_screen_.get();
270 chromeos::LocallyManagedUserCreationScreen*
271 WizardController::GetLocallyManagedUserCreationScreen() {
272 if (!locally_managed_user_creation_screen_.get()) {
273 locally_managed_user_creation_screen_.reset(
274 new chromeos::LocallyManagedUserCreationScreen(
275 this, oobe_display_->GetLocallyManagedUserCreationScreenActor()));
277 return locally_managed_user_creation_screen_.get();
280 void WizardController::ShowNetworkScreen() {
281 VLOG(1) << "Showing network screen.";
282 SetStatusAreaVisible(false);
283 SetCurrentScreen(GetNetworkScreen());
286 void WizardController::ShowLoginScreen(const LoginScreenContext& context) {
287 if (!time_eula_accepted_.is_null()) {
288 base::TimeDelta delta = base::Time::Now() - time_eula_accepted_;
289 UMA_HISTOGRAM_MEDIUM_TIMES("OOBE.EULAToSignInTime", delta);
291 VLOG(1) << "Showing login screen.";
292 SetStatusAreaVisible(true);
293 host_->StartSignInScreen(context);
294 smooth_show_timer_.Stop();
295 oobe_display_ = NULL;
296 login_screen_started_ = true;
299 void WizardController::ResumeLoginScreen() {
300 VLOG(1) << "Resuming login screen.";
301 SetStatusAreaVisible(true);
302 host_->ResumeSignInScreen();
303 smooth_show_timer_.Stop();
304 oobe_display_ = NULL;
307 void WizardController::ShowUpdateScreen() {
308 VLOG(1) << "Showing update screen.";
309 SetStatusAreaVisible(true);
310 SetCurrentScreen(GetUpdateScreen());
313 void WizardController::ShowUserImageScreen() {
314 const chromeos::UserManager* user_manager = chromeos::UserManager::Get();
315 // Skip user image selection for public sessions and ephemeral logins.
316 if (user_manager->IsLoggedInAsPublicAccount() ||
317 user_manager->IsCurrentUserNonCryptohomeDataEphemeral()) {
318 OnUserImageSkipped();
319 return;
321 VLOG(1) << "Showing user image screen.";
323 bool profile_picture_enabled = true;
324 std::string user_id;
325 if (screen_parameters_.get()) {
326 screen_parameters_->GetBoolean("profile_picture_enabled",
327 &profile_picture_enabled);
328 screen_parameters_->GetString("user_id", &user_id);
331 // Status area has been already shown at sign in screen so it
332 // doesn't make sense to hide it here and then show again at user session as
333 // this produces undesired UX transitions.
334 SetStatusAreaVisible(true);
336 UserImageScreen* screen = GetUserImageScreen();
337 if (!user_id.empty())
338 screen->SetUserID(user_id);
339 screen->SetProfilePictureEnabled(profile_picture_enabled);
341 SetCurrentScreen(screen);
344 void WizardController::ShowEulaScreen() {
345 VLOG(1) << "Showing EULA screen.";
346 SetStatusAreaVisible(false);
347 SetCurrentScreen(GetEulaScreen());
350 void WizardController::ShowEnrollmentScreen() {
351 SetStatusAreaVisible(true);
353 bool is_auto_enrollment = false;
354 std::string user;
355 if (screen_parameters_.get()) {
356 screen_parameters_->GetBoolean("is_auto_enrollment", &is_auto_enrollment);
357 screen_parameters_->GetString("user", &user);
360 EnrollmentScreen* screen = GetEnrollmentScreen();
361 screen->SetParameters(is_auto_enrollment,
362 !ShouldAutoStartEnrollment() || CanExitEnrollment(),
363 user);
364 SetCurrentScreen(screen);
367 void WizardController::ShowResetScreen() {
368 VLOG(1) << "Showing reset screen.";
369 SetStatusAreaVisible(false);
370 SetCurrentScreen(GetResetScreen());
373 void WizardController::ShowKioskEnableScreen() {
374 VLOG(1) << "Showing kiosk enable screen.";
375 SetStatusAreaVisible(false);
376 SetCurrentScreen(GetKioskEnableScreen());
379 void WizardController::ShowKioskAutolaunchScreen() {
380 VLOG(1) << "Showing kiosk autolaunch screen.";
381 SetStatusAreaVisible(false);
382 SetCurrentScreen(GetKioskAutolaunchScreen());
385 void WizardController::ShowTermsOfServiceScreen() {
386 // Only show the Terms of Service when logging into a public account and Terms
387 // of Service have been specified through policy. In all other cases, advance
388 // to the user image screen immediately.
389 if (!chromeos::UserManager::Get()->IsLoggedInAsPublicAccount() ||
390 !ProfileManager::GetActiveUserProfile()->GetPrefs()->
391 IsManagedPreference(prefs::kTermsOfServiceURL)) {
392 ShowUserImageScreen();
393 return;
396 VLOG(1) << "Showing Terms of Service screen.";
397 SetStatusAreaVisible(true);
398 SetCurrentScreen(GetTermsOfServiceScreen());
401 void WizardController::ShowWrongHWIDScreen() {
402 VLOG(1) << "Showing wrong HWID screen.";
403 SetStatusAreaVisible(false);
404 SetCurrentScreen(GetWrongHWIDScreen());
407 void WizardController::ShowLocallyManagedUserCreationScreen() {
408 VLOG(1) << "Showing Locally managed user creation screen screen.";
409 SetStatusAreaVisible(true);
410 LocallyManagedUserCreationScreen* screen =
411 GetLocallyManagedUserCreationScreen();
412 SetCurrentScreen(screen);
415 void WizardController::SkipToLoginForTesting(
416 const LoginScreenContext& context) {
417 StartupUtils::MarkEulaAccepted();
418 PerformPostEulaActions();
419 PerformPostUpdateActions();
420 ShowLoginScreen(context);
423 void WizardController::AddObserver(Observer* observer) {
424 observer_list_.AddObserver(observer);
427 void WizardController::RemoveObserver(Observer* observer) {
428 observer_list_.RemoveObserver(observer);
431 void WizardController::OnSessionStart() {
432 FOR_EACH_OBSERVER(Observer, observer_list_, OnSessionStart());
435 void WizardController::SkipUpdateEnrollAfterEula() {
436 skip_update_enroll_after_eula_ = true;
439 ///////////////////////////////////////////////////////////////////////////////
440 // WizardController, ExitHandlers:
441 void WizardController::OnNetworkConnected() {
442 if (is_official_build_) {
443 if (!StartupUtils::IsEulaAccepted()) {
444 ShowEulaScreen();
445 } else {
446 // Possible cases:
447 // 1. EULA was accepted, forced shutdown/reboot during update.
448 // 2. EULA was accepted, planned reboot after update.
449 // Make sure that device is up-to-date.
450 InitiateOOBEUpdate();
452 } else {
453 InitiateOOBEUpdate();
457 void WizardController::OnNetworkOffline() {
458 // TODO(dpolukhin): if(is_out_of_box_) we cannot work offline and
459 // should report some error message here and stay on the same screen.
460 ShowLoginScreen(LoginScreenContext());
463 void WizardController::OnConnectionFailed() {
464 // TODO(dpolukhin): show error message after login screen is displayed.
465 ShowLoginScreen(LoginScreenContext());
468 void WizardController::OnUpdateCompleted() {
469 OnOOBECompleted();
472 void WizardController::OnEulaAccepted() {
473 time_eula_accepted_ = base::Time::Now();
474 StartupUtils::MarkEulaAccepted();
475 bool uma_enabled =
476 OptionsUtil::ResolveMetricsReportingEnabled(usage_statistics_reporting_);
478 CrosSettings::Get()->SetBoolean(kStatsReportingPref, uma_enabled);
479 if (uma_enabled) {
480 #if defined(GOOGLE_CHROME_BUILD)
481 // The crash reporter initialization needs IO to complete.
482 base::ThreadRestrictions::ScopedAllowIO allow_io;
483 breakpad::InitCrashReporter(std::string());
484 #endif
487 if (skip_update_enroll_after_eula_) {
488 PerformPostEulaActions();
489 PerformPostUpdateActions();
490 ShowEnrollmentScreen();
491 } else {
492 InitiateOOBEUpdate();
496 void WizardController::OnUpdateErrorCheckingForUpdate() {
497 // TODO(nkostylev): Update should be required during OOBE.
498 // We do not want to block users from being able to proceed to the login
499 // screen if there is any error checking for an update.
500 // They could use "browse without sign-in" feature to set up the network to be
501 // able to perform the update later.
502 OnOOBECompleted();
505 void WizardController::OnUpdateErrorUpdating() {
506 // If there was an error while getting or applying the update,
507 // return to network selection screen.
508 // TODO(nkostylev): Show message to the user explaining update error.
509 // TODO(nkostylev): Update should be required during OOBE.
510 // Temporary fix, need to migrate to new API. http://crosbug.com/4321
511 OnOOBECompleted();
514 void WizardController::EnableUserImageScreenReturnToPreviousHack() {
515 user_image_screen_return_to_previous_hack_ = true;
518 void WizardController::OnUserImageSelected() {
519 if (user_image_screen_return_to_previous_hack_) {
520 user_image_screen_return_to_previous_hack_ = false;
521 DCHECK(previous_screen_);
522 if (previous_screen_) {
523 SetCurrentScreen(previous_screen_);
524 return;
527 // Launch browser and delete login host controller.
528 BrowserThread::PostTask(
529 BrowserThread::UI,
530 FROM_HERE,
531 base::Bind(&chromeos::LoginUtils::DoBrowserLaunch,
532 base::Unretained(chromeos::LoginUtils::Get()),
533 ProfileManager::GetActiveUserProfile(), host_));
534 host_ = NULL;
537 void WizardController::OnUserImageSkipped() {
538 OnUserImageSelected();
541 void WizardController::OnEnrollmentDone() {
542 // Mark OOBE as completed only if enterprise enrollment was part of the
543 // forced flow (i.e. app kiosk).
544 if (ShouldAutoStartEnrollment())
545 PerformPostUpdateActions();
547 // TODO(mnissler): Unify the logic for auto-login for Public Sessions and
548 // Kiosk Apps and make this code cover both cases: http://crbug.com/234694.
549 if (KioskAppManager::Get()->IsAutoLaunchEnabled())
550 AutoLaunchKioskApp();
551 else
552 ShowLoginScreen(LoginScreenContext());
555 void WizardController::OnResetCanceled() {
556 if (previous_screen_)
557 SetCurrentScreen(previous_screen_);
558 else
559 ShowLoginScreen(LoginScreenContext());
562 void WizardController::OnKioskAutolaunchCanceled() {
563 ShowLoginScreen(LoginScreenContext());
566 void WizardController::OnKioskAutolaunchConfirmed() {
567 DCHECK(KioskAppManager::Get()->IsAutoLaunchEnabled());
568 AutoLaunchKioskApp();
571 void WizardController::OnKioskEnableCompleted() {
572 ShowLoginScreen(LoginScreenContext());
575 void WizardController::OnWrongHWIDWarningSkipped() {
576 if (previous_screen_)
577 SetCurrentScreen(previous_screen_);
578 else
579 ShowLoginScreen(LoginScreenContext());
582 void WizardController::OnAutoEnrollmentDone() {
583 VLOG(1) << "Automagic enrollment done, resuming previous signin";
584 ResumeLoginScreen();
587 void WizardController::OnOOBECompleted() {
588 if (ShouldAutoStartEnrollment()) {
589 ShowEnrollmentScreen();
590 } else {
591 PerformPostUpdateActions();
592 ShowLoginScreen(LoginScreenContext());
596 void WizardController::OnTermsOfServiceDeclined() {
597 // If the user declines the Terms of Service, end the session and return to
598 // the login screen.
599 DBusThreadManager::Get()->GetSessionManagerClient()->StopSession();
602 void WizardController::OnTermsOfServiceAccepted() {
603 // If the user accepts the Terms of Service, advance to the user image screen.
604 ShowUserImageScreen();
607 void WizardController::InitiateOOBEUpdate() {
608 PerformPostEulaActions();
609 SetCurrentScreenSmooth(GetUpdateScreen(), true);
610 GetUpdateScreen()->StartNetworkCheck();
613 void WizardController::PerformPostEulaActions() {
614 // Now that EULA has been accepted (for official builds), enable portal check.
615 // ChromiumOS builds would go though this code path too.
616 NetworkHandler::Get()->network_state_handler()->SetCheckPortalList(
617 NetworkStateHandler::kDefaultCheckPortalList);
618 host_->CheckForAutoEnrollment();
619 host_->PrewarmAuthentication();
620 NetworkPortalDetector::Get()->Enable(true);
623 void WizardController::PerformPostUpdateActions() {
624 StartupUtils::MarkOobeCompleted();
627 void WizardController::SetCurrentScreen(WizardScreen* new_current) {
628 SetCurrentScreenSmooth(new_current, false);
631 void WizardController::ShowCurrentScreen() {
632 // ShowCurrentScreen may get called by smooth_show_timer_ even after
633 // flow has been switched to sign in screen (ExistingUserController).
634 if (!oobe_display_)
635 return;
637 smooth_show_timer_.Stop();
639 FOR_EACH_OBSERVER(Observer, observer_list_, OnScreenChanged(current_screen_));
641 oobe_display_->ShowScreen(current_screen_);
644 void WizardController::SetCurrentScreenSmooth(WizardScreen* new_current,
645 bool use_smoothing) {
646 if (current_screen_ == new_current ||
647 new_current == NULL ||
648 oobe_display_ == NULL) {
649 return;
652 smooth_show_timer_.Stop();
654 if (current_screen_)
655 oobe_display_->HideScreen(current_screen_);
657 previous_screen_ = current_screen_;
658 current_screen_ = new_current;
660 if (use_smoothing) {
661 smooth_show_timer_.Start(
662 FROM_HERE,
663 base::TimeDelta::FromMilliseconds(kShowDelayMs),
664 this,
665 &WizardController::ShowCurrentScreen);
666 } else {
667 ShowCurrentScreen();
671 void WizardController::SetStatusAreaVisible(bool visible) {
672 host_->SetStatusAreaVisible(visible);
675 void WizardController::AdvanceToScreenWithParams(
676 const std::string& screen_name,
677 base::DictionaryValue* screen_parameters) {
678 screen_parameters_.reset(screen_parameters);
679 AdvanceToScreen(screen_name);
682 void WizardController::AdvanceToScreen(const std::string& screen_name) {
683 if (screen_name == kNetworkScreenName) {
684 ShowNetworkScreen();
685 } else if (screen_name == kLoginScreenName) {
686 ShowLoginScreen(LoginScreenContext());
687 } else if (screen_name == kUpdateScreenName) {
688 InitiateOOBEUpdate();
689 } else if (screen_name == kUserImageScreenName) {
690 ShowUserImageScreen();
691 } else if (screen_name == kEulaScreenName) {
692 ShowEulaScreen();
693 } else if (screen_name == kResetScreenName) {
694 ShowResetScreen();
695 } else if (screen_name == kKioskEnableScreenName) {
696 ShowKioskEnableScreen();
697 } else if (screen_name == kKioskAutolaunchScreenName) {
698 ShowKioskAutolaunchScreen();
699 } else if (screen_name == kEnrollmentScreenName) {
700 ShowEnrollmentScreen();
701 } else if (screen_name == kTermsOfServiceScreenName) {
702 ShowTermsOfServiceScreen();
703 } else if (screen_name == kWrongHWIDScreenName) {
704 ShowWrongHWIDScreen();
705 } else if (screen_name == kLocallyManagedUserCreationScreenName) {
706 ShowLocallyManagedUserCreationScreen();
707 } else if (screen_name == kAppLaunchSplashScreenName) {
708 AutoLaunchKioskApp();
709 } else if (screen_name != kTestNoScreenName) {
710 if (is_out_of_box_) {
711 ShowNetworkScreen();
712 } else {
713 ShowLoginScreen(LoginScreenContext());
718 ///////////////////////////////////////////////////////////////////////////////
719 // WizardController, chromeos::ScreenObserver overrides:
720 void WizardController::OnExit(ExitCodes exit_code) {
721 VLOG(1) << "Wizard screen exit code: " << exit_code;
722 switch (exit_code) {
723 case NETWORK_CONNECTED:
724 OnNetworkConnected();
725 break;
726 case CONNECTION_FAILED:
727 OnConnectionFailed();
728 break;
729 case UPDATE_INSTALLED:
730 case UPDATE_NOUPDATE:
731 OnUpdateCompleted();
732 break;
733 case UPDATE_ERROR_CHECKING_FOR_UPDATE:
734 OnUpdateErrorCheckingForUpdate();
735 break;
736 case UPDATE_ERROR_UPDATING:
737 OnUpdateErrorUpdating();
738 break;
739 case USER_IMAGE_SELECTED:
740 OnUserImageSelected();
741 break;
742 case EULA_ACCEPTED:
743 OnEulaAccepted();
744 break;
745 case EULA_BACK:
746 ShowNetworkScreen();
747 break;
748 case ENTERPRISE_ENROLLMENT_COMPLETED:
749 OnEnrollmentDone();
750 break;
751 case ENTERPRISE_ENROLLMENT_BACK:
752 ShowNetworkScreen();
753 break;
754 case RESET_CANCELED:
755 OnResetCanceled();
756 break;
757 case KIOSK_AUTOLAUNCH_CANCELED:
758 OnKioskAutolaunchCanceled();
759 break;
760 case KIOSK_AUTOLAUNCH_CONFIRMED:
761 OnKioskAutolaunchConfirmed();
762 break;
763 case KIOSK_ENABLE_COMPLETED:
764 OnKioskEnableCompleted();
765 break;
766 case ENTERPRISE_AUTO_MAGIC_ENROLLMENT_COMPLETED:
767 OnAutoEnrollmentDone();
768 break;
769 case TERMS_OF_SERVICE_DECLINED:
770 OnTermsOfServiceDeclined();
771 break;
772 case TERMS_OF_SERVICE_ACCEPTED:
773 OnTermsOfServiceAccepted();
774 break;
775 case WRONG_HWID_WARNING_SKIPPED:
776 OnWrongHWIDWarningSkipped();
777 break;
778 default:
779 NOTREACHED();
783 void WizardController::OnSetUserNamePassword(const std::string& username,
784 const std::string& password) {
785 username_ = username;
786 password_ = password;
789 void WizardController::SetUsageStatisticsReporting(bool val) {
790 usage_statistics_reporting_ = val;
793 bool WizardController::GetUsageStatisticsReporting() const {
794 return usage_statistics_reporting_;
797 chromeos::ErrorScreen* WizardController::GetErrorScreen() {
798 if (!error_screen_.get()) {
799 error_screen_.reset(
800 new chromeos::ErrorScreen(this, oobe_display_->GetErrorScreenActor()));
802 return error_screen_.get();
805 void WizardController::ShowErrorScreen() {
806 VLOG(1) << "Showing error screen.";
807 SetCurrentScreen(GetErrorScreen());
810 void WizardController::HideErrorScreen(WizardScreen* parent_screen) {
811 DCHECK(parent_screen);
812 VLOG(1) << "Hiding error screen.";
813 SetCurrentScreen(parent_screen);
816 void WizardController::AutoLaunchKioskApp() {
817 KioskAppManager::App app_data;
818 std::string app_id = KioskAppManager::Get()->GetAutoLaunchApp();
819 CHECK(KioskAppManager::Get()->GetApp(app_id, &app_data));
821 host_->StartAppLaunch(app_id);
824 // static
825 void WizardController::SetZeroDelays() {
826 kShowDelayMs = 0;
827 zero_delay_enabled_ = true;
830 // static
831 bool WizardController::IsZeroDelayEnabled() {
832 return zero_delay_enabled_;
835 // static
836 void WizardController::SkipPostLoginScreensForTesting() {
837 skip_post_login_screens_ = true;
840 // static
841 bool WizardController::ShouldAutoStartEnrollment() {
842 return g_browser_process->browser_policy_connector()->
843 GetDeviceCloudPolicyManager()->ShouldAutoStartEnrollment();
846 bool WizardController::CanExitEnrollment() const {
847 return g_browser_process->browser_policy_connector()->
848 GetDeviceCloudPolicyManager()->CanExitEnrollment();
851 void WizardController::OnLocalStateInitialized(bool /* succeeded */) {
852 if (GetLocalState()->GetInitializationStatus() !=
853 PrefService::INITIALIZATION_STATUS_ERROR) {
854 return;
856 GetErrorScreen()->SetUIState(ErrorScreen::UI_STATE_LOCAL_STATE_ERROR);
857 SetStatusAreaVisible(false);
858 ShowErrorScreen();
861 PrefService* WizardController::GetLocalState() {
862 if (local_state_for_testing_)
863 return local_state_for_testing_;
864 return g_browser_process->local_state();
867 } // namespace chromeos