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

Side by Side Diff: chrome/browser/google/google_update_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: chromium tweak 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 "chrome/browser/google/google_update_win.h" 5 #include "chrome/browser/google/google_update_win.h"
6 6
7 #include <atlbase.h> 7 #include <atlbase.h>
8 #include <atlcom.h> 8 #include <atlcom.h>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "base/metrics/sparse_histogram.h" 15 #include "base/metrics/sparse_histogram.h"
16 #include "base/path_service.h" 16 #include "base/path_service.h"
17 #include "base/sequenced_task_runner_helpers.h"
18 #include "base/single_thread_task_runner.h"
17 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
18 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
19 #include "base/task_runner.h" 21 #include "base/strings/utf_string_conversions.h"
20 #include "base/thread_task_runner_handle.h" 22 #include "base/thread_task_runner_handle.h"
23 #include "base/time/time.h"
24 #include "base/win/scoped_bstr.h"
21 #include "base/win/windows_version.h" 25 #include "base/win/windows_version.h"
22 #include "chrome/grit/generated_resources.h" 26 #include "chrome/grit/generated_resources.h"
23 #include "chrome/installer/util/browser_distribution.h" 27 #include "chrome/installer/util/browser_distribution.h"
24 #include "chrome/installer/util/google_update_settings.h"
25 #include "chrome/installer/util/helper.h" 28 #include "chrome/installer/util/helper.h"
26 #include "chrome/installer/util/install_util.h" 29 #include "chrome/installer/util/install_util.h"
27 #include "content/public/browser/browser_thread.h"
28 #include "ui/base/l10n/l10n_util.h" 30 #include "ui/base/l10n/l10n_util.h"
29 #include "ui/base/win/atl_module.h" 31 #include "ui/base/win/atl_module.h"
32 #include "ui/gfx/geometry/safe_integer_conversions.h"
30 33
31 namespace { 34 namespace {
32 35
33 OnDemandAppsClassFactory* g_google_update_factory = nullptr; 36 // The status of the upgrade. UPGRADE_STARTED and UPGRADE_CHECK_STARTED are
37 // internal states and will not be reported as results to the listener.
38 // These values are used for a histogram. Do not reorder.
39 enum GoogleUpdateUpgradeResult {
Peter Kasting 2015/05/09 02:19:01 Nit: I still kinda think "Status" would be a bette
grt (UTC plus 2) 2015/05/12 20:21:51 Done.
40 // The upgrade has started. DEPRECATED.
41 // UPGRADE_STARTED = 0,
42 // A check for upgrade has been initiated. DEPRECATED.
43 // UPGRADE_CHECK_STARTED = 1,
44 // An update is available.
45 UPGRADE_IS_AVAILABLE = 2,
46 // The upgrade happened successfully.
47 UPGRADE_SUCCESSFUL = 3,
48 // No need to upgrade, Chrome is up to date.
49 UPGRADE_ALREADY_UP_TO_DATE = 4,
50 // An error occurred.
51 UPGRADE_ERROR = 5,
52 NUM_UPGRADE_RESULTS
53 };
54
55 GoogleUpdate3ClassFactory* g_google_update_factory = nullptr;
56
57 // The time interval, in milliseconds, between polls to Google Update. This
58 // value was chosen unscientificaly during an informal discussion.
59 const int64_t kGoogleUpdatePollIntervalMs = 250;
Peter Kasting 2015/05/09 02:19:02 Nit: I would define this in the narrowest possible
grt (UTC plus 2) 2015/05/12 20:21:51 I believe the convention is to have constants like
Peter Kasting 2015/05/12 22:04:33 There are examples both ways in the code. It's no
grt (UTC plus 2) 2015/05/13 13:04:04 Just so you know that this choice isn't arbitrary:
60
61 // Constants from Google Update.
62 const HRESULT GOOPDATE_E_APP_UPDATE_DISABLED_BY_POLICY = 0x80040813;
63 const HRESULT GOOPDATEINSTALL_E_INSTALLER_FAILED = 0x80040902;
34 64
35 // Check if the currently running instance can be updated by Google Update. 65 // Check if the currently running instance can be updated by Google Update.
36 // Returns GOOGLE_UPDATE_NO_ERROR only if the instance running is a Google 66 // Returns GOOGLE_UPDATE_NO_ERROR only if the instance running is a Google
37 // Chrome distribution installed in a standard location. 67 // Chrome distribution installed in a standard location.
38 GoogleUpdateErrorCode CanUpdateCurrentChrome( 68 GoogleUpdateErrorCode CanUpdateCurrentChrome(
39 const base::FilePath& chrome_exe_path, 69 const base::FilePath& chrome_exe_path,
40 bool system_level) { 70 bool system_level) {
41 #if !defined(GOOGLE_CHROME_BUILD) 71 #if !defined(GOOGLE_CHROME_BUILD)
42 return CANNOT_UPGRADE_CHROME_IN_THIS_DIRECTORY; 72 return CANNOT_UPGRADE_CHROME_IN_THIS_DIRECTORY;
43 #else 73 #else
44 DCHECK_NE(InstallUtil::IsPerUserInstall(chrome_exe_path), system_level); 74 DCHECK_NE(InstallUtil::IsPerUserInstall(chrome_exe_path), system_level);
45 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 75 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
46 base::FilePath user_exe_path = installer::GetChromeInstallPath(false, dist); 76 base::FilePath user_exe_path = installer::GetChromeInstallPath(false, dist);
47 base::FilePath machine_exe_path = installer::GetChromeInstallPath(true, dist); 77 base::FilePath machine_exe_path = installer::GetChromeInstallPath(true, dist);
48 if (!base::FilePath::CompareEqualIgnoreCase(chrome_exe_path.value(), 78 if (!base::FilePath::CompareEqualIgnoreCase(chrome_exe_path.value(),
49 user_exe_path.value()) && 79 user_exe_path.value()) &&
50 !base::FilePath::CompareEqualIgnoreCase(chrome_exe_path.value(), 80 !base::FilePath::CompareEqualIgnoreCase(chrome_exe_path.value(),
51 machine_exe_path.value())) { 81 machine_exe_path.value())) {
52 return CANNOT_UPGRADE_CHROME_IN_THIS_DIRECTORY; 82 return CANNOT_UPGRADE_CHROME_IN_THIS_DIRECTORY;
53 } 83 }
54 84
55 base::string16 app_guid = installer::GetAppGuidForUpdates(system_level);
56 DCHECK(!app_guid.empty());
57
58 GoogleUpdateSettings::UpdatePolicy update_policy =
59 GoogleUpdateSettings::GetAppUpdatePolicy(app_guid, NULL);
60
61 if (update_policy == GoogleUpdateSettings::UPDATES_DISABLED)
62 return GOOGLE_UPDATE_DISABLED_BY_POLICY;
63
64 if (update_policy == GoogleUpdateSettings::AUTO_UPDATES_ONLY)
65 return GOOGLE_UPDATE_DISABLED_BY_POLICY_AUTO_ONLY;
66
67 return GOOGLE_UPDATE_NO_ERROR; 85 return GOOGLE_UPDATE_NO_ERROR;
68 #endif 86 #endif
69 } 87 }
70 88
71 // Creates an instance of a COM Local Server class using either plain vanilla 89 // Creates an instance of a COM Local Server class using either plain vanilla
72 // CoCreateInstance, or using the Elevation moniker if running on Vista. 90 // CoCreateInstance, or using the Elevation moniker if running on Vista.
73 // hwnd must refer to a foregound window in order to get the UAC prompt 91 // hwnd must refer to a foregound window in order to get the UAC prompt
74 // showing up in the foreground if running on Vista. It can also be NULL if 92 // showing up in the foreground if running on Vista. It can also be NULL if
75 // background UAC prompts are desired. 93 // background UAC prompts are desired.
76 HRESULT CoCreateInstanceAsAdmin(REFCLSID class_id, 94 HRESULT CoCreateInstanceAsAdmin(REFCLSID class_id,
(...skipping 23 matching lines...) Expand all
100 bind_opts.hwnd = hwnd; 118 bind_opts.hwnd = hwnd;
101 119
102 return CoGetObject(elevation_moniker_name.c_str(), &bind_opts, interface_id, 120 return CoGetObject(elevation_moniker_name.c_str(), &bind_opts, interface_id,
103 interface_ptr); 121 interface_ptr);
104 } 122 }
105 123
106 return CoCreateInstance(class_id, NULL, CLSCTX_LOCAL_SERVER, interface_id, 124 return CoCreateInstance(class_id, NULL, CLSCTX_LOCAL_SERVER, interface_id,
107 interface_ptr); 125 interface_ptr);
108 } 126 }
109 127
110 HRESULT CreateOnDemandAppsClass( 128 HRESULT CreateGoogleUpdate3Class(
111 bool system_level, 129 bool system_level,
112 bool install_if_newer, 130 bool install_update_if_possible,
113 gfx::AcceleratedWidget elevation_window, 131 gfx::AcceleratedWidget elevation_window,
114 base::win::ScopedComPtr<IGoogleUpdate>* on_demand) { 132 base::win::ScopedComPtr<IGoogleUpdate3>* google_update) {
115 if (g_google_update_factory) 133 if (g_google_update_factory)
116 return g_google_update_factory->Run(on_demand); 134 return g_google_update_factory->Run(google_update);
117 135
118 // For a user-level install, update checks and updates can both be done by a 136 // For a user-level install, update checks and updates can both be done by a
119 // normal user with the UserAppsClass. 137 // normal user with the UserClass.
120 if (!system_level) 138 if (!system_level)
121 return on_demand->CreateInstance(CLSID_OnDemandUserAppsClass); 139 return google_update->CreateInstance(CLSID_GoogleUpdate3UserClass);
122 140
123 // For a system-level install, update checks can be done by a normal user with 141 // For a system-level install, update checks can be done by a normal user with
124 // the MachineAppsClass. 142 // the ServiceClass.
125 if (!install_if_newer) 143 if (!install_update_if_possible)
126 return on_demand->CreateInstance(CLSID_OnDemandMachineAppsClass); 144 return google_update->CreateInstance(CLSID_GoogleUpdate3ServiceClass);
127 145
128 // For a system-level install, an update requires Admin privileges for writing 146 // For a system-level install, an update requires Admin privileges for writing
129 // to %ProgramFiles%. Elevate while instantiating the MachineAppsClass. 147 // to %ProgramFiles%. Elevate while instantiating the ServiceClass.
130 return CoCreateInstanceAsAdmin(CLSID_OnDemandMachineAppsClass, 148 return CoCreateInstanceAsAdmin(CLSID_GoogleUpdate3ServiceClass,
131 IID_IGoogleUpdate, elevation_window, 149 IID_IGoogleUpdate3, elevation_window,
132 on_demand->ReceiveVoid()); 150 google_update->ReceiveVoid());
133 } 151 }
134
135
136 // GoogleUpdateJobObserver -----------------------------------------------------
137
138 // The GoogleUpdateJobObserver COM class is responsible for receiving status
139 // reports from google Update. It keeps track of the progress as Google Update
140 // notifies this observer and runs a completion callback once Google Update
141 // reports that it is done.
142 class GoogleUpdateJobObserver : public CComObjectRootEx<CComSingleThreadModel>,
143 public IJobObserver {
144 public:
145 BEGIN_COM_MAP(GoogleUpdateJobObserver)
146 COM_INTERFACE_ENTRY(IJobObserver)
147 END_COM_MAP()
148
149 GoogleUpdateJobObserver();
150 virtual ~GoogleUpdateJobObserver();
151
152 // Sets the callback to be invoked when Google Update reports that the job is
153 // done.
154 void set_on_complete_callback(const base::Closure& on_complete_callback) {
155 on_complete_callback_ = on_complete_callback;
156 }
157
158 // Returns the results of the update operation.
159 GoogleUpdateUpgradeResult result() const {
160 // Intermediary steps should never be reported to the client.
161 DCHECK_NE(UPGRADE_STARTED, result_);
162 DCHECK_NE(UPGRADE_CHECK_STARTED, result_);
163 return result_;
164 }
165
166 // Returns which version Google Update found on the server (if a more
167 // recent version was found). Otherwise, this will be blank.
168 base::string16 new_version() const { return new_version_; }
169
170 // Returns the Google Update supplied error string that describes the error
171 // that occurred during the update check/upgrade.
172 base::string16 error_message() const { return error_message_; }
173
174 private:
175 // IJobObserver:
176 STDMETHOD(OnShow)() override;
177 STDMETHOD(OnCheckingForUpdate)() override;
178 STDMETHOD(OnUpdateAvailable)(const TCHAR* version_string) override;
179 STDMETHOD(OnWaitingToDownload)() override;
180 STDMETHOD(OnDownloading)(int time_remaining_ms, int pos) override;
181 STDMETHOD(OnWaitingToInstall)() override;
182 STDMETHOD(OnInstalling)() override;
183 STDMETHOD(OnPause)() override;
184 STDMETHOD(OnComplete)(LegacyCompletionCodes code, const TCHAR* text) override;
185 STDMETHOD(SetEventSink)(IProgressWndEvents* event_sink) override;
186
187 // The task runner associated with the thread in which the job runs.
188 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
189
190 // A callback to be run to complete processing;
191 base::Closure on_complete_callback_;
192
193 // The status/result of the Google Update operation.
194 GoogleUpdateUpgradeResult result_;
195
196 // The version string Google Update found.
197 base::string16 new_version_;
198
199 // An error message, if any.
200 base::string16 error_message_;
201
202 // Allows us control the upgrade process to a small degree. After OnComplete
203 // has been called, this object can not be used.
204 base::win::ScopedComPtr<IProgressWndEvents> event_sink_;
205
206 DISALLOW_COPY_AND_ASSIGN(GoogleUpdateJobObserver);
207 };
208
209 GoogleUpdateJobObserver::GoogleUpdateJobObserver()
210 : task_runner_(base::ThreadTaskRunnerHandle::Get()),
211 result_(UPGRADE_ERROR) {
212 }
213
214 GoogleUpdateJobObserver::~GoogleUpdateJobObserver() {
215 }
216
217 STDMETHODIMP GoogleUpdateJobObserver::OnShow() {
218 return S_OK;
219 }
220
221 STDMETHODIMP GoogleUpdateJobObserver::OnCheckingForUpdate() {
222 result_ = UPGRADE_CHECK_STARTED;
223 return S_OK;
224 }
225
226 STDMETHODIMP GoogleUpdateJobObserver::OnUpdateAvailable(
227 const TCHAR* version_string) {
228 result_ = UPGRADE_IS_AVAILABLE;
229 new_version_ = version_string;
230 return S_OK;
231 }
232
233 STDMETHODIMP GoogleUpdateJobObserver::OnWaitingToDownload() {
234 return S_OK;
235 }
236
237 STDMETHODIMP GoogleUpdateJobObserver::OnDownloading(int time_remaining_ms,
238 int pos) {
239 return S_OK;
240 }
241
242 STDMETHODIMP GoogleUpdateJobObserver::OnWaitingToInstall() {
243 return S_OK;
244 }
245
246 STDMETHODIMP GoogleUpdateJobObserver::OnInstalling() {
247 result_ = UPGRADE_STARTED;
248 return S_OK;
249 }
250
251 STDMETHODIMP GoogleUpdateJobObserver::OnPause() {
252 return S_OK;
253 }
254
255 STDMETHODIMP GoogleUpdateJobObserver::OnComplete(LegacyCompletionCodes code,
256 const TCHAR* text) {
257 if (code == COMPLETION_CODE_ERROR) {
258 error_message_ = text;
259 result_ = UPGRADE_ERROR;
260 } else {
261 // Everything that isn't an error is some form of success. Chrome doesn't
262 // support any of the fancy codes (e.g., COMPLETION_CODE_REBOOT), but they
263 // shouldn't be generated anyway.
264 LOG_IF(DFATAL, (code != COMPLETION_CODE_SUCCESS &&
265 code != COMPLETION_CODE_SUCCESS_CLOSE_UI))
266 << "Unexpected LegacyCompletionCode from IGoogleUpdate: " << code;
267 if (result_ == UPGRADE_STARTED)
268 result_ = UPGRADE_SUCCESSFUL;
269 else if (result_ == UPGRADE_CHECK_STARTED)
270 result_ = UPGRADE_ALREADY_UP_TO_DATE;
271 }
272
273 event_sink_ = NULL;
274
275 task_runner_->PostTask(FROM_HERE, on_complete_callback_);
276 return S_OK;
277 }
278
279 STDMETHODIMP GoogleUpdateJobObserver::SetEventSink(
280 IProgressWndEvents* event_sink) {
281 event_sink_ = event_sink;
282 return S_OK;
283 }
284
285 152
286 // UpdateCheckDriver ----------------------------------------------------------- 153 // UpdateCheckDriver -----------------------------------------------------------
287 154
288 // A driver that is created and destroyed on the caller's thread and drives 155 // A driver that is created and destroyed on the caller's thread and drives
289 // Google Update on another. 156 // Google Update on another.
290 class UpdateCheckDriver { 157 class UpdateCheckDriver {
291 public: 158 public:
292 // Runs an update check on |task_runner|, invoking |callback| on the caller's 159 // Runs an update check on |task_runner|, invoking methods of |delegate| on
293 // thread upon completion. |task_runner| must run a TYPE_UI message loop if 160 // the caller's thread to report progress and final results.
294 // the default IGoogleUpdate on-demand COM class is used. 161 static void RunUpdateCheck(
295 static void RunUpdateCheck(const scoped_refptr<base::TaskRunner>& task_runner, 162 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
296 bool install_if_newer, 163 const std::string& locale,
297 gfx::AcceleratedWidget elevation_window, 164 bool install_update_if_possible,
298 const UpdateCheckCallback& callback); 165 gfx::AcceleratedWidget elevation_window,
166 const base::WeakPtr<UpdateCheckDelegate>& delegate);
299 167
300 private: 168 private:
301 friend class base::DeleteHelper<UpdateCheckDriver>; 169 friend class base::DeleteHelper<UpdateCheckDriver>;
302 170
303 explicit UpdateCheckDriver(const UpdateCheckCallback& callback); 171 UpdateCheckDriver(
304 172 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
305 // Runs the caller's update check callback with the results of the operation. 173 const std::string& locale,
174 bool install_update_if_possible,
175 gfx::AcceleratedWidget elevation_window,
176 const base::WeakPtr<UpdateCheckDelegate>& delegate);
177
178 // Invokes a completion or error method on the caller's delegate, as
179 // appropriate.
306 ~UpdateCheckDriver(); 180 ~UpdateCheckDriver();
307 181
308 // Starts an update check. 182 // Starts an update check.
309 void BeginUpdateCheck(bool install_if_newer, 183 void BeginUpdateCheck();
310 gfx::AcceleratedWidget elevation_window); 184
311 185 // Helper function for starting an update check. Returns a success result if
Peter Kasting 2015/05/09 02:19:02 Nit: Maybe "Returns the result of the update check
grt (UTC plus 2) 2015/05/12 20:21:51 Done.
312 // Helper function for starting an update check. Returns true if the check was 186 // the check was properly started. Otherwise, returns the failing HRESULT and
313 // properly started, in which case CompleteUpdateCheck will be invoked upon 187 // sets |error_code| as appropriate.
314 // completion to return results to the caller on its own thread. 188 HRESULT BeginUpdateCheckInternal(GoogleUpdateErrorCode* error_code);
315 bool BeginUpdateCheckInternal(bool install_if_newer, 189
316 gfx::AcceleratedWidget elevation_window); 190 // Prepares to return the error indicated by |error_code| and |error_string|
317 191 // to the caller. All values are composed into an error message to be shown to
318 // Invoked when results are in from Google Update. 192 // the user.
Peter Kasting 2015/05/09 02:19:02 As a reader I don't know what it means to "prepare
grt (UTC plus 2) 2015/05/12 20:21:51 Done.
319 void CompleteUpdateCheck();
320
321 // Prepares |results| to return the upgrade error indicated by |error_code|
322 // and |hr|. The string " -- system level" is included in the generated error
323 // message when |system_level| is true.
324 void OnUpgradeError(GoogleUpdateErrorCode error_code, 193 void OnUpgradeError(GoogleUpdateErrorCode error_code,
325 HRESULT hr, 194 HRESULT hresult,
326 bool system_level); 195 int installer_exit_code,
327 196 const base::string16& error_string);
328 // The caller's task runner, on which |result_callback_| will be run. 197
198 // Returns true if |current_state| and |state_value| can be obtained from the
199 // ongoing update check. Otherwise, populates |hresult| with the reason they
200 // could not be obtained.
201 bool GetCurrentState(base::win::ScopedComPtr<ICurrentState>* current_state,
202 CurrentState* state_value,
203 HRESULT* hresult) const;
204
205 // Returns true if |current_state| and |state_value| constitute an error state
206 // for the ongoing update check, in which case |error_code| is populated with
207 // one of GOOGLE_UPDATE_ERROR_UPDATING, GOOGLE_UPDATE_DISABLED_BY_POLICY, or
208 // GOOGLE_UPDATE_ONDEMAND_CLASS_REPORTED_ERROR. |hresult| is populated with
209 // the most relevant HRESULT (which may be a value from Google Update; see
210 // https://code.google.com/p/omaha/source/browse/trunk/base/error.h). In case
211 // Chrome's installer failed during execution, |installer_exit_code| may be
212 // populated with its process exit code (see enum installer::InstallStatus in
213 // chrome/installer/util/util_constants.h); otherwise, it will be -1.
214 // |error_string| will be populated with a completion message if one is
215 // provided by Google Update.
216 bool IsErrorState(const base::win::ScopedComPtr<ICurrentState>& current_state,
217 CurrentState state_value,
218 GoogleUpdateErrorCode* error_code,
219 HRESULT* hresult,
220 int* installer_exit_code,
221 base::string16* error_string) const;
222
223 // Returns true if |current_state| and |state_value| constitute a final state
224 // for the ongoing update check, in which case |upgrade_result| is populated
225 // with one of UPGRADE_ALREADY_UP_TO_DATE or UPGRADE_IS_AVAILABLE (in case a
226 // pure check is being performed rather than an update) or UPGRADE_SUCCESSFUL
227 // (in case an update is being performed). For the UPGRADE_IS_AVAILABLE case,
228 // |new_version| will be populated with the available version, if provided by
229 // Google Update.
230 bool IsFinalState(const base::win::ScopedComPtr<ICurrentState>& current_state,
231 CurrentState state_value,
232 GoogleUpdateUpgradeResult* upgrade_result,
233 base::string16* new_version) const;
234
235 // Returns true if |current_state| and |state_value| constitute an
236 // intermediate state for the ongoing update check. |new_version| will be
237 // populated with the version to be installed if it is provided by Google
238 // Update for the current state. |progress| will be populated with a number
239 // between 0 and 100 according to how far Google Update has progressed in the
240 // download and install process.
241 bool IsIntermediateState(
242 const base::win::ScopedComPtr<ICurrentState>& current_state,
243 CurrentState state_value,
244 base::string16* new_version,
245 int* progress) const;
246
247 // Polls Google Update to determine the state of the ongoing check or
248 // update. If the process has reached a terminal state, this instance will be
249 // deleted and the caller will be notified of the final status. Otherwise, the
250 // caller will be notified of the intermediate state (iff it differs from a
251 // previous notification) and another future poll will be scheduled.
252 void PollGoogleUpdate();
253
254 // The task runner on which the update checks runs.
255 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
256
257 // The caller's task runner, on which methods of |delegate_| will be invoked.
329 scoped_refptr<base::SingleThreadTaskRunner> result_runner_; 258 scoped_refptr<base::SingleThreadTaskRunner> result_runner_;
330 259
331 // The caller's callback to be run when the update check is compelte. 260 // The UI locale.
332 UpdateCheckCallback result_callback_; 261 std::string locale_;
333 262
334 // The results of the update check. 263 // False to only check for an update; true to also install one if available.
264 bool install_update_if_possible_;
265
266 // A parent window in case any UX is required (e.g., an elevation prompt).
267 gfx::AcceleratedWidget elevation_window_;
268
269 // The caller's delegate by which feedback is conveyed.
270 base::WeakPtr<UpdateCheckDelegate> delegate_;
271
272 // True if operating on a per-machine installation rather than a per-user one.
273 bool system_level_;
274
275 // The on-demand updater that is doing the work.
276 base::win::ScopedComPtr<IGoogleUpdate3> google_update_;
277
278 // An app bundle containing the application being updated.
279 base::win::ScopedComPtr<IAppBundle> app_bundle_;
280
281 // The application being updated (Chrome, Chrome Binaries, or Chrome SxS).
282 base::win::ScopedComPtr<IApp> app_;
283
284 // The most progress value reported most recently to the caller.
Peter Kasting 2015/05/09 02:19:02 Nit: Eliminate first "most"
grt (UTC plus 2) 2015/05/12 20:21:51 Done.
285 int last_progress_;
Peter Kasting 2015/05/09 02:19:01 Nit: last_reported_progress_?
grt (UTC plus 2) 2015/05/12 20:21:51 Done.
286
287 // The results of the update check to be logged via UMA and/or reported to the
288 // caller.
335 GoogleUpdateUpgradeResult result_; 289 GoogleUpdateUpgradeResult result_;
336 GoogleUpdateErrorCode error_code_; 290 GoogleUpdateErrorCode error_code_;
337 base::string16 error_message_; 291 base::string16 error_message_;
338 base::string16 version_; 292 base::string16 new_version_;
339 HRESULT hresult_; 293 HRESULT hresult_;
340 294 int installer_exit_code_;
341 // A direct pointer to the job observer by which the driver is notified of
342 // interesting events from Google Update.
343 CComObject<GoogleUpdateJobObserver>* job_observer_;
344
345 // A scoped pointer to |job_observer_| that holds a reference to it, keeping
346 // it alive.
347 base::win::ScopedComPtr<IJobObserver> job_holder_;
348
349 // The on-demand updater that is doing the work.
350 base::win::ScopedComPtr<IGoogleUpdate> on_demand_;
351 295
352 DISALLOW_COPY_AND_ASSIGN(UpdateCheckDriver); 296 DISALLOW_COPY_AND_ASSIGN(UpdateCheckDriver);
353 }; 297 };
354 298
355 // static 299 // static
356 void UpdateCheckDriver::RunUpdateCheck( 300 void UpdateCheckDriver::RunUpdateCheck(
357 const scoped_refptr<base::TaskRunner>& task_runner, 301 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
358 bool install_if_newer, 302 const std::string& locale,
303 bool install_update_if_possible,
359 gfx::AcceleratedWidget elevation_window, 304 gfx::AcceleratedWidget elevation_window,
360 const UpdateCheckCallback& callback) { 305 const base::WeakPtr<UpdateCheckDelegate>& delegate) {
361 // The driver is owned by itself, and will self-destruct when its work is 306 // The driver is owned by itself, and will self-destruct when its work is
362 // done. 307 // done.
363 UpdateCheckDriver* driver = new UpdateCheckDriver(callback); 308 UpdateCheckDriver* driver =
364 task_runner->PostTask( 309 new UpdateCheckDriver(task_runner, locale, install_update_if_possible,
365 FROM_HERE, 310 elevation_window, delegate);
366 base::Bind(&UpdateCheckDriver::BeginUpdateCheck, base::Unretained(driver), 311 task_runner->PostTask(FROM_HERE,
367 install_if_newer, elevation_window)); 312 base::Bind(&UpdateCheckDriver::BeginUpdateCheck,
313 base::Unretained(driver)));
368 } 314 }
369 315
370 // Runs on the caller's thread. 316 // Runs on the caller's thread.
371 UpdateCheckDriver::UpdateCheckDriver(const UpdateCheckCallback& callback) 317 UpdateCheckDriver::UpdateCheckDriver(
372 : result_runner_(base::ThreadTaskRunnerHandle::Get()), 318 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
373 result_callback_(callback), 319 const std::string& locale,
320 bool install_update_if_possible,
321 gfx::AcceleratedWidget elevation_window,
322 const base::WeakPtr<UpdateCheckDelegate>& delegate)
323 : task_runner_(task_runner),
324 result_runner_(base::ThreadTaskRunnerHandle::Get()),
325 locale_(locale),
326 install_update_if_possible_(install_update_if_possible),
327 elevation_window_(elevation_window),
328 delegate_(delegate),
329 system_level_(false),
330 last_progress_(0),
374 result_(UPGRADE_ERROR), 331 result_(UPGRADE_ERROR),
375 error_code_(GOOGLE_UPDATE_NO_ERROR), 332 error_code_(GOOGLE_UPDATE_NO_ERROR),
376 hresult_(S_OK), 333 hresult_(S_OK),
377 job_observer_(nullptr) { 334 installer_exit_code_(-1) {
378 } 335 }
379 336
380 UpdateCheckDriver::~UpdateCheckDriver() { 337 UpdateCheckDriver::~UpdateCheckDriver() {
381 DCHECK(result_runner_->BelongsToCurrentThread()); 338 DCHECK(result_runner_->BelongsToCurrentThread());
382 // If there is an error, then error_code must not be blank, and vice versa. 339 // If there is an error, then error_code must not be blank, and vice versa.
383 DCHECK_NE(result_ == UPGRADE_ERROR, error_code_ == GOOGLE_UPDATE_NO_ERROR); 340 DCHECK_NE(result_ == UPGRADE_ERROR, error_code_ == GOOGLE_UPDATE_NO_ERROR);
384 UMA_HISTOGRAM_ENUMERATION("GoogleUpdate.UpgradeResult", result_, 341 UMA_HISTOGRAM_ENUMERATION("GoogleUpdate.UpgradeResult", result_,
385 NUM_UPGRADE_RESULTS); 342 NUM_UPGRADE_RESULTS);
386 if (result_ == UPGRADE_ERROR) { 343 if (result_ == UPGRADE_ERROR) {
387 UMA_HISTOGRAM_ENUMERATION("GoogleUpdate.UpdateErrorCode", error_code_, 344 UMA_HISTOGRAM_ENUMERATION("GoogleUpdate.UpdateErrorCode", error_code_,
388 NUM_ERROR_CODES); 345 NUM_ERROR_CODES);
389 if (hresult_ != S_OK) 346 if (FAILED(hresult_))
390 UMA_HISTOGRAM_SPARSE_SLOWLY("GoogleUpdate.ErrorHresult", hresult_); 347 UMA_HISTOGRAM_SPARSE_SLOWLY("GoogleUpdate.ErrorHresult", hresult_);
391 } 348 if (installer_exit_code_ != -1) {
392 result_callback_.Run(result_, error_code_, error_message_, version_); 349 UMA_HISTOGRAM_SPARSE_SLOWLY("GoogleUpdate.InstallerExitCode",
393 } 350 installer_exit_code_);
394 351 }
395 void UpdateCheckDriver::BeginUpdateCheck( 352 }
396 bool install_if_newer, 353 if (delegate_) {
397 gfx::AcceleratedWidget elevation_window) { 354 if (result_ == UPGRADE_ERROR)
398 // Return results immediately if the driver is not waiting for Google Update. 355 delegate_->OnError(error_code_, error_message_, new_version_);
399 if (!BeginUpdateCheckInternal(install_if_newer, elevation_window)) 356 else if (install_update_if_possible_)
357 delegate_->OnUpgradeComplete(new_version_);
358 else
359 delegate_->OnUpdateCheckComplete(new_version_);
360 }
361 }
362
363 void UpdateCheckDriver::BeginUpdateCheck() {
364 GoogleUpdateErrorCode error_code = GOOGLE_UPDATE_NO_ERROR;
365 HRESULT hresult = BeginUpdateCheckInternal(&error_code);
366 if (SUCCEEDED(hresult)) {
367 // Start polling.
368 task_runner_->PostTask(FROM_HERE,
369 base::Bind(&UpdateCheckDriver::PollGoogleUpdate,
370 base::Unretained(this)));
371 } else {
372 // Return results immediately if the driver is not polling Google Update.
Peter Kasting 2015/05/09 02:19:01 Nit: This sounds as if the code will be conditiona
grt (UTC plus 2) 2015/05/12 20:21:51 Done.
373 OnUpgradeError(error_code, hresult, -1, base::string16());
400 result_runner_->DeleteSoon(FROM_HERE, this); 374 result_runner_->DeleteSoon(FROM_HERE, this);
401 } 375 }
402 376 }
403 bool UpdateCheckDriver::BeginUpdateCheckInternal( 377
404 bool install_if_newer, 378 HRESULT UpdateCheckDriver::BeginUpdateCheckInternal(
405 gfx::AcceleratedWidget elevation_window) { 379 GoogleUpdateErrorCode* error_code) {
406 base::FilePath chrome_exe; 380 base::FilePath chrome_exe;
407 if (!PathService::Get(base::DIR_EXE, &chrome_exe)) 381 if (!PathService::Get(base::DIR_EXE, &chrome_exe))
408 NOTREACHED(); 382 NOTREACHED();
409 383
410 const bool system_level = !InstallUtil::IsPerUserInstall(chrome_exe); 384 system_level_ = !InstallUtil::IsPerUserInstall(chrome_exe);
411
412 // The failures handled here are:
413 // CANNOT_UPGRADE_CHROME_IN_THIS_DIRECTORY,
414 // GOOGLE_UPDATE_DISABLED_BY_POLICY, and
415 // GOOGLE_UPDATE_DISABLED_BY_POLICY_AUTO_ONLY.
416 error_code_ = CanUpdateCurrentChrome(chrome_exe, system_level);
417 if (error_code_ != GOOGLE_UPDATE_NO_ERROR) {
418 // These failures are handled in the UX with custom messages.
419 result_ = UPGRADE_ERROR;
420 return false;
421 }
422 385
423 // Make sure ATL is initialized in this module. 386 // Make sure ATL is initialized in this module.
424 ui::win::CreateATLModuleIfNeeded(); 387 ui::win::CreateATLModuleIfNeeded();
425 388
426 HRESULT hr = 389 *error_code = CanUpdateCurrentChrome(chrome_exe, system_level_);
427 CComObject<GoogleUpdateJobObserver>::CreateInstance(&job_observer_); 390 if (*error_code != GOOGLE_UPDATE_NO_ERROR)
428 if (hr != S_OK) { 391 return E_FAIL;
429 // Most of the error messages come straight from Google Update. This one is 392
430 // deemed worthy enough to also warrant its own error. 393 HRESULT hresult =
431 OnUpgradeError(GOOGLE_UPDATE_JOB_SERVER_CREATION_FAILED, hr, false); 394 CreateGoogleUpdate3Class(system_level_, install_update_if_possible_,
395 elevation_window_, &google_update_);
396 if (FAILED(hresult)) {
397 *error_code = GOOGLE_UPDATE_ONDEMAND_CLASS_NOT_FOUND;
398 return hresult;
399 }
400
401 // The class was created, so all subsequent errors are reported as:
402 *error_code = GOOGLE_UPDATE_ONDEMAND_CLASS_REPORTED_ERROR;
403 base::string16 app_guid = installer::GetAppGuidForUpdates(system_level_);
404 DCHECK(!app_guid.empty());
405
406 {
407 base::win::ScopedComPtr<IDispatch> dispatch;
408 hresult = google_update_->createAppBundle(dispatch.Receive());
409 if (FAILED(hresult))
410 return hresult;
411 hresult = dispatch.QueryInterface(app_bundle_.Receive());
412 if (FAILED(hresult))
413 return hresult;
414 }
415
416 if (!locale_.empty()) {
417 // Ignore the result of this since, while setting the display language is
418 // nice to have, a failure to do so does not affect the likelihood that the
419 // update check and/or install will succeed.
420 app_bundle_->put_displayLanguage(
421 base::win::ScopedBstr(base::UTF8ToUTF16(locale_).c_str()));
422 }
423
424 hresult = app_bundle_->initialize();
425 if (FAILED(hresult))
426 return hresult;
427
428 {
Peter Kasting 2015/05/09 02:19:02 Nit: This scope unnecessary
grt (UTC plus 2) 2015/05/12 20:21:51 Done.
429 base::win::ScopedComPtr<IDispatch> dispatch;
430 hresult = app_bundle_->createInstalledApp(
431 base::win::ScopedBstr(app_guid.c_str()), dispatch.Receive());
432 if (FAILED(hresult))
433 return hresult;
434 hresult = dispatch.QueryInterface(app_.Receive());
435 if (FAILED(hresult))
436 return hresult;
437 }
438 return app_bundle_->checkForUpdate();
439 }
440
441 bool UpdateCheckDriver::GetCurrentState(
442 base::win::ScopedComPtr<ICurrentState>* current_state,
443 CurrentState* state_value,
444 HRESULT* hresult) const {
445 {
446 base::win::ScopedComPtr<IDispatch> dispatch;
447 *hresult = app_->get_currentState(dispatch.Receive());
448 if (FAILED(*hresult))
449 return false;
450 *hresult = dispatch.QueryInterface(current_state->Receive());
451 if (FAILED(*hresult))
452 return false;
453 }
454 LONG value = 0;
455 *hresult = (*current_state)->get_stateValue(&value);
456 if (FAILED(*hresult))
432 return false; 457 return false;
433 } 458 *state_value = static_cast<CurrentState>(value);
434 // Hold a reference on the observer for the lifetime of the driver.
435 job_holder_ = job_observer_;
436
437 job_observer_->set_on_complete_callback(base::Bind(
438 &UpdateCheckDriver::CompleteUpdateCheck, base::Unretained(this)));
439
440 hr = CreateOnDemandAppsClass(system_level, install_if_newer, elevation_window,
441 &on_demand_);
442 if (hr != S_OK) {
443 OnUpgradeError(GOOGLE_UPDATE_ONDEMAND_CLASS_NOT_FOUND, hr, system_level);
444 return false;
445 }
446
447 base::string16 app_guid = installer::GetAppGuidForUpdates(system_level);
448 DCHECK(!app_guid.empty());
449
450 if (install_if_newer)
451 hr = on_demand_->Update(app_guid.c_str(), job_observer_);
452 else
453 hr = on_demand_->CheckForUpdate(app_guid.c_str(), job_observer_);
454
455 if (hr != S_OK) {
456 OnUpgradeError(GOOGLE_UPDATE_ONDEMAND_CLASS_REPORTED_ERROR, hr,
457 system_level);
458 return false;
459 }
460 return true; 459 return true;
461 } 460 }
462 461
463 void UpdateCheckDriver::CompleteUpdateCheck() { 462 bool UpdateCheckDriver::IsErrorState(
464 result_ = job_observer_->result(); 463 const base::win::ScopedComPtr<ICurrentState>& current_state,
465 if (result_ == UPGRADE_ERROR) { 464 CurrentState state_value,
466 error_code_ = GOOGLE_UPDATE_ERROR_UPDATING; 465 GoogleUpdateErrorCode* error_code,
467 error_message_ = job_observer_->error_message(); 466 HRESULT* hresult,
468 } else { 467 int* installer_exit_code,
469 version_ = job_observer_->new_version(); 468 base::string16* error_string) const {
469 if (state_value == STATE_ERROR) {
470 // In general, errors reported by Google Update fall under this category
471 // (see special case below).
472 *error_code = GOOGLE_UPDATE_ERROR_UPDATING;
473
474 // In general, the exit code of Chrome's installer is unknown (see special
475 // case below).
476 *installer_exit_code = -1;
477
478 // Report the error_code provided by Google Update if possible, or the
479 // reason it wasn't possible otherwise.
480 LONG long_value = 0;
481 *hresult = current_state->get_errorCode(&long_value);
482 if (SUCCEEDED(*hresult))
483 *hresult = long_value;
484
485 // Special cases:
486 // - Use a custom error code if Google Update repoted that the update was
487 // disabled by a Group Policy setting.
488 // - Extract the exit code of Chrome's installer if Google Update repoted
489 // that the update failed because of a failure in the installer.
490 LONG code = 0;
491 if (*hresult == GOOPDATE_E_APP_UPDATE_DISABLED_BY_POLICY) {
492 *error_code = GOOGLE_UPDATE_DISABLED_BY_POLICY;
493 } else if (*hresult == GOOPDATEINSTALL_E_INSTALLER_FAILED &&
494 SUCCEEDED(current_state->get_installerResultCode(&code))) {
495 *installer_exit_code = code;
496 }
497
498 base::win::ScopedBstr message;
499 if (SUCCEEDED(current_state->get_completionMessage(message.Receive())))
500 error_string->assign(message, message.Length());
501
502 return true;
503 }
504 if (state_value == STATE_UPDATE_AVAILABLE && install_update_if_possible_) {
505 *hresult = app_bundle_->install();
506 if (FAILED(*hresult)) {
507 // Report a failure to start the install as a general error while trying
508 // to interact with Google Update.
509 *error_code = GOOGLE_UPDATE_ONDEMAND_CLASS_REPORTED_ERROR;
510 *installer_exit_code = -1;
511 return true;
512 }
513 // Return false for handling in IsIntermediateState.
514 }
515 return false;
516 }
517
518 bool UpdateCheckDriver::IsFinalState(
519 const base::win::ScopedComPtr<ICurrentState>& current_state,
520 CurrentState state_value,
521 GoogleUpdateUpgradeResult* upgrade_result,
522 base::string16* new_version) const {
523 if (state_value == STATE_UPDATE_AVAILABLE && !install_update_if_possible_) {
524 base::win::ScopedBstr version;
525 *upgrade_result = UPGRADE_IS_AVAILABLE;
526 if (SUCCEEDED(current_state->get_availableVersion(version.Receive())))
527 new_version->assign(version, version.Length());
528 return true;
529 }
530 if (state_value == STATE_INSTALL_COMPLETE) {
531 DCHECK(install_update_if_possible_);
532 *upgrade_result = UPGRADE_SUCCESSFUL;
533 return true;
534 }
535 if (state_value == STATE_NO_UPDATE) {
536 *upgrade_result = UPGRADE_ALREADY_UP_TO_DATE;
537 return true;
538 }
539 return false;
540 }
541
542 bool UpdateCheckDriver::IsIntermediateState(
543 const base::win::ScopedComPtr<ICurrentState>& current_state,
544 CurrentState state_value,
545 base::string16* new_version,
546 int* progress) const {
547 // ERROR will have been handled in IsErrorState. UPDATE_AVAILABLE, and
548 // NO_UPDATE will have been handled in IsFinalState if not doing an install,
549 // as will STATE_INSTALL_COMPLETE when doing an install. All other states
550 // following UPDATE_AVAILABLE will only happen when an install is to be done.
551 DCHECK(state_value < STATE_UPDATE_AVAILABLE || install_update_if_possible_);
552 *progress = 0;
553
554 switch (state_value) {
555 case STATE_INIT:
556 case STATE_WAITING_TO_CHECK_FOR_UPDATE:
557 case STATE_CHECKING_FOR_UPDATE:
558 // There is no news to report yet.
559 break;
560
561 case STATE_UPDATE_AVAILABLE: {
562 base::win::ScopedBstr version;
563 if (SUCCEEDED(current_state->get_availableVersion(version.Receive())))
564 new_version->assign(version, version.Length());
565 break;
566 }
567
568 case STATE_WAITING_TO_DOWNLOAD:
569 case STATE_RETRYING_DOWNLOAD:
570 break;
571
572 case STATE_DOWNLOADING: {
573 ULONG bytes_downloaded = 0;
574 ULONG total_bytes = 0;
575 if (SUCCEEDED(current_state->get_bytesDownloaded(&bytes_downloaded)) &&
576 SUCCEEDED(current_state->get_totalBytesToDownload(&total_bytes)) &&
577 total_bytes) {
578 // 0-50 is downloading.
579 *progress = gfx::ToFlooredInt((static_cast<double>(bytes_downloaded) /
580 static_cast<double>(total_bytes)) *
581 50.0);
582 }
583 break;
584 }
585
586 case STATE_DOWNLOAD_COMPLETE:
587 case STATE_EXTRACTING:
588 case STATE_APPLYING_DIFFERENTIAL_PATCH:
589 case STATE_READY_TO_INSTALL:
590 case STATE_WAITING_TO_INSTALL:
591 *progress = 50;
592 break;
593
594 case STATE_INSTALLING: {
595 *progress = 50;
596 LONG install_progress = 0;
597 if (SUCCEEDED(current_state->get_installProgress(&install_progress)) &&
598 install_progress >= 0 && install_progress <= 100) {
599 // 50-100 is installing.
600 *progress = (50 + install_progress / 2);
601 }
602 break;
603 }
604
605 case STATE_INSTALL_COMPLETE:
606 case STATE_PAUSED:
607 case STATE_NO_UPDATE:
608 case STATE_ERROR:
609 default:
610 NOTREACHED();
611 UMA_HISTOGRAM_SPARSE_SLOWLY("GoogleUpdate.UnexpectedState", state_value);
612 return false;
613 }
614 return true;
615 }
616
617 void UpdateCheckDriver::PollGoogleUpdate() {
618 base::win::ScopedComPtr<ICurrentState> state;
619 CurrentState state_value = STATE_INIT;
620 HRESULT hresult = S_OK;
621 GoogleUpdateErrorCode error_code = GOOGLE_UPDATE_NO_ERROR;
622 int installer_exit_code = -1;
623 base::string16 error_string;
624 GoogleUpdateUpgradeResult upgrade_result = UPGRADE_ERROR;
625 base::string16 new_version;
626 int progress = 0;
627
628 if (!GetCurrentState(&state, &state_value, &hresult)) {
629 OnUpgradeError(GOOGLE_UPDATE_ONDEMAND_CLASS_REPORTED_ERROR, hresult, -1,
630 base::string16());
631 } else if (IsErrorState(state, state_value, &error_code, &hresult,
632 &installer_exit_code, &error_string)) {
633 OnUpgradeError(error_code, hresult, installer_exit_code, error_string);
634 } else if (IsFinalState(state, state_value, &upgrade_result, &new_version)) {
635 result_ = upgrade_result;
636 error_code_ = GOOGLE_UPDATE_NO_ERROR;
637 error_message_.clear();
638 if (!new_version.empty())
639 new_version_ = new_version;
640 hresult_ = S_OK;
641 installer_exit_code_ = -1;
642 } else if (IsIntermediateState(state, state_value, &new_version, &progress)) {
643 bool got_new_version = new_version_.empty() && !new_version.empty();
644 if (got_new_version)
645 new_version_ = new_version;
646 // Give the caller this status update if it differs from the last one given.
647 if (got_new_version || progress != last_progress_) {
648 last_progress_ = progress;
649
650 // It is safe to post this task with an unretained pointer since the task
651 // is guaranteed to run before a subsequent DeleteSoon is handled.
652 result_runner_->PostTask(
653 FROM_HERE, base::Bind(&UpdateCheckDelegate::OnUpgradeProgress,
654 delegate_, last_progress_, new_version_));
655 }
656
657 // Schedule the next check.
658 task_runner_->PostDelayedTask(
659 FROM_HERE, base::Bind(&UpdateCheckDriver::PollGoogleUpdate,
660 base::Unretained(this)),
661 base::TimeDelta::FromMilliseconds(kGoogleUpdatePollIntervalMs));
662 // Early return for this non-terminal state.
663 return;
470 } 664 }
471 665
472 // Release the reference on the COM objects before bouncing back to the 666 // Release the reference on the COM objects before bouncing back to the
473 // caller's thread. 667 // caller's thread.
474 on_demand_.Release(); 668 state.Release();
475 job_holder_.Release(); 669 app_.Release();
476 job_observer_ = nullptr; 670 app_bundle_.Release();
671 google_update_.Release();
477 672
478 result_runner_->DeleteSoon(FROM_HERE, this); 673 result_runner_->DeleteSoon(FROM_HERE, this);
479 } 674 }
480 675
481 void UpdateCheckDriver::OnUpgradeError(GoogleUpdateErrorCode error_code, 676 void UpdateCheckDriver::OnUpgradeError(GoogleUpdateErrorCode error_code,
482 HRESULT hr, 677 HRESULT hresult,
483 bool system_level) { 678 int installer_exit_code,
679 const base::string16& error_string) {
484 result_ = UPGRADE_ERROR; 680 result_ = UPGRADE_ERROR;
485 error_code_ = error_code; 681 error_code_ = error_code;
486 hresult_ = hr; 682 hresult_ = hresult;
683 installer_exit_code_ = installer_exit_code;
487 base::string16 error_msg = 684 base::string16 error_msg =
488 base::StringPrintf(L"%d: 0x%x", error_code_, hresult_); 685 base::StringPrintf(L"%d: 0x%x", error_code_, hresult_);
489 if (system_level) 686 if (installer_exit_code_ != -1)
687 error_msg += base::StringPrintf(L": %d", installer_exit_code_);
688 if (system_level_)
490 error_msg += L" -- system level"; 689 error_msg += L" -- system level";
491 error_message_ = l10n_util::GetStringFUTF16( 690 if (error_string.empty()) {
492 IDS_ABOUT_BOX_ERROR_UPDATE_CHECK_FAILED, error_msg); 691 error_message_ = l10n_util::GetStringFUTF16(
692 IDS_ABOUT_BOX_ERROR_UPDATE_CHECK_FAILED, error_msg);
693 } else {
694 error_message_ = l10n_util::GetStringFUTF16(
695 IDS_ABOUT_BOX_GOOGLE_UPDATE_ERROR, error_string, error_msg);
696 }
493 } 697 }
494 698
495 } // namespace 699 } // namespace
496 700
497 701
498 // Globals --------------------------------------------------------------------- 702 // Globals ---------------------------------------------------------------------
499 703
500 void BeginUpdateCheck(const scoped_refptr<base::TaskRunner>& task_runner, 704 void BeginUpdateCheck(
501 bool install_if_newer, 705 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
502 gfx::AcceleratedWidget elevation_window, 706 const std::string& locale,
503 const UpdateCheckCallback& callback) { 707 bool install_update_if_possible,
504 UpdateCheckDriver::RunUpdateCheck(task_runner, install_if_newer, 708 gfx::AcceleratedWidget elevation_window,
505 elevation_window, callback); 709 const base::WeakPtr<UpdateCheckDelegate>& delegate) {
710 UpdateCheckDriver::RunUpdateCheck(task_runner, locale,
711 install_update_if_possible,
712 elevation_window, delegate);
506 } 713 }
507 714
508 715
509 // Private API exposed for testing. -------------------------------------------- 716 // Private API exposed for testing. --------------------------------------------
510 717
511 void SetGoogleUpdateFactoryForTesting( 718 void SetGoogleUpdateFactoryForTesting(
512 const OnDemandAppsClassFactory& google_update_factory) { 719 const GoogleUpdate3ClassFactory& google_update_factory) {
513 if (g_google_update_factory) { 720 if (g_google_update_factory) {
514 delete g_google_update_factory; 721 delete g_google_update_factory;
515 g_google_update_factory = nullptr; 722 g_google_update_factory = nullptr;
516 } 723 }
517 if (!google_update_factory.is_null()) { 724 if (!google_update_factory.is_null()) {
518 g_google_update_factory = 725 g_google_update_factory =
519 new OnDemandAppsClassFactory(google_update_factory); 726 new GoogleUpdate3ClassFactory(google_update_factory);
520 } 727 }
521 } 728 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698