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

Side by Side Diff: chrome/browser/extensions/api/messaging/native_process_launcher_posix.cc

Issue 197873014: Revert of Implement ScopedFD in terms of ScopedGeneric. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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/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"
10 #include "base/logging.h" 9 #include "base/logging.h"
11 #include "base/path_service.h" 10 #include "base/path_service.h"
12 #include "base/posix/eintr_wrapper.h" 11 #include "base/posix/eintr_wrapper.h"
13 #include "base/process/launch.h" 12 #include "base/process/launch.h"
14 #include "chrome/common/chrome_paths.h" 13 #include "chrome/common/chrome_paths.h"
15 14
16 namespace extensions { 15 namespace extensions {
17 16
18 namespace { 17 namespace {
19 18
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 base::ProcessHandle* process_handle, 51 base::ProcessHandle* process_handle,
53 base::PlatformFile* read_file, 52 base::PlatformFile* read_file,
54 base::PlatformFile* write_file) { 53 base::PlatformFile* write_file) {
55 base::FileHandleMappingVector fd_map; 54 base::FileHandleMappingVector fd_map;
56 55
57 int read_pipe_fds[2] = {0}; 56 int read_pipe_fds[2] = {0};
58 if (HANDLE_EINTR(pipe(read_pipe_fds)) != 0) { 57 if (HANDLE_EINTR(pipe(read_pipe_fds)) != 0) {
59 LOG(ERROR) << "Bad read pipe"; 58 LOG(ERROR) << "Bad read pipe";
60 return false; 59 return false;
61 } 60 }
62 base::ScopedFD read_pipe_read_fd(read_pipe_fds[0]); 61 file_util::ScopedFD read_pipe_read_fd(&read_pipe_fds[0]);
63 base::ScopedFD read_pipe_write_fd(read_pipe_fds[1]); 62 file_util::ScopedFD read_pipe_write_fd(&read_pipe_fds[1]);
64 fd_map.push_back(std::make_pair(read_pipe_write_fd.get(), STDOUT_FILENO)); 63 fd_map.push_back(std::make_pair(*read_pipe_write_fd, STDOUT_FILENO));
65 64
66 int write_pipe_fds[2] = {0}; 65 int write_pipe_fds[2] = {0};
67 if (HANDLE_EINTR(pipe(write_pipe_fds)) != 0) { 66 if (HANDLE_EINTR(pipe(write_pipe_fds)) != 0) {
68 LOG(ERROR) << "Bad write pipe"; 67 LOG(ERROR) << "Bad write pipe";
69 return false; 68 return false;
70 } 69 }
71 base::ScopedFD write_pipe_read_fd(write_pipe_fds[0]); 70 file_util::ScopedFD write_pipe_read_fd(&write_pipe_fds[0]);
72 base::ScopedFD write_pipe_write_fd(write_pipe_fds[1]); 71 file_util::ScopedFD write_pipe_write_fd(&write_pipe_fds[1]);
73 fd_map.push_back(std::make_pair(write_pipe_read_fd.get(), STDIN_FILENO)); 72 fd_map.push_back(std::make_pair(*write_pipe_read_fd, STDIN_FILENO));
74 73
75 base::LaunchOptions options; 74 base::LaunchOptions options;
76 options.fds_to_remap = &fd_map; 75 options.fds_to_remap = &fd_map;
77 if (!base::LaunchProcess(command_line, options, process_handle)) { 76 if (!base::LaunchProcess(command_line, options, process_handle)) {
78 LOG(ERROR) << "Error launching process"; 77 LOG(ERROR) << "Error launching process";
79 return false; 78 return false;
80 } 79 }
81 80
82 // We will not be reading from the write pipe, nor writing from the read pipe. 81 // We will not be reading from the write pipe, nor writing from the read pipe.
83 write_pipe_read_fd.reset(); 82 write_pipe_read_fd.reset();
84 read_pipe_write_fd.reset(); 83 read_pipe_write_fd.reset();
85 84
86 *read_file = read_pipe_read_fd.release(); 85 *read_file = *read_pipe_read_fd.release();
87 *write_file = write_pipe_write_fd.release(); 86 *write_file = *write_pipe_write_fd.release();
88 87
89 return true; 88 return true;
90 } 89 }
91 90
92 } // namespace extensions 91 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/messaging/native_message_process_host_unittest.cc ('k') | chrome/browser/mac/relauncher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698