OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 5 #include "chrome/browser/google/google_update.h" |
6 | 6 |
7 #include <atlbase.h> | 7 #include <atlbase.h> |
8 #include <atlcom.h> | 8 #include <atlcom.h> |
9 | 9 |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 this, &GoogleUpdate::InitiateGoogleUpdateCheck, install_if_newer, | 224 this, &GoogleUpdate::InitiateGoogleUpdateCheck, install_if_newer, |
225 window, MessageLoop::current())); | 225 window, MessageLoop::current())); |
226 } | 226 } |
227 | 227 |
228 //////////////////////////////////////////////////////////////////////////////// | 228 //////////////////////////////////////////////////////////////////////////////// |
229 // GoogleUpdate, private: | 229 // GoogleUpdate, private: |
230 | 230 |
231 bool GoogleUpdate::InitiateGoogleUpdateCheck(bool install_if_newer, | 231 bool GoogleUpdate::InitiateGoogleUpdateCheck(bool install_if_newer, |
232 Window* window, | 232 Window* window, |
233 MessageLoop* main_loop) { | 233 MessageLoop* main_loop) { |
234 | |
235 FilePath chrome_exe_path; | 234 FilePath chrome_exe_path; |
236 if (!PathService::Get(base::DIR_EXE, &chrome_exe_path)) { | 235 if (!PathService::Get(base::DIR_EXE, &chrome_exe_path)) { |
237 NOTREACHED(); | 236 NOTREACHED(); |
238 return false; | 237 return false; |
239 } | 238 } |
240 std::wstring chrome_exe = chrome_exe_path.value(); | 239 std::wstring chrome_exe = chrome_exe_path.value(); |
241 | 240 |
242 std::transform(chrome_exe.begin(), chrome_exe.end(), | 241 std::transform(chrome_exe.begin(), chrome_exe.end(), |
243 chrome_exe.begin(), tolower); | 242 chrome_exe.begin(), tolower); |
244 | 243 |
245 if (!CanUpdateCurrentChrome(chrome_exe)) { | 244 if (!CanUpdateCurrentChrome(chrome_exe)) { |
246 main_loop->PostTask(FROM_HERE, NewRunnableMethod(this, | 245 main_loop->PostTask(FROM_HERE, NewRunnableMethod(this, |
247 &GoogleUpdate::ReportResults, UPGRADE_ERROR, | 246 &GoogleUpdate::ReportResults, UPGRADE_ERROR, |
248 CANNOT_UPGRADE_CHROME_IN_THIS_DIRECTORY)); | 247 CANNOT_UPGRADE_CHROME_IN_THIS_DIRECTORY)); |
249 return false; | 248 return false; |
250 } | 249 } |
251 | 250 |
252 CComObject<GoogleUpdateJobObserver>* job_observer; | 251 CComObject<GoogleUpdateJobObserver>* job_observer; |
253 HRESULT hr = | 252 HRESULT hr = |
254 CComObject<GoogleUpdateJobObserver>::CreateInstance(&job_observer); | 253 CComObject<GoogleUpdateJobObserver>::CreateInstance(&job_observer); |
255 if (hr != S_OK) { | 254 if (hr != S_OK) { |
256 return ReportFailure(hr, GOOGLE_UPDATE_JOB_SERVER_CREATION_FAILED, | 255 return ReportFailure(hr, GOOGLE_UPDATE_JOB_SERVER_CREATION_FAILED, |
257 main_loop); | 256 main_loop); |
258 } | 257 } |
259 | 258 |
260 ScopedComPtr<IJobObserver> job_holder(job_observer); | 259 ScopedComPtr<IJobObserver> job_holder(job_observer); |
261 | 260 |
262 ScopedComPtr<IGoogleUpdate> on_demand; | 261 ScopedComPtr<IGoogleUpdate> on_demand; |
263 | 262 |
| 263 bool system_level = false; |
| 264 |
264 if (InstallUtil::IsPerUserInstall(chrome_exe.c_str())) { | 265 if (InstallUtil::IsPerUserInstall(chrome_exe.c_str())) { |
265 hr = on_demand.CreateInstance(CLSID_OnDemandUserAppsClass); | 266 hr = on_demand.CreateInstance(CLSID_OnDemandUserAppsClass); |
266 } else { | 267 } else { |
267 // The Update operation needs Admin privileges for writing | 268 // The Update operation needs Admin privileges for writing |
268 // to %ProgramFiles%. On Vista we need to elevate before instantiating | 269 // to %ProgramFiles%. On Vista we need to elevate before instantiating |
269 // the updater instance. | 270 // the updater instance. |
270 if (!install_if_newer) { | 271 if (!install_if_newer) { |
271 hr = on_demand.CreateInstance(CLSID_OnDemandMachineAppsClass); | 272 hr = on_demand.CreateInstance(CLSID_OnDemandMachineAppsClass); |
272 } else { | 273 } else { |
273 HWND foreground_hwnd = NULL; | 274 HWND foreground_hwnd = NULL; |
274 if (window != NULL) { | 275 if (window != NULL) { |
275 foreground_hwnd = window->GetNativeWindow(); | 276 foreground_hwnd = window->GetNativeWindow(); |
276 } | 277 } |
277 | 278 |
278 hr = CoCreateInstanceAsAdmin(CLSID_OnDemandMachineAppsClass, | 279 hr = CoCreateInstanceAsAdmin(CLSID_OnDemandMachineAppsClass, |
279 IID_IGoogleUpdate, foreground_hwnd, | 280 IID_IGoogleUpdate, foreground_hwnd, |
280 reinterpret_cast<void**>(on_demand.Receive())); | 281 reinterpret_cast<void**>(on_demand.Receive())); |
281 } | 282 } |
| 283 system_level = true; |
282 } | 284 } |
283 | 285 |
284 if (hr != S_OK) | 286 if (hr != S_OK) |
285 return ReportFailure(hr, GOOGLE_UPDATE_ONDEMAND_CLASS_NOT_FOUND, main_loop); | 287 return ReportFailure(hr, GOOGLE_UPDATE_ONDEMAND_CLASS_NOT_FOUND, main_loop); |
286 | 288 |
287 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 289 std::wstring app_guid = installer::GetAppGuidForUpdates(system_level); |
| 290 DCHECK(!app_guid.empty()); |
| 291 |
288 if (!install_if_newer) | 292 if (!install_if_newer) |
289 hr = on_demand->CheckForUpdate(dist->GetAppGuid().c_str(), job_observer); | 293 hr = on_demand->CheckForUpdate(app_guid.c_str(), job_observer); |
290 else | 294 else |
291 hr = on_demand->Update(dist->GetAppGuid().c_str(), job_observer); | 295 hr = on_demand->Update(app_guid.c_str(), job_observer); |
292 | 296 |
293 if (hr != S_OK) | 297 if (hr != S_OK) |
294 return ReportFailure(hr, GOOGLE_UPDATE_ONDEMAND_CLASS_REPORTED_ERROR, | 298 return ReportFailure(hr, GOOGLE_UPDATE_ONDEMAND_CLASS_REPORTED_ERROR, |
295 main_loop); | 299 main_loop); |
296 | 300 |
297 // We need to spin the message loop while Google Update is running so that it | 301 // We need to spin the message loop while Google Update is running so that it |
298 // can report back to us through GoogleUpdateJobObserver. This message loop | 302 // can report back to us through GoogleUpdateJobObserver. This message loop |
299 // will terminate once Google Update sends us the completion status | 303 // will terminate once Google Update sends us the completion status |
300 // (success/error). See OnComplete(). | 304 // (success/error). See OnComplete(). |
301 MessageLoop::current()->Run(); | 305 MessageLoop::current()->Run(); |
(...skipping 27 matching lines...) Expand all Loading... |
329 } | 333 } |
330 | 334 |
331 bool GoogleUpdate::ReportFailure(HRESULT hr, GoogleUpdateErrorCode error_code, | 335 bool GoogleUpdate::ReportFailure(HRESULT hr, GoogleUpdateErrorCode error_code, |
332 MessageLoop* main_loop) { | 336 MessageLoop* main_loop) { |
333 NOTREACHED() << "Communication with Google Update failed: " << hr | 337 NOTREACHED() << "Communication with Google Update failed: " << hr |
334 << " error: " << error_code; | 338 << " error: " << error_code; |
335 main_loop->PostTask(FROM_HERE, NewRunnableMethod(this, | 339 main_loop->PostTask(FROM_HERE, NewRunnableMethod(this, |
336 &GoogleUpdate::ReportResults, UPGRADE_ERROR, error_code)); | 340 &GoogleUpdate::ReportResults, UPGRADE_ERROR, error_code)); |
337 return false; | 341 return false; |
338 } | 342 } |
OLD | NEW |