summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/login/update_screen.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/chromeos/login/update_screen.cc')
-rw-r--r--chrome/browser/chromeos/login/update_screen.cc211
1 files changed, 113 insertions, 98 deletions
diff --git a/chrome/browser/chromeos/login/update_screen.cc b/chrome/browser/chromeos/login/update_screen.cc
index 8e9a05a..20b04b0 100644
--- a/chrome/browser/chromeos/login/update_screen.cc
+++ b/chrome/browser/chromeos/login/update_screen.cc
@@ -5,18 +5,24 @@
#include "chrome/browser/chromeos/login/update_screen.h"
#include "base/logging.h"
+#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/login/screen_observer.h"
#include "chrome/browser/chromeos/login/update_view.h"
namespace {
-// Update window should appear for at least kMinimalUpdateTime seconds.
-const int kMinimalUpdateTime = 3;
+// Progress bar stages. Each represents progress bar value
+// at the beginning of each stage.
+// TODO(nkostylev): Base stage progress values on approximate time.
+// TODO(nkostylev): Animate progress during each state.
+const int kBeforeUpdateCheckProgress = 7;
+const int kBeforeDownloadProgress = 14;
+const int kBeforeVerifyingProgress = 74;
+const int kBeforeFinalizingProgress = 81;
+const int kProgressComplete = 100;
-// Progress bar increment step.
-const int kBeforeUpdateCheckProgressIncrement = 10;
-const int kAfterUpdateCheckProgressIncrement = 10;
-const int kUpdateCompleteProgressIncrement = 75;
+// Defines what part of update progress does download part takes.
+const int kDownloadProgressIncrement = 60;
} // anonymous namespace
@@ -24,64 +30,64 @@ namespace chromeos {
UpdateScreen::UpdateScreen(WizardScreenDelegate* delegate)
: DefaultViewScreen<chromeos::UpdateView>(delegate),
- update_result_(UPGRADE_STARTED),
- update_error_(GOOGLE_UPDATE_NO_ERROR),
- checking_for_update_(true) {
+ checking_for_update_(true),
+ maximal_curtain_time_(0),
+ reboot_check_delay_(0) {
}
UpdateScreen::~UpdateScreen() {
// Remove pointer to this object from view.
if (view())
view()->set_controller(NULL);
- // Google Updater is holding a pointer to us until it reports status,
- // so we need to remove it in case we were still listening.
- if (google_updater_.get())
- google_updater_->set_status_listener(NULL);
+ CrosLibrary::Get()->GetUpdateLibrary()->RemoveObserver(this);
}
-void UpdateScreen::OnReportResults(GoogleUpdateUpgradeResult result,
- GoogleUpdateErrorCode error_code,
- const std::wstring& version) {
- // Drop the last reference to the object so that it gets cleaned up here.
- if (google_updater_.get()) {
- google_updater_->set_status_listener(NULL);
- google_updater_ = NULL;
+void UpdateScreen::UpdateStatusChanged(UpdateLibrary* library) {
+ UpdateStatusOperation status = library->status().status;
+ if (checking_for_update_ && status > UPDATE_STATUS_CHECKING_FOR_UPDATE) {
+ checking_for_update_ = false;
}
- // Depending on the result decide what to do next.
- update_result_ = result;
- update_error_ = error_code;
- LOG(INFO) << "Update result: " << result;
- if (error_code != GOOGLE_UPDATE_NO_ERROR)
- LOG(INFO) << "Update error code: " << error_code;
- LOG(INFO) << "Update version: " << version;
- switch (update_result_) {
- case UPGRADE_IS_AVAILABLE:
- checking_for_update_ = false;
- // Advance view progress bar.
- view()->AddProgress(kAfterUpdateCheckProgressIncrement);
- // Create new Google Updater instance and install the update.
- google_updater_ = CreateGoogleUpdate();
- google_updater_->CheckForUpdate(true, NULL);
- LOG(INFO) << "Installing an update";
+
+ switch (status) {
+ case UPDATE_STATUS_CHECKING_FOR_UPDATE:
+ // Do nothing in these cases, we don't want to notify the user of the
+ // check unless there is an update.
break;
- case UPGRADE_SUCCESSFUL:
- view()->AddProgress(kUpdateCompleteProgressIncrement);
- minimal_update_time_timer_.Stop();
- checking_for_update_ = false;
- // TODO(nkostylev): Call reboot API. http://crosbug.com/4002
- ExitUpdate();
+ case UPDATE_STATUS_UPDATE_AVAILABLE:
+ view()->SetProgress(kBeforeDownloadProgress);
+ LOG(INFO) << "Update available: " << library->status().new_version;
break;
- case UPGRADE_ALREADY_UP_TO_DATE:
- checking_for_update_ = false;
- view()->AddProgress(kAfterUpdateCheckProgressIncrement);
- // Fall through.
- case UPGRADE_ERROR:
- if (MinimalUpdateTimeElapsed()) {
- ExitUpdate();
+ case UPDATE_STATUS_DOWNLOADING:
+ {
+ view()->ShowCurtain(false);
+ int download_progress = static_cast<int>(
+ library->status().download_progress * kDownloadProgressIncrement);
+ view()->SetProgress(kBeforeDownloadProgress + download_progress);
}
break;
+ case UPDATE_STATUS_VERIFYING:
+ view()->SetProgress(kBeforeVerifyingProgress);
+ break;
+ case UPDATE_STATUS_FINALIZING:
+ view()->SetProgress(kBeforeFinalizingProgress);
+ break;
+ case UPDATE_STATUS_UPDATED_NEED_REBOOT:
+ view()->SetProgress(kProgressComplete);
+ view()->ShowCurtain(false);
+ CrosLibrary::Get()->GetUpdateLibrary()->RebootAfterUpdate();
+ LOG(INFO) << "Reboot API was called. Waiting for reboot.";
+ reboot_timer_.Start(base::TimeDelta::FromSeconds(reboot_check_delay_),
+ this,
+ &UpdateScreen::OnWaitForRebootTimeElapsed);
+ break;
+ case UPDATE_STATUS_IDLE:
+ case UPDATE_STATUS_ERROR:
+ case UPDATE_STATUS_REPORTING_ERROR_EVENT:
+ ExitUpdate();
+ break;
default:
NOTREACHED();
+ break;
}
}
@@ -90,72 +96,81 @@ void UpdateScreen::StartUpdate() {
view()->Reset();
view()->set_controller(this);
- // Start the minimal update time timer.
- minimal_update_time_timer_.Start(
- base::TimeDelta::FromSeconds(kMinimalUpdateTime),
- this,
- &UpdateScreen::OnMinimalUpdateTimeElapsed);
-
- // Create Google Updater object and check if there is an update available.
- checking_for_update_ = true;
- google_updater_ = CreateGoogleUpdate();
- google_updater_->CheckForUpdate(false, NULL);
- view()->AddProgress(kBeforeUpdateCheckProgressIncrement);
- LOG(INFO) << "Checking for update";
+ // Start the maximal curtain time timer.
+ if (maximal_curtain_time_ > 0) {
+ maximal_curtain_time_timer_.Start(
+ base::TimeDelta::FromSeconds(maximal_curtain_time_),
+ this,
+ &UpdateScreen::OnMaximalCurtainTimeElapsed);
+ } else {
+ view()->ShowCurtain(false);
+ }
+
+ view()->SetProgress(kBeforeUpdateCheckProgress);
+
+ if (!CrosLibrary::Get()->EnsureLoaded()) {
+ LOG(ERROR) << "Error loading CrosLibrary";
+ } else {
+ CrosLibrary::Get()->GetUpdateLibrary()->AddObserver(this);
+ LOG(INFO) << "Checking for update";
+ if (!CrosLibrary::Get()->GetUpdateLibrary()->CheckForUpdate()) {
+ ExitUpdate();
+ }
+ }
}
void UpdateScreen::CancelUpdate() {
#if !defined(OFFICIAL_BUILD)
- update_result_ = UPGRADE_ALREADY_UP_TO_DATE;
- update_error_ = GOOGLE_UPDATE_NO_ERROR;
ExitUpdate();
#endif
}
void UpdateScreen::ExitUpdate() {
- if (google_updater_.get()) {
- google_updater_->set_status_listener(NULL);
- google_updater_ = NULL;
- }
- minimal_update_time_timer_.Stop();
+ maximal_curtain_time_timer_.Stop();
ScreenObserver* observer = delegate()->GetObserver(this);
- if (observer) {
- switch (update_result_) {
- case UPGRADE_ALREADY_UP_TO_DATE:
- observer->OnExit(ScreenObserver::UPDATE_NOUPDATE);
- break;
- case UPGRADE_SUCCESSFUL:
- observer->OnExit(ScreenObserver::UPDATE_INSTALLED);
- break;
- case UPGRADE_ERROR:
- if (checking_for_update_) {
- observer->OnExit(ScreenObserver::UPDATE_ERROR_CHECKING_FOR_UPDATE);
- } else {
- observer->OnExit(ScreenObserver::UPDATE_ERROR_UPDATING);
- }
- break;
- default:
- NOTREACHED();
- }
+
+ if (!CrosLibrary::Get()->EnsureLoaded()) {
+ observer->OnExit(ScreenObserver::UPDATE_ERROR_CHECKING_FOR_UPDATE);
+ }
+
+ UpdateLibrary* update_library = CrosLibrary::Get()->GetUpdateLibrary();
+ update_library->RemoveObserver(this);
+ switch (update_library->status().status) {
+ case UPDATE_STATUS_IDLE:
+ observer->OnExit(ScreenObserver::UPDATE_NOUPDATE);
+ break;
+ case UPDATE_STATUS_ERROR:
+ case UPDATE_STATUS_REPORTING_ERROR_EVENT:
+ observer->OnExit(checking_for_update_ ?
+ ScreenObserver::UPDATE_ERROR_CHECKING_FOR_UPDATE :
+ ScreenObserver::UPDATE_ERROR_UPDATING);
+ break;
+ default:
+ NOTREACHED();
}
}
-bool UpdateScreen::MinimalUpdateTimeElapsed() {
- return !minimal_update_time_timer_.IsRunning();
+void UpdateScreen::OnMaximalCurtainTimeElapsed() {
+ view()->ShowCurtain(false);
}
-GoogleUpdate* UpdateScreen::CreateGoogleUpdate() {
- GoogleUpdate* updater = new GoogleUpdate();
- updater->set_status_listener(this);
- return updater;
+void UpdateScreen::OnWaitForRebootTimeElapsed() {
+ LOG(ERROR) << "Unable to reboot - asking user for a manual reboot.";
+ view()->ShowManualRebootInfo();
}
-void UpdateScreen::OnMinimalUpdateTimeElapsed() {
- if (update_result_ == UPGRADE_SUCCESSFUL ||
- update_result_ == UPGRADE_ALREADY_UP_TO_DATE ||
- update_result_ == UPGRADE_ERROR) {
- ExitUpdate();
- }
+void UpdateScreen::SetMaximalCurtainTime(int seconds) {
+ if (seconds <= 0)
+ maximal_curtain_time_timer_.Stop();
+ DCHECK(!maximal_curtain_time_timer_.IsRunning());
+ maximal_curtain_time_ = seconds;
+}
+
+void UpdateScreen::SetRebootCheckDelay(int seconds) {
+ if (seconds <= 0)
+ reboot_timer_.Stop();
+ DCHECK(!reboot_timer_.IsRunning());
+ reboot_check_delay_ = seconds;
}
} // namespace chromeos