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

Side by Side Diff: chrome_frame/update_launcher.cc

Issue 6355011: When changing Ready Mode state from within an IE process, use chrome_launcher... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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
« no previous file with comments | « chrome_frame/update_launcher.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome_frame/update_launcher.h"
6
7 #include <windows.h>
8 #include <Shellapi.h>
9
10 #include "google_update_idl.h" // NOLINT
11
12 namespace {
13
14 const wchar_t kChromeFrameGuid[] = L"{8BA986DA-5100-405E-AA35-86F34A02ACBF}";
15
16 const DWORD kLaunchFailureExitCode = 0xFF;
17
18 const wchar_t kUpdateCommandFlag[] = L"--update-cmd";
19
20 // Waits indefinitely for the provided process to exit. Returns the process's
21 // exit code, or kLaunchFailureExitCode if an error occurs in the waiting.
22 DWORD WaitForProcessExitCode(HANDLE handle) {
23 DWORD exit_code = 0;
24
25 DWORD wait_result = ::WaitForSingleObject(handle, INFINITE);
26
27 if (wait_result == WAIT_OBJECT_0 && ::GetExitCodeProcess(handle, &exit_code))
28 return exit_code;
29
30 return kLaunchFailureExitCode;
31 }
32
33 } // namespace
34
35 namespace update_launcher {
36
37 std::wstring GetUpdateCommandFromArguments(const wchar_t* command_line) {
38 std::wstring command;
39
40 if (command_line != NULL) {
41 int num_args = 0;
42 wchar_t** args = NULL;
43 args = ::CommandLineToArgvW(command_line, &num_args);
44
45 if (args) {
46 if (num_args == 3 && _wcsicmp(args[1], kUpdateCommandFlag) == 0)
47 command = args[2];
48 ::LocalFree(args);
49 }
50 }
51
52 return command;
53 }
54
55 // Because we do not have 'base' and all of its pretty RAII helpers, please
56 // ensure that this function only ever contains a single 'return', in order
57 // to reduce the chance of introducing a leak.
58 DWORD LaunchUpdateCommand(const std::wstring& command) {
59 DWORD exit_code = kLaunchFailureExitCode;
60
61 HRESULT hr = ::CoInitialize(NULL);
62
63 if (SUCCEEDED(hr)) {
64 IProcessLauncher* ipl = NULL;
65 HANDLE process = NULL;
66
67 hr = ::CoCreateInstance(__uuidof(ProcessLauncherClass), NULL,
68 CLSCTX_ALL, __uuidof(IProcessLauncher),
69 reinterpret_cast<void**>(&ipl));
70
71 if (SUCCEEDED(hr)) {
72 ULONG_PTR phandle = NULL;
73 DWORD id = ::GetCurrentProcessId();
74
75 hr = ipl->LaunchCmdElevated(kChromeFrameGuid,
76 command.c_str(), id, &phandle);
77 if (SUCCEEDED(hr)) {
78 process = reinterpret_cast<HANDLE>(phandle);
79 exit_code = WaitForProcessExitCode(process);
80 }
81 }
82
83 if (process)
84 ::CloseHandle(process);
85 if (ipl)
86 ipl->Release();
87
88 ::CoUninitialize();
89 }
90
91 return exit_code;
92 }
93
94 } // namespace process_launcher
OLDNEW
« no previous file with comments | « chrome_frame/update_launcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698