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 ...@@ -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"> <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. Your computer will restart when the update is complete.
</message> </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"> <message name="IDS_WELCOME_SCREEN_TITLE" desc="Title of the OOBE welcome screen">
Connect Connect
</message> </message>
......
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
namespace chromeos { namespace chromeos {
using ::testing::AtLeast;
using ::testing::NotNull;
MockUpdateScreen::MockUpdateScreen(ScreenObserver* screen_observer, MockUpdateScreen::MockUpdateScreen(ScreenObserver* screen_observer,
UpdateScreenActor* actor) UpdateScreenActor* actor)
: UpdateScreen(screen_observer, actor) { : UpdateScreen(screen_observer, actor) {
...@@ -14,10 +17,19 @@ MockUpdateScreen::MockUpdateScreen(ScreenObserver* screen_observer, ...@@ -14,10 +17,19 @@ MockUpdateScreen::MockUpdateScreen(ScreenObserver* screen_observer,
MockUpdateScreen::~MockUpdateScreen() { MockUpdateScreen::~MockUpdateScreen() {
} }
MockUpdateScreenActor::MockUpdateScreenActor() { MockUpdateScreenActor::MockUpdateScreenActor()
: screen_(NULL) {
EXPECT_CALL(*this, MockSetDelegate(NotNull())).Times(AtLeast(1));
} }
MockUpdateScreenActor::~MockUpdateScreenActor() { MockUpdateScreenActor::~MockUpdateScreenActor() {
if (screen_)
screen_->OnActorDestroyed(this);
}
void MockUpdateScreenActor::SetDelegate(UpdateScreenActor::Delegate* screen) {
screen_ = screen;
MockSetDelegate(screen);
} }
} // namespace chromeos } // namespace chromeos
...@@ -26,6 +26,9 @@ class MockUpdateScreenActor : public UpdateScreenActor { ...@@ -26,6 +26,9 @@ class MockUpdateScreenActor : public UpdateScreenActor {
MockUpdateScreenActor(); MockUpdateScreenActor();
virtual ~MockUpdateScreenActor(); virtual ~MockUpdateScreenActor();
virtual void SetDelegate(UpdateScreenActor::Delegate* screen) OVERRIDE;
MOCK_METHOD1(MockSetDelegate, void(UpdateScreenActor::Delegate* screen));
MOCK_METHOD0(Show, void()); MOCK_METHOD0(Show, void());
MOCK_METHOD0(Hide, void()); MOCK_METHOD0(Hide, void());
MOCK_METHOD0(PrepareToShow, void()); MOCK_METHOD0(PrepareToShow, void());
...@@ -33,6 +36,9 @@ class MockUpdateScreenActor : public UpdateScreenActor { ...@@ -33,6 +36,9 @@ class MockUpdateScreenActor : public UpdateScreenActor {
MOCK_METHOD1(SetProgress, void(int progress)); MOCK_METHOD1(SetProgress, void(int progress));
MOCK_METHOD1(ShowCurtain, void(bool enable)); MOCK_METHOD1(ShowCurtain, void(bool enable));
MOCK_METHOD1(ShowPreparingUpdatesInfo, void(bool enable)); MOCK_METHOD1(ShowPreparingUpdatesInfo, void(bool enable));
private:
UpdateScreenActor::Delegate* screen_;
}; };
} // namespace chromeos } // namespace chromeos
......
...@@ -77,12 +77,15 @@ UpdateScreen::UpdateScreen(ScreenObserver* screen_observer, ...@@ -77,12 +77,15 @@ UpdateScreen::UpdateScreen(ScreenObserver* screen_observer,
is_shown_(false), is_shown_(false),
ignore_idle_status_(true), ignore_idle_status_(true),
actor_(actor) { actor_(actor) {
actor_->SetDelegate(this);
GetInstanceSet().insert(this); GetInstanceSet().insert(this);
} }
UpdateScreen::~UpdateScreen() { UpdateScreen::~UpdateScreen() {
CrosLibrary::Get()->GetUpdateLibrary()->RemoveObserver(this); CrosLibrary::Get()->GetUpdateLibrary()->RemoveObserver(this);
GetInstanceSet().erase(this); GetInstanceSet().erase(this);
if (actor_)
actor_->SetDelegate(NULL);
} }
void UpdateScreen::UpdateStatusChanged(UpdateLibrary* library) { void UpdateScreen::UpdateStatusChanged(UpdateLibrary* library) {
...@@ -190,6 +193,7 @@ void UpdateScreen::StartUpdate() { ...@@ -190,6 +193,7 @@ void UpdateScreen::StartUpdate() {
} }
void UpdateScreen::CancelUpdate() { void UpdateScreen::CancelUpdate() {
VLOG(1) << "Forced update cancel";
ExitUpdate(REASON_UPDATE_CANCELED); ExitUpdate(REASON_UPDATE_CANCELED);
} }
...@@ -293,4 +297,9 @@ bool UpdateScreen::HasCriticalUpdate() { ...@@ -293,4 +297,9 @@ bool UpdateScreen::HasCriticalUpdate() {
return true; return true;
} }
void UpdateScreen::OnActorDestroyed(UpdateScreenActor* actor) {
if (actor_ == actor)
actor_ = NULL;
}
} // namespace chromeos } // namespace chromeos
...@@ -12,17 +12,18 @@ ...@@ -12,17 +12,18 @@
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/timer.h" #include "base/timer.h"
#include "chrome/browser/chromeos/cros/update_library.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" #include "chrome/browser/chromeos/login/wizard_screen.h"
namespace chromeos { namespace chromeos {
class ScreenObserver; class ScreenObserver;
class UpdateScreenActor;
// Controller for the update screen. It does not depend on the specific // Controller for the update screen. It does not depend on the specific
// implementation of the screen showing (Views of WebUI based), the dependency // implementation of the screen showing (Views of WebUI based), the dependency
// is moved to the UpdateScreenActor instead. // is moved to the UpdateScreenActor instead.
class UpdateScreen: public UpdateLibrary::Observer, class UpdateScreen: public UpdateLibrary::Observer,
public UpdateScreenActor::Delegate,
public WizardScreen { public WizardScreen {
public: public:
UpdateScreen(ScreenObserver* screen_observer, UpdateScreenActor* actor); UpdateScreen(ScreenObserver* screen_observer, UpdateScreenActor* actor);
...@@ -33,13 +34,14 @@ class UpdateScreen: public UpdateLibrary::Observer, ...@@ -33,13 +34,14 @@ class UpdateScreen: public UpdateLibrary::Observer,
virtual void Show(); virtual void Show();
virtual void Hide(); 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 // Checks for updates and performs an update if needed. Made virtual to
// simplify mocking. // simplify mocking.
virtual void StartUpdate(); virtual void StartUpdate();
// Force cancel update. Made virtual to simplify mocking.
virtual void CancelUpdate();
// Reboot check delay get/set, in seconds. // Reboot check delay get/set, in seconds.
int reboot_check_delay() const { return reboot_check_delay_; } int reboot_check_delay() const { return reboot_check_delay_; }
void SetRebootCheckDelay(int seconds); void SetRebootCheckDelay(int seconds);
......
...@@ -13,8 +13,19 @@ class ScreenObserver; ...@@ -13,8 +13,19 @@ class ScreenObserver;
class UpdateScreenActor { class UpdateScreenActor {
public: public:
class Delegate {
public:
virtual ~Delegate() {}
// Force cancel update.
virtual void CancelUpdate() = 0;
virtual void OnActorDestroyed(UpdateScreenActor* actor) = 0;
};
virtual ~UpdateScreenActor() {} virtual ~UpdateScreenActor() {}
// Sets screen this actor belongs to.
virtual void SetDelegate(Delegate* screen) = 0;
// Shows the screen. // Shows the screen.
virtual void Show() = 0; virtual void Show() = 0;
......
...@@ -17,7 +17,17 @@ namespace chromeos { ...@@ -17,7 +17,17 @@ namespace chromeos {
ViewsUpdateScreenActor::ViewsUpdateScreenActor(ViewScreenDelegate* delegate) ViewsUpdateScreenActor::ViewsUpdateScreenActor(ViewScreenDelegate* delegate)
: DefaultViewScreen<chromeos::UpdateView>(delegate, : DefaultViewScreen<chromeos::UpdateView>(delegate,
kUpdateScreenWidth, kUpdateScreenWidth,
kUpdateScreenHeight) { kUpdateScreenHeight),
screen_(NULL) {
}
ViewsUpdateScreenActor::~ViewsUpdateScreenActor() {
if (screen_)
screen_->OnActorDestroyed(this);
}
void ViewsUpdateScreenActor::SetDelegate(UpdateScreenActor::Delegate* screen) {
screen_ = screen;
} }
void ViewsUpdateScreenActor::PrepareToShow() { void ViewsUpdateScreenActor::PrepareToShow() {
......
...@@ -16,8 +16,9 @@ class ViewsUpdateScreenActor : public DefaultViewScreen<UpdateView>, ...@@ -16,8 +16,9 @@ class ViewsUpdateScreenActor : public DefaultViewScreen<UpdateView>,
public UpdateScreenActor { public UpdateScreenActor {
public: public:
explicit ViewsUpdateScreenActor(ViewScreenDelegate* delegate); explicit ViewsUpdateScreenActor(ViewScreenDelegate* delegate);
virtual ~ViewsUpdateScreenActor() {} virtual ~ViewsUpdateScreenActor();
virtual void SetDelegate(UpdateScreenActor::Delegate* screen) OVERRIDE;
virtual void PrepareToShow(); virtual void PrepareToShow();
virtual void Show(); virtual void Show();
virtual void Hide(); virtual void Hide();
...@@ -27,6 +28,8 @@ class ViewsUpdateScreenActor : public DefaultViewScreen<UpdateView>, ...@@ -27,6 +28,8 @@ class ViewsUpdateScreenActor : public DefaultViewScreen<UpdateView>,
virtual void ShowPreparingUpdatesInfo(bool visible); virtual void ShowPreparingUpdatesInfo(bool visible);
private: private:
UpdateScreenActor::Delegate* screen_;
DISALLOW_COPY_AND_ASSIGN(ViewsUpdateScreenActor); DISALLOW_COPY_AND_ASSIGN(ViewsUpdateScreenActor);
}; };
......
...@@ -278,6 +278,13 @@ hr.bottom { ...@@ -278,6 +278,13 @@ hr.bottom {
width: 32em; width: 32em;
} }
#update #update-cancel-hint {
color: #a00;
left: 50%;
margin: 1em -16em;
position: absolute;
}
#update progress { #update progress {
margin: 13px 0; margin: 13px 0;
width: 380px; width: 380px;
......
<div class="step right hidden" id="update"> <div class="step right hidden" id="update">
<div id="update-cancel-hint" hidden>
<p i18n-content="cancelUpdateHint"></p>
</div>
<div id="update-screen-curtain"> <div id="update-screen-curtain">
<p i18n-content="checkingForUpdates"></p> <p i18n-content="checkingForUpdates"></p>
</div> </div>
......
...@@ -47,6 +47,18 @@ cr.define('oobe', function() { ...@@ -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 { return {
UpdateScreen: UpdateScreen UpdateScreen: UpdateScreen
}; };
......
...@@ -19,10 +19,14 @@ const char kUpdateScreen[] = "update"; ...@@ -19,10 +19,14 @@ const char kUpdateScreen[] = "update";
namespace chromeos { namespace chromeos {
UpdateScreenHandler::UpdateScreenHandler() : show_on_init_(false) { UpdateScreenHandler::UpdateScreenHandler()
: screen_(NULL),
show_on_init_(false) {
} }
UpdateScreenHandler::~UpdateScreenHandler() { UpdateScreenHandler::~UpdateScreenHandler() {
if (screen_)
screen_->OnActorDestroyed(this);
} }
void UpdateScreenHandler::GetLocalizedStrings( void UpdateScreenHandler::GetLocalizedStrings(
...@@ -33,6 +37,12 @@ void UpdateScreenHandler::GetLocalizedStrings( ...@@ -33,6 +37,12 @@ void UpdateScreenHandler::GetLocalizedStrings(
l10n_util::GetStringUTF16(IDS_CHECKING_FOR_UPDATES)); l10n_util::GetStringUTF16(IDS_CHECKING_FOR_UPDATES));
localized_strings->SetString("installingUpdateDesc", localized_strings->SetString("installingUpdateDesc",
l10n_util::GetStringUTF16(IDS_INSTALLING_UPDATE_DESC)); 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() { void UpdateScreenHandler::Initialize() {
...@@ -42,12 +52,19 @@ void UpdateScreenHandler::Initialize() { ...@@ -42,12 +52,19 @@ void UpdateScreenHandler::Initialize() {
} }
} }
void UpdateScreenHandler::SetDelegate(UpdateScreenActor::Delegate* screen) {
screen_ = screen;
}
void UpdateScreenHandler::Show() { void UpdateScreenHandler::Show() {
if (!page_is_ready()) { if (!page_is_ready()) {
show_on_init_ = true; show_on_init_ = true;
return; return;
} }
ShowScreen(kUpdateScreen, NULL); ShowScreen(kUpdateScreen, NULL);
#if !defined(OFFICIAL_BUILD)
web_ui_->CallJavascriptFunction("oobe.UpdateScreen.enableUpdateCancel");
#endif
} }
void UpdateScreenHandler::Hide() { void UpdateScreenHandler::Hide() {
...@@ -87,6 +104,18 @@ void UpdateScreenHandler::ShowPreparingUpdatesInfo(bool visible) { ...@@ -87,6 +104,18 @@ void UpdateScreenHandler::ShowPreparingUpdatesInfo(bool visible) {
} }
void UpdateScreenHandler::RegisterMessages() { 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 } // namespace chromeos
...@@ -21,6 +21,7 @@ class UpdateScreenHandler : public UpdateScreenActor, ...@@ -21,6 +21,7 @@ class UpdateScreenHandler : public UpdateScreenActor,
virtual void Initialize(); virtual void Initialize();
// UpdateScreenActor implementation: // UpdateScreenActor implementation:
virtual void SetDelegate(UpdateScreenActor::Delegate* screen) OVERRIDE;
virtual void Show(); virtual void Show();
virtual void Hide(); virtual void Hide();
virtual void PrepareToShow(); virtual void PrepareToShow();
...@@ -33,6 +34,12 @@ class UpdateScreenHandler : public UpdateScreenActor, ...@@ -33,6 +34,12 @@ class UpdateScreenHandler : public UpdateScreenActor,
virtual void RegisterMessages(); virtual void RegisterMessages();
private: 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. // Keeps whether screen should be shown right after initialization.
bool show_on_init_; 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