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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/files/scoped_file.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/path_service.h" | 11 #include "base/path_service.h" |
11 #include "base/posix/eintr_wrapper.h" | 12 #include "base/posix/eintr_wrapper.h" |
12 #include "base/process/launch.h" | 13 #include "base/process/launch.h" |
13 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
14 | 15 |
15 namespace extensions { | 16 namespace extensions { |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 base::ProcessHandle* process_handle, | 52 base::ProcessHandle* process_handle, |
52 base::PlatformFile* read_file, | 53 base::PlatformFile* read_file, |
53 base::PlatformFile* write_file) { | 54 base::PlatformFile* write_file) { |
54 base::FileHandleMappingVector fd_map; | 55 base::FileHandleMappingVector fd_map; |
55 | 56 |
56 int read_pipe_fds[2] = {0}; | 57 int read_pipe_fds[2] = {0}; |
57 if (HANDLE_EINTR(pipe(read_pipe_fds)) != 0) { | 58 if (HANDLE_EINTR(pipe(read_pipe_fds)) != 0) { |
58 LOG(ERROR) << "Bad read pipe"; | 59 LOG(ERROR) << "Bad read pipe"; |
59 return false; | 60 return false; |
60 } | 61 } |
61 file_util::ScopedFD read_pipe_read_fd(&read_pipe_fds[0]); | 62 base::ScopedFD read_pipe_read_fd(read_pipe_fds[0]); |
62 file_util::ScopedFD read_pipe_write_fd(&read_pipe_fds[1]); | 63 base::ScopedFD read_pipe_write_fd(read_pipe_fds[1]); |
63 fd_map.push_back(std::make_pair(*read_pipe_write_fd, STDOUT_FILENO)); | 64 fd_map.push_back(std::make_pair(read_pipe_write_fd.get(), STDOUT_FILENO)); |
64 | 65 |
65 int write_pipe_fds[2] = {0}; | 66 int write_pipe_fds[2] = {0}; |
66 if (HANDLE_EINTR(pipe(write_pipe_fds)) != 0) { | 67 if (HANDLE_EINTR(pipe(write_pipe_fds)) != 0) { |
67 LOG(ERROR) << "Bad write pipe"; | 68 LOG(ERROR) << "Bad write pipe"; |
68 return false; | 69 return false; |
69 } | 70 } |
70 file_util::ScopedFD write_pipe_read_fd(&write_pipe_fds[0]); | 71 base::ScopedFD write_pipe_read_fd(write_pipe_fds[0]); |
71 file_util::ScopedFD write_pipe_write_fd(&write_pipe_fds[1]); | 72 base::ScopedFD write_pipe_write_fd(write_pipe_fds[1]); |
72 fd_map.push_back(std::make_pair(*write_pipe_read_fd, STDIN_FILENO)); | 73 fd_map.push_back(std::make_pair(write_pipe_read_fd.get(), STDIN_FILENO)); |
73 | 74 |
74 base::LaunchOptions options; | 75 base::LaunchOptions options; |
75 options.fds_to_remap = &fd_map; | 76 options.fds_to_remap = &fd_map; |
76 if (!base::LaunchProcess(command_line, options, process_handle)) { | 77 if (!base::LaunchProcess(command_line, options, process_handle)) { |
77 LOG(ERROR) << "Error launching process"; | 78 LOG(ERROR) << "Error launching process"; |
78 return false; | 79 return false; |
79 } | 80 } |
80 | 81 |
81 // We will not be reading from the write pipe, nor writing from the read pipe. | 82 // We will not be reading from the write pipe, nor writing from the read pipe. |
82 write_pipe_read_fd.reset(); | 83 write_pipe_read_fd.reset(); |
83 read_pipe_write_fd.reset(); | 84 read_pipe_write_fd.reset(); |
84 | 85 |
85 *read_file = *read_pipe_read_fd.release(); | 86 *read_file = read_pipe_read_fd.release(); |
86 *write_file = *write_pipe_write_fd.release(); | 87 *write_file = write_pipe_write_fd.release(); |
87 | 88 |
88 return true; | 89 return true; |
89 } | 90 } |
90 | 91 |
91 } // namespace extensions | 92 } // namespace extensions |
OLD | NEW |