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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 *error_message = "Path to native messaging host manifest must be absolute."; | 82 *error_message = "Path to native messaging host manifest must be absolute."; |
83 return base::FilePath(); | 83 return base::FilePath(); |
84 } | 84 } |
85 | 85 |
86 return manifest_path; | 86 return manifest_path; |
87 } | 87 } |
88 | 88 |
89 // static | 89 // static |
90 bool NativeProcessLauncher::LaunchNativeProcess( | 90 bool NativeProcessLauncher::LaunchNativeProcess( |
91 const CommandLine& command_line, | 91 const CommandLine& command_line, |
92 base::ProcessHandle* process_handle, | 92 base::Process* process, |
93 base::File* read_file, | 93 base::File* read_file, |
94 base::File* write_file) { | 94 base::File* write_file) { |
95 // Timeout for the IO pipes. | 95 // Timeout for the IO pipes. |
96 const DWORD kTimeoutMs = 5000; | 96 const DWORD kTimeoutMs = 5000; |
97 | 97 |
98 // Windows will use default buffer size when 0 is passed to | 98 // Windows will use default buffer size when 0 is passed to |
99 // CreateNamedPipeW(). | 99 // CreateNamedPipeW(). |
100 const DWORD kBufferSize = 0; | 100 const DWORD kBufferSize = 0; |
101 | 101 |
102 if (!command_line.GetProgram().IsAbsolute()) { | 102 if (!command_line.GetProgram().IsAbsolute()) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 | 144 |
145 base::string16 command_line_string = command_line.GetCommandLineString(); | 145 base::string16 command_line_string = command_line.GetCommandLineString(); |
146 | 146 |
147 base::string16 command = base::StringPrintf( | 147 base::string16 command = base::StringPrintf( |
148 L"%ls /c %ls < %ls > %ls", | 148 L"%ls /c %ls < %ls > %ls", |
149 comspec.get(), command_line_string.c_str(), | 149 comspec.get(), command_line_string.c_str(), |
150 in_pipe_name.c_str(), out_pipe_name.c_str()); | 150 in_pipe_name.c_str(), out_pipe_name.c_str()); |
151 | 151 |
152 base::LaunchOptions options; | 152 base::LaunchOptions options; |
153 options.start_hidden = true; | 153 options.start_hidden = true; |
154 base::win::ScopedHandle cmd_handle; | 154 base::Process cmd_process = base::LaunchProcess(command.c_str(), options); |
155 if (!base::LaunchProcess(command.c_str(), options, &cmd_handle)) { | 155 if (!cmd_process.IsValid()) { |
156 LOG(ERROR) << "Error launching process " | 156 LOG(ERROR) << "Error launching process " |
157 << command_line.GetProgram().MaybeAsASCII(); | 157 << command_line.GetProgram().MaybeAsASCII(); |
158 return false; | 158 return false; |
159 } | 159 } |
160 | 160 |
161 bool stdout_connected = ConnectNamedPipe(stdout_pipe.Get(), NULL) ? | 161 bool stdout_connected = ConnectNamedPipe(stdout_pipe.Get(), NULL) ? |
162 TRUE : GetLastError() == ERROR_PIPE_CONNECTED; | 162 TRUE : GetLastError() == ERROR_PIPE_CONNECTED; |
163 bool stdin_connected = ConnectNamedPipe(stdin_pipe.Get(), NULL) ? | 163 bool stdin_connected = ConnectNamedPipe(stdin_pipe.Get(), NULL) ? |
164 TRUE : GetLastError() == ERROR_PIPE_CONNECTED; | 164 TRUE : GetLastError() == ERROR_PIPE_CONNECTED; |
165 if (!stdout_connected || !stdin_connected) { | 165 if (!stdout_connected || !stdin_connected) { |
166 base::KillProcess(cmd_handle.Get(), 0, false); | 166 base::KillProcess(cmd_process.Handle(), 0, false); |
167 LOG(ERROR) << "Failed to connect IO pipes when starting " | 167 LOG(ERROR) << "Failed to connect IO pipes when starting " |
168 << command_line.GetProgram().MaybeAsASCII(); | 168 << command_line.GetProgram().MaybeAsASCII(); |
169 return false; | 169 return false; |
170 } | 170 } |
171 | 171 |
172 *process_handle = cmd_handle.Take(); | 172 *process = cmd_process.Pass(); |
173 *read_file = base::File(stdout_pipe.Take()); | 173 *read_file = base::File(stdout_pipe.Take()); |
174 *write_file = base::File(stdin_pipe.Take()); | 174 *write_file = base::File(stdin_pipe.Take()); |
175 | 175 |
176 return true; | 176 return true; |
177 } | 177 } |
178 | 178 |
179 } // namespace extensions | 179 } // namespace extensions |
OLD | NEW |