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

Unified Diff: chrome_frame/update_launcher.cc

Issue 14251022: Allow multiple exits from LaunchUpdateCommand() for safety and clarity. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome_frame/update_launcher.cc
===================================================================
--- chrome_frame/update_launcher.cc (revision 194255)
+++ chrome_frame/update_launcher.cc (working copy)
@@ -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 @@
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;
+ if (!com_initializer.succeeded())
+ return kLaunchFailureExitCode;
- HRESULT hr = ipl.CreateInstance(__uuidof(ProcessLauncherClass));
+ base::win::ScopedComPtr<IProcessLauncher> ipl;
+ if (FAILED(ipl.CreateInstance(__uuidof(ProcessLauncherClass))))
+ return kLaunchFailureExitCode;
- if (SUCCEEDED(hr)) {
- ULONG_PTR phandle = NULL;
- DWORD id = ::GetCurrentProcessId();
+ ULONG_PTR phandle = NULL;
+ if (FAILED(ipl->LaunchCmdElevated(kChromeFrameGuid, command.c_str(),
+ ::GetCurrentProcessId(), &phandle)))
+ return kLaunchFailureExitCode;
- hr = ipl->LaunchCmdElevated(kChromeFrameGuid,
- command.c_str(), id, &phandle);
- if (SUCCEEDED(hr)) {
- process = reinterpret_cast<HANDLE>(phandle);
- exit_code = WaitForProcessExitCode(process);
- }
- }
-
- if (process)
- ::CloseHandle(process);
- }
-
- return exit_code;
+ base::win::ScopedHandle process(reinterpret_cast<HANDLE>(phandle));
+ return WaitForProcessExitCode(process);
}
} // namespace process_launcher
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698