Home | History | Annotate | Download | only in login
      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 #include "chrome/browser/chromeos/login/wizard_controller.h"
      6 
      7 #include <signal.h>
      8 #include <stdlib.h>
      9 #include <sys/types.h>
     10 
     11 #include <string>
     12 #include <vector>
     13 
     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"
     65 
     66 using content::BrowserThread;
     67 
     68 // If reboot didn't happen, ask user to reboot device manually.
     69 const int kWaitForRebootTimeSec = 3;
     70 
     71 // Interval in ms which is used for smooth screen showing.
     72 static int kShowDelayMs = 400;
     73 
     74 namespace chromeos {
     75 
     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";
     92 
     93 // Passing this parameter as a "first screen" initiates full OOBE flow.
     94 const char WizardController::kOutOfBoxScreenName[] = "oobe";
     95 
     96 // Special test value that commands not to create any window yet.
     97 const char WizardController::kTestNoScreenName[] = "test:nowindow";
     98 
     99 // Initialize default controller.
    100 // static
    101 WizardController* WizardController::default_controller_ = NULL;
    102 
    103 // static
    104 bool WizardController::skip_post_login_screens_ = false;
    105 
    106 // static
    107 bool WizardController::zero_delay_enabled_ = false;
    108 
    109 ///////////////////////////////////////////////////////////////////////////////
    110 // WizardController, public:
    111 
    112 PrefService* WizardController::local_state_for_testing_ = NULL;
    113 
    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;
    133 }
    134 
    135 WizardController::~WizardController() {
    136   if (default_controller_ == this) {
    137     default_controller_ = NULL;
    138   } else {
    139     NOTREACHED() << "More than one controller are alive.";
    140   }
    141 }
    142 
    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();
    149 
    150   bool oobe_complete = StartupUtils::IsOobeCompleted();
    151   if (!oobe_complete || first_screen_name == kOutOfBoxScreenName)
    152     is_out_of_box_ = true;
    153 
    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.
    159   //
    160   // TODO (ygorshenin@): implement handling of the local state
    161   // corruption in the case of asynchronious loading.
    162   //
    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()));
    175     }
    176   }
    177 
    178   AdvanceToScreen(first_screen_name);
    179   if (!IsMachineHWIDCorrect() && !StartupUtils::IsDeviceRegistered() &&
    180       first_screen_name.empty())
    181     ShowWrongHWIDScreen();
    182 }
    183 
    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();
    189 }
    190 
    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);
    196   }
    197   return update_screen_.get();
    198 }
    199 
    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();
    206 }
    207 
    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();
    213 }
    214 
    215 chromeos::EnrollmentScreen*
    216     WizardController::GetEnrollmentScreen() {
    217   if (!enrollment_screen_.get()) {
    218     enrollment_screen_.reset(
    219         new chromeos::EnrollmentScreen(
    220             this, oobe_display_->GetEnrollmentScreenActor()));
    221   }
    222   return enrollment_screen_.get();
    223 }
    224 
    225 chromeos::ResetScreen* WizardController::GetResetScreen() {
    226   if (!reset_screen_.get()) {
    227     reset_screen_.reset(
    228         new chromeos::ResetScreen(this, oobe_display_->GetResetScreenActor()));
    229   }
    230   return reset_screen_.get();
    231 }
    232 
    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()));
    239   }
    240   return kiosk_enable_screen_.get();
    241 }
    242 
    243 chromeos::KioskAutolaunchScreen* WizardController::GetKioskAutolaunchScreen() {
    244   if (!autolaunch_screen_.get()) {
    245     autolaunch_screen_.reset(
    246         new chromeos::KioskAutolaunchScreen(
    247             this, oobe_display_->GetKioskAutolaunchScreenActor()));
    248   }
    249   return autolaunch_screen_.get();
    250 }
    251 
    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()));
    257   }
    258   return terms_of_service_screen_.get();
    259 }
    260 
    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()));
    266   }
    267   return wrong_hwid_screen_.get();
    268 }
    269 
    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()));
    276   }
    277   return locally_managed_user_creation_screen_.get();
    278 }
    279 
    280 void WizardController::ShowNetworkScreen() {
    281   VLOG(1) << "Showing network screen.";
    282   SetStatusAreaVisible(false);
    283   SetCurrentScreen(GetNetworkScreen());
    284 }
    285 
    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);
    290   }
    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;
    297 }
    298 
    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;
    305 }
    306 
    307 void WizardController::ShowUpdateScreen() {
    308   VLOG(1) << "Showing update screen.";
    309   SetStatusAreaVisible(true);
    310   SetCurrentScreen(GetUpdateScreen());
    311 }
    312 
    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;
    320   }
    321   VLOG(1) << "Showing user image screen.";
    322 
    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);
    329   }
    330 
    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);
    335 
    336   UserImageScreen* screen = GetUserImageScreen();
    337   if (!user_id.empty())
    338     screen->SetUserID(user_id);
    339   screen->SetProfilePictureEnabled(profile_picture_enabled);
    340 
    341   SetCurrentScreen(screen);
    342 }
    343 
    344 void WizardController::ShowEulaScreen() {
    345   VLOG(1) << "Showing EULA screen.";
    346   SetStatusAreaVisible(false);
    347   SetCurrentScreen(GetEulaScreen());
    348 }
    349 
    350 void WizardController::ShowEnrollmentScreen() {
    351   SetStatusAreaVisible(true);
    352 
    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);
    358   }
    359 
    360   EnrollmentScreen* screen = GetEnrollmentScreen();
    361   screen->SetParameters(is_auto_enrollment,
    362                         !ShouldAutoStartEnrollment() || CanExitEnrollment(),
    363                         user);
    364   SetCurrentScreen(screen);
    365 }
    366 
    367 void WizardController::ShowResetScreen() {
    368   VLOG(1) << "Showing reset screen.";
    369   SetStatusAreaVisible(false);
    370   SetCurrentScreen(GetResetScreen());
    371 }
    372 
    373 void WizardController::ShowKioskEnableScreen() {
    374   VLOG(1) << "Showing kiosk enable screen.";
    375   SetStatusAreaVisible(false);
    376   SetCurrentScreen(GetKioskEnableScreen());
    377 }
    378 
    379 void WizardController::ShowKioskAutolaunchScreen() {
    380   VLOG(1) << "Showing kiosk autolaunch screen.";
    381   SetStatusAreaVisible(false);
    382   SetCurrentScreen(GetKioskAutolaunchScreen());
    383 }
    384 
    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::GetDefaultProfile()->GetPrefs()->IsManagedPreference(
    391           prefs::kTermsOfServiceURL)) {
    392     ShowUserImageScreen();
    393     return;
    394   }
    395 
    396   VLOG(1) << "Showing Terms of Service screen.";
    397   SetStatusAreaVisible(true);
    398   SetCurrentScreen(GetTermsOfServiceScreen());
    399 }
    400 
    401 void WizardController::ShowWrongHWIDScreen() {
    402   VLOG(1) << "Showing wrong HWID screen.";
    403   SetStatusAreaVisible(false);
    404   SetCurrentScreen(GetWrongHWIDScreen());
    405 }
    406 
    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);
    413 }
    414 
    415 void WizardController::SkipToLoginForTesting(
    416     const LoginScreenContext& context) {
    417   StartupUtils::MarkEulaAccepted();
    418   PerformPostEulaActions();
    419   PerformPostUpdateActions();
    420   ShowLoginScreen(context);
    421 }
    422 
    423 void WizardController::AddObserver(Observer* observer) {
    424   observer_list_.AddObserver(observer);
    425 }
    426 
    427 void WizardController::RemoveObserver(Observer* observer) {
    428   observer_list_.RemoveObserver(observer);
    429 }
    430 
    431 void WizardController::OnSessionStart() {
    432   FOR_EACH_OBSERVER(Observer, observer_list_, OnSessionStart());
    433 }
    434 
    435 void WizardController::SkipUpdateEnrollAfterEula() {
    436   skip_update_enroll_after_eula_ = true;
    437 }
    438 
    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();
    451     }
    452   } else {
    453     InitiateOOBEUpdate();
    454   }
    455 }
    456 
    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());
    461 }
    462 
    463 void WizardController::OnConnectionFailed() {
    464   // TODO(dpolukhin): show error message after login screen is displayed.
    465   ShowLoginScreen(LoginScreenContext());
    466 }
    467 
    468 void WizardController::OnUpdateCompleted() {
    469   OnOOBECompleted();
    470 }
    471 
    472 void WizardController::OnEulaAccepted() {
    473   time_eula_accepted_ = base::Time::Now();
    474   StartupUtils::MarkEulaAccepted();
    475   bool uma_enabled =
    476       OptionsUtil::ResolveMetricsReportingEnabled(usage_statistics_reporting_);
    477 
    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
    485   }
    486 
    487   if (skip_update_enroll_after_eula_) {
    488     PerformPostEulaActions();
    489     PerformPostUpdateActions();
    490     ShowEnrollmentScreen();
    491   } else {
    492     InitiateOOBEUpdate();
    493   }
    494 }
    495 
    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();
    503 }
    504 
    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();
    512 }
    513 
    514 void WizardController::EnableUserImageScreenReturnToPreviousHack() {
    515   user_image_screen_return_to_previous_hack_ = true;
    516 }
    517 
    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;
    525     }
    526   }
    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::GetDefaultProfile(), host_));
    534   host_ = NULL;
    535   // TODO(avayvod): Sync image with Google Sync.
    536 }
    537 
    538 void WizardController::OnUserImageSkipped() {
    539   OnUserImageSelected();
    540 }
    541 
    542 void WizardController::OnEnrollmentDone() {
    543   // Mark OOBE as completed only if enterprise enrollment was part of the
    544   // forced flow (i.e. app kiosk).
    545   if (ShouldAutoStartEnrollment())
    546     PerformPostUpdateActions();
    547 
    548   // TODO(mnissler): Unify the logic for auto-login for Public Sessions and
    549   // Kiosk Apps and make this code cover both cases: http://crbug.com/234694.
    550   if (KioskAppManager::Get()->IsAutoLaunchEnabled())
    551     AutoLaunchKioskApp();
    552   else
    553     ShowLoginScreen(LoginScreenContext());
    554 }
    555 
    556 void WizardController::OnResetCanceled() {
    557   if (previous_screen_)
    558     SetCurrentScreen(previous_screen_);
    559   else
    560     ShowLoginScreen(LoginScreenContext());
    561 }
    562 
    563 void WizardController::OnKioskAutolaunchCanceled() {
    564   ShowLoginScreen(LoginScreenContext());
    565 }
    566 
    567 void WizardController::OnKioskAutolaunchConfirmed() {
    568   DCHECK(KioskAppManager::Get()->IsAutoLaunchEnabled());
    569   AutoLaunchKioskApp();
    570 }
    571 
    572 void WizardController::OnKioskEnableCompleted() {
    573   ShowLoginScreen(LoginScreenContext());
    574 }
    575 
    576 void WizardController::OnWrongHWIDWarningSkipped() {
    577   if (previous_screen_)
    578     SetCurrentScreen(previous_screen_);
    579   else
    580     ShowLoginScreen(LoginScreenContext());
    581 }
    582 
    583 void WizardController::OnAutoEnrollmentDone() {
    584   VLOG(1) << "Automagic enrollment done, resuming previous signin";
    585   ResumeLoginScreen();
    586 }
    587 
    588 void WizardController::OnOOBECompleted() {
    589   if (ShouldAutoStartEnrollment()) {
    590     ShowEnrollmentScreen();
    591   } else {
    592     PerformPostUpdateActions();
    593     ShowLoginScreen(LoginScreenContext());
    594   }
    595 }
    596 
    597 void WizardController::OnTermsOfServiceDeclined() {
    598   // If the user declines the Terms of Service, end the session and return to
    599   // the login screen.
    600   DBusThreadManager::Get()->GetSessionManagerClient()->StopSession();
    601 }
    602 
    603 void WizardController::OnTermsOfServiceAccepted() {
    604   // If the user accepts the Terms of Service, advance to the user image screen.
    605   ShowUserImageScreen();
    606 }
    607 
    608 void WizardController::InitiateOOBEUpdate() {
    609   PerformPostEulaActions();
    610   SetCurrentScreenSmooth(GetUpdateScreen(), true);
    611   GetUpdateScreen()->StartNetworkCheck();
    612 }
    613 
    614 void WizardController::PerformPostEulaActions() {
    615   // Now that EULA has been accepted (for official builds), enable portal check.
    616   // ChromiumOS builds would go though this code path too.
    617   NetworkHandler::Get()->network_state_handler()->SetCheckPortalList(
    618       NetworkStateHandler::kDefaultCheckPortalList);
    619   host_->CheckForAutoEnrollment();
    620   host_->PrewarmAuthentication();
    621   NetworkPortalDetector::Get()->Enable(true);
    622 }
    623 
    624 void WizardController::PerformPostUpdateActions() {
    625   StartupUtils::MarkOobeCompleted();
    626 }
    627 
    628 void WizardController::SetCurrentScreen(WizardScreen* new_current) {
    629   SetCurrentScreenSmooth(new_current, false);
    630 }
    631 
    632 void WizardController::ShowCurrentScreen() {
    633   // ShowCurrentScreen may get called by smooth_show_timer_ even after
    634   // flow has been switched to sign in screen (ExistingUserController).
    635   if (!oobe_display_)
    636     return;
    637 
    638   smooth_show_timer_.Stop();
    639 
    640   FOR_EACH_OBSERVER(Observer, observer_list_, OnScreenChanged(current_screen_));
    641 
    642   oobe_display_->ShowScreen(current_screen_);
    643 }
    644 
    645 void WizardController::SetCurrentScreenSmooth(WizardScreen* new_current,
    646                                               bool use_smoothing) {
    647   if (current_screen_ == new_current ||
    648       new_current == NULL ||
    649       oobe_display_ == NULL) {
    650     return;
    651   }
    652 
    653   smooth_show_timer_.Stop();
    654 
    655   if (current_screen_)
    656     oobe_display_->HideScreen(current_screen_);
    657 
    658   previous_screen_ = current_screen_;
    659   current_screen_ = new_current;
    660 
    661   if (use_smoothing) {
    662     smooth_show_timer_.Start(
    663         FROM_HERE,
    664         base::TimeDelta::FromMilliseconds(kShowDelayMs),
    665         this,
    666         &WizardController::ShowCurrentScreen);
    667   } else {
    668     ShowCurrentScreen();
    669   }
    670 }
    671 
    672 void WizardController::SetStatusAreaVisible(bool visible) {
    673   host_->SetStatusAreaVisible(visible);
    674 }
    675 
    676 void WizardController::AdvanceToScreenWithParams(
    677     const std::string& screen_name,
    678     base::DictionaryValue* screen_parameters) {
    679   screen_parameters_.reset(screen_parameters);
    680   AdvanceToScreen(screen_name);
    681 }
    682 
    683 void WizardController::AdvanceToScreen(const std::string& screen_name) {
    684   if (screen_name == kNetworkScreenName) {
    685     ShowNetworkScreen();
    686   } else if (screen_name == kLoginScreenName) {
    687     ShowLoginScreen(LoginScreenContext());
    688   } else if (screen_name == kUpdateScreenName) {
    689     InitiateOOBEUpdate();
    690   } else if (screen_name == kUserImageScreenName) {
    691     ShowUserImageScreen();
    692   } else if (screen_name == kEulaScreenName) {
    693     ShowEulaScreen();
    694   } else if (screen_name == kResetScreenName) {
    695     ShowResetScreen();
    696   } else if (screen_name == kKioskEnableScreenName) {
    697     ShowKioskEnableScreen();
    698   } else if (screen_name == kKioskAutolaunchScreenName) {
    699     ShowKioskAutolaunchScreen();
    700   } else if (screen_name == kEnrollmentScreenName) {
    701     ShowEnrollmentScreen();
    702   } else if (screen_name == kTermsOfServiceScreenName) {
    703     ShowTermsOfServiceScreen();
    704   } else if (screen_name == kWrongHWIDScreenName) {
    705     ShowWrongHWIDScreen();
    706   } else if (screen_name == kLocallyManagedUserCreationScreenName) {
    707     ShowLocallyManagedUserCreationScreen();
    708   } else if (screen_name == kAppLaunchSplashScreenName) {
    709     AutoLaunchKioskApp();
    710   } else if (screen_name != kTestNoScreenName) {
    711     if (is_out_of_box_) {
    712       ShowNetworkScreen();
    713     } else {
    714       ShowLoginScreen(LoginScreenContext());
    715     }
    716   }
    717 }
    718 
    719 ///////////////////////////////////////////////////////////////////////////////
    720 // WizardController, chromeos::ScreenObserver overrides:
    721 void WizardController::OnExit(ExitCodes exit_code) {
    722   VLOG(1) << "Wizard screen exit code: " << exit_code;
    723   switch (exit_code) {
    724     case NETWORK_CONNECTED:
    725       OnNetworkConnected();
    726       break;
    727     case CONNECTION_FAILED:
    728       OnConnectionFailed();
    729       break;
    730     case UPDATE_INSTALLED:
    731     case UPDATE_NOUPDATE:
    732       OnUpdateCompleted();
    733       break;
    734     case UPDATE_ERROR_CHECKING_FOR_UPDATE:
    735       OnUpdateErrorCheckingForUpdate();
    736       break;
    737     case UPDATE_ERROR_UPDATING:
    738       OnUpdateErrorUpdating();
    739       break;
    740     case USER_IMAGE_SELECTED:
    741       OnUserImageSelected();
    742       break;
    743     case EULA_ACCEPTED:
    744       OnEulaAccepted();
    745       break;
    746     case EULA_BACK:
    747       ShowNetworkScreen();
    748       break;
    749     case ENTERPRISE_ENROLLMENT_COMPLETED:
    750       OnEnrollmentDone();
    751       break;
    752     case ENTERPRISE_ENROLLMENT_BACK:
    753       ShowNetworkScreen();
    754       break;
    755     case RESET_CANCELED:
    756       OnResetCanceled();
    757       break;
    758     case KIOSK_AUTOLAUNCH_CANCELED:
    759       OnKioskAutolaunchCanceled();
    760       break;
    761     case KIOSK_AUTOLAUNCH_CONFIRMED:
    762       OnKioskAutolaunchConfirmed();
    763       break;
    764     case KIOSK_ENABLE_COMPLETED:
    765       OnKioskEnableCompleted();
    766       break;
    767     case ENTERPRISE_AUTO_MAGIC_ENROLLMENT_COMPLETED:
    768       OnAutoEnrollmentDone();
    769       break;
    770     case TERMS_OF_SERVICE_DECLINED:
    771       OnTermsOfServiceDeclined();
    772       break;
    773     case TERMS_OF_SERVICE_ACCEPTED:
    774       OnTermsOfServiceAccepted();
    775       break;
    776     case WRONG_HWID_WARNING_SKIPPED:
    777       OnWrongHWIDWarningSkipped();
    778       break;
    779     default:
    780       NOTREACHED();
    781   }
    782 }
    783 
    784 void WizardController::OnSetUserNamePassword(const std::string& username,
    785                                              const std::string& password) {
    786   username_ = username;
    787   password_ = password;
    788 }
    789 
    790 void WizardController::SetUsageStatisticsReporting(bool val) {
    791   usage_statistics_reporting_ = val;
    792 }
    793 
    794 bool WizardController::GetUsageStatisticsReporting() const {
    795   return usage_statistics_reporting_;
    796 }
    797 
    798 chromeos::ErrorScreen* WizardController::GetErrorScreen() {
    799   if (!error_screen_.get()) {
    800     error_screen_.reset(
    801         new chromeos::ErrorScreen(this, oobe_display_->GetErrorScreenActor()));
    802   }
    803   return error_screen_.get();
    804 }
    805 
    806 void WizardController::ShowErrorScreen() {
    807   VLOG(1) << "Showing error screen.";
    808   SetCurrentScreen(GetErrorScreen());
    809 }
    810 
    811 void WizardController::HideErrorScreen(WizardScreen* parent_screen) {
    812   DCHECK(parent_screen);
    813   VLOG(1) << "Hiding error screen.";
    814   SetCurrentScreen(parent_screen);
    815 }
    816 
    817 void WizardController::AutoLaunchKioskApp() {
    818   KioskAppManager::App app_data;
    819   std::string app_id = KioskAppManager::Get()->GetAutoLaunchApp();
    820   CHECK(KioskAppManager::Get()->GetApp(app_id, &app_data));
    821 
    822   host_->StartAppLaunch(app_id);
    823 }
    824 
    825 // static
    826 void WizardController::SetZeroDelays() {
    827   kShowDelayMs = 0;
    828   zero_delay_enabled_ = true;
    829 }
    830 
    831 // static
    832 bool WizardController::IsZeroDelayEnabled() {
    833   return zero_delay_enabled_;
    834 }
    835 
    836 // static
    837 void WizardController::SkipPostLoginScreensForTesting() {
    838   skip_post_login_screens_ = true;
    839 }
    840 
    841 // static
    842 bool WizardController::ShouldAutoStartEnrollment() {
    843   return g_browser_process->browser_policy_connector()->
    844       GetDeviceCloudPolicyManager()->ShouldAutoStartEnrollment();
    845 }
    846 
    847 bool WizardController::CanExitEnrollment() const {
    848   return g_browser_process->browser_policy_connector()->
    849       GetDeviceCloudPolicyManager()->CanExitEnrollment();
    850 }
    851 
    852 void WizardController::OnLocalStateInitialized(bool /* succeeded */) {
    853   if (GetLocalState()->GetInitializationStatus() !=
    854       PrefService::INITIALIZATION_STATUS_ERROR) {
    855     return;
    856   }
    857   GetErrorScreen()->SetUIState(ErrorScreen::UI_STATE_LOCAL_STATE_ERROR);
    858   SetStatusAreaVisible(false);
    859   ShowErrorScreen();
    860 }
    861 
    862 PrefService* WizardController::GetLocalState() {
    863   if (local_state_for_testing_)
    864     return local_state_for_testing_;
    865   return g_browser_process->local_state();
    866 }
    867 
    868 }  // namespace chromeos
    869