Chromium Code Reviews| 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" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 if (args) { | 43 if (args) { |
| 44 if (num_args == 3 && _wcsicmp(args[1], kUpdateCommandFlag) == 0) | 44 if (num_args == 3 && _wcsicmp(args[1], kUpdateCommandFlag) == 0) |
| 45 command = args[2]; | 45 command = args[2]; |
| 46 ::LocalFree(args); | 46 ::LocalFree(args); |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 | 49 |
| 50 return command; | 50 return command; |
| 51 } | 51 } |
| 52 | 52 |
| 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) { | 53 DWORD LaunchUpdateCommand(const std::wstring& command) { |
| 57 DWORD exit_code = kLaunchFailureExitCode; | 54 base::win::ScopedCOMInitializer com_initializer; |
| 55 if (!com_initializer.succeeded()) | |
| 56 return kLaunchFailureExitCode; | |
| 58 | 57 |
| 59 base::win::ScopedCOMInitializer com_initializer; | 58 base::win::ScopedComPtr<IProcessLauncher> ipl; |
| 60 if (com_initializer.succeeded()) { | 59 if (FAILED(ipl.CreateInstance(__uuidof(ProcessLauncherClass)))) |
| 61 base::win::ScopedComPtr<IProcessLauncher> ipl; | 60 return kLaunchFailureExitCode; |
| 62 HANDLE process = NULL; | |
| 63 | 61 |
| 64 HRESULT hr = ipl.CreateInstance(__uuidof(ProcessLauncherClass)); | 62 ULONG_PTR phandle = NULL; |
|
grt (UTC plus 2)
2013/04/15 23:32:54
can this be a base::win::ScopedHandle, using its R
Peter Kasting
2013/04/16 00:09:22
I don't think using Receive() will work because th
| |
| 63 if (FAILED(ipl->LaunchCmdElevated(kChromeFrameGuid, command.c_str(), | |
| 64 ::GetCurrentProcessId(), &phandle))) | |
| 65 return kLaunchFailureExitCode; | |
| 65 | 66 |
| 66 if (SUCCEEDED(hr)) { | 67 HANDLE process = reinterpret_cast<HANDLE>(phandle); |
| 67 ULONG_PTR phandle = NULL; | 68 DWORD exit_code = WaitForProcessExitCode(process); |
| 68 DWORD id = ::GetCurrentProcessId(); | 69 if (process) |
| 69 | 70 ::CloseHandle(process); |
| 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; | 71 return exit_code; |
| 83 } | 72 } |
| 84 | 73 |
| 85 } // namespace process_launcher | 74 } // namespace process_launcher |
| OLD | NEW |