Home | History | Annotate | Download | only in screens
      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/screens/error_screen.h"
      6 
      7 #include "base/command_line.h"
      8 #include "chrome/browser/chromeos/login/chrome_restart_request.h"
      9 #include "chrome/browser/chromeos/login/screens/error_screen_actor.h"
     10 #include "chrome/browser/chromeos/login/startup_utils.h"
     11 #include "chrome/browser/chromeos/login/wizard_controller.h"
     12 #include "chrome/browser/chromeos/settings/cros_settings.h"
     13 
     14 namespace {
     15 void* const kCanaryConstant = (void*)0xbaddecafbaddecafLLU;
     16 }
     17 
     18 namespace chromeos {
     19 
     20 ErrorScreen::ErrorScreen(ScreenObserver* screen_observer,
     21                          ErrorScreenActor* actor)
     22     : WizardScreen(screen_observer),
     23       canary_1_(kCanaryConstant),
     24       actor_(actor),
     25       canary_2_(kCanaryConstant),
     26       parent_screen_(OobeDisplay::SCREEN_UNKNOWN),
     27       weak_factory_(this) {
     28   CHECK(actor_);
     29   actor_->SetDelegate(this);
     30 }
     31 
     32 ErrorScreen::~ErrorScreen() {
     33   CHECK(this);
     34   CHECK(canary_1_ == kCanaryConstant);
     35   CHECK(canary_2_ == kCanaryConstant);
     36   CHECK(actor_);
     37   actor_->SetDelegate(NULL);
     38 }
     39 
     40 void ErrorScreen::PrepareToShow() {
     41 }
     42 
     43 void ErrorScreen::Show() {
     44   DCHECK(actor_);
     45   actor_->Show(parent_screen(), NULL);
     46 }
     47 
     48 void ErrorScreen::Hide() {
     49   DCHECK(actor_);
     50   actor_->Hide();
     51 }
     52 
     53 std::string ErrorScreen::GetName() const {
     54   return WizardController::kErrorScreenName;
     55 }
     56 
     57 void ErrorScreen::OnErrorShow() {}
     58 
     59 void ErrorScreen::OnErrorHide() {}
     60 
     61 void ErrorScreen::OnLaunchOobeGuestSession() {
     62   DeviceSettingsService::Get()->GetOwnershipStatusAsync(
     63       base::Bind(&ErrorScreen::StartGuestSessionAfterOwnershipCheck,
     64                  weak_factory_.GetWeakPtr()));
     65 }
     66 
     67 void ErrorScreen::OnAuthFailure(const AuthFailure& error) {
     68   // The only condition leading here is guest mount failure, which should not
     69   // happen in practice. For now, just log an error so this situation is visible
     70   // in logs if it ever occurs.
     71   NOTREACHED() << "Guest login failed.";
     72   guest_login_performer_.reset();
     73 }
     74 
     75 void ErrorScreen::OnAuthSuccess(const UserContext& user_context) {
     76   LOG(FATAL);
     77 }
     78 
     79 void ErrorScreen::OnOffTheRecordAuthSuccess() {
     80   // Restart Chrome to enter the guest session.
     81   const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
     82   CommandLine command_line(browser_command_line.GetProgram());
     83   std::string cmd_line_str =
     84       GetOffTheRecordCommandLine(GURL(),
     85                                  StartupUtils::IsOobeCompleted(),
     86                                  browser_command_line,
     87                                  &command_line);
     88 
     89   RestartChrome(cmd_line_str);
     90 }
     91 
     92 void ErrorScreen::OnPasswordChangeDetected() {
     93   LOG(FATAL);
     94 }
     95 
     96 void ErrorScreen::WhiteListCheckFailed(const std::string& email) {
     97   LOG(FATAL);
     98 }
     99 
    100 void ErrorScreen::PolicyLoadFailed() {
    101   LOG(FATAL);
    102 }
    103 
    104 void ErrorScreen::OnOnlineChecked(const std::string& username, bool success) {
    105   LOG(FATAL);
    106 }
    107 
    108 void ErrorScreen::FixCaptivePortal() {
    109   DCHECK(actor_);
    110   actor_->FixCaptivePortal();
    111 }
    112 
    113 void ErrorScreen::ShowCaptivePortal() {
    114   DCHECK(actor_);
    115   actor_->ShowCaptivePortal();
    116 }
    117 
    118 void ErrorScreen::HideCaptivePortal() {
    119   DCHECK(actor_);
    120   actor_->HideCaptivePortal();
    121 }
    122 
    123 void ErrorScreen::SetUIState(UIState ui_state) {
    124   DCHECK(actor_);
    125   actor_->SetUIState(ui_state);
    126 }
    127 
    128 ErrorScreen::UIState ErrorScreen::GetUIState() const {
    129   DCHECK(actor_);
    130   return actor_->ui_state();
    131 }
    132 
    133 void ErrorScreen::SetErrorState(ErrorState error_state,
    134                                 const std::string& network) {
    135   DCHECK(actor_);
    136   actor_->SetErrorState(error_state, network);
    137 }
    138 
    139 void ErrorScreen::AllowGuestSignin(bool allow) {
    140   DCHECK(actor_);
    141   actor_->AllowGuestSignin(allow);
    142 }
    143 
    144 void ErrorScreen::ShowConnectingIndicator(bool show) {
    145   DCHECK(actor_);
    146   actor_->ShowConnectingIndicator(show);
    147 }
    148 
    149 void ErrorScreen::StartGuestSessionAfterOwnershipCheck(
    150     DeviceSettingsService::OwnershipStatus ownership_status) {
    151 
    152   // Make sure to disallow guest login if it's explicitly disabled.
    153   CrosSettingsProvider::TrustedStatus trust_status =
    154       CrosSettings::Get()->PrepareTrustedValues(
    155           base::Bind(&ErrorScreen::StartGuestSessionAfterOwnershipCheck,
    156                      weak_factory_.GetWeakPtr(),
    157                      ownership_status));
    158   switch (trust_status) {
    159     case CrosSettingsProvider::TEMPORARILY_UNTRUSTED:
    160       // Wait for a callback.
    161       return;
    162     case CrosSettingsProvider::PERMANENTLY_UNTRUSTED:
    163       // Only allow guest sessions if there is no owner yet.
    164       if (ownership_status == DeviceSettingsService::OWNERSHIP_NONE)
    165         break;
    166       return;
    167     case CrosSettingsProvider::TRUSTED: {
    168       // Honor kAccountsPrefAllowGuest.
    169       bool allow_guest = false;
    170       CrosSettings::Get()->GetBoolean(kAccountsPrefAllowGuest, &allow_guest);
    171       if (allow_guest)
    172         break;
    173       return;
    174     }
    175   }
    176 
    177   if (guest_login_performer_)
    178     return;
    179 
    180   guest_login_performer_.reset(new LoginPerformer(this));
    181   guest_login_performer_->LoginOffTheRecord();
    182 }
    183 
    184 }  // namespace chromeos
    185