Chromium Code Reviews| Index: chrome/browser/ui/webui/help/version_updater_win.cc |
| diff --git a/chrome/browser/ui/webui/help/version_updater_win.cc b/chrome/browser/ui/webui/help/version_updater_win.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9621591d81855e24592010ea09b51751d48272bf |
| --- /dev/null |
| +++ b/chrome/browser/ui/webui/help/version_updater_win.cc |
| @@ -0,0 +1,163 @@ |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/webui/help/version_updater_win.h" |
| + |
| +#include "base/i18n/rtl.h" |
| +#include "base/logging.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/string16.h" |
| +#include "base/threading/thread_restrictions.h" |
| +#include "base/version.h" |
| +#include "base/win/windows_version.h" |
| +#include "base/win/win_util.h" |
| +#include "chrome/browser/ui/browser_list.h" |
| +#include "chrome/common/chrome_version_info.h" |
| +#include "chrome/installer/util/browser_distribution.h" |
| +#include "chrome/installer/util/install_util.h" |
| +#include "content/public/browser/user_metrics.h" |
| +#include "grit/chromium_strings.h" |
| +#include "grit/generated_resources.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| + |
| +using content::UserMetricsAction; |
| + |
| +VersionUpdater* VersionUpdater::Create() { |
| + return new VersionUpdaterWin; |
| +} |
| + |
| +VersionUpdaterWin::VersionUpdaterWin() |
| + : google_updater_(new GoogleUpdate()) { |
| + google_updater_->set_status_listener(this); |
| +} |
| + |
| +VersionUpdaterWin::~VersionUpdaterWin() { |
| + // The Google Updater will hold a pointer to us until it reports status, so we |
| + // need to let it know that we will no longer be listening. |
| + if (google_updater_) |
| + google_updater_->set_status_listener(NULL); |
| +} |
| + |
| +void VersionUpdaterWin::CheckForUpdate(const StatusCallback& callback) { |
| + callback_ = callback; |
| + |
| + // On-demand updates for Chrome don't work in Vista RTM when UAC is turned |
| + // off. So, in this case we just want the About box to not mention |
| + // on-demand updates. Silent updates (in the background) should still |
| + // work as before - enabling UAC or installing the latest service pack |
| + // for Vista is another option. |
| + if (!(base::win::GetVersion() == base::win::VERSION_VISTA && |
| + (base::win::OSInfo::GetInstance()->service_pack().major == 0) && |
| + !base::win::UserAccountControlIsEnabled())) { |
| + UpdateStatus(UPGRADE_CHECK_STARTED, GOOGLE_UPDATE_NO_ERROR, string16()); |
| + google_updater_->CheckForUpdate(false, // Don't upgrade yet. |
| + NULL); // No window widget. |
| + } |
| +} |
| + |
| +void VersionUpdaterWin::RelaunchBrowser() const { |
| + BrowserList::AttemptRestart(); |
| +} |
| + |
| +void VersionUpdaterWin::OnReportResults( |
| + GoogleUpdateUpgradeResult result, GoogleUpdateErrorCode error_code, |
| + const string16& error_message, const string16& version) { |
| + // Drop the last reference to the object so that it gets cleaned up here. |
| + google_updater_ = NULL; |
| + UpdateStatus(result, error_code, error_message); |
| +} |
| + |
| +void VersionUpdaterWin::UpdateStatus(GoogleUpdateUpgradeResult result, |
| + GoogleUpdateErrorCode error_code, |
| + const string16& error_message) { |
| +#if !defined(GOOGLE_CHROME_BUILD) |
| + // For Chromium builds it would show an error message. |
| + // But it looks weird because in fact there is no error, |
| + // just the update server is not available for non-official builds. |
| + return; |
| +#endif |
|
Finnur
2012/03/27 10:44:25
This comment is (and was) misleading. We show an e
James Hawkins
2012/03/28 20:52:32
That's not currently the case, though we can make
Finnur
2012/03/28 22:09:12
It is good to have an error to look up, as opposed
|
| + |
| + Status status = UPDATED; |
| + string16 message; |
| + |
| + switch (result) { |
| + case UPGRADE_CHECK_STARTED: { |
| + content::RecordAction(UserMetricsAction("UpgradeCheck_Started")); |
| + status = CHECKING; |
| + break; |
| + } |
| + case UPGRADE_STARTED: { |
| + content::RecordAction(UserMetricsAction("Upgrade_Started")); |
| + status = UPDATING; |
| + break; |
| + } |
| + case UPGRADE_IS_AVAILABLE: { |
| + content::RecordAction( |
| + UserMetricsAction("UpgradeCheck_UpgradeIsAvailable")); |
| + DCHECK(!google_updater_); // Should have been nulled out already. |
| + google_updater_ = new GoogleUpdate(); |
| + google_updater_->set_status_listener(this); |
| + UpdateStatus(UPGRADE_STARTED, GOOGLE_UPDATE_NO_ERROR, string16()); |
| + google_updater_->CheckForUpdate(true, // Upgrade now. |
| + NULL); // No window widget. |
| + return; |
| + } |
| + case UPGRADE_ALREADY_UP_TO_DATE: { |
| + // Google Update reported that Chrome is up-to-date. Now make sure that we |
| + // are running the latest version and if not, notify the user by falling |
| + // into the next case of UPGRADE_SUCCESSFUL. |
| + // |
| + // The extra version check is necessary on Windows because the application |
| + // may be already up to date on disk though the running app is still |
| + // out of date. Chrome OS doesn't quite have this issue since the |
| + // OS/App are updated together. If a newer version of the OS has been |
| + // staged then UPGRADE_SUCESSFUL will be returned. |
| + BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| + base::ThreadRestrictions::ScopedAllowIO allow_io; |
| + chrome::VersionInfo version_info; |
| + scoped_ptr<Version> installed_version( |
| + InstallUtil::GetChromeVersion(dist, false)); |
| + if (!installed_version.get()) { |
| + // User-level Chrome is not installed, check system-level. |
| + installed_version.reset(InstallUtil::GetChromeVersion(dist, true)); |
| + } |
| + scoped_ptr<Version> running_version( |
| + Version::GetVersionFromString(version_info.Version())); |
| + if (!installed_version.get() || |
| + (installed_version->CompareTo(*running_version) <= 0)) { |
| + content::RecordAction( |
| + UserMetricsAction("UpgradeCheck_AlreadyUpToDate")); |
| + status = UPDATED; |
| + break; |
| + } |
| + |
| + content::RecordAction(UserMetricsAction("UpgradeCheck_AlreadyUpgraded")); |
| + status = NEARLY_UPDATED; |
|
Finnur
2012/03/27 10:44:25
Umm... aren't you missing a break here now to avoi
James Hawkins
2012/03/28 20:52:32
Done.
|
| + } |
| + case UPGRADE_SUCCESSFUL: { |
| + content::RecordAction(UserMetricsAction("UpgradeCheck_Upgraded")); |
| + status = NEARLY_UPDATED; |
| + break; |
| + } |
| + case UPGRADE_ERROR: { |
| + content::RecordAction(UserMetricsAction("UpgradeCheck_Error")); |
| + status = FAILED; |
| + if (!error_message.empty()) { |
| + message = |
| + l10n_util::GetStringFUTF16(IDS_ABOUT_BOX_ERROR_DURING_UPDATE_CHECK, |
| + error_message); |
| + } |
| + if (error_code != GOOGLE_UPDATE_DISABLED_BY_POLICY) { |
| + message = |
| + l10n_util::GetStringFUTF16Int(IDS_UPGRADE_ERROR, error_code); |
| + } else { |
| + message = |
| + l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY); |
| + } |
| + break; |
| + } |
| + } |
| + |
| + callback_.Run(status, 0, message); |
| +} |