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

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

Issue 12406002: Pass ID of the calling extension to the native messaging host. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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/logging.h" 9 #include "base/logging.h"
10 #include "base/posix/eintr_wrapper.h" 10 #include "base/posix/eintr_wrapper.h"
(...skipping 19 matching lines...) Expand all
30 const std::string& native_host_name, 30 const std::string& native_host_name,
31 std::string* error_message) { 31 std::string* error_message) {
32 base::FilePath manifest_path = 32 base::FilePath manifest_path =
33 base::FilePath(kNativeMessagingDirectory).Append( 33 base::FilePath(kNativeMessagingDirectory).Append(
34 native_host_name + ".json"); 34 native_host_name + ".json");
35 return NativeMessagingHostManifest::Load(manifest_path, error_message); 35 return NativeMessagingHostManifest::Load(manifest_path, error_message);
36 } 36 }
37 37
38 // static 38 // static
39 bool NativeProcessLauncher::LaunchNativeProcess( 39 bool NativeProcessLauncher::LaunchNativeProcess(
40 const base::FilePath& path, 40 const CommandLine& command_line,
41 base::PlatformFile* read_file, 41 base::PlatformFile* read_file,
42 base::PlatformFile* write_file) { 42 base::PlatformFile* write_file) {
43 base::FileHandleMappingVector fd_map; 43 base::FileHandleMappingVector fd_map;
44 44
45 int read_pipe_fds[2] = {0}; 45 int read_pipe_fds[2] = {0};
46 if (HANDLE_EINTR(pipe(read_pipe_fds)) != 0) { 46 if (HANDLE_EINTR(pipe(read_pipe_fds)) != 0) {
47 LOG(ERROR) << "Bad read pipe"; 47 LOG(ERROR) << "Bad read pipe";
48 return false; 48 return false;
49 } 49 }
50 file_util::ScopedFD read_pipe_read_fd(&read_pipe_fds[0]); 50 file_util::ScopedFD read_pipe_read_fd(&read_pipe_fds[0]);
51 file_util::ScopedFD read_pipe_write_fd(&read_pipe_fds[1]); 51 file_util::ScopedFD read_pipe_write_fd(&read_pipe_fds[1]);
52 fd_map.push_back(std::make_pair(*read_pipe_write_fd, STDOUT_FILENO)); 52 fd_map.push_back(std::make_pair(*read_pipe_write_fd, STDOUT_FILENO));
53 53
54 int write_pipe_fds[2] = {0}; 54 int write_pipe_fds[2] = {0};
55 if (HANDLE_EINTR(pipe(write_pipe_fds)) != 0) { 55 if (HANDLE_EINTR(pipe(write_pipe_fds)) != 0) {
56 LOG(ERROR) << "Bad write pipe"; 56 LOG(ERROR) << "Bad write pipe";
57 return false; 57 return false;
58 } 58 }
59 file_util::ScopedFD write_pipe_read_fd(&write_pipe_fds[0]); 59 file_util::ScopedFD write_pipe_read_fd(&write_pipe_fds[0]);
60 file_util::ScopedFD write_pipe_write_fd(&write_pipe_fds[1]); 60 file_util::ScopedFD write_pipe_write_fd(&write_pipe_fds[1]);
61 fd_map.push_back(std::make_pair(*write_pipe_read_fd, STDIN_FILENO)); 61 fd_map.push_back(std::make_pair(*write_pipe_read_fd, STDIN_FILENO));
62 62
63 CommandLine line(path);
64 base::LaunchOptions options; 63 base::LaunchOptions options;
65 options.fds_to_remap = &fd_map; 64 options.fds_to_remap = &fd_map;
66 int process_id; 65 int process_id;
67 if (!base::LaunchProcess(line, options, &process_id)) { 66 if (!base::LaunchProcess(command_line, options, &process_id)) {
68 LOG(ERROR) << "Error launching process"; 67 LOG(ERROR) << "Error launching process";
69 return false; 68 return false;
70 } 69 }
71 70
72 // We will not be reading from the write pipe, nor writing from the read pipe. 71 // We will not be reading from the write pipe, nor writing from the read pipe.
73 write_pipe_read_fd.reset(); 72 write_pipe_read_fd.reset();
74 read_pipe_write_fd.reset(); 73 read_pipe_write_fd.reset();
75 74
76 *read_file = *read_pipe_read_fd.release(); 75 *read_file = *read_pipe_read_fd.release();
77 *write_file = *write_pipe_write_fd.release(); 76 *write_file = *write_pipe_write_fd.release();
78 77
79 return true; 78 return true;
80 } 79 }
81 80
82 } // namespace extensions 81 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698