summaryrefslogtreecommitdiffstats
path: root/chrome/plugin
diff options
context:
space:
mode:
authordmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-08 19:28:09 +0000
committerdmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-08 19:28:09 +0000
commit42ce94ec8e98df0744cc1dea26b49c084fe185f0 (patch)
tree8b585da323dc3bbabb3c61a8941aed90e1819648 /chrome/plugin
parentade3ef65f389b00a101da5eb18a02b966d354b18 (diff)
downloadchromium_src-42ce94ec8e98df0744cc1dea26b49c084fe185f0.zip
chromium_src-42ce94ec8e98df0744cc1dea26b49c084fe185f0.tar.gz
chromium_src-42ce94ec8e98df0744cc1dea26b49c084fe185f0.tar.bz2
Convert over to channel handles
This hides some of the internals of the posix channels from users, and gets rid of several #ifdef POSIX blocks. Generally simplifies usage of channels xplatform. BUG=none TEST=build Review URL: http://codereview.chromium.org/5598010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68621 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/plugin')
-rw-r--r--chrome/plugin/plugin_channel.cc39
-rw-r--r--chrome/plugin/plugin_channel.h16
-rw-r--r--chrome/plugin/plugin_channel_base.cc22
-rw-r--r--chrome/plugin/plugin_channel_base.h7
-rw-r--r--chrome/plugin/plugin_thread.cc2
5 files changed, 12 insertions, 74 deletions
diff --git a/chrome/plugin/plugin_channel.cc b/chrome/plugin/plugin_channel.cc
index 0b6d5da..b3b12951 100644
--- a/chrome/plugin/plugin_channel.cc
+++ b/chrome/plugin/plugin_channel.cc
@@ -162,9 +162,6 @@ void PluginChannel::NotifyRenderersOfPendingShutdown() {
PluginChannel::PluginChannel()
: renderer_handle_(0),
renderer_id_(-1),
-#if defined(OS_POSIX)
- renderer_fd_(-1),
-#endif
in_send_(0),
off_the_record_(false),
filter_(new MessageFilter()) {
@@ -175,11 +172,6 @@ PluginChannel::PluginChannel()
}
PluginChannel::~PluginChannel() {
-#if defined(OS_POSIX)
- // Won't be needing this any more.
- CloseRendererFD();
-#endif
-
if (renderer_handle_)
base::CloseProcessHandle(renderer_handle_);
@@ -293,12 +285,6 @@ base::WaitableEvent* PluginChannel::GetModalDialogEvent(
}
void PluginChannel::OnChannelConnected(int32 peer_pid) {
-#if defined(OS_POSIX)
- // By this point, the renderer must have its own copy of the plugin channel
- // FD.
- CloseRendererFD();
-#endif
-
base::ProcessHandle handle;
if (!base::OpenProcessHandle(peer_pid, &handle)) {
NOTREACHED();
@@ -308,11 +294,6 @@ void PluginChannel::OnChannelConnected(int32 peer_pid) {
}
void PluginChannel::OnChannelError() {
-#if defined(OS_POSIX)
- // Won't be needing this any more.
- CloseRendererFD();
-#endif
-
base::CloseProcessHandle(renderer_handle_);
renderer_handle_ = 0;
PluginChannelBase::OnChannelError();
@@ -336,17 +317,6 @@ void PluginChannel::CleanUp() {
}
bool PluginChannel::Init(MessageLoop* ipc_message_loop, bool create_pipe_now) {
-#if defined(OS_POSIX)
- // This gets called when the PluginChannel is initially created. At this
- // point, create the socketpair and assign the plugin side FD to the channel
- // name. Keep the renderer side FD as a member variable in the PluginChannel
- // to be able to transmit it through IPC.
- int plugin_fd;
- if (!IPC::SocketPair(&plugin_fd, &renderer_fd_))
- return false;
- IPC::AddChannelSocket(channel_name(), plugin_fd);
-#endif
-
if (!PluginChannelBase::Init(ipc_message_loop, create_pipe_now))
return false;
@@ -354,12 +324,3 @@ bool PluginChannel::Init(MessageLoop* ipc_message_loop, bool create_pipe_now) {
return true;
}
-#if defined(OS_POSIX)
-void PluginChannel::CloseRendererFD() {
- if (renderer_fd_ != -1) {
- if (HANDLE_EINTR(close(renderer_fd_)) < 0)
- PLOG(ERROR) << "close";
- renderer_fd_ = -1;
- }
-}
-#endif
diff --git a/chrome/plugin/plugin_channel.h b/chrome/plugin/plugin_channel.h
index 2c00cf8..519e03c 100644
--- a/chrome/plugin/plugin_channel.h
+++ b/chrome/plugin/plugin_channel.h
@@ -50,7 +50,7 @@ class PluginChannel : public PluginChannelBase {
void set_off_the_record(bool value) { off_the_record_ = value; }
#if defined(OS_POSIX)
- int renderer_fd() const { return renderer_fd_; }
+ int renderer_fd() const { return channel_->GetClientFileDescriptor(); }
#endif
protected:
@@ -80,13 +80,6 @@ class PluginChannel : public PluginChannelBase {
const std::string& domain,
base::Time begin_time);
-#if defined(OS_POSIX)
- // Close the plugin process' copy of the renderer's side of the plugin
- // channel. This can be called after the renderer is known to have its own
- // copy of renderer_fd_.
- void CloseRendererFD();
-#endif
-
std::vector<scoped_refptr<WebPluginDelegateStub> > plugin_stubs_;
// Handle to the renderer process who is on the other side of the channel.
@@ -95,13 +88,6 @@ class PluginChannel : public PluginChannelBase {
// The id of the renderer who is on the other side of the channel.
int renderer_id_;
-#if defined(OS_POSIX)
- // FD for the renderer end of the socket. It is closed when the IPC layer
- // indicates that the channel is connected, proving that the renderer has
- // access to its side of the socket.
- int renderer_fd_;
-#endif
-
int in_send_; // Tracks if we're in a Send call.
bool log_messages_; // True if we should log sent and received messages.
bool off_the_record_; // True if the renderer is in off the record mode.
diff --git a/chrome/plugin/plugin_channel_base.cc b/chrome/plugin/plugin_channel_base.cc
index 6494afb..37bc1c4 100644
--- a/chrome/plugin/plugin_channel_base.cc
+++ b/chrome/plugin/plugin_channel_base.cc
@@ -28,11 +28,11 @@ static base::LazyInstance<std::stack<scoped_refptr<PluginChannelBase> > >
static int next_pipe_id = 0;
PluginChannelBase* PluginChannelBase::GetChannel(
- const std::string& channel_key, IPC::Channel::Mode mode,
+ const IPC::ChannelHandle& channel_handle, IPC::Channel::Mode mode,
PluginChannelFactory factory, MessageLoop* ipc_message_loop,
bool create_pipe_now) {
scoped_refptr<PluginChannelBase> channel;
-
+ std::string channel_key = channel_handle.name;
PluginChannelMap::const_iterator iter = g_plugin_channels_.find(channel_key);
if (iter == g_plugin_channels_.end()) {
channel = factory();
@@ -43,10 +43,10 @@ PluginChannelBase* PluginChannelBase::GetChannel(
DCHECK(channel != NULL);
if (!channel->channel_valid()) {
- channel->channel_name_ = channel_key;
+ channel->channel_handle_ = channel_handle;
if (mode == IPC::Channel::MODE_SERVER) {
- channel->channel_name_.append(".");
- channel->channel_name_.append(base::IntToString(next_pipe_id++));
+ channel->channel_handle_.name.append(".");
+ channel->channel_handle_.name.append(base::IntToString(next_pipe_id++));
}
channel->mode_ = mode;
if (channel->Init(ipc_message_loop, create_pipe_now)) {
@@ -115,7 +115,7 @@ NPObjectBase* PluginChannelBase::GetNPObjectListenerForRoute(int route_id) {
bool PluginChannelBase::Init(MessageLoop* ipc_message_loop,
bool create_pipe_now) {
channel_.reset(new IPC::SyncChannel(
- channel_name_, mode_, this, ipc_message_loop, create_pipe_now,
+ channel_handle_, mode_, this, ipc_message_loop, create_pipe_now,
ChildProcess::current()->GetShutDownEvent()));
channel_valid_ = true;
return true;
@@ -219,11 +219,6 @@ void PluginChannelBase::RemoveRoute(int route_id) {
for (PluginChannelMap::iterator iter = g_plugin_channels_.begin();
iter != g_plugin_channels_.end(); ++iter) {
if (iter->second == this) {
-#if defined(OS_POSIX)
- if (channel_valid()) {
- IPC::RemoveAndCloseChannelSocket(channel_name());
- }
-#endif
g_plugin_channels_.erase(iter);
return;
}
@@ -239,10 +234,5 @@ void PluginChannelBase::OnControlMessageReceived(const IPC::Message& msg) {
}
void PluginChannelBase::OnChannelError() {
-#if defined(OS_POSIX)
- if (channel_valid()) {
- IPC::RemoveAndCloseChannelSocket(channel_name());
- }
-#endif
channel_valid_ = false;
}
diff --git a/chrome/plugin/plugin_channel_base.h b/chrome/plugin/plugin_channel_base.h
index 30fdc22..22103e8 100644
--- a/chrome/plugin/plugin_channel_base.h
+++ b/chrome/plugin/plugin_channel_base.h
@@ -16,6 +16,7 @@
#include "chrome/common/message_router.h"
#include "chrome/plugin/npobject_base.h"
#include "gfx/native_widget_types.h"
+#include "ipc/ipc_channel_handle.h"
#include "ipc/ipc_sync_channel.h"
// Encapsulates an IPC channel between a renderer and a plugin process.
@@ -38,7 +39,7 @@ class PluginChannelBase : public IPC::Channel::Listener,
virtual bool Send(IPC::Message* msg);
int peer_pid() { return peer_pid_; }
- std::string channel_name() const { return channel_name_; }
+ IPC::ChannelHandle channel_handle() const { return channel_handle_; }
// Returns the number of open plugin channels in this process.
static int Count();
@@ -75,7 +76,7 @@ class PluginChannelBase : public IPC::Channel::Listener,
// must still ref count the returned value. When there are no more routes
// on the channel and its ref count is 0, the object deletes itself.
static PluginChannelBase* GetChannel(
- const std::string& channel_key, IPC::Channel::Mode mode,
+ const IPC::ChannelHandle& channel_handle, IPC::Channel::Mode mode,
PluginChannelFactory factory, MessageLoop* ipc_message_loop,
bool create_pipe_now);
@@ -105,7 +106,7 @@ class PluginChannelBase : public IPC::Channel::Listener,
private:
IPC::Channel::Mode mode_;
- std::string channel_name_;
+ IPC::ChannelHandle channel_handle_;
int plugin_count_;
int peer_pid_;
diff --git a/chrome/plugin/plugin_thread.cc b/chrome/plugin/plugin_thread.cc
index 7c57f4d..7e2b921 100644
--- a/chrome/plugin/plugin_thread.cc
+++ b/chrome/plugin/plugin_thread.cc
@@ -143,7 +143,7 @@ void PluginThread::OnCreateChannel(int renderer_id,
renderer_id, ChildProcess::current()->io_message_loop()));
IPC::ChannelHandle channel_handle;
if (channel.get()) {
- channel_handle.name = channel->channel_name();
+ channel_handle.name = channel->channel_handle().name;
#if defined(OS_POSIX)
// On POSIX, pass the renderer-side FD.
channel_handle.socket = base::FileDescriptor(channel->renderer_fd(), false);