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/browser/extensions/api/messaging/native_process_launcher.h" | 5 #include "chrome/browser/extensions/api/messaging/native_process_launcher.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 | 129 |
130 string16 command_line_string = command_line.GetCommandLineString(); | 130 string16 command_line_string = command_line.GetCommandLineString(); |
131 | 131 |
132 string16 command = base::StringPrintf( | 132 string16 command = base::StringPrintf( |
133 L"%ls /c %ls < %ls > %ls", | 133 L"%ls /c %ls < %ls > %ls", |
134 comspec.get(), command_line_string.c_str(), | 134 comspec.get(), command_line_string.c_str(), |
135 in_pipe_name.c_str(), out_pipe_name.c_str()); | 135 in_pipe_name.c_str(), out_pipe_name.c_str()); |
136 | 136 |
137 base::LaunchOptions options; | 137 base::LaunchOptions options; |
138 options.start_hidden = true; | 138 options.start_hidden = true; |
139 base::ProcessHandle cmd_handle; | 139 base::win::ScopedHandle cmd_handle; |
140 if (!base::LaunchProcess(command.c_str(), options, &cmd_handle)) { | 140 if (!base::LaunchProcess(command.c_str(), options, &cmd_handle)) { |
141 LOG(ERROR) << "Error launching process " | 141 LOG(ERROR) << "Error launching process " |
142 << command_line.GetProgram().MaybeAsASCII(); | 142 << command_line.GetProgram().MaybeAsASCII(); |
143 return false; | 143 return false; |
144 } | 144 } |
145 | 145 |
146 bool stdout_connected = ConnectNamedPipe(stdout_pipe.Get(), NULL) ? | 146 bool stdout_connected = ConnectNamedPipe(stdout_pipe.Get(), NULL) ? |
147 TRUE : GetLastError() == ERROR_PIPE_CONNECTED; | 147 TRUE : GetLastError() == ERROR_PIPE_CONNECTED; |
148 bool stdin_connected = ConnectNamedPipe(stdin_pipe.Get(), NULL) ? | 148 bool stdin_connected = ConnectNamedPipe(stdin_pipe.Get(), NULL) ? |
149 TRUE : GetLastError() == ERROR_PIPE_CONNECTED; | 149 TRUE : GetLastError() == ERROR_PIPE_CONNECTED; |
150 if (!stdout_connected || !stdin_connected) { | 150 if (!stdout_connected || !stdin_connected) { |
151 base::KillProcess(cmd_handle, 0, false); | 151 base::KillProcess(cmd_handle.Get(), 0, false); |
152 base::CloseProcessHandle(cmd_handle); | |
153 LOG(ERROR) << "Failed to connect IO pipes when starting " | 152 LOG(ERROR) << "Failed to connect IO pipes when starting " |
154 << command_line.GetProgram().MaybeAsASCII(); | 153 << command_line.GetProgram().MaybeAsASCII(); |
155 return false; | 154 return false; |
156 } | 155 } |
157 | 156 |
158 *process_handle = cmd_handle; | 157 *process_handle = cmd_handle.Take(); |
159 *read_file = stdout_pipe.Take(); | 158 *read_file = stdout_pipe.Take(); |
160 *write_file = stdin_pipe.Take(); | 159 *write_file = stdin_pipe.Take(); |
161 | 160 |
162 return true; | 161 return true; |
163 } | 162 } |
164 | 163 |
165 } // namespace extensions | 164 } // namespace extensions |
OLD | NEW |