Additional checks/calls for cases when WebUI may be already gone but OOBE screen instance is not.

BUG=chromium-os:32901
TEST=bvt

Review URL: https://chromiumcodereview.appspot.com/10832009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148522 0039d316-1c4b-4281-b951-d872f2087c98
parent 3d209566
......@@ -15,7 +15,9 @@ namespace chromeos {
EulaScreen::EulaScreen(ScreenObserver* observer, EulaScreenActor* actor)
: WizardScreen(observer), actor_(actor), password_fetcher_(this) {
actor_->SetDelegate(this);
DCHECK(actor_);
if (actor_)
actor_->SetDelegate(this);
}
EulaScreen::~EulaScreen() {
......@@ -24,18 +26,21 @@ EulaScreen::~EulaScreen() {
}
void EulaScreen::PrepareToShow() {
actor_->PrepareToShow();
if (actor_)
actor_->PrepareToShow();
}
void EulaScreen::Show() {
// Command to own the TPM.
chromeos::CrosLibrary::Get()->
GetCryptohomeLibrary()->TpmCanAttemptOwnership();
actor_->Show();
if (actor_)
actor_->Show();
}
void EulaScreen::Hide() {
actor_->Hide();
if (actor_)
actor_->Hide();
}
std::string EulaScreen::GetName() const {
......@@ -73,7 +78,7 @@ void EulaScreen::InitiatePasswordFetch() {
if (tpm_password_.empty()) {
password_fetcher_.Fetch();
// Will call actor after password has been fetched.
} else {
} else if (actor_) {
actor_->OnPasswordFetched(tpm_password_);
}
}
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
......@@ -17,11 +17,19 @@ MockNetworkScreen::MockNetworkScreen(ScreenObserver* observer,
MockNetworkScreen::~MockNetworkScreen() {
}
MockNetworkScreenActor::MockNetworkScreenActor() {
EXPECT_CALL(*this, SetDelegate(NotNull())).Times(AtLeast(1));
EXPECT_CALL(*this, MockSetDelegate(NotNull())).Times(AtLeast(1));
}
MockNetworkScreenActor::~MockNetworkScreenActor() {
if (delegate_)
delegate_->OnActorDestroyed(this);
}
void MockNetworkScreenActor::SetDelegate(Delegate* delegate) {
delegate_ = delegate;
MockSetDelegate(delegate);
}
} // namespace chromeos
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
......@@ -23,7 +23,9 @@ class MockNetworkScreenActor : public NetworkScreenActor {
MockNetworkScreenActor();
virtual ~MockNetworkScreenActor();
MOCK_METHOD1(SetDelegate, void(Delegate* screen));
virtual void SetDelegate(Delegate* delegate);
MOCK_METHOD1(MockSetDelegate, void(Delegate* delegate));
MOCK_METHOD0(PrepareToShow, void());
MOCK_METHOD0(Show, void());
MOCK_METHOD0(Hide, void());
......@@ -34,6 +36,10 @@ class MockNetworkScreenActor : public NetworkScreenActor {
MOCK_METHOD1(EnableContinue, void(bool enabled));
MOCK_CONST_METHOD0(IsContinueEnabled, bool());
MOCK_CONST_METHOD0(IsConnecting, bool());
private:
Delegate* delegate_;
};
} // namespace chromeos
......
......@@ -37,10 +37,14 @@ NetworkScreen::NetworkScreen(ScreenObserver* screen_observer,
is_network_subscribed_(false),
continue_pressed_(false),
actor_(actor) {
actor_->SetDelegate(this);
DCHECK(actor_);
if (actor_)
actor_->SetDelegate(this);
}
NetworkScreen::~NetworkScreen() {
if (actor_)
actor_->SetDelegate(NULL);
connection_timer_.Stop();
UnsubscribeNetworkNotification();
}
......@@ -49,16 +53,19 @@ NetworkScreen::~NetworkScreen() {
// NetworkScreen, WizardScreen implementation:
void NetworkScreen::PrepareToShow() {
actor_->PrepareToShow();
if (actor_)
actor_->PrepareToShow();
}
void NetworkScreen::Show() {
actor_->Show();
if (actor_)
actor_->Show();
Refresh();
}
void NetworkScreen::Hide() {
actor_->Hide();
if (actor_)
actor_->Hide();
}
std::string NetworkScreen::GetName() const {
......@@ -83,6 +90,11 @@ void NetworkScreen::Refresh() {
///////////////////////////////////////////////////////////////////////////////
// NetworkScreen, NetworkScreenActor::Delegate implementation:
void NetworkScreen::OnActorDestroyed(NetworkScreenActor* actor) {
if (actor_ == actor)
actor_ = NULL;
}
void NetworkScreen::OnContinuePressed() {
NetworkLibrary* network = CrosLibrary::Get()->GetNetworkLibrary();
if (network && network->Connected()) {
......@@ -124,7 +136,7 @@ void NetworkScreen::OnConnectionTimeout() {
NetworkLibrary* network = CrosLibrary::Get()->GetNetworkLibrary();
bool is_connected = network && network->Connected();
if (!is_connected) {
if (!is_connected && actor_) {
// Show error bubble.
actor_->ShowError(
l10n_util::GetStringFUTF16(
......@@ -163,8 +175,10 @@ void NetworkScreen::StopWaitingForConnection(const string16& network_id) {
connection_timer_.Stop();
network_id_ = network_id;
actor_->ShowConnectingStatus(false, network_id_);
actor_->EnableContinue(is_connected);
if (actor_) {
actor_->ShowConnectingStatus(false, network_id_);
actor_->EnableContinue(is_connected);
}
}
void NetworkScreen::WaitForConnection(const string16& network_id) {
......@@ -177,9 +191,10 @@ void NetworkScreen::WaitForConnection(const string16& network_id) {
}
network_id_ = network_id;
actor_->ShowConnectingStatus(continue_pressed_, network_id_);
actor_->EnableContinue(false);
if (actor_) {
actor_->ShowConnectingStatus(continue_pressed_, network_id_);
actor_->EnableContinue(false);
}
}
} // namespace chromeos
......@@ -34,6 +34,7 @@ class NetworkScreen : public WizardScreen,
virtual void OnNetworkManagerChanged(NetworkLibrary* network_lib) OVERRIDE;
// NetworkScreenActor::Delegate implementation:
virtual void OnActorDestroyed(NetworkScreenActor* actor) OVERRIDE;
virtual void OnContinuePressed() OVERRIDE;
NetworkScreenActor* actor() const { return actor_; }
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
......@@ -16,6 +16,7 @@ class NetworkScreenActor {
class Delegate {
public:
virtual ~Delegate() {}
virtual void OnActorDestroyed(NetworkScreenActor* actor) = 0;
virtual void OnContinuePressed() = 0;
};
......
......@@ -96,7 +96,9 @@ UpdateScreen::UpdateScreen(ScreenObserver* screen_observer,
is_shown_(false),
ignore_idle_status_(true),
actor_(actor) {
actor_->SetDelegate(this);
DCHECK(actor_);
if (actor_)
actor_->SetDelegate(this);
GetInstanceSet().insert(this);
}
......@@ -109,6 +111,9 @@ UpdateScreen::~UpdateScreen() {
void UpdateScreen::UpdateStatusChanged(
const UpdateEngineClient::Status& status) {
if (!actor_)
return;
if (is_checking_for_update_ &&
status.status > UpdateEngineClient::UPDATE_STATUS_CHECKING_FOR_UPDATE) {
is_checking_for_update_ = false;
......@@ -223,12 +228,15 @@ void UpdateScreen::CancelUpdate() {
void UpdateScreen::Show() {
is_shown_ = true;
actor_->Show();
actor_->SetProgress(kBeforeUpdateCheckProgress);
if (actor_) {
actor_->Show();
actor_->SetProgress(kBeforeUpdateCheckProgress);
}
}
void UpdateScreen::Hide() {
actor_->Hide();
if (actor_)
actor_->Hide();
is_shown_ = false;
}
......@@ -237,7 +245,8 @@ std::string UpdateScreen::GetName() const {
}
void UpdateScreen::PrepareToShow() {
actor_->PrepareToShow();
if (actor_)
actor_->PrepareToShow();
}
void UpdateScreen::ExitUpdate(UpdateScreen::ExitReason reason) {
......@@ -287,7 +296,8 @@ void UpdateScreen::ExitUpdate(UpdateScreen::ExitReason reason) {
void UpdateScreen::OnWaitForRebootTimeElapsed() {
LOG(ERROR) << "Unable to reboot - asking user for a manual reboot.";
MakeSureScreenIsShown();
actor_->ShowManualRebootInfo();
if (actor_)
actor_->ShowManualRebootInfo();
}
void UpdateScreen::MakeSureScreenIsShown() {
......@@ -308,6 +318,8 @@ void UpdateScreen::SetIgnoreIdleStatus(bool ignore_idle_status) {
void UpdateScreen::UpdateDownloadingStats(
const UpdateEngineClient::Status& status) {
if (!actor_)
return;
base::Time download_current_time = base::Time::Now();
if (download_current_time >= download_last_time_ + kMinTimeStep &&
status.download_progress >=
......
......@@ -47,6 +47,8 @@ NetworkScreenHandler::NetworkScreenHandler()
}
NetworkScreenHandler::~NetworkScreenHandler() {
if (screen_)
screen_->OnActorDestroyed(this);
}
// NetworkScreenHandler, NetworkScreenActor implementation: --------------------
......@@ -151,7 +153,8 @@ void NetworkScreenHandler::RegisterMessages() {
void NetworkScreenHandler::HandleOnExit(const ListValue* args) {
ClearErrors();
screen_->OnContinuePressed();
if (screen_)
screen_->OnContinuePressed();
}
void NetworkScreenHandler::HandleOnLanguageChanged(const ListValue* args) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment