Commit cbf2d90c authored by ivankr@chromium.org's avatar ivankr@chromium.org

[cros] check for updates in WebUI OOBE can be cancelled in dev builds.

BUG=chromium-os:18464
TEST=Manual: pressing ESC on OOBE update screen cancels update check.


Review URL: http://codereview.chromium.org/7774009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98801 0039d316-1c4b-4281-b951-d872f2087c98
parent a0f76291
......@@ -10794,6 +10794,12 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_INSTALLING_UPDATE_DESC" desc="Additional info shown on the updates installation screen during OOBE">
Your computer will restart when the update is complete.
</message>
<message name="IDS_UPDATE_CANCEL" desc="Message telling to press Escape to cancel update on a non-official build">
Press ESCAPE to skip (Non-official builds only).
</message>
<message name="IDS_UPDATE_CANCELLED" desc="Message shown when the update has been cancelled by user">
Cancelling update...
</message>
<message name="IDS_WELCOME_SCREEN_TITLE" desc="Title of the OOBE welcome screen">
Connect
</message>
......
......@@ -6,6 +6,9 @@
namespace chromeos {
using ::testing::AtLeast;
using ::testing::NotNull;
MockUpdateScreen::MockUpdateScreen(ScreenObserver* screen_observer,
UpdateScreenActor* actor)
: UpdateScreen(screen_observer, actor) {
......@@ -14,10 +17,19 @@ MockUpdateScreen::MockUpdateScreen(ScreenObserver* screen_observer,
MockUpdateScreen::~MockUpdateScreen() {
}
MockUpdateScreenActor::MockUpdateScreenActor() {
MockUpdateScreenActor::MockUpdateScreenActor()
: screen_(NULL) {
EXPECT_CALL(*this, MockSetDelegate(NotNull())).Times(AtLeast(1));
}
MockUpdateScreenActor::~MockUpdateScreenActor() {
if (screen_)
screen_->OnActorDestroyed(this);
}
void MockUpdateScreenActor::SetDelegate(UpdateScreenActor::Delegate* screen) {
screen_ = screen;
MockSetDelegate(screen);
}
} // namespace chromeos
......@@ -26,6 +26,9 @@ class MockUpdateScreenActor : public UpdateScreenActor {
MockUpdateScreenActor();
virtual ~MockUpdateScreenActor();
virtual void SetDelegate(UpdateScreenActor::Delegate* screen) OVERRIDE;
MOCK_METHOD1(MockSetDelegate, void(UpdateScreenActor::Delegate* screen));
MOCK_METHOD0(Show, void());
MOCK_METHOD0(Hide, void());
MOCK_METHOD0(PrepareToShow, void());
......@@ -33,6 +36,9 @@ class MockUpdateScreenActor : public UpdateScreenActor {
MOCK_METHOD1(SetProgress, void(int progress));
MOCK_METHOD1(ShowCurtain, void(bool enable));
MOCK_METHOD1(ShowPreparingUpdatesInfo, void(bool enable));
private:
UpdateScreenActor::Delegate* screen_;
};
} // namespace chromeos
......
......@@ -77,12 +77,15 @@ UpdateScreen::UpdateScreen(ScreenObserver* screen_observer,
is_shown_(false),
ignore_idle_status_(true),
actor_(actor) {
actor_->SetDelegate(this);
GetInstanceSet().insert(this);
}
UpdateScreen::~UpdateScreen() {
CrosLibrary::Get()->GetUpdateLibrary()->RemoveObserver(this);
GetInstanceSet().erase(this);
if (actor_)
actor_->SetDelegate(NULL);
}
void UpdateScreen::UpdateStatusChanged(UpdateLibrary* library) {
......@@ -190,6 +193,7 @@ void UpdateScreen::StartUpdate() {
}
void UpdateScreen::CancelUpdate() {
VLOG(1) << "Forced update cancel";
ExitUpdate(REASON_UPDATE_CANCELED);
}
......@@ -293,4 +297,9 @@ bool UpdateScreen::HasCriticalUpdate() {
return true;
}
void UpdateScreen::OnActorDestroyed(UpdateScreenActor* actor) {
if (actor_ == actor)
actor_ = NULL;
}
} // namespace chromeos
......@@ -12,17 +12,18 @@
#include "base/memory/scoped_ptr.h"
#include "base/timer.h"
#include "chrome/browser/chromeos/cros/update_library.h"
#include "chrome/browser/chromeos/login/update_screen_actor.h"
#include "chrome/browser/chromeos/login/wizard_screen.h"
namespace chromeos {
class ScreenObserver;
class UpdateScreenActor;
// Controller for the update screen. It does not depend on the specific
// implementation of the screen showing (Views of WebUI based), the dependency
// is moved to the UpdateScreenActor instead.
class UpdateScreen: public UpdateLibrary::Observer,
public UpdateScreenActor::Delegate,
public WizardScreen {
public:
UpdateScreen(ScreenObserver* screen_observer, UpdateScreenActor* actor);
......@@ -33,13 +34,14 @@ class UpdateScreen: public UpdateLibrary::Observer,
virtual void Show();
virtual void Hide();
// UpdateScreenActor::Delegate implementation:
virtual void CancelUpdate() OVERRIDE;
virtual void OnActorDestroyed(UpdateScreenActor* actor) OVERRIDE;
// Checks for updates and performs an update if needed. Made virtual to
// simplify mocking.
virtual void StartUpdate();
// Force cancel update. Made virtual to simplify mocking.
virtual void CancelUpdate();
// Reboot check delay get/set, in seconds.
int reboot_check_delay() const { return reboot_check_delay_; }
void SetRebootCheckDelay(int seconds);
......
......@@ -13,8 +13,19 @@ class ScreenObserver;
class UpdateScreenActor {
public:
class Delegate {
public:
virtual ~Delegate() {}
// Force cancel update.
virtual void CancelUpdate() = 0;
virtual void OnActorDestroyed(UpdateScreenActor* actor) = 0;
};
virtual ~UpdateScreenActor() {}
// Sets screen this actor belongs to.
virtual void SetDelegate(Delegate* screen) = 0;
// Shows the screen.
virtual void Show() = 0;
......
......@@ -17,7 +17,17 @@ namespace chromeos {
ViewsUpdateScreenActor::ViewsUpdateScreenActor(ViewScreenDelegate* delegate)
: DefaultViewScreen<chromeos::UpdateView>(delegate,
kUpdateScreenWidth,
kUpdateScreenHeight) {
kUpdateScreenHeight),
screen_(NULL) {
}
ViewsUpdateScreenActor::~ViewsUpdateScreenActor() {
if (screen_)
screen_->OnActorDestroyed(this);
}
void ViewsUpdateScreenActor::SetDelegate(UpdateScreenActor::Delegate* screen) {
screen_ = screen;
}
void ViewsUpdateScreenActor::PrepareToShow() {
......
......@@ -16,8 +16,9 @@ class ViewsUpdateScreenActor : public DefaultViewScreen<UpdateView>,
public UpdateScreenActor {
public:
explicit ViewsUpdateScreenActor(ViewScreenDelegate* delegate);
virtual ~ViewsUpdateScreenActor() {}
virtual ~ViewsUpdateScreenActor();
virtual void SetDelegate(UpdateScreenActor::Delegate* screen) OVERRIDE;
virtual void PrepareToShow();
virtual void Show();
virtual void Hide();
......@@ -27,6 +28,8 @@ class ViewsUpdateScreenActor : public DefaultViewScreen<UpdateView>,
virtual void ShowPreparingUpdatesInfo(bool visible);
private:
UpdateScreenActor::Delegate* screen_;
DISALLOW_COPY_AND_ASSIGN(ViewsUpdateScreenActor);
};
......
......@@ -278,6 +278,13 @@ hr.bottom {
width: 32em;
}
#update #update-cancel-hint {
color: #a00;
left: 50%;
margin: 1em -16em;
position: absolute;
}
#update progress {
margin: 13px 0;
width: 380px;
......
<div class="step right hidden" id="update">
<div id="update-cancel-hint" hidden>
<p i18n-content="cancelUpdateHint"></p>
</div>
<div id="update-screen-curtain">
<p i18n-content="checkingForUpdates"></p>
</div>
......
......@@ -47,6 +47,18 @@ cr.define('oobe', function() {
}
};
UpdateScreen.enableUpdateCancel = function() {
$('update-cancel-hint').hidden = false;
document.addEventListener('keydown', function(e) {
if (e.keyCode == 27) { // Escape
var updateCancelHint = $('update-cancel-hint').children[0];
updateCancelHint.textContent =
localStrings.getString('cancelledUpdateMessage');
chrome.send('cancelUpdate');
}
});
};
return {
UpdateScreen: UpdateScreen
};
......
......@@ -19,10 +19,14 @@ const char kUpdateScreen[] = "update";
namespace chromeos {
UpdateScreenHandler::UpdateScreenHandler() : show_on_init_(false) {
UpdateScreenHandler::UpdateScreenHandler()
: screen_(NULL),
show_on_init_(false) {
}
UpdateScreenHandler::~UpdateScreenHandler() {
if (screen_)
screen_->OnActorDestroyed(this);
}
void UpdateScreenHandler::GetLocalizedStrings(
......@@ -33,6 +37,12 @@ void UpdateScreenHandler::GetLocalizedStrings(
l10n_util::GetStringUTF16(IDS_CHECKING_FOR_UPDATES));
localized_strings->SetString("installingUpdateDesc",
l10n_util::GetStringUTF16(IDS_INSTALLING_UPDATE_DESC));
#if !defined(OFFICIAL_BUILD)
localized_strings->SetString("cancelUpdateHint",
l10n_util::GetStringUTF16(IDS_UPDATE_CANCEL));
localized_strings->SetString("cancelledUpdateMessage",
l10n_util::GetStringUTF16(IDS_UPDATE_CANCELLED));
#endif
}
void UpdateScreenHandler::Initialize() {
......@@ -42,12 +52,19 @@ void UpdateScreenHandler::Initialize() {
}
}
void UpdateScreenHandler::SetDelegate(UpdateScreenActor::Delegate* screen) {
screen_ = screen;
}
void UpdateScreenHandler::Show() {
if (!page_is_ready()) {
show_on_init_ = true;
return;
}
ShowScreen(kUpdateScreen, NULL);
#if !defined(OFFICIAL_BUILD)
web_ui_->CallJavascriptFunction("oobe.UpdateScreen.enableUpdateCancel");
#endif
}
void UpdateScreenHandler::Hide() {
......@@ -87,6 +104,18 @@ void UpdateScreenHandler::ShowPreparingUpdatesInfo(bool visible) {
}
void UpdateScreenHandler::RegisterMessages() {
#if !defined(OFFICIAL_BUILD)
web_ui_->RegisterMessageCallback(
"cancelUpdate",
NewCallback(this, &UpdateScreenHandler::HandleUpdateCancel));
#endif
}
#if !defined(OFFICIAL_BUILD)
void UpdateScreenHandler::HandleUpdateCancel(const base::ListValue* args) {
DCHECK(args && args->empty());
screen_->CancelUpdate();
}
#endif
} // namespace chromeos
......@@ -21,6 +21,7 @@ class UpdateScreenHandler : public UpdateScreenActor,
virtual void Initialize();
// UpdateScreenActor implementation:
virtual void SetDelegate(UpdateScreenActor::Delegate* screen) OVERRIDE;
virtual void Show();
virtual void Hide();
virtual void PrepareToShow();
......@@ -33,6 +34,12 @@ class UpdateScreenHandler : public UpdateScreenActor,
virtual void RegisterMessages();
private:
#if !defined(OFFICIAL_BUILD)
// Called when user presses Escape to cancel update.
void HandleUpdateCancel(const base::ListValue* args);
#endif
UpdateScreenActor::Delegate* screen_;
// Keeps whether screen should be shown right after initialization.
bool show_on_init_;
......
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