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

Side by Side Diff: chrome/browser/ui/webui/help/version_updater_win.cc

Issue 1117263002: Switch on-demand update checks to the less-old GoogleUpdate3 API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: better ui message when updates are disabled by policy Created 5 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm>
6
5 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
6 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
7 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
8 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
9 #include "base/version.h" 11 #include "base/version.h"
10 #include "base/win/win_util.h" 12 #include "base/win/win_util.h"
11 #include "base/win/windows_version.h" 13 #include "base/win/windows_version.h"
14 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/google/google_update_win.h" 15 #include "chrome/browser/google/google_update_win.h"
13 #include "chrome/browser/lifetime/application_lifetime.h" 16 #include "chrome/browser/lifetime/application_lifetime.h"
14 #include "chrome/browser/ui/browser.h" 17 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/webui/help/version_updater.h" 18 #include "chrome/browser/ui/webui/help/version_updater.h"
16 #include "chrome/common/chrome_version_info.h" 19 #include "chrome/common/chrome_version_info.h"
17 #include "chrome/grit/chromium_strings.h" 20 #include "chrome/grit/chromium_strings.h"
18 #include "chrome/grit/generated_resources.h" 21 #include "chrome/grit/generated_resources.h"
19 #include "chrome/installer/util/browser_distribution.h" 22 #include "chrome/installer/util/browser_distribution.h"
20 #include "chrome/installer/util/install_util.h" 23 #include "chrome/installer/util/install_util.h"
21 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
(...skipping 15 matching lines...) Expand all
37 // Clients must use VersionUpdater::Create(). 40 // Clients must use VersionUpdater::Create().
38 VersionUpdaterWin(); 41 VersionUpdaterWin();
39 ~VersionUpdaterWin() override; 42 ~VersionUpdaterWin() override;
40 43
41 // VersionUpdater implementation. 44 // VersionUpdater implementation.
42 void CheckForUpdate(const StatusCallback& callback) override; 45 void CheckForUpdate(const StatusCallback& callback) override;
43 void RelaunchBrowser() const override; 46 void RelaunchBrowser() const override;
44 47
45 // chrome::UpdateCheckCallback. 48 // chrome::UpdateCheckCallback.
46 void OnUpdateCheckResults(GoogleUpdateUpgradeResult result, 49 void OnUpdateCheckResults(GoogleUpdateUpgradeResult result,
50 double progress,
47 GoogleUpdateErrorCode error_code, 51 GoogleUpdateErrorCode error_code,
48 const base::string16& error_message, 52 const base::string16& error_message,
49 const base::string16& version); 53 const base::string16& version);
50 54
51 // Update the UI to show the status of the upgrade. 55 // Update the UI to show the status of the upgrade.
52 void UpdateStatus(GoogleUpdateUpgradeResult result, 56 void UpdateStatus(GoogleUpdateUpgradeResult result,
57 double update_progress,
53 GoogleUpdateErrorCode error_code, 58 GoogleUpdateErrorCode error_code,
54 const base::string16& error_message); 59 const base::string16& error_message);
55 60
56 // Got the intalled version so the handling of the UPGRADE_ALREADY_UP_TO_DATE 61 // Got the intalled version so the handling of the UPGRADE_ALREADY_UP_TO_DATE
57 // result case can now be completeb on the UI thread. 62 // result case can now be completeb on the UI thread.
58 void GotInstalledVersion(const Version& version); 63 void GotInstalledVersion(const Version& version);
59 64
60 // Returns a window that can be used for elevation. 65 // Returns a window that can be used for elevation.
61 gfx::AcceleratedWidget GetElevationParent(); 66 gfx::AcceleratedWidget GetElevationParent();
62 67
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 callback_ = callback; 130 callback_ = callback;
126 131
127 // On-demand updates for Chrome don't work in Vista RTM when UAC is turned 132 // On-demand updates for Chrome don't work in Vista RTM when UAC is turned
128 // off. So, in this case, the version updater must not mention 133 // off. So, in this case, the version updater must not mention
129 // on-demand updates. Silent updates (in the background) should still 134 // on-demand updates. Silent updates (in the background) should still
130 // work as before - enabling UAC or installing the latest service pack 135 // work as before - enabling UAC or installing the latest service pack
131 // for Vista is another option. 136 // for Vista is another option.
132 if (!(base::win::GetVersion() == base::win::VERSION_VISTA && 137 if (!(base::win::GetVersion() == base::win::VERSION_VISTA &&
133 (base::win::OSInfo::GetInstance()->service_pack().major == 0) && 138 (base::win::OSInfo::GetInstance()->service_pack().major == 0) &&
134 !base::win::UserAccountControlIsEnabled())) { 139 !base::win::UserAccountControlIsEnabled())) {
135 UpdateStatus(UPGRADE_CHECK_STARTED, GOOGLE_UPDATE_NO_ERROR, 140 UpdateStatus(UPGRADE_CHECK_STARTED, 0.0, GOOGLE_UPDATE_NO_ERROR,
136 base::string16()); 141 base::string16());
137 // Specify false to not upgrade yet. 142 // Specify false to not upgrade yet.
138 BeginUpdateCheckOnFileThread(false); 143 BeginUpdateCheckOnFileThread(false);
139 } 144 }
140 } 145 }
141 146
142 void VersionUpdaterWin::RelaunchBrowser() const { 147 void VersionUpdaterWin::RelaunchBrowser() const {
143 chrome::AttemptRestart(); 148 chrome::AttemptRestart();
144 } 149 }
145 150
146 void VersionUpdaterWin::OnUpdateCheckResults( 151 void VersionUpdaterWin::OnUpdateCheckResults(
147 GoogleUpdateUpgradeResult result, 152 GoogleUpdateUpgradeResult result,
153 double progress,
148 GoogleUpdateErrorCode error_code, 154 GoogleUpdateErrorCode error_code,
149 const base::string16& error_message, 155 const base::string16& error_message,
150 const base::string16& version) { 156 const base::string16& version) {
151 UpdateStatus(result, error_code, error_message); 157 UpdateStatus(result, progress, error_code, error_message);
152 } 158 }
153 159
154 void VersionUpdaterWin::UpdateStatus(GoogleUpdateUpgradeResult result, 160 void VersionUpdaterWin::UpdateStatus(GoogleUpdateUpgradeResult result,
161 double update_progress,
155 GoogleUpdateErrorCode error_code, 162 GoogleUpdateErrorCode error_code,
156 const base::string16& error_message) { 163 const base::string16& error_message) {
157 // For Chromium builds it would show an error message. 164 // For Chromium builds it would show an error message.
158 // But it looks weird because in fact there is no error, 165 // But it looks weird because in fact there is no error,
159 // just the update server is not available for non-official builds. 166 // just the update server is not available for non-official builds.
160 #if defined(GOOGLE_CHROME_BUILD) 167 #if defined(GOOGLE_CHROME_BUILD)
161 Status status = UPDATED; 168 Status status = UPDATED;
169 int progress = 0;
162 base::string16 message; 170 base::string16 message;
163 171
164 switch (result) { 172 switch (result) {
165 case UPGRADE_CHECK_STARTED: { 173 case UPGRADE_CHECK_STARTED: {
166 status = CHECKING; 174 status = CHECKING;
167 break; 175 break;
168 } 176 }
169 case UPGRADE_STARTED: { 177 case UPGRADE_STARTED: {
170 status = UPDATING; 178 status = UPDATING;
179 progress = static_cast<int>((update_progress * 100.0) + 0.5);
Peter Kasting 2015/05/07 01:12:28 Technically, things like this should probably use
grt (UTC plus 2) 2015/05/08 18:51:51 Awesome, I didn't know that was a thing.
180 progress = std::min(progress, 100);
171 break; 181 break;
172 } 182 }
173 case UPGRADE_IS_AVAILABLE: { 183 case UPGRADE_IS_AVAILABLE: {
174 UpdateStatus(UPGRADE_STARTED, GOOGLE_UPDATE_NO_ERROR, base::string16()); 184 UpdateStatus(UPGRADE_STARTED, 0.0, GOOGLE_UPDATE_NO_ERROR,
185 base::string16());
175 // Specify true to upgrade now. 186 // Specify true to upgrade now.
176 BeginUpdateCheckOnFileThread(true); 187 BeginUpdateCheckOnFileThread(true);
177 return; 188 return;
178 } 189 }
179 case UPGRADE_ALREADY_UP_TO_DATE: { 190 case UPGRADE_ALREADY_UP_TO_DATE: {
180 // Google Update reported that Chrome is up-to-date. 191 // Google Update reported that Chrome is up-to-date.
181 // To confirm the updated version is running, the reading 192 // To confirm the updated version is running, the reading
182 // must be done on the file thread. The rest of this case 193 // must be done on the file thread. The rest of this case
183 // will be handled within GotInstalledVersion. 194 // will be handled within GotInstalledVersion.
184 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, base::Bind( 195 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, base::Bind(
185 &VersionReader::GetVersionFromFileThread, 196 &VersionReader::GetVersionFromFileThread,
186 new VersionReader(weak_factory_.GetWeakPtr()))); 197 new VersionReader(weak_factory_.GetWeakPtr())));
187 return; 198 return;
188 } 199 }
189 case UPGRADE_SUCCESSFUL: { 200 case UPGRADE_SUCCESSFUL: {
190 status = NEARLY_UPDATED; 201 status = NEARLY_UPDATED;
191 break; 202 break;
192 } 203 }
193 case UPGRADE_ERROR: { 204 case UPGRADE_ERROR: {
194 status = FAILED; 205 status = FAILED;
195 if (error_code == GOOGLE_UPDATE_DISABLED_BY_POLICY) { 206 // Google Update provides a nice message for the policy case. Use this
196 message = 207 // generic error for the policy case only if no message from Google Update
197 l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY); 208 // is missing.
Peter Kasting 2015/05/07 01:12:28 "if no message is missing"? Is there a double neg
grt (UTC plus 2) 2015/05/08 18:51:51 Done.
198 } else if (error_code == GOOGLE_UPDATE_DISABLED_BY_POLICY_AUTO_ONLY) { 209 if (error_code != GOOGLE_UPDATE_DISABLED_BY_POLICY ||
199 message = 210 error_message.empty()) {
200 l10n_util::GetStringUTF16(IDS_UPGRADE_DISABLED_BY_POLICY_MANUAL);
201 } else {
202 message = 211 message =
203 l10n_util::GetStringFUTF16Int(IDS_UPGRADE_ERROR, error_code); 212 l10n_util::GetStringFUTF16Int(IDS_UPGRADE_ERROR, error_code);
204 } 213 }
205 214
206 if (!error_message.empty()) { 215 if (!error_message.empty()) {
207 message += 216 message +=
208 l10n_util::GetStringFUTF16(IDS_ABOUT_BOX_ERROR_DURING_UPDATE_CHECK, 217 l10n_util::GetStringFUTF16(IDS_ABOUT_BOX_ERROR_DURING_UPDATE_CHECK,
209 error_message); 218 error_message);
210 } 219 }
211 break; 220 break;
212 } 221 }
213 } 222 }
214 223
215 // TODO(mad): Get proper progress value instead of passing 0. 224 callback_.Run(status, progress, message);
216 // http://crbug.com/136117
217 callback_.Run(status, 0, message);
218 #endif // defined(GOOGLE_CHROME_BUILD) 225 #endif // defined(GOOGLE_CHROME_BUILD)
219 } 226 }
220 227
221 void VersionUpdaterWin::GotInstalledVersion(const Version& version) { 228 void VersionUpdaterWin::GotInstalledVersion(const Version& version) {
222 // This must be called on the UI thread so that callback_ can be called. 229 // This must be called on the UI thread so that callback_ can be called.
223 DCHECK_CURRENTLY_ON(BrowserThread::UI); 230 DCHECK_CURRENTLY_ON(BrowserThread::UI);
224 231
225 // Make sure that the latest version is running and if not, 232 // Make sure that the latest version is running and if not,
226 // notify the user by setting the status to NEARLY_UPDATED. 233 // notify the user by setting the status to NEARLY_UPDATED.
227 // 234 //
(...skipping 25 matching lines...) Expand all
253 EnumThreadWindows(GetCurrentThreadId(), 260 EnumThreadWindows(GetCurrentThreadId(),
254 WindowEnumeration, 261 WindowEnumeration,
255 reinterpret_cast<LPARAM>(&window)); 262 reinterpret_cast<LPARAM>(&window));
256 return window; 263 return window;
257 } 264 }
258 265
259 void VersionUpdaterWin::BeginUpdateCheckOnFileThread(bool install_if_newer) { 266 void VersionUpdaterWin::BeginUpdateCheckOnFileThread(bool install_if_newer) {
260 scoped_refptr<base::TaskRunner> task_runner( 267 scoped_refptr<base::TaskRunner> task_runner(
261 content::BrowserThread::GetMessageLoopProxyForThread( 268 content::BrowserThread::GetMessageLoopProxyForThread(
262 content::BrowserThread::FILE)); 269 content::BrowserThread::FILE));
263 BeginUpdateCheck(task_runner, install_if_newer, GetElevationParent(), 270 BeginUpdateCheck(task_runner, g_browser_process->GetApplicationLocale(),
271 install_if_newer, GetElevationParent(),
264 base::Bind(&VersionUpdaterWin::OnUpdateCheckResults, 272 base::Bind(&VersionUpdaterWin::OnUpdateCheckResults,
265 weak_factory_.GetWeakPtr())); 273 weak_factory_.GetWeakPtr()));
266 } 274 }
267 275
268 } // namespace 276 } // namespace
269 277
270 VersionUpdater* VersionUpdater::Create(content::BrowserContext* /* context */) { 278 VersionUpdater* VersionUpdater::Create(content::BrowserContext* /* context */) {
271 return new VersionUpdaterWin; 279 return new VersionUpdaterWin;
272 } 280 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698