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. | |
|
Finnur
2012/03/16 12:03:22
How does setting a NULL window widget work when up
James Hawkins
2012/03/26 23:18:14
I didn't quite understand the requirement of the w
Finnur
2012/03/27 10:44:25
InitiateGoogleUpdateCheck needs the widget for ele
James Hawkins
2012/03/28 20:52:32
We don't have a GetWidget() for WebUI. So you're
Finnur
2012/03/28 22:09:12
Oh, I see. In that case it doesn't matter, I guess
ananta
2012/03/30 20:52:54
I don't remember adding this code :(. However Finn
| |
| 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) { | |
|
Finnur
2012/03/16 12:03:22
Where's the check to make sure we don't try to upg
James Hawkins
2012/03/26 23:18:14
Done.
| |
| 74 Status status = UPDATED; | |
| 75 string16 message; | |
| 76 | |
| 77 switch (result) { | |
| 78 case UPGRADE_CHECK_STARTED: { | |
| 79 content::RecordAction(UserMetricsAction("UpgradeCheck_Started")); | |
| 80 status = CHECKING; | |
| 81 break; | |
| 82 } | |
| 83 case UPGRADE_STARTED: { | |
| 84 content::RecordAction(UserMetricsAction("Upgrade_Started")); | |
| 85 status = UPDATING; | |
| 86 break; | |
| 87 } | |
| 88 case UPGRADE_IS_AVAILABLE: { | |
| 89 content::RecordAction( | |
| 90 UserMetricsAction("UpgradeCheck_UpgradeIsAvailable")); | |
| 91 DCHECK(!google_updater_); // Should have been nulled out already. | |
| 92 google_updater_ = new GoogleUpdate(); | |
| 93 google_updater_->set_status_listener(this); | |
| 94 UpdateStatus(UPGRADE_STARTED, GOOGLE_UPDATE_NO_ERROR, string16()); | |
| 95 google_updater_->CheckForUpdate(true, // Upgrade now. | |
| 96 NULL); // No window widget. | |
|
Finnur
2012/03/16 12:03:22
Is the page that shows this a singleton or can the
James Hawkins
2012/03/26 23:18:14
chrome:chrome (and thus the help page) is a single
| |
| 97 return; | |
| 98 } | |
| 99 case UPGRADE_ALREADY_UP_TO_DATE: { | |
| 100 // The extra version check is necessary on Windows because the application | |
| 101 // may be already up to date on disk though the running app is still | |
| 102 // out of date. Chrome OS doesn't quite have this issue since the | |
| 103 // OS/App are updated together. If a newer version of the OS has been | |
| 104 // staged then UPGRADE_SUCESSFUL will be returned. | |
|
Finnur
2012/03/16 12:03:22
nit: Separate these two clauses with linebreak and
James Hawkins
2012/03/26 23:18:14
Done.
| |
| 105 // Google Update reported that Chrome is up-to-date. Now make sure that we | |
| 106 // are running the latest version and if not, notify the user by falling | |
| 107 // into the next case of UPGRADE_SUCCESSFUL. | |
| 108 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
| 109 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
| 110 chrome::VersionInfo version_info; | |
| 111 scoped_ptr<Version> installed_version( | |
| 112 InstallUtil::GetChromeVersion(dist, false)); | |
| 113 if (!installed_version.get()) { | |
| 114 // User-level Chrome is not installed, check system-level. | |
| 115 installed_version.reset(InstallUtil::GetChromeVersion(dist, true)); | |
| 116 } | |
| 117 scoped_ptr<Version> running_version( | |
| 118 Version::GetVersionFromString(version_info.Version())); | |
| 119 if (!installed_version.get() || | |
| 120 (installed_version->CompareTo(*running_version) <= 0)) { | |
| 121 content::RecordAction( | |
| 122 UserMetricsAction("UpgradeCheck_AlreadyUpToDate")); | |
| 123 status = UPDATED; | |
| 124 break; | |
| 125 } | |
| 126 // No break here as we want to notify user about upgrade if there is one. | |
| 127 } | |
| 128 case UPGRADE_SUCCESSFUL: { | |
| 129 if (result == UPGRADE_ALREADY_UP_TO_DATE) | |
| 130 content::RecordAction( | |
| 131 UserMetricsAction("UpgradeCheck_AlreadyUpgraded")); | |
| 132 else | |
| 133 content::RecordAction(UserMetricsAction("UpgradeCheck_Upgraded")); | |
|
Finnur
2012/03/16 12:03:22
You need braces (multiline).
Alternatively (since
James Hawkins
2012/03/26 23:18:14
Done.
| |
| 134 status = NEARLY_UPDATED; | |
| 135 break; | |
| 136 } | |
| 137 case UPGRADE_ERROR: { | |
| 138 content::RecordAction(UserMetricsAction("UpgradeCheck_Error")); | |
| 139 status = FAILED; | |
| 140 if (!error_message.empty()) { | |
| 141 message = | |
| 142 l10n_util::GetStringFUTF16(IDS_ABOUT_BOX_ERROR_DURING_UPDATE_CHECK, | |
| 143 error_message); | |
| 144 } | |
| 145 if (error_code != GOOGLE_UPDATE_DISABLED_BY_POLICY) { | |
| 146 message = | |
| 147 l10n_util::GetStringFUTF16Int(IDS_UPGRADE_ERROR, error_code); | |
| 148 } else { | |
| 149 message = | |
| 150 l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY); | |
| 151 } | |
| 152 break; | |
| 153 } | |
| 154 } | |
| 155 | |
| 156 callback_.Run(status, 0, message); | |
| 157 } | |
| OLD | NEW |