Skip to content

Commit

Permalink
ipc: Allow ChannelProxy to be set as a channel endpoint.
Browse files Browse the repository at this point in the history
BUG=493414

Review URL: https://codereview.chromium.org/1270543004

Cr-Commit-Position: refs/heads/master@{#341231}
  • Loading branch information
erikchen authored and Commit bot committed Jul 31, 2015
1 parent 4466769 commit bcc7961
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
9 changes: 9 additions & 0 deletions ipc/attachment_broker_unprivileged.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "ipc/attachment_broker_unprivileged.h"

#include "ipc/ipc_channel.h"
#include "ipc/ipc_channel_proxy.h"

namespace IPC {

Expand All @@ -21,4 +22,12 @@ void AttachmentBrokerUnprivileged::DesignateBrokerCommunicationChannel(
channel->set_attachment_broker_endpoint(true);
}

void AttachmentBrokerUnprivileged::DesignateBrokerCommunicationChannel(
IPC::ChannelProxy* proxy) {
DCHECK(proxy);
DCHECK(!sender_);
sender_ = proxy;
proxy->SetAttachmentBrokerEndpoint(true);
}

} // namespace IPC
2 changes: 2 additions & 0 deletions ipc/attachment_broker_unprivileged.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace IPC {

class Channel;
class ChannelProxy;
class Sender;

// This abstract subclass of AttachmentBroker is intended for use in
Expand All @@ -23,6 +24,7 @@ class IPC_EXPORT AttachmentBrokerUnprivileged : public IPC::AttachmentBroker {
// In each unprivileged process, exactly one channel should be used to
// communicate brokerable attachments with the broker process.
void DesignateBrokerCommunicationChannel(IPC::Channel* channel);
void DesignateBrokerCommunicationChannel(IPC::ChannelProxy* proxy);

protected:
IPC::Sender* get_sender() { return sender_; }
Expand Down
8 changes: 7 additions & 1 deletion ipc/ipc_channel_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ ChannelProxy::Context::Context(
channel_connected_called_(false),
channel_send_thread_safe_(false),
message_filter_router_(new MessageFilterRouter()),
peer_pid_(base::kNullProcessId) {
peer_pid_(base::kNullProcessId),
attachment_broker_endpoint_(false) {
DCHECK(ipc_task_runner_.get());
// The Listener thread where Messages are handled must be a separate thread
// to avoid oversubscribing the IO thread. If you trigger this error, you
Expand All @@ -58,6 +59,7 @@ void ChannelProxy::Context::CreateChannel(scoped_ptr<ChannelFactory> factory) {
channel_id_ = factory->GetName();
channel_ = factory->BuildChannel(this);
channel_send_thread_safe_ = channel_->IsSendThreadSafe();
channel_->set_attachment_broker_endpoint(attachment_broker_endpoint_);
}

bool ChannelProxy::Context::TryFilters(const Message& message) {
Expand Down Expand Up @@ -504,6 +506,10 @@ base::ScopedFD ChannelProxy::TakeClientFileDescriptor() {
}
#endif

void ChannelProxy::SetAttachmentBrokerEndpoint(bool is_endpoint) {
context()->set_attachment_broker_endpoint(is_endpoint);
}

//-----------------------------------------------------------------------------

} // namespace IPC
10 changes: 10 additions & 0 deletions ipc/ipc_channel_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ class IPC_EXPORT ChannelProxy : public Sender, public base::NonThreadSafe {
base::ScopedFD TakeClientFileDescriptor();
#endif

void SetAttachmentBrokerEndpoint(bool is_endpoint);

protected:
class Context;
// A subclass uses this constructor if it needs to add more information
Expand Down Expand Up @@ -217,6 +219,10 @@ class IPC_EXPORT ChannelProxy : public Sender, public base::NonThreadSafe {
// Create the Channel
void CreateChannel(scoped_ptr<ChannelFactory> factory);

void set_attachment_broker_endpoint(bool is_endpoint) {
attachment_broker_endpoint_ = is_endpoint;
}

// Methods called on the IO thread.
void OnSendMessage(scoped_ptr<Message> message_ptr);
void OnAddFilter();
Expand Down Expand Up @@ -266,6 +272,10 @@ class IPC_EXPORT ChannelProxy : public Sender, public base::NonThreadSafe {
// Cached copy of the peer process ID. Set on IPC but read on both IPC and
// listener threads.
base::ProcessId peer_pid_;

// Whether this channel is used as an endpoint for sending and receiving
// brokerable attachment messages to/from the broker process.
bool attachment_broker_endpoint_;
};

Context* context() { return context_.get(); }
Expand Down

0 comments on commit bcc7961

Please sign in to comment.