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

Side by Side Diff: chrome_frame/update_launcher.cc

Issue 11050009: Use ScopedCOMInitializer in more places. While this doesn't always simplify code, it does mean we … (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "google_update/google_update_idl.h" 11 #include "google_update/google_update_idl.h"
11 12
12 namespace { 13 namespace {
13 14
14 const wchar_t kChromeFrameGuid[] = L"{8BA986DA-5100-405E-AA35-86F34A02ACBF}"; 15 const wchar_t kChromeFrameGuid[] = L"{8BA986DA-5100-405E-AA35-86F34A02ACBF}";
15 16
16 const DWORD kLaunchFailureExitCode = 0xFF; 17 const DWORD kLaunchFailureExitCode = 0xFF;
17 18
18 const wchar_t kUpdateCommandFlag[] = L"--update-cmd"; 19 const wchar_t kUpdateCommandFlag[] = L"--update-cmd";
19 20
(...skipping 27 matching lines...) Expand all
47 48
48 return command; 49 return command;
49 } 50 }
50 51
51 // Because we do not have 'base' and all of its pretty RAII helpers, please 52 // Because we do not have 'base' and all of its pretty RAII helpers, please
52 // ensure that this function only ever contains a single 'return', in order 53 // ensure that this function only ever contains a single 'return', in order
53 // to reduce the chance of introducing a leak. 54 // to reduce the chance of introducing a leak.
54 DWORD LaunchUpdateCommand(const std::wstring& command) { 55 DWORD LaunchUpdateCommand(const std::wstring& command) {
55 DWORD exit_code = kLaunchFailureExitCode; 56 DWORD exit_code = kLaunchFailureExitCode;
56 57
57 HRESULT hr = ::CoInitialize(NULL); 58 base::win::ScopedCOMInitializer com_initializer;
58 59 if (com_initializer.succeeded()) {
59 if (SUCCEEDED(hr)) {
60 IProcessLauncher* ipl = NULL; 60 IProcessLauncher* ipl = NULL;
61 HANDLE process = NULL; 61 HANDLE process = NULL;
62 62
63 hr = ::CoCreateInstance(__uuidof(ProcessLauncherClass), NULL, 63 HRESULT hr = ::CoCreateInstance(__uuidof(ProcessLauncherClass), NULL,
64 CLSCTX_ALL, __uuidof(IProcessLauncher), 64 CLSCTX_ALL, __uuidof(IProcessLauncher),
65 reinterpret_cast<void**>(&ipl)); 65 reinterpret_cast<void**>(&ipl));
66 66
67 if (SUCCEEDED(hr)) { 67 if (SUCCEEDED(hr)) {
68 ULONG_PTR phandle = NULL; 68 ULONG_PTR phandle = NULL;
69 DWORD id = ::GetCurrentProcessId(); 69 DWORD id = ::GetCurrentProcessId();
70 70
71 hr = ipl->LaunchCmdElevated(kChromeFrameGuid, 71 hr = ipl->LaunchCmdElevated(kChromeFrameGuid,
72 command.c_str(), id, &phandle); 72 command.c_str(), id, &phandle);
73 if (SUCCEEDED(hr)) { 73 if (SUCCEEDED(hr)) {
74 process = reinterpret_cast<HANDLE>(phandle); 74 process = reinterpret_cast<HANDLE>(phandle);
75 exit_code = WaitForProcessExitCode(process); 75 exit_code = WaitForProcessExitCode(process);
76 } 76 }
77 } 77 }
78 78
79 if (process) 79 if (process)
80 ::CloseHandle(process); 80 ::CloseHandle(process);
81 if (ipl) 81 if (ipl)
82 ipl->Release(); 82 ipl->Release();
83
84 ::CoUninitialize();
85 } 83 }
86 84
87 return exit_code; 85 return exit_code;
88 } 86 }
89 87
90 } // namespace process_launcher 88 } // namespace process_launcher
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698