summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-16 16:43:34 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-16 16:43:34 +0000
commit9605c8ed9aeb8e337eb2fdcc6d1461682143cc31 (patch)
tree91f3ddb682421dccbaae277afdeb87ab0ac9267e
parent3be6cefe98d1c6eba57239db2aa956070e021229 (diff)
downloadchromium_src-9605c8ed9aeb8e337eb2fdcc6d1461682143cc31.zip
chromium_src-9605c8ed9aeb8e337eb2fdcc6d1461682143cc31.tar.gz
chromium_src-9605c8ed9aeb8e337eb2fdcc6d1461682143cc31.tar.bz2
Allow multiple exits from LaunchUpdateCommand() for safety and clarity.
BUG=none TEST=none Review URL: https://codereview.chromium.org/14251022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194370 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome_frame/update_launcher.cc39
1 files changed, 13 insertions, 26 deletions
diff --git a/chrome_frame/update_launcher.cc b/chrome_frame/update_launcher.cc
index bd7860e..fac34a0 100644
--- a/chrome_frame/update_launcher.cc
+++ b/chrome_frame/update_launcher.cc
@@ -9,6 +9,7 @@
#include "base/win/scoped_com_initializer.h"
#include "base/win/scoped_comptr.h"
+#include "base/win/scoped_handle.h"
#include "google_update/google_update_idl.h"
namespace {
@@ -50,36 +51,22 @@ std::wstring GetUpdateCommandFromArguments(const wchar_t* command_line) {
return command;
}
-// Because we do not have 'base' and all of its pretty RAII helpers, please
-// ensure that this function only ever contains a single 'return', in order
-// to reduce the chance of introducing a leak.
DWORD LaunchUpdateCommand(const std::wstring& command) {
- DWORD exit_code = kLaunchFailureExitCode;
-
base::win::ScopedCOMInitializer com_initializer;
- if (com_initializer.succeeded()) {
- base::win::ScopedComPtr<IProcessLauncher> ipl;
- HANDLE process = NULL;
-
- HRESULT hr = ipl.CreateInstance(__uuidof(ProcessLauncherClass));
-
- if (SUCCEEDED(hr)) {
- ULONG_PTR phandle = NULL;
- DWORD id = ::GetCurrentProcessId();
-
- hr = ipl->LaunchCmdElevated(kChromeFrameGuid,
- command.c_str(), id, &phandle);
- if (SUCCEEDED(hr)) {
- process = reinterpret_cast<HANDLE>(phandle);
- exit_code = WaitForProcessExitCode(process);
- }
- }
+ if (!com_initializer.succeeded())
+ return kLaunchFailureExitCode;
- if (process)
- ::CloseHandle(process);
- }
+ base::win::ScopedComPtr<IProcessLauncher> ipl;
+ if (FAILED(ipl.CreateInstance(__uuidof(ProcessLauncherClass))))
+ return kLaunchFailureExitCode;
+
+ ULONG_PTR phandle = NULL;
+ if (FAILED(ipl->LaunchCmdElevated(kChromeFrameGuid, command.c_str(),
+ ::GetCurrentProcessId(), &phandle)))
+ return kLaunchFailureExitCode;
- return exit_code;
+ base::win::ScopedHandle process(reinterpret_cast<HANDLE>(phandle));
+ return WaitForProcessExitCode(process);
}
} // namespace process_launcher