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