Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Use of this source code is governed by a BSD-style license that can be | |
| 2 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/webui/help/version_updater_win.h" | |
| 6 | |
| 7 #include "base/i18n/rtl.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/string16.h" | |
| 11 #include "base/threading/thread_restrictions.h" | |
| 12 #include "base/version.h" | |
| 13 #include "base/win/windows_version.h" | |
| 14 #include "base/win/win_util.h" | |
| 15 #include "chrome/browser/ui/browser_list.h" | |
| 16 #include "chrome/common/chrome_version_info.h" | |
| 17 #include "chrome/installer/util/browser_distribution.h" | |
| 18 #include "chrome/installer/util/install_util.h" | |
| 19 #include "content/public/browser/user_metrics.h" | |
| 20 #include "grit/chromium_strings.h" | |
| 21 #include "grit/generated_resources.h" | |
| 22 #include "ui/base/l10n/l10n_util.h" | |
| 23 | |
| 24 using content::UserMetricsAction; | |
| 25 | |
| 26 VersionUpdater* VersionUpdater::Create() { | |
| 27 return new VersionUpdaterWin; | |
| 28 } | |
| 29 | |
| 30 VersionUpdaterWin::VersionUpdaterWin() | |
| 31 : google_updater_(new GoogleUpdate()) { | |
| 32 google_updater_->set_status_listener(this); | |
| 33 } | |
| 34 | |
| 35 VersionUpdaterWin::~VersionUpdaterWin() { | |
| 36 // The Google Updater will hold a pointer to us until it reports status, so we | |
| 37 // need to let it know that we will no longer be listening. | |
| 38 if (google_updater_) | |
| 39 google_updater_->set_status_listener(NULL); | |
| 40 } | |
| 41 | |
| 42 void VersionUpdaterWin::CheckForUpdate(const StatusCallback& callback) { | |
| 43 callback_ = callback; | |
| 44 | |
| 45 // On-demand updates for Chrome don't work in Vista RTM when UAC is turned | |
| 46 // off. So, in this case we just want the About box to not mention | |
| 47 // on-demand updates. Silent updates (in the background) should still | |
| 48 // work as before - enabling UAC or installing the latest service pack | |
| 49 // for Vista is another option. | |
| 50 if (!(base::win::GetVersion() == base::win::VERSION_VISTA && | |
| 51 (base::win::OSInfo::GetInstance()->service_pack().major == 0) && | |
| 52 !base::win::UserAccountControlIsEnabled())) { | |
| 53 UpdateStatus(UPGRADE_CHECK_STARTED, GOOGLE_UPDATE_NO_ERROR, string16()); | |
| 54 google_updater_->CheckForUpdate(false, // Don't upgrade yet. | |
| 55 NULL); // No window widget. | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 void VersionUpdaterWin::RelaunchBrowser() const { | |
| 60 BrowserList::AttemptRestart(); | |
| 61 } | |
| 62 | |
| 63 void VersionUpdaterWin::OnReportResults( | |
| 64 GoogleUpdateUpgradeResult result, GoogleUpdateErrorCode error_code, | |
| 65 const string16& error_message, const string16& version) { | |
| 66 // Drop the last reference to the object so that it gets cleaned up here. | |
| 67 google_updater_ = NULL; | |
| 68 UpdateStatus(result, error_code, error_message); | |
| 69 } | |
| 70 | |
| 71 void VersionUpdaterWin::UpdateStatus(GoogleUpdateUpgradeResult result, | |
| 72 GoogleUpdateErrorCode error_code, | |
| 73 const string16& error_message) { | |
| 74 #if !defined(GOOGLE_CHROME_BUILD) | |
| 75 // For Chromium builds it would show an error message. | |
| 76 // But it looks weird because in fact there is no error, | |
| 77 // just the update server is not available for non-official builds. | |
| 78 return; | |
| 79 #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
| |
| 80 | |
| 81 Status status = UPDATED; | |
| 82 string16 message; | |
| 83 | |
| 84 switch (result) { | |
| 85 case UPGRADE_CHECK_STARTED: { | |
| 86 content::RecordAction(UserMetricsAction("UpgradeCheck_Started")); | |
| 87 status = CHECKING; | |
| 88 break; | |
| 89 } | |
| 90 case UPGRADE_STARTED: { | |
| 91 content::RecordAction(UserMetricsAction("Upgrade_Started")); | |
| 92 status = UPDATING; | |
| 93 break; | |
| 94 } | |
| 95 case UPGRADE_IS_AVAILABLE: { | |
| 96 content::RecordAction( | |
| 97 UserMetricsAction("UpgradeCheck_UpgradeIsAvailable")); | |
| 98 DCHECK(!google_updater_); // Should have been nulled out already. | |
| 99 google_updater_ = new GoogleUpdate(); | |
| 100 google_updater_->set_status_listener(this); | |
| 101 UpdateStatus(UPGRADE_STARTED, GOOGLE_UPDATE_NO_ERROR, string16()); | |
| 102 google_updater_->CheckForUpdate(true, // Upgrade now. | |
| 103 NULL); // No window widget. | |
| 104 return; | |
| 105 } | |
| 106 case UPGRADE_ALREADY_UP_TO_DATE: { | |
| 107 // Google Update reported that Chrome is up-to-date. Now make sure that we | |
| 108 // are running the latest version and if not, notify the user by falling | |
| 109 // into the next case of UPGRADE_SUCCESSFUL. | |
| 110 // | |
| 111 // The extra version check is necessary on Windows because the application | |
| 112 // may be already up to date on disk though the running app is still | |
| 113 // out of date. Chrome OS doesn't quite have this issue since the | |
| 114 // OS/App are updated together. If a newer version of the OS has been | |
| 115 // staged then UPGRADE_SUCESSFUL will be returned. | |
| 116 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
| 117 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
| 118 chrome::VersionInfo version_info; | |
| 119 scoped_ptr<Version> installed_version( | |
| 120 InstallUtil::GetChromeVersion(dist, false)); | |
| 121 if (!installed_version.get()) { | |
| 122 // User-level Chrome is not installed, check system-level. | |
| 123 installed_version.reset(InstallUtil::GetChromeVersion(dist, true)); | |
| 124 } | |
| 125 scoped_ptr<Version> running_version( | |
| 126 Version::GetVersionFromString(version_info.Version())); | |
| 127 if (!installed_version.get() || | |
| 128 (installed_version->CompareTo(*running_version) <= 0)) { | |
| 129 content::RecordAction( | |
| 130 UserMetricsAction("UpgradeCheck_AlreadyUpToDate")); | |
| 131 status = UPDATED; | |
| 132 break; | |
| 133 } | |
| 134 | |
| 135 content::RecordAction(UserMetricsAction("UpgradeCheck_AlreadyUpgraded")); | |
| 136 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.
| |
| 137 } | |
| 138 case UPGRADE_SUCCESSFUL: { | |
| 139 content::RecordAction(UserMetricsAction("UpgradeCheck_Upgraded")); | |
| 140 status = NEARLY_UPDATED; | |
| 141 break; | |
| 142 } | |
| 143 case UPGRADE_ERROR: { | |
| 144 content::RecordAction(UserMetricsAction("UpgradeCheck_Error")); | |
| 145 status = FAILED; | |
| 146 if (!error_message.empty()) { | |
| 147 message = | |
| 148 l10n_util::GetStringFUTF16(IDS_ABOUT_BOX_ERROR_DURING_UPDATE_CHECK, | |
| 149 error_message); | |
| 150 } | |
| 151 if (error_code != GOOGLE_UPDATE_DISABLED_BY_POLICY) { | |
| 152 message = | |
| 153 l10n_util::GetStringFUTF16Int(IDS_UPGRADE_ERROR, error_code); | |
| 154 } else { | |
| 155 message = | |
| 156 l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY); | |
| 157 } | |
| 158 break; | |
| 159 } | |
| 160 } | |
| 161 | |
| 162 callback_.Run(status, 0, message); | |
| 163 } | |
| OLD | NEW |