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