| OLD | NEW |
| 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_frame/update_launcher.h" | 5 #include "chrome_frame/update_launcher.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <Shellapi.h> | 8 #include <Shellapi.h> |
| 9 | 9 |
| 10 #include "base/win/scoped_com_initializer.h" | 10 #include "base/win/scoped_com_initializer.h" |
| 11 #include "base/win/scoped_comptr.h" | 11 #include "base/win/scoped_comptr.h" |
| 12 #include "base/win/scoped_handle.h" |
| 12 #include "google_update/google_update_idl.h" | 13 #include "google_update/google_update_idl.h" |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 const wchar_t kChromeFrameGuid[] = L"{8BA986DA-5100-405E-AA35-86F34A02ACBF}"; | 17 const wchar_t kChromeFrameGuid[] = L"{8BA986DA-5100-405E-AA35-86F34A02ACBF}"; |
| 17 | 18 |
| 18 const DWORD kLaunchFailureExitCode = 0xFF; | 19 const DWORD kLaunchFailureExitCode = 0xFF; |
| 19 | 20 |
| 20 const wchar_t kUpdateCommandFlag[] = L"--update-cmd"; | 21 const wchar_t kUpdateCommandFlag[] = L"--update-cmd"; |
| 21 | 22 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 43 if (args) { | 44 if (args) { |
| 44 if (num_args == 3 && _wcsicmp(args[1], kUpdateCommandFlag) == 0) | 45 if (num_args == 3 && _wcsicmp(args[1], kUpdateCommandFlag) == 0) |
| 45 command = args[2]; | 46 command = args[2]; |
| 46 ::LocalFree(args); | 47 ::LocalFree(args); |
| 47 } | 48 } |
| 48 } | 49 } |
| 49 | 50 |
| 50 return command; | 51 return command; |
| 51 } | 52 } |
| 52 | 53 |
| 53 // Because we do not have 'base' and all of its pretty RAII helpers, please | |
| 54 // ensure that this function only ever contains a single 'return', in order | |
| 55 // to reduce the chance of introducing a leak. | |
| 56 DWORD LaunchUpdateCommand(const std::wstring& command) { | 54 DWORD LaunchUpdateCommand(const std::wstring& command) { |
| 57 DWORD exit_code = kLaunchFailureExitCode; | 55 base::win::ScopedCOMInitializer com_initializer; |
| 56 if (!com_initializer.succeeded()) |
| 57 return kLaunchFailureExitCode; |
| 58 | 58 |
| 59 base::win::ScopedCOMInitializer com_initializer; | 59 base::win::ScopedComPtr<IProcessLauncher> ipl; |
| 60 if (com_initializer.succeeded()) { | 60 if (FAILED(ipl.CreateInstance(__uuidof(ProcessLauncherClass)))) |
| 61 base::win::ScopedComPtr<IProcessLauncher> ipl; | 61 return kLaunchFailureExitCode; |
| 62 HANDLE process = NULL; | |
| 63 | 62 |
| 64 HRESULT hr = ipl.CreateInstance(__uuidof(ProcessLauncherClass)); | 63 ULONG_PTR phandle = NULL; |
| 64 if (FAILED(ipl->LaunchCmdElevated(kChromeFrameGuid, command.c_str(), |
| 65 ::GetCurrentProcessId(), &phandle))) |
| 66 return kLaunchFailureExitCode; |
| 65 | 67 |
| 66 if (SUCCEEDED(hr)) { | 68 base::win::ScopedHandle process(reinterpret_cast<HANDLE>(phandle)); |
| 67 ULONG_PTR phandle = NULL; | 69 return WaitForProcessExitCode(process); |
| 68 DWORD id = ::GetCurrentProcessId(); | |
| 69 | |
| 70 hr = ipl->LaunchCmdElevated(kChromeFrameGuid, | |
| 71 command.c_str(), id, &phandle); | |
| 72 if (SUCCEEDED(hr)) { | |
| 73 process = reinterpret_cast<HANDLE>(phandle); | |
| 74 exit_code = WaitForProcessExitCode(process); | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 if (process) | |
| 79 ::CloseHandle(process); | |
| 80 } | |
| 81 | |
| 82 return exit_code; | |
| 83 } | 70 } |
| 84 | 71 |
| 85 } // namespace process_launcher | 72 } // namespace process_launcher |
| OLD | NEW |