Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(852)

Unified Diff: chrome/browser/chromeos/login/screens/update_screen.cc

Issue 863263006: Migrating UpdateScreen to ScreenContext (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: refactor Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/login/screens/update_screen.cc
diff --git a/chrome/browser/chromeos/login/screens/update_screen.cc b/chrome/browser/chromeos/login/screens/update_screen.cc
index e6872c093ba4f8a6c4daf4043b1a2c401b03b794..045742154919ee5f31853f5dd822bbec2ae2708a 100644
--- a/chrome/browser/chromeos/login/screens/update_screen.cc
+++ b/chrome/browser/chromeos/login/screens/update_screen.cc
@@ -15,12 +15,15 @@
#include "chrome/browser/chromeos/login/screen_manager.h"
#include "chrome/browser/chromeos/login/screens/base_screen_delegate.h"
#include "chrome/browser/chromeos/login/screens/error_screen.h"
-#include "chrome/browser/chromeos/login/screens/update_screen_actor.h"
+#include "chrome/browser/chromeos/login/screens/update_view.h"
#include "chrome/browser/chromeos/login/startup_utils.h"
#include "chrome/browser/chromeos/login/wizard_controller.h"
+#include "chrome/grit/chromium_strings.h"
+#include "chrome/grit/generated_resources.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/network/network_state.h"
#include "content/public/browser/browser_thread.h"
+#include "ui/base/l10n/l10n_util.h"
using content::BrowserThread;
using pairing_chromeos::HostPairingController;
@@ -29,6 +32,9 @@ namespace chromeos {
namespace {
+// If reboot didn't happen, ask user to reboot device manually.
+const int kWaitForRebootTimeSec = 3;
+
// Progress bar stages. Each represents progress bar value
// at the beginning of each stage.
// TODO(nkostylev): Base stage progress values on approximate time.
@@ -94,41 +100,39 @@ UpdateScreen* UpdateScreen::Get(ScreenManager* manager) {
}
UpdateScreen::UpdateScreen(BaseScreenDelegate* base_screen_delegate,
- UpdateScreenActor* actor,
+ UpdateView* view,
HostPairingController* remora_controller)
- : BaseScreen(base_screen_delegate),
+ : UpdateModel(base_screen_delegate),
state_(STATE_IDLE),
- reboot_check_delay_(0),
+ reboot_check_delay_(kWaitForRebootTimeSec),
is_checking_for_update_(true),
is_downloading_update_(false),
- is_ignore_update_deadlines_(false),
+ is_ignore_update_deadlines_(true),
is_shown_(false),
ignore_idle_status_(true),
- actor_(actor),
+ view_(view),
remora_controller_(remora_controller),
is_first_detection_notification_(true),
is_first_portal_notification_(true),
histogram_helper_(new ErrorScreensHistogramHelper("Update")),
weak_factory_(this) {
- DCHECK(actor_);
- if (actor_)
- actor_->SetDelegate(this);
+ if (view_)
+ view_->Bind(*this);
+
GetInstanceSet().insert(this);
}
UpdateScreen::~UpdateScreen() {
+ if (view_)
+ view_->Unbind();
+
DBusThreadManager::Get()->GetUpdateEngineClient()->RemoveObserver(this);
NetworkPortalDetector::Get()->RemoveObserver(this);
GetInstanceSet().erase(this);
- if (actor_)
- actor_->SetDelegate(NULL);
}
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;
@@ -147,17 +151,19 @@ void UpdateScreen::UpdateStatusChanged(
break;
case UpdateEngineClient::UPDATE_STATUS_UPDATE_AVAILABLE:
MakeSureScreenIsShown();
- actor_->SetProgress(kBeforeDownloadProgress);
- actor_->ShowEstimatedTimeLeft(false);
+ GetContextEditor()
+ .SetInteger(kContextKeyProgress, kBeforeDownloadProgress)
+ .SetBoolean(kContextKeyShowEstimatedTimeLeft, false);
if (!HasCriticalUpdate()) {
VLOG(1) << "Noncritical update available: " << status.new_version;
ExitUpdate(REASON_UPDATE_NON_CRITICAL);
} else {
VLOG(1) << "Critical update available: " << status.new_version;
- actor_->SetProgressMessage(
- UpdateScreenActor::PROGRESS_MESSAGE_UPDATE_AVAILABLE);
- actor_->ShowProgressMessage(true);
- actor_->ShowCurtain(false);
+ GetContextEditor()
+ .SetString(kContextKeyProgressMessage,
+ l10n_util::GetStringUTF16(IDS_UPDATE_AVAILABLE))
+ .SetBoolean(kContextKeyShowProgressMessage, true)
+ .SetBoolean(kContextKeyShowCurtain, false);
}
break;
case UpdateEngineClient::UPDATE_STATUS_DOWNLOADING:
@@ -177,10 +183,11 @@ void UpdateScreen::UpdateStatusChanged(
ExitUpdate(REASON_UPDATE_NON_CRITICAL);
} else {
VLOG(1) << "Critical update available: " << status.new_version;
- actor_->SetProgressMessage(
- UpdateScreenActor::PROGRESS_MESSAGE_INSTALLING_UPDATE);
- actor_->ShowProgressMessage(true);
- actor_->ShowCurtain(false);
+ GetContextEditor()
+ .SetString(kContextKeyProgressMessage,
+ l10n_util::GetStringUTF16(IDS_INSTALLING_UPDATE))
+ .SetBoolean(kContextKeyShowProgressMessage, true)
+ .SetBoolean(kContextKeyShowCurtain, false);
}
}
UpdateDownloadingStats(status);
@@ -188,23 +195,27 @@ void UpdateScreen::UpdateStatusChanged(
break;
case UpdateEngineClient::UPDATE_STATUS_VERIFYING:
MakeSureScreenIsShown();
- actor_->SetProgress(kBeforeVerifyingProgress);
- actor_->SetProgressMessage(UpdateScreenActor::PROGRESS_MESSAGE_VERIFYING);
- actor_->ShowProgressMessage(true);
+ GetContextEditor()
+ .SetInteger(kContextKeyProgress, kBeforeVerifyingProgress)
+ .SetString(kContextKeyProgressMessage,
+ l10n_util::GetStringUTF16(IDS_UPDATE_VERIFYING))
+ .SetBoolean(kContextKeyShowProgressMessage, true);
break;
case UpdateEngineClient::UPDATE_STATUS_FINALIZING:
MakeSureScreenIsShown();
- actor_->SetProgress(kBeforeFinalizingProgress);
- actor_->SetProgressMessage(
- UpdateScreenActor::PROGRESS_MESSAGE_FINALIZING);
- actor_->ShowProgressMessage(true);
+ GetContextEditor()
+ .SetInteger(kContextKeyProgress, kBeforeFinalizingProgress)
+ .SetString(kContextKeyProgressMessage,
+ l10n_util::GetStringUTF16(IDS_UPDATE_FINALIZING))
+ .SetBoolean(kContextKeyShowProgressMessage, true);
break;
case UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT:
MakeSureScreenIsShown();
- actor_->SetProgress(kProgressComplete);
- actor_->ShowEstimatedTimeLeft(false);
+ GetContextEditor()
+ .SetInteger(kContextKeyProgress, kProgressComplete)
+ .SetBoolean(kContextKeyShowEstimatedTimeLeft, false);
if (HasCriticalUpdate()) {
- actor_->ShowCurtain(false);
+ GetContextEditor().SetBoolean(kContextKeyShowCurtain, false);
VLOG(1) << "Initiate reboot after update";
SetHostPairingControllerStatus(
HostPairingController::UPDATE_STATUS_REBOOTING);
@@ -298,33 +309,59 @@ void UpdateScreen::StartNetworkCheck() {
NetworkPortalDetector::Get()->AddAndFireObserver(this);
}
-void UpdateScreen::CancelUpdate() {
- VLOG(1) << "Forced update cancel";
- ExitUpdate(REASON_UPDATE_CANCELED);
+void UpdateScreen::PrepareToShow() {
+ if (!view_)
+ return;
+
+ view_->PrepareToShow();
}
void UpdateScreen::Show() {
is_shown_ = true;
histogram_helper_->OnScreenShow();
- if (actor_) {
- actor_->Show();
- actor_->SetProgress(kBeforeUpdateCheckProgress);
- }
+
+#if !defined(OFFICIAL_BUILD)
+ GetContextEditor().SetBoolean(kContextKeyCancelUpdateShortcutEnabled, true);
+#endif
+ GetContextEditor().SetInteger(kContextKeyProgress,
+ kBeforeUpdateCheckProgress);
+
+ if (view_)
+ view_->Show();
}
void UpdateScreen::Hide() {
- if (actor_)
- actor_->Hide();
+ if (view_)
+ view_->Hide();
is_shown_ = false;
}
-std::string UpdateScreen::GetName() const {
- return WizardController::kUpdateScreenName;
+void UpdateScreen::Initialize(::login::ScreenContext* context) {
+ UpdateModel::Initialize(context);
}
-void UpdateScreen::PrepareToShow() {
- if (actor_)
- actor_->PrepareToShow();
+void UpdateScreen::OnViewDestroyed(UpdateView* view) {
+ if (view_ == view)
+ view_ = nullptr;
+}
+
+void UpdateScreen::OnUserAction(const std::string& action_id) {
+#if !defined(OFFICIAL_BUILD)
+ if (action_id == kUserActionCancelUpdateShortcut)
+ CancelUpdate();
+#endif
+}
+
+void UpdateScreen::OnContextKeyUpdated(
+ const ::login::ScreenContext::KeyType& key) {
+ UpdateModel::OnContextKeyUpdated(key);
+}
+
+void UpdateScreen::OnConnectToNetworkRequested() {
+ if (state_ == STATE_ERROR) {
+ LOG(WARNING) << "Hiding error message since AP was reselected";
+ StartUpdateCheck();
+ }
}
void UpdateScreen::ExitUpdate(UpdateScreen::ExitReason reason) {
@@ -378,8 +415,8 @@ void UpdateScreen::ExitUpdate(UpdateScreen::ExitReason reason) {
void UpdateScreen::OnWaitForRebootTimeElapsed() {
LOG(ERROR) << "Unable to reboot - asking user for a manual reboot.";
MakeSureScreenIsShown();
- if (actor_)
- actor_->ShowManualRebootInfo();
+ GetContextEditor().SetString(kContextKeyUpdateMessage,
+ l10n_util::GetStringUTF16(IDS_UPDATE_COMPLETED));
}
void UpdateScreen::MakeSureScreenIsShown() {
@@ -387,21 +424,17 @@ void UpdateScreen::MakeSureScreenIsShown() {
get_base_screen_delegate()->ShowCurrentScreen();
}
-void UpdateScreen::SetRebootCheckDelay(int seconds) {
- if (seconds <= 0)
- reboot_timer_.Stop();
- DCHECK(!reboot_timer_.IsRunning());
- reboot_check_delay_ = seconds;
-}
-
void UpdateScreen::SetIgnoreIdleStatus(bool ignore_idle_status) {
ignore_idle_status_ = ignore_idle_status;
}
+void UpdateScreen::CancelUpdate() {
+ VLOG(1) << "Forced update cancel";
+ ExitUpdate(REASON_UPDATE_CANCELED);
+}
+
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) {
// Estimate downloading rate.
@@ -437,14 +470,16 @@ void UpdateScreen::UpdateDownloadingStats(
// |bound possible estimations.
time_left = std::min(time_left, kMaxTimeLeft);
- actor_->ShowEstimatedTimeLeft(true);
- actor_->SetEstimatedTimeLeft(
- base::TimeDelta::FromSeconds(static_cast<int64>(time_left)));
+ GetContextEditor()
+ .SetBoolean(kContextKeyShowEstimatedTimeLeft, true)
+ .SetInteger(kContextKeyEstimatedTimeLeftSec,
+ static_cast<int>(time_left));
}
int download_progress = static_cast<int>(
status.download_progress * kDownloadProgressIncrement);
- actor_->SetProgress(kBeforeDownloadProgress + download_progress);
+ GetContextEditor().SetInteger(kContextKeyProgress,
+ kBeforeDownloadProgress + download_progress);
}
bool UpdateScreen::HasCriticalUpdate() {
@@ -466,18 +501,6 @@ bool UpdateScreen::HasCriticalUpdate() {
return true;
}
-void UpdateScreen::OnActorDestroyed(UpdateScreenActor* actor) {
- if (actor_ == actor)
- actor_ = NULL;
-}
-
-void UpdateScreen::OnConnectToNetworkRequested() {
- if (state_ == STATE_ERROR) {
- LOG(WARNING) << "Hiding error message since AP was reselected";
- StartUpdateCheck();
- }
-}
-
ErrorScreen* UpdateScreen::GetErrorScreen() {
return get_base_screen_delegate()->GetErrorScreen();
}
« no previous file with comments | « chrome/browser/chromeos/login/screens/update_screen.h ('k') | chrome/browser/chromeos/login/screens/update_screen_actor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698