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

Side by Side Diff: chrome/plugin/plugin_channel.cc

Issue 149062: mac/linux: rework plugin channel file descriptor creation (Closed)
Patch Set: address review comments Created 11 years, 5 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
« no previous file with comments | « chrome/plugin/plugin_channel.h ('k') | chrome/plugin/plugin_thread.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/plugin/plugin_channel.h" 5 #include "chrome/plugin/plugin_channel.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/process_util.h" 8 #include "base/process_util.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "chrome/common/child_process.h" 11 #include "chrome/common/child_process.h"
12 #include "chrome/common/plugin_messages.h" 12 #include "chrome/common/plugin_messages.h"
13 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/plugin/plugin_thread.h" 14 #include "chrome/plugin/plugin_thread.h"
15 15
16 #if defined(OS_POSIX) 16 #if defined(OS_POSIX)
17 #include "chrome/common/ipc_channel_posix.h" 17 #include "chrome/common/ipc_channel_posix.h"
18 #endif 18 #endif
19 19
20 PluginChannel* PluginChannel::GetPluginChannel( 20 PluginChannel* PluginChannel::GetPluginChannel(
21 int process_id, MessageLoop* ipc_message_loop, int channel_fd) { 21 int process_id, MessageLoop* ipc_message_loop) {
22 // map renderer's process id to a (single) channel to that process 22 // map renderer's process id to a (single) channel to that process
23 std::string channel_name = StringPrintf( 23 std::string channel_name = StringPrintf(
24 "%d.r%d", base::GetCurrentProcId(), process_id); 24 "%d.r%d", base::GetCurrentProcId(), process_id);
25 25
26 #if defined(OS_POSIX)
27 // If we were provided an already-open channel, associate it with
28 // the channel name in this process's name<->socket map.
29 if (channel_fd > 0)
30 IPC::AddChannelSocket(channel_name, channel_fd);
31 #endif
32
33 return static_cast<PluginChannel*>(PluginChannelBase::GetChannel( 26 return static_cast<PluginChannel*>(PluginChannelBase::GetChannel(
34 channel_name, 27 channel_name,
35 IPC::Channel::MODE_SERVER, 28 IPC::Channel::MODE_SERVER,
36 ClassFactory, 29 ClassFactory,
37 ipc_message_loop, 30 ipc_message_loop,
38 false)); 31 false));
39 } 32 }
40 33
41 PluginChannel::PluginChannel() : renderer_handle_(0), in_send_(0), 34 PluginChannel::PluginChannel()
42 off_the_record_(false) { 35 : renderer_handle_(0),
36 #if defined(OS_POSIX)
37 renderer_fd_(-1),
38 #endif
39 in_send_(0),
40 off_the_record_(false) {
43 SendUnblockingOnlyDuringDispatch(); 41 SendUnblockingOnlyDuringDispatch();
44 ChildProcess::current()->AddRefProcess(); 42 ChildProcess::current()->AddRefProcess();
45 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 43 const CommandLine* command_line = CommandLine::ForCurrentProcess();
46 log_messages_ = command_line->HasSwitch(switches::kLogPluginMessages); 44 log_messages_ = command_line->HasSwitch(switches::kLogPluginMessages);
47 } 45 }
48 46
49 PluginChannel::~PluginChannel() { 47 PluginChannel::~PluginChannel() {
50 if (renderer_handle_) 48 if (renderer_handle_)
51 base::CloseProcessHandle(renderer_handle_); 49 base::CloseProcessHandle(renderer_handle_);
50 #if defined(OS_POSIX)
51 // If we still have the FD, close it.
52 if (renderer_fd_ != -1) {
53 close(renderer_fd_);
54 }
55 #endif
52 ChildProcess::current()->ReleaseProcess(); 56 ChildProcess::current()->ReleaseProcess();
53 } 57 }
54 58
55 bool PluginChannel::Send(IPC::Message* msg) { 59 bool PluginChannel::Send(IPC::Message* msg) {
56 in_send_++; 60 in_send_++;
57 if (log_messages_) { 61 if (log_messages_) {
58 LOG(INFO) << "sending message @" << msg << " on channel @" << this 62 LOG(INFO) << "sending message @" << msg << " on channel @" << this
59 << " with type " << msg->type(); 63 << " with type " << msg->type();
60 } 64 }
61 bool result = PluginChannelBase::Send(msg); 65 bool result = PluginChannelBase::Send(msg);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 RemoveRoute(plugin_stubs_[i]->instance_id()); 141 RemoveRoute(plugin_stubs_[i]->instance_id());
138 142
139 // Need to addref this object temporarily because otherwise removing the last 143 // Need to addref this object temporarily because otherwise removing the last
140 // stub will cause the destructor of this object to be called, however at 144 // stub will cause the destructor of this object to be called, however at
141 // that point plugin_stubs_ will have one element and its destructor will be 145 // that point plugin_stubs_ will have one element and its destructor will be
142 // called twice. 146 // called twice.
143 scoped_refptr<PluginChannel> me(this); 147 scoped_refptr<PluginChannel> me(this);
144 148
145 plugin_stubs_.clear(); 149 plugin_stubs_.clear();
146 } 150 }
151
152 bool PluginChannel::Init(MessageLoop* ipc_message_loop, bool create_pipe_now) {
153 #if defined(OS_POSIX)
154 // This gets called when the PluginChannel is initially created. At this
155 // point, create the socketpair and assign the plugin side FD to the channel
156 // name. Keep the renderer side FD as a member variable in the PluginChannel
157 // to be able to transmit it through IPC.
158 int plugin_fd;
159 IPC::SocketPair(&plugin_fd, &renderer_fd_);
160 IPC::AddChannelSocket(channel_name(), plugin_fd);
161 #endif
162 return PluginChannelBase::Init(ipc_message_loop, create_pipe_now);
163 }
OLDNEW
« no previous file with comments | « chrome/plugin/plugin_channel.h ('k') | chrome/plugin/plugin_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698