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.
5 #include "chrome/browser/chromeos/login/screens/error_screen.h"
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/net/network_portal_detector.h"
13 #include "chrome/browser/chromeos/settings/cros_settings.h"
17 ErrorScreen::ErrorScreen(ScreenObserver
* screen_observer
,
18 ErrorScreenActor
* actor
)
19 : WizardScreen(screen_observer
),
21 parent_screen_(OobeDisplay::SCREEN_UNKNOWN
),
24 actor_
->SetDelegate(this);
25 AddObserver(NetworkPortalDetector::Get());
28 ErrorScreen::~ErrorScreen() {
29 actor_
->SetDelegate(NULL
);
30 RemoveObserver(NetworkPortalDetector::Get());
33 void ErrorScreen::AddObserver(Observer
* observer
) {
35 observers_
.AddObserver(observer
);
38 void ErrorScreen::RemoveObserver(Observer
* observer
) {
40 observers_
.RemoveObserver(observer
);
43 void ErrorScreen::PrepareToShow() {
46 void ErrorScreen::Show() {
48 actor_
->Show(parent_screen(), NULL
);
51 void ErrorScreen::Hide() {
56 std::string
ErrorScreen::GetName() const {
57 return WizardController::kErrorScreenName
;
60 void ErrorScreen::OnErrorShow() {
61 FOR_EACH_OBSERVER(Observer
, observers_
, OnErrorScreenShow());
64 void ErrorScreen::OnErrorHide() {
65 FOR_EACH_OBSERVER(Observer
, observers_
, OnErrorScreenHide());
68 void ErrorScreen::OnLaunchOobeGuestSession() {
69 DeviceSettingsService::Get()->GetOwnershipStatusAsync(
70 base::Bind(&ErrorScreen::StartGuestSessionAfterOwnershipCheck
,
71 weak_factory_
.GetWeakPtr()));
74 void ErrorScreen::OnLoginFailure(const LoginFailure
& error
) {
75 // The only condition leading here is guest mount failure, which should not
76 // happen in practice. For now, just log an error so this situation is visible
77 // in logs if it ever occurs.
78 NOTREACHED() << "Guest login failed.";
79 guest_login_performer_
.reset();
82 void ErrorScreen::OnLoginSuccess(const UserContext
& user_context
) {
86 void ErrorScreen::OnOffTheRecordLoginSuccess() {
87 // Restart Chrome to enter the guest session.
88 const CommandLine
& browser_command_line
= *CommandLine::ForCurrentProcess();
89 CommandLine
command_line(browser_command_line
.GetProgram());
90 std::string cmd_line_str
=
91 GetOffTheRecordCommandLine(GURL(),
92 StartupUtils::IsOobeCompleted(),
96 RestartChrome(cmd_line_str
);
99 void ErrorScreen::OnPasswordChangeDetected() {
103 void ErrorScreen::WhiteListCheckFailed(const std::string
& email
) {
107 void ErrorScreen::PolicyLoadFailed() {
111 void ErrorScreen::OnOnlineChecked(const std::string
& username
, bool success
) {
115 void ErrorScreen::FixCaptivePortal() {
117 actor_
->FixCaptivePortal();
120 void ErrorScreen::ShowCaptivePortal() {
122 actor_
->ShowCaptivePortal();
125 void ErrorScreen::HideCaptivePortal() {
127 actor_
->HideCaptivePortal();
130 void ErrorScreen::SetUIState(UIState ui_state
) {
132 actor_
->SetUIState(ui_state
);
135 ErrorScreen::UIState
ErrorScreen::GetUIState() const {
137 return actor_
->ui_state();
140 void ErrorScreen::SetErrorState(ErrorState error_state
,
141 const std::string
& network
) {
143 actor_
->SetErrorState(error_state
, network
);
146 void ErrorScreen::AllowGuestSignin(bool allow
) {
148 actor_
->AllowGuestSignin(allow
);
151 void ErrorScreen::ShowConnectingIndicator(bool show
) {
153 actor_
->ShowConnectingIndicator(show
);
156 void ErrorScreen::StartGuestSessionAfterOwnershipCheck(
157 DeviceSettingsService::OwnershipStatus ownership_status
) {
159 // Make sure to disallow guest login if it's explicitly disabled.
160 CrosSettingsProvider::TrustedStatus trust_status
=
161 CrosSettings::Get()->PrepareTrustedValues(
162 base::Bind(&ErrorScreen::StartGuestSessionAfterOwnershipCheck
,
163 weak_factory_
.GetWeakPtr(),
165 switch (trust_status
) {
166 case CrosSettingsProvider::TEMPORARILY_UNTRUSTED
:
167 // Wait for a callback.
169 case CrosSettingsProvider::PERMANENTLY_UNTRUSTED
:
170 // Only allow guest sessions if there is no owner yet.
171 if (ownership_status
== DeviceSettingsService::OWNERSHIP_NONE
)
174 case CrosSettingsProvider::TRUSTED
: {
175 // Honor kAccountsPrefAllowGuest.
176 bool allow_guest
= false;
177 CrosSettings::Get()->GetBoolean(kAccountsPrefAllowGuest
, &allow_guest
);
184 if (guest_login_performer_
)
187 guest_login_performer_
.reset(new LoginPerformer(this));
188 guest_login_performer_
->LoginOffTheRecord();
191 } // namespace chromeos