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 { 15void* const kCanaryConstant = (void*)0xbaddecafbaddecafLLU; 16} 17 18namespace chromeos { 19 20ErrorScreen::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 32ErrorScreen::~ErrorScreen() { 33 CHECK(this); 34 CHECK(canary_1_ == kCanaryConstant); 35 CHECK(canary_2_ == kCanaryConstant); 36 CHECK(actor_); 37 actor_->SetDelegate(NULL); 38} 39 40void ErrorScreen::PrepareToShow() { 41} 42 43void ErrorScreen::Show() { 44 DCHECK(actor_); 45 actor_->Show(parent_screen(), NULL); 46} 47 48void ErrorScreen::Hide() { 49 DCHECK(actor_); 50 actor_->Hide(); 51} 52 53std::string ErrorScreen::GetName() const { 54 return WizardController::kErrorScreenName; 55} 56 57void ErrorScreen::OnErrorShow() {} 58 59void ErrorScreen::OnErrorHide() {} 60 61void ErrorScreen::OnLaunchOobeGuestSession() { 62 DeviceSettingsService::Get()->GetOwnershipStatusAsync( 63 base::Bind(&ErrorScreen::StartGuestSessionAfterOwnershipCheck, 64 weak_factory_.GetWeakPtr())); 65} 66 67void 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 75void ErrorScreen::OnAuthSuccess(const UserContext& user_context) { 76 LOG(FATAL); 77} 78 79void 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 92void ErrorScreen::OnPasswordChangeDetected() { 93 LOG(FATAL); 94} 95 96void ErrorScreen::WhiteListCheckFailed(const std::string& email) { 97 LOG(FATAL); 98} 99 100void ErrorScreen::PolicyLoadFailed() { 101 LOG(FATAL); 102} 103 104void ErrorScreen::OnOnlineChecked(const std::string& username, bool success) { 105 LOG(FATAL); 106} 107 108void ErrorScreen::FixCaptivePortal() { 109 DCHECK(actor_); 110 actor_->FixCaptivePortal(); 111} 112 113void ErrorScreen::ShowCaptivePortal() { 114 DCHECK(actor_); 115 actor_->ShowCaptivePortal(); 116} 117 118void ErrorScreen::HideCaptivePortal() { 119 DCHECK(actor_); 120 actor_->HideCaptivePortal(); 121} 122 123void ErrorScreen::SetUIState(UIState ui_state) { 124 DCHECK(actor_); 125 actor_->SetUIState(ui_state); 126} 127 128ErrorScreen::UIState ErrorScreen::GetUIState() const { 129 DCHECK(actor_); 130 return actor_->ui_state(); 131} 132 133void ErrorScreen::SetErrorState(ErrorState error_state, 134 const std::string& network) { 135 DCHECK(actor_); 136 actor_->SetErrorState(error_state, network); 137} 138 139void ErrorScreen::AllowGuestSignin(bool allow) { 140 DCHECK(actor_); 141 actor_->AllowGuestSignin(allow); 142} 143 144void ErrorScreen::ShowConnectingIndicator(bool show) { 145 DCHECK(actor_); 146 actor_->ShowConnectingIndicator(show); 147} 148 149void 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