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/app/breakpad_linux.h"
     23 #include "chrome/browser/browser_process.h"
     24 #include "chrome/browser/chromeos/app_mode/kiosk_app_launcher.h"
     25 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h"
     26 #include "chrome/browser/chromeos/customization_document.h"
     27 #include "chrome/browser/chromeos/login/enrollment/enrollment_screen.h"
     28 #include "chrome/browser/chromeos/login/existing_user_controller.h"
     29 #include "chrome/browser/chromeos/login/helper.h"
     30 #include "chrome/browser/chromeos/login/hwid_checker.h"
     31 #include "chrome/browser/chromeos/login/login_display_host.h"
     32 #include "chrome/browser/chromeos/login/login_utils.h"
     33 #include "chrome/browser/chromeos/login/managed/locally_managed_user_creation_screen.h"
     34 #include "chrome/browser/chromeos/login/oobe_display.h"
     35 #include "chrome/browser/chromeos/login/screens/error_screen.h"
     36 #include "chrome/browser/chromeos/login/screens/eula_screen.h"
     37 #include "chrome/browser/chromeos/login/screens/kiosk_autolaunch_screen.h"
     38 #include "chrome/browser/chromeos/login/screens/kiosk_enable_screen.h"
     39 #include "chrome/browser/chromeos/login/screens/network_screen.h"
     40 #include "chrome/browser/chromeos/login/screens/reset_screen.h"
     41 #include "chrome/browser/chromeos/login/screens/terms_of_service_screen.h"
     42 #include "chrome/browser/chromeos/login/screens/update_screen.h"
     43 #include "chrome/browser/chromeos/login/screens/user_image_screen.h"
     44 #include "chrome/browser/chromeos/login/screens/wrong_hwid_screen.h"
     45 #include "chrome/browser/chromeos/login/startup_utils.h"
     46 #include "chrome/browser/chromeos/login/user_manager.h"
     47 #include "chrome/browser/chromeos/net/network_portal_detector.h"
     48 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
     49 #include "chrome/browser/chromeos/settings/cros_settings.h"
     50 #include "chrome/browser/chromeos/settings/cros_settings_names.h"
     51 #include "chrome/browser/policy/browser_policy_connector.h"
     52 #include "chrome/browser/profiles/profile.h"
     53 #include "chrome/browser/profiles/profile_manager.h"
     54 #include "chrome/browser/ui/options/options_util.h"
     55 #include "chrome/common/chrome_constants.h"
     56 #include "chrome/common/pref_names.h"
     57 #include "chromeos/chromeos_constants.h"
     58 #include "chromeos/dbus/dbus_thread_manager.h"
     59 #include "chromeos/dbus/session_manager_client.h"
     60 #include "chromeos/network/network_state_handler.h"
     61 #include "content/public/browser/browser_thread.h"
     62 #include "ui/base/accelerators/accelerator.h"
     63 #include "ui/base/l10n/l10n_util.h"
     64 
     65 using content::BrowserThread;
     66 
     67 namespace {
     68 
     69 // A string pref with initial locale set in VPD or manifest.
     70 const char kInitialLocale[] = "intl.initial_locale";
     71 
     72 // A boolean pref of the OOBE complete flag (first OOBE part before login).
     73 const char kOobeComplete[] = "OobeComplete";
     74 
     75 // A boolean pref of the device registered flag (second part after first login).
     76 const char kDeviceRegistered[] = "DeviceRegistered";
     77 
     78 // Time in seconds that we wait for the device to reboot.
     79 // If reboot didn't happen, ask user to reboot device manually.
     80 const int kWaitForRebootTimeSec = 3;
     81 
     82 // Interval in ms which is used for smooth screen showing.
     83 static int kShowDelayMs = 400;
     84 
     85 // Saves boolean "Local State" preference and forces its persistence to disk.
     86 void SaveBoolPreferenceForced(const char* pref_name, bool value) {
     87   PrefService* prefs = g_browser_process->local_state();
     88   prefs->SetBoolean(pref_name, value);
     89   prefs->CommitPendingWrite();
     90 }
     91 
     92 // Saves integer "Local State" preference and forces its persistence to disk.
     93 void SaveIntegerPreferenceForced(const char* pref_name, int value) {
     94   PrefService* prefs = g_browser_process->local_state();
     95   prefs->SetInteger(pref_name, value);
     96   prefs->CommitPendingWrite();
     97 }
     98 
     99 // Saves string "Local State" preference and forces its persistence to disk.
    100 void SaveStringPreferenceForced(const char* pref_name,
    101                                 const std::string& value) {
    102   PrefService* prefs = g_browser_process->local_state();
    103   prefs->SetString(pref_name, value);
    104   prefs->CommitPendingWrite();
    105 }
    106 
    107 }  // namespace
    108 
    109 namespace chromeos {
    110 
    111 const char WizardController::kNetworkScreenName[] = "network";
    112 const char WizardController::kLoginScreenName[] = "login";
    113 const char WizardController::kUpdateScreenName[] = "update";
    114 const char WizardController::kUserImageScreenName[] = "image";
    115 const char WizardController::kEulaScreenName[] = "eula";
    116 const char WizardController::kEnrollmentScreenName[] = "enroll";
    117 const char WizardController::kResetScreenName[] = "reset";
    118 const char WizardController::kKioskEnableScreenName[] = "kiosk-enable";
    119 const char WizardController::kKioskAutolaunchScreenName[] = "autolaunch";
    120 const char WizardController::kErrorScreenName[] = "error-message";
    121 const char WizardController::kTermsOfServiceScreenName[] = "tos";
    122 const char WizardController::kWrongHWIDScreenName[] = "wrong-hwid";
    123 const char WizardController::kLocallyManagedUserCreationScreenName[] =
    124   "locally-managed-user-creation-flow";
    125 
    126 // Passing this parameter as a "first screen" initiates full OOBE flow.
    127 const char WizardController::kOutOfBoxScreenName[] = "oobe";
    128 
    129 // Special test value that commands not to create any window yet.
    130 const char WizardController::kTestNoScreenName[] = "test:nowindow";
    131 
    132 // Initialize default controller.
    133 // static
    134 WizardController* WizardController::default_controller_ = NULL;
    135 
    136 // static
    137 bool WizardController::skip_post_login_screens_ = false;
    138 
    139 // static
    140 bool WizardController::zero_delay_enabled_ = false;
    141 
    142 ///////////////////////////////////////////////////////////////////////////////
    143 // WizardController, public:
    144 
    145 WizardController::WizardController(chromeos::LoginDisplayHost* host,
    146                                    chromeos::OobeDisplay* oobe_display)
    147     : current_screen_(NULL),
    148       previous_screen_(NULL),
    149 #if defined(GOOGLE_CHROME_BUILD)
    150       is_official_build_(true),
    151 #else
    152       is_official_build_(false),
    153 #endif
    154       is_out_of_box_(false),
    155       host_(host),
    156       oobe_display_(oobe_display),
    157       usage_statistics_reporting_(true),
    158       skip_update_enroll_after_eula_(false),
    159       login_screen_started_(false),
    160       user_image_screen_return_to_previous_hack_(false) {
    161   DCHECK(default_controller_ == NULL);
    162   default_controller_ = this;
    163 }
    164 
    165 WizardController::~WizardController() {
    166   if (default_controller_ == this) {
    167     default_controller_ = NULL;
    168   } else {
    169     NOTREACHED() << "More than one controller are alive.";
    170   }
    171 }
    172 
    173 void WizardController::Init(
    174     const std::string& first_screen_name,
    175     scoped_ptr<base::DictionaryValue> screen_parameters) {
    176   VLOG(1) << "Starting OOBE wizard with screen: " << first_screen_name;
    177   first_screen_name_ = first_screen_name;
    178   screen_parameters_ = screen_parameters.Pass();
    179 
    180   bool oobe_complete = StartupUtils::IsOobeCompleted();
    181   if (!oobe_complete || first_screen_name == kOutOfBoxScreenName)
    182     is_out_of_box_ = true;
    183 
    184   AdvanceToScreen(first_screen_name);
    185   if (!IsMachineHWIDCorrect() && !StartupUtils::IsDeviceRegistered() &&
    186       first_screen_name.empty())
    187     ShowWrongHWIDScreen();
    188 }
    189 
    190 chromeos::NetworkScreen* WizardController::GetNetworkScreen() {
    191   if (!network_screen_.get())
    192     network_screen_.reset(new chromeos::NetworkScreen(
    193         this, oobe_display_->GetNetworkScreenActor()));
    194   return network_screen_.get();
    195 }
    196 
    197 chromeos::UpdateScreen* WizardController::GetUpdateScreen() {
    198   if (!update_screen_.get()) {
    199     update_screen_.reset(new chromeos::UpdateScreen(
    200         this, oobe_display_->GetUpdateScreenActor()));
    201     update_screen_->SetRebootCheckDelay(kWaitForRebootTimeSec);
    202   }
    203   return update_screen_.get();
    204 }
    205 
    206 chromeos::UserImageScreen* WizardController::GetUserImageScreen() {
    207   if (!user_image_screen_.get())
    208     user_image_screen_.reset(
    209         new chromeos::UserImageScreen(
    210             this, oobe_display_->GetUserImageScreenActor()));
    211   return user_image_screen_.get();
    212 }
    213 
    214 chromeos::EulaScreen* WizardController::GetEulaScreen() {
    215   if (!eula_screen_.get())
    216     eula_screen_.reset(new chromeos::EulaScreen(
    217         this, oobe_display_->GetEulaScreenActor()));
    218   return eula_screen_.get();
    219 }
    220 
    221 chromeos::EnrollmentScreen*
    222     WizardController::GetEnrollmentScreen() {
    223   if (!enrollment_screen_.get()) {
    224     enrollment_screen_.reset(
    225         new chromeos::EnrollmentScreen(
    226             this, oobe_display_->GetEnrollmentScreenActor()));
    227   }
    228   return enrollment_screen_.get();
    229 }
    230 
    231 chromeos::ResetScreen* WizardController::GetResetScreen() {
    232   if (!reset_screen_.get()) {
    233     reset_screen_.reset(
    234         new chromeos::ResetScreen(this, oobe_display_->GetResetScreenActor()));
    235   }
    236   return reset_screen_.get();
    237 }
    238 
    239 chromeos::KioskEnableScreen* WizardController::GetKioskEnableScreen() {
    240   if (!kiosk_enable_screen_.get()) {
    241     kiosk_enable_screen_.reset(
    242         new chromeos::KioskEnableScreen(
    243             this,
    244             oobe_display_->GetKioskEnableScreenActor()));
    245   }
    246   return kiosk_enable_screen_.get();
    247 }
    248 
    249 chromeos::KioskAutolaunchScreen* WizardController::GetKioskAutolaunchScreen() {
    250   if (!autolaunch_screen_.get()) {
    251     autolaunch_screen_.reset(
    252         new chromeos::KioskAutolaunchScreen(
    253             this, oobe_display_->GetKioskAutolaunchScreenActor()));
    254   }
    255   return autolaunch_screen_.get();
    256 }
    257 
    258 chromeos::TermsOfServiceScreen* WizardController::GetTermsOfServiceScreen() {
    259   if (!terms_of_service_screen_.get()) {
    260     terms_of_service_screen_.reset(
    261         new chromeos::TermsOfServiceScreen(
    262             this, oobe_display_->GetTermsOfServiceScreenActor()));
    263   }
    264   return terms_of_service_screen_.get();
    265 }
    266 
    267 chromeos::WrongHWIDScreen* WizardController::GetWrongHWIDScreen() {
    268   if (!wrong_hwid_screen_.get()) {
    269     wrong_hwid_screen_.reset(
    270         new chromeos::WrongHWIDScreen(
    271             this, oobe_display_->GetWrongHWIDScreenActor()));
    272   }
    273   return wrong_hwid_screen_.get();
    274 }
    275 
    276 chromeos::LocallyManagedUserCreationScreen*
    277     WizardController::GetLocallyManagedUserCreationScreen() {
    278   if (!locally_managed_user_creation_screen_.get()) {
    279     locally_managed_user_creation_screen_.reset(
    280         new chromeos::LocallyManagedUserCreationScreen(
    281             this, oobe_display_->GetLocallyManagedUserCreationScreenActor()));
    282   }
    283   return locally_managed_user_creation_screen_.get();
    284 }
    285 
    286 void WizardController::ShowNetworkScreen() {
    287   VLOG(1) << "Showing network screen.";
    288   SetStatusAreaVisible(false);
    289   SetCurrentScreen(GetNetworkScreen());
    290 }
    291 
    292 void WizardController::ShowLoginScreen() {
    293   if (!time_eula_accepted_.is_null()) {
    294     base::TimeDelta delta = base::Time::Now() - time_eula_accepted_;
    295     UMA_HISTOGRAM_MEDIUM_TIMES("OOBE.EULAToSignInTime", delta);
    296   }
    297   VLOG(1) << "Showing login screen.";
    298   SetStatusAreaVisible(true);
    299   host_->StartSignInScreen();
    300   smooth_show_timer_.Stop();
    301   oobe_display_ = NULL;
    302   login_screen_started_ = true;
    303 }
    304 
    305 void WizardController::ResumeLoginScreen() {
    306   VLOG(1) << "Resuming login screen.";
    307   SetStatusAreaVisible(true);
    308   host_->ResumeSignInScreen();
    309   smooth_show_timer_.Stop();
    310   oobe_display_ = NULL;
    311 }
    312 
    313 void WizardController::ShowUpdateScreen() {
    314   VLOG(1) << "Showing update screen.";
    315   SetStatusAreaVisible(true);
    316   SetCurrentScreen(GetUpdateScreen());
    317 }
    318 
    319 void WizardController::ShowUserImageScreen() {
    320   const chromeos::UserManager* user_manager = chromeos::UserManager::Get();
    321   // Skip user image selection for public sessions and ephemeral logins.
    322   if (user_manager->IsLoggedInAsPublicAccount() ||
    323       user_manager->IsCurrentUserNonCryptohomeDataEphemeral()) {
    324     OnUserImageSkipped();
    325     return;
    326   }
    327   VLOG(1) << "Showing user image screen.";
    328 
    329   bool profile_picture_enabled = true;
    330   std::string user_id;
    331   if (screen_parameters_.get()) {
    332     screen_parameters_->GetBoolean("profile_picture_enabled",
    333         &profile_picture_enabled);
    334     screen_parameters_->GetString("user_id", &user_id);
    335   }
    336 
    337   // Status area has been already shown at sign in screen so it
    338   // doesn't make sense to hide it here and then show again at user session as
    339   // this produces undesired UX transitions.
    340   SetStatusAreaVisible(true);
    341 
    342   UserImageScreen* screen = GetUserImageScreen();
    343   if (!user_id.empty())
    344     screen->SetUserID(user_id);
    345   screen->SetProfilePictureEnabled(profile_picture_enabled);
    346 
    347   SetCurrentScreen(screen);
    348   host_->SetShutdownButtonEnabled(false);
    349 }
    350 
    351 void WizardController::ShowEulaScreen() {
    352   VLOG(1) << "Showing EULA screen.";
    353   SetStatusAreaVisible(false);
    354   SetCurrentScreen(GetEulaScreen());
    355 }
    356 
    357 void WizardController::ShowEnrollmentScreen() {
    358   SetStatusAreaVisible(true);
    359 
    360   bool is_auto_enrollment = false;
    361   std::string user;
    362   if (screen_parameters_.get()) {
    363     screen_parameters_->GetBoolean("is_auto_enrollment", &is_auto_enrollment);
    364     screen_parameters_->GetString("user", &user);
    365   }
    366 
    367   EnrollmentScreen* screen = GetEnrollmentScreen();
    368   screen->SetParameters(is_auto_enrollment,
    369                         !ShouldAutoStartEnrollment() || CanExitEnrollment(),
    370                         user);
    371   SetCurrentScreen(screen);
    372 }
    373 
    374 void WizardController::ShowResetScreen() {
    375   VLOG(1) << "Showing reset screen.";
    376   SetStatusAreaVisible(false);
    377   SetCurrentScreen(GetResetScreen());
    378 }
    379 
    380 void WizardController::ShowKioskEnableScreen() {
    381   VLOG(1) << "Showing kiosk enable screen.";
    382   SetStatusAreaVisible(false);
    383   SetCurrentScreen(GetKioskEnableScreen());
    384 }
    385 
    386 void WizardController::ShowKioskAutolaunchScreen() {
    387   VLOG(1) << "Showing kiosk autolaunch screen.";
    388   SetStatusAreaVisible(false);
    389   SetCurrentScreen(GetKioskAutolaunchScreen());
    390 }
    391 
    392 void WizardController::ShowTermsOfServiceScreen() {
    393   // Only show the Terms of Service when logging into a public account and Terms
    394   // of Service have been specified through policy. In all other cases, advance
    395   // to the user image screen immediately.
    396   if (!chromeos::UserManager::Get()->IsLoggedInAsPublicAccount() ||
    397       !ProfileManager::GetDefaultProfile()->GetPrefs()->IsManagedPreference(
    398           prefs::kTermsOfServiceURL)) {
    399     ShowUserImageScreen();
    400     return;
    401   }
    402 
    403   VLOG(1) << "Showing Terms of Service screen.";
    404   SetStatusAreaVisible(true);
    405   SetCurrentScreen(GetTermsOfServiceScreen());
    406 }
    407 
    408 void WizardController::ShowWrongHWIDScreen() {
    409   VLOG(1) << "Showing wrong HWID screen.";
    410   SetStatusAreaVisible(false);
    411   SetCurrentScreen(GetWrongHWIDScreen());
    412 }
    413 
    414 void WizardController::ShowLocallyManagedUserCreationScreen() {
    415   VLOG(1) << "Showing Locally managed user creation screen screen.";
    416   SetStatusAreaVisible(true);
    417   LocallyManagedUserCreationScreen* screen =
    418       GetLocallyManagedUserCreationScreen();
    419   SetCurrentScreen(screen);
    420 }
    421 
    422 void WizardController::SkipToLoginForTesting() {
    423   StartupUtils::MarkEulaAccepted();
    424   PerformPostEulaActions();
    425   PerformPostUpdateActions();
    426   ShowLoginScreen();
    427 }
    428 
    429 void WizardController::SkipPostLoginScreensForTesting() {
    430   skip_post_login_screens_ = true;
    431 }
    432 
    433 void WizardController::AddObserver(Observer* observer) {
    434   observer_list_.AddObserver(observer);
    435 }
    436 
    437 void WizardController::RemoveObserver(Observer* observer) {
    438   observer_list_.RemoveObserver(observer);
    439 }
    440 
    441 void WizardController::OnSessionStart() {
    442   FOR_EACH_OBSERVER(Observer, observer_list_, OnSessionStart());
    443 }
    444 
    445 void WizardController::SkipUpdateEnrollAfterEula() {
    446   skip_update_enroll_after_eula_ = true;
    447 }
    448 
    449 ///////////////////////////////////////////////////////////////////////////////
    450 // WizardController, ExitHandlers:
    451 void WizardController::OnNetworkConnected() {
    452   if (is_official_build_) {
    453     if (!StartupUtils::IsEulaAccepted()) {
    454       ShowEulaScreen();
    455     } else {
    456       // Possible cases:
    457       // 1. EULA was accepted, forced shutdown/reboot during update.
    458       // 2. EULA was accepted, planned reboot after update.
    459       // Make sure that device is up-to-date.
    460       InitiateOOBEUpdate();
    461     }
    462   } else {
    463     InitiateOOBEUpdate();
    464   }
    465 }
    466 
    467 void WizardController::OnNetworkOffline() {
    468   // TODO(dpolukhin): if(is_out_of_box_) we cannot work offline and
    469   // should report some error message here and stay on the same screen.
    470   ShowLoginScreen();
    471 }
    472 
    473 void WizardController::OnConnectionFailed() {
    474   // TODO(dpolukhin): show error message after login screen is displayed.
    475   ShowLoginScreen();
    476 }
    477 
    478 void WizardController::OnUpdateCompleted() {
    479   OnOOBECompleted();
    480 }
    481 
    482 void WizardController::OnEulaAccepted() {
    483   time_eula_accepted_ = base::Time::Now();
    484   StartupUtils::MarkEulaAccepted();
    485   bool uma_enabled =
    486       OptionsUtil::ResolveMetricsReportingEnabled(usage_statistics_reporting_);
    487 
    488   CrosSettings::Get()->SetBoolean(kStatsReportingPref, uma_enabled);
    489   if (uma_enabled) {
    490 #if defined(GOOGLE_CHROME_BUILD)
    491     // The crash reporter initialization needs IO to complete.
    492     base::ThreadRestrictions::ScopedAllowIO allow_io;
    493     InitCrashReporter();
    494 #endif
    495   }
    496 
    497   if (skip_update_enroll_after_eula_) {
    498     PerformPostEulaActions();
    499     PerformPostUpdateActions();
    500     ShowEnrollmentScreen();
    501   } else {
    502     InitiateOOBEUpdate();
    503   }
    504 }
    505 
    506 void WizardController::OnUpdateErrorCheckingForUpdate() {
    507   // TODO(nkostylev): Update should be required during OOBE.
    508   // We do not want to block users from being able to proceed to the login
    509   // screen if there is any error checking for an update.
    510   // They could use "browse without sign-in" feature to set up the network to be
    511   // able to perform the update later.
    512   OnOOBECompleted();
    513 }
    514 
    515 void WizardController::OnUpdateErrorUpdating() {
    516   // If there was an error while getting or applying the update,
    517   // return to network selection screen.
    518   // TODO(nkostylev): Show message to the user explaining update error.
    519   // TODO(nkostylev): Update should be required during OOBE.
    520   // Temporary fix, need to migrate to new API. http://crosbug.com/4321
    521   OnOOBECompleted();
    522 }
    523 
    524 void WizardController::EnableUserImageScreenReturnToPreviousHack() {
    525   user_image_screen_return_to_previous_hack_ = true;
    526 }
    527 
    528 void WizardController::OnUserImageSelected() {
    529   if (user_image_screen_return_to_previous_hack_) {
    530     user_image_screen_return_to_previous_hack_ = false;
    531     DCHECK(previous_screen_);
    532     if (previous_screen_) {
    533       SetCurrentScreen(previous_screen_);
    534       return;
    535     }
    536   }
    537   // Launch browser and delete login host controller.
    538   BrowserThread::PostTask(
    539       BrowserThread::UI,
    540       FROM_HERE,
    541       base::Bind(&chromeos::LoginUtils::DoBrowserLaunch,
    542                  base::Unretained(chromeos::LoginUtils::Get()),
    543                  ProfileManager::GetDefaultProfile(), host_));
    544   host_ = NULL;
    545   // TODO(avayvod): Sync image with Google Sync.
    546 }
    547 
    548 void WizardController::OnUserImageSkipped() {
    549   OnUserImageSelected();
    550 }
    551 
    552 void WizardController::OnEnrollmentDone() {
    553   // Mark OOBE as completed only if enterprise enrollment was part of the
    554   // forced flow (i.e. app kiosk).
    555   if (ShouldAutoStartEnrollment())
    556     PerformPostUpdateActions();
    557 
    558   // TODO(mnissler): Unify the logic for auto-login for Public Sessions and
    559   // Kiosk Apps and make this code cover both cases: http://crbug.com/234694.
    560   if (KioskAppManager::Get()->IsAutoLaunchEnabled())
    561     AutoLaunchKioskApp();
    562   else
    563     ShowLoginScreen();
    564 }
    565 
    566 void WizardController::OnResetCanceled() {
    567   if (previous_screen_)
    568     SetCurrentScreen(previous_screen_);
    569   else
    570     ShowLoginScreen();
    571 }
    572 
    573 void WizardController::OnKioskAutolaunchCanceled() {
    574   ShowLoginScreen();
    575 }
    576 
    577 void WizardController::OnKioskAutolaunchConfirmed() {
    578   DCHECK(KioskAppManager::Get()->IsAutoLaunchEnabled());
    579   AutoLaunchKioskApp();
    580 }
    581 
    582 void WizardController::OnKioskEnableCompleted() {
    583   ShowLoginScreen();
    584 }
    585 
    586 void WizardController::OnWrongHWIDWarningSkipped() {
    587   if (previous_screen_)
    588     SetCurrentScreen(previous_screen_);
    589   else
    590     ShowLoginScreen();
    591 }
    592 
    593 void WizardController::OnAutoEnrollmentDone() {
    594   VLOG(1) << "Automagic enrollment done, resuming previous signin";
    595   ResumeLoginScreen();
    596 }
    597 
    598 void WizardController::OnOOBECompleted() {
    599   if (ShouldAutoStartEnrollment()) {
    600     ShowEnrollmentScreen();
    601   } else {
    602     PerformPostUpdateActions();
    603     ShowLoginScreen();
    604   }
    605 }
    606 
    607 void WizardController::OnTermsOfServiceDeclined() {
    608   // If the user declines the Terms of Service, end the session and return to
    609   // the login screen.
    610   DBusThreadManager::Get()->GetSessionManagerClient()->StopSession();
    611 }
    612 
    613 void WizardController::OnTermsOfServiceAccepted() {
    614   // If the user accepts the Terms of Service, advance to the user image screen.
    615   ShowUserImageScreen();
    616 }
    617 
    618 void WizardController::InitiateOOBEUpdate() {
    619   PerformPostEulaActions();
    620   SetCurrentScreenSmooth(GetUpdateScreen(), true);
    621   GetUpdateScreen()->StartNetworkCheck();
    622 }
    623 
    624 void WizardController::PerformPostEulaActions() {
    625   // Now that EULA has been accepted (for official builds), enable portal check.
    626   // ChromiumOS builds would go though this code path too.
    627   NetworkHandler::Get()->network_state_handler()->SetCheckPortalList(
    628       NetworkStateHandler::kDefaultCheckPortalList);
    629   host_->CheckForAutoEnrollment();
    630   host_->PrewarmAuthentication();
    631   NetworkPortalDetector* detector = NetworkPortalDetector::GetInstance();
    632   if (NetworkPortalDetector::IsEnabledInCommandLine() && detector)
    633     detector->Enable(true);
    634 }
    635 
    636 void WizardController::PerformPostUpdateActions() {
    637   StartupUtils::MarkOobeCompleted();
    638 }
    639 
    640 void WizardController::SetCurrentScreen(WizardScreen* new_current) {
    641   SetCurrentScreenSmooth(new_current, false);
    642 }
    643 
    644 void WizardController::ShowCurrentScreen() {
    645   // ShowCurrentScreen may get called by smooth_show_timer_ even after
    646   // flow has been switched to sign in screen (ExistingUserController).
    647   if (!oobe_display_)
    648     return;
    649 
    650   smooth_show_timer_.Stop();
    651 
    652   FOR_EACH_OBSERVER(Observer, observer_list_, OnScreenChanged(current_screen_));
    653 
    654   oobe_display_->ShowScreen(current_screen_);
    655 }
    656 
    657 void WizardController::SetCurrentScreenSmooth(WizardScreen* new_current,
    658                                               bool use_smoothing) {
    659   if (current_screen_ == new_current ||
    660       new_current == NULL ||
    661       oobe_display_ == NULL) {
    662     return;
    663   }
    664 
    665   smooth_show_timer_.Stop();
    666 
    667   if (current_screen_)
    668     oobe_display_->HideScreen(current_screen_);
    669 
    670   previous_screen_ = current_screen_;
    671   current_screen_ = new_current;
    672 
    673   if (use_smoothing) {
    674     smooth_show_timer_.Start(
    675         FROM_HERE,
    676         base::TimeDelta::FromMilliseconds(kShowDelayMs),
    677         this,
    678         &WizardController::ShowCurrentScreen);
    679   } else {
    680     ShowCurrentScreen();
    681   }
    682 }
    683 
    684 void WizardController::SetStatusAreaVisible(bool visible) {
    685   host_->SetStatusAreaVisible(visible);
    686 }
    687 
    688 void WizardController::AdvanceToScreenWithParams(
    689     const std::string& screen_name,
    690     base::DictionaryValue* screen_parameters) {
    691   screen_parameters_.reset(screen_parameters);
    692   AdvanceToScreen(screen_name);
    693 }
    694 
    695 void WizardController::AdvanceToScreen(const std::string& screen_name) {
    696   if (screen_name == kNetworkScreenName) {
    697     ShowNetworkScreen();
    698   } else if (screen_name == kLoginScreenName) {
    699     ShowLoginScreen();
    700   } else if (screen_name == kUpdateScreenName) {
    701     InitiateOOBEUpdate();
    702   } else if (screen_name == kUserImageScreenName) {
    703     ShowUserImageScreen();
    704   } else if (screen_name == kEulaScreenName) {
    705     ShowEulaScreen();
    706   } else if (screen_name == kResetScreenName) {
    707     ShowResetScreen();
    708   } else if (screen_name == kKioskEnableScreenName) {
    709     ShowKioskEnableScreen();
    710   } else if (screen_name == kKioskAutolaunchScreenName) {
    711     ShowKioskAutolaunchScreen();
    712   } else if (screen_name == kEnrollmentScreenName) {
    713     ShowEnrollmentScreen();
    714   } else if (screen_name == kTermsOfServiceScreenName) {
    715     ShowTermsOfServiceScreen();
    716   } else if (screen_name == kWrongHWIDScreenName) {
    717     ShowWrongHWIDScreen();
    718   } else if (screen_name == kLocallyManagedUserCreationScreenName) {
    719     ShowLocallyManagedUserCreationScreen();
    720   } else if (screen_name != kTestNoScreenName) {
    721     if (is_out_of_box_) {
    722       ShowNetworkScreen();
    723     } else {
    724       ShowLoginScreen();
    725     }
    726   }
    727 }
    728 
    729 ///////////////////////////////////////////////////////////////////////////////
    730 // WizardController, chromeos::ScreenObserver overrides:
    731 void WizardController::OnExit(ExitCodes exit_code) {
    732   LOG(INFO) << "Wizard screen exit code: " << exit_code;
    733   switch (exit_code) {
    734     case NETWORK_CONNECTED:
    735       OnNetworkConnected();
    736       break;
    737     case CONNECTION_FAILED:
    738       OnConnectionFailed();
    739       break;
    740     case UPDATE_INSTALLED:
    741     case UPDATE_NOUPDATE:
    742       OnUpdateCompleted();
    743       break;
    744     case UPDATE_ERROR_CHECKING_FOR_UPDATE:
    745       OnUpdateErrorCheckingForUpdate();
    746       break;
    747     case UPDATE_ERROR_UPDATING:
    748       OnUpdateErrorUpdating();
    749       break;
    750     case USER_IMAGE_SELECTED:
    751       OnUserImageSelected();
    752       break;
    753     case EULA_ACCEPTED:
    754       OnEulaAccepted();
    755       break;
    756     case EULA_BACK:
    757       ShowNetworkScreen();
    758       break;
    759     case ENTERPRISE_ENROLLMENT_COMPLETED:
    760       OnEnrollmentDone();
    761       break;
    762     case RESET_CANCELED:
    763       OnResetCanceled();
    764       break;
    765     case KIOSK_AUTOLAUNCH_CANCELED:
    766       OnKioskAutolaunchCanceled();
    767       break;
    768     case KIOSK_AUTOLAUNCH_CONFIRMED:
    769       OnKioskAutolaunchConfirmed();
    770       break;
    771     case KIOSK_ENABLE_COMPLETED:
    772       OnKioskEnableCompleted();
    773       break;
    774     case ENTERPRISE_AUTO_MAGIC_ENROLLMENT_COMPLETED:
    775       OnAutoEnrollmentDone();
    776       break;
    777     case TERMS_OF_SERVICE_DECLINED:
    778       OnTermsOfServiceDeclined();
    779       break;
    780     case TERMS_OF_SERVICE_ACCEPTED:
    781       OnTermsOfServiceAccepted();
    782       break;
    783     case WRONG_HWID_WARNING_SKIPPED:
    784       OnWrongHWIDWarningSkipped();
    785       break;
    786     default:
    787       NOTREACHED();
    788   }
    789 }
    790 
    791 void WizardController::OnSetUserNamePassword(const std::string& username,
    792                                              const std::string& password) {
    793   username_ = username;
    794   password_ = password;
    795 }
    796 
    797 void WizardController::SetUsageStatisticsReporting(bool val) {
    798   usage_statistics_reporting_ = val;
    799 }
    800 
    801 bool WizardController::GetUsageStatisticsReporting() const {
    802   return usage_statistics_reporting_;
    803 }
    804 
    805 chromeos::ErrorScreen* WizardController::GetErrorScreen() {
    806   if (!error_screen_.get()) {
    807     error_screen_.reset(
    808         new chromeos::ErrorScreen(this, oobe_display_->GetErrorScreenActor()));
    809   }
    810   return error_screen_.get();
    811 }
    812 
    813 void WizardController::ShowErrorScreen() {
    814   VLOG(1) << "Showing error screen.";
    815   SetCurrentScreen(GetErrorScreen());
    816 }
    817 
    818 void WizardController::HideErrorScreen(WizardScreen* parent_screen) {
    819   DCHECK(parent_screen);
    820   VLOG(1) << "Hiding error screen.";
    821   SetCurrentScreen(parent_screen);
    822 }
    823 
    824 void WizardController::AutoLaunchKioskApp() {
    825   KioskAppManager::App app_data;
    826   std::string app_id = KioskAppManager::Get()->GetAutoLaunchApp();
    827   CHECK(KioskAppManager::Get()->GetApp(app_id, &app_data));
    828   if (ExistingUserController::current_controller())
    829     ExistingUserController::current_controller()->PrepareKioskAppLaunch();
    830 
    831   // KioskAppLauncher deletes itself when done.
    832   (new KioskAppLauncher(KioskAppManager::Get(), app_id))->Start();
    833 }
    834 
    835 // static
    836 bool WizardController::IsZeroDelayEnabled() {
    837   return zero_delay_enabled_;
    838 }
    839 
    840 // static
    841 void WizardController::SetZeroDelays() {
    842   kShowDelayMs = 0;
    843   zero_delay_enabled_ = true;
    844 }
    845 
    846 bool WizardController::ShouldAutoStartEnrollment() const {
    847   return g_browser_process->browser_policy_connector()->
    848       GetDeviceCloudPolicyManager()->ShouldAutoStartEnrollment();
    849 }
    850 
    851 bool WizardController::CanExitEnrollment() const {
    852   return g_browser_process->browser_policy_connector()->
    853       GetDeviceCloudPolicyManager()->CanExitEnrollment();
    854 }
    855 
    856 }  // namespace chromeos
    857