diff options
author | erikchen <erikchen@chromium.org> | 2015-06-16 13:20:51 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-16 20:22:34 +0000 |
commit | 151b2f982d66d76337668b0b7f26ab0cd9d7ff34 (patch) | |
tree | b5a43af376e7bcdabb5a28e8fa451e0011862b8e /ipc | |
parent | a4b3a55e702f00a77e13edbbdcc62f63d3da525f (diff) | |
download | chromium_src-151b2f982d66d76337668b0b7f26ab0cd9d7ff34.zip chromium_src-151b2f982d66d76337668b0b7f26ab0cd9d7ff34.tar.gz chromium_src-151b2f982d66d76337668b0b7f26ab0cd9d7ff34.tar.bz2 |
IPC: Add new classes required for attachment brokering.
The implementations of these classes are just stubs.
BUG=493414
Review URL: https://codereview.chromium.org/1180313007
Cr-Commit-Position: refs/heads/master@{#334676}
Diffstat (limited to 'ipc')
-rw-r--r-- | ipc/BUILD.gn | 6 | ||||
-rw-r--r-- | ipc/attachment_broker.h | 52 | ||||
-rw-r--r-- | ipc/attachment_broker_win.cc | 34 | ||||
-rw-r--r-- | ipc/attachment_broker_win.h | 34 | ||||
-rw-r--r-- | ipc/brokerable_attachment.cc | 19 | ||||
-rw-r--r-- | ipc/brokerable_attachment.h | 41 | ||||
-rw-r--r-- | ipc/handle_attachment_win.h | 24 | ||||
-rw-r--r-- | ipc/ipc.gypi | 6 | ||||
-rw-r--r-- | ipc/ipc_message_attachment.h | 1 | ||||
-rw-r--r-- | ipc/mojo/ipc_channel_mojo.cc | 3 |
10 files changed, 220 insertions, 0 deletions
diff --git a/ipc/BUILD.gn b/ipc/BUILD.gn index b756921..f5f6595 100644 --- a/ipc/BUILD.gn +++ b/ipc/BUILD.gn @@ -6,6 +6,12 @@ import("//testing/test.gni") component("ipc") { sources = [ + "attachment_broker.h", + "attachment_broker_win.cc", + "attachment_broker_win.h", + "brokerable_attachment.cc", + "brokerable_attachment.h", + "handle_attachment_win.h", "ipc_channel.cc", "ipc_channel.h", "ipc_channel_common.cc", diff --git a/ipc/attachment_broker.h b/ipc/attachment_broker.h new file mode 100644 index 0000000..35a6386 --- /dev/null +++ b/ipc/attachment_broker.h @@ -0,0 +1,52 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef IPC_ATTACHMENT_BROKER_H_ +#define IPC_ATTACHMENT_BROKER_H_ + +#include "base/macros.h" +#include "base/process/process_handle.h" +#include "ipc/brokerable_attachment.h" +#include "ipc/ipc_export.h" + +namespace IPC { + +class AttachmentBroker; +// Classes that inherit from this abstract base class are capable of +// communicating with a broker to send and receive attachments to Chrome IPC +// messages. +class IPC_EXPORT SupportsAttachmentBrokering { + public: + // Returns an AttachmentBroker used to broker attachments of IPC messages to + // other processes. There must be exactly one AttachmentBroker per process. + virtual AttachmentBroker* GetAttachmentBroker() = 0; +}; + +// Responsible for brokering attachments to Chrome IPC messages. On platforms +// that support attachment brokering, every IPC channel should have a reference +// to a AttachmentBroker. +class IPC_EXPORT AttachmentBroker { + public: + AttachmentBroker() {} + virtual ~AttachmentBroker() {} + + // Sends |attachment| to |destination_process|. The implementation uses an + // IPC::Channel to communicate with the broker process. This may be the same + // IPC::Channel that is requesting the brokering of an attachment. + virtual void SendAttachmentToProcess(BrokerableAttachment* attachment, + base::ProcessId destination_process) = 0; + + // Returns whether the attachment was available. If the attachment was + // available, populates the output parameter |attachment|. The caller then + // becomes the owner of |attachment|. + virtual bool GetAttachmentWithId(BrokerableAttachment::AttachmentId id, + BrokerableAttachment* attachment) = 0; + + private: + DISALLOW_COPY_AND_ASSIGN(AttachmentBroker); +}; + +} // namespace IPC + +#endif // IPC_ATTACHMENT_BROKER_H_ diff --git a/ipc/attachment_broker_win.cc b/ipc/attachment_broker_win.cc new file mode 100644 index 0000000..caf80b8 --- /dev/null +++ b/ipc/attachment_broker_win.cc @@ -0,0 +1,34 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ipc/attachment_broker_win.h" + +namespace IPC { + +AttachmentBrokerWin::AttachmentBrokerWin() { +} + +AttachmentBrokerWin::~AttachmentBrokerWin() { +} + +void AttachmentBrokerWin::OnReceiveDuplicatedHandle( + HANDLE, + BrokerableAttachment::AttachmentId id) { + // TODO(erikchen): Implement me. http://crbug.com/493414 +} + +void AttachmentBrokerWin::SendAttachmentToProcess( + BrokerableAttachment* attachment, + base::ProcessId destination_process) { + // TODO(erikchen): Implement me. http://crbug.com/493414 +} + +bool AttachmentBrokerWin::GetAttachmentWithId( + BrokerableAttachment::AttachmentId id, + BrokerableAttachment* attachment) { + // TODO(erikchen): Implement me. http://crbug.com/493414 + return false; +} + +} // namespace IPC diff --git a/ipc/attachment_broker_win.h b/ipc/attachment_broker_win.h new file mode 100644 index 0000000..8c021e7 --- /dev/null +++ b/ipc/attachment_broker_win.h @@ -0,0 +1,34 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef IPC_ATTACHMENT_BROKER_WIN_H_ +#define IPC_ATTACHMENT_BROKER_WIN_H_ + +#include "ipc/attachment_broker.h" +#include "ipc/ipc_export.h" +#include "ipc/ipc_sender.h" + +namespace IPC { + +// This class is an implementation of AttachmentBroker for the Windows platform. +class IPC_EXPORT AttachmentBrokerWin : public IPC::AttachmentBroker { + public: + AttachmentBrokerWin(); + virtual ~AttachmentBrokerWin(); + + // In a non-broker process, the single instance of this class listens for + // an IPC from the broker process indicating that a new attachment has been + // duplicated. + void OnReceiveDuplicatedHandle(HANDLE, BrokerableAttachment::AttachmentId id); + + // IPC::AttachmentBroker overrides. + void SendAttachmentToProcess(BrokerableAttachment* attachment, + base::ProcessId destination_process) override; + bool GetAttachmentWithId(BrokerableAttachment::AttachmentId id, + BrokerableAttachment* attachment) override; +}; + +} // namespace IPC + +#endif // IPC_ATTACHMENT_BROKER_WIN_H_ diff --git a/ipc/brokerable_attachment.cc b/ipc/brokerable_attachment.cc new file mode 100644 index 0000000..be5d51b --- /dev/null +++ b/ipc/brokerable_attachment.cc @@ -0,0 +1,19 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ipc/brokerable_attachment.h" + +namespace IPC { + +BrokerableAttachment::BrokerableAttachment() { +} + +BrokerableAttachment::~BrokerableAttachment() { +} + +BrokerableAttachment::AttachmentId BrokerableAttachment::GetIdentifier() const { + return id_; +} + +} // namespace IPC diff --git a/ipc/brokerable_attachment.h b/ipc/brokerable_attachment.h new file mode 100644 index 0000000..42d8e9f --- /dev/null +++ b/ipc/brokerable_attachment.h @@ -0,0 +1,41 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef IPC_BROKERABLE_ATTACHMENT_H_ +#define IPC_BROKERABLE_ATTACHMENT_H_ + +#include <stdint.h> + +#include "base/macros.h" +#include "ipc/ipc_export.h" +#include "ipc/ipc_message_attachment.h" + +namespace IPC { + +// This subclass of MessageAttachment requires an AttachmentBroker to be +// attached to a Chrome IPC message. +class IPC_EXPORT BrokerableAttachment : public MessageAttachment { + public: + // An id uniquely identifies an attachment sent via a broker. + struct IPC_EXPORT AttachmentId { + uint32_t nonce[4]; + }; + + // The identifier is unique across all Chrome processes. + AttachmentId GetIdentifier() const; + + protected: + BrokerableAttachment(); + ~BrokerableAttachment() override; + + private: + // This member uniquely identifies a BrokerableAttachment across all Chrome + // processes. + AttachmentId id_; + DISALLOW_COPY_AND_ASSIGN(BrokerableAttachment); +}; + +} // namespace IPC + +#endif // IPC_BROKERABLE_ATTACHMENT_H_ diff --git a/ipc/handle_attachment_win.h b/ipc/handle_attachment_win.h new file mode 100644 index 0000000..b539907 --- /dev/null +++ b/ipc/handle_attachment_win.h @@ -0,0 +1,24 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef IPC_HANDLE_ATTACHMENT_WIN_H_ +#define IPC_HANDLE_ATTACHMENT_WIN_H_ + +#include "ipc/brokerable_attachment.h" +#include "ipc/ipc_export.h" + +namespace IPC { +namespace internal { + +// This class represents a Windows HANDLE attached to a Chrome IPC message. +class IPC_EXPORT HandleAttachmentWin : public BrokerableAttachment { + private: + Type GetType() const override { return TYPE_WIN_HANDLE; } + HANDLE handle_; +}; + +} // namespace internal +} // namespace IPC + +#endif // IPC_HANDLE_ATTACHMENT_WIN_H_ diff --git a/ipc/ipc.gypi b/ipc/ipc.gypi index a10790e..65979d1 100644 --- a/ipc/ipc.gypi +++ b/ipc/ipc.gypi @@ -11,6 +11,12 @@ # This part is shared between the targets defined below. ['ipc_target==1', { 'sources': [ + 'attachment_broker.h', + 'attachment_broker_win.cc', + 'attachment_broker_win.h', + 'brokerable_attachment.cc', + 'brokerable_attachment.h', + 'handle_attachment_win.h', 'ipc_channel.cc', 'ipc_channel.h', 'ipc_channel_factory.cc', diff --git a/ipc/ipc_message_attachment.h b/ipc/ipc_message_attachment.h index ba7f0e8..63dddfe 100644 --- a/ipc/ipc_message_attachment.h +++ b/ipc/ipc_message_attachment.h @@ -20,6 +20,7 @@ class IPC_EXPORT MessageAttachment enum Type { TYPE_PLATFORM_FILE, // The instance is |PlatformFileAttachment|. TYPE_MOJO_HANDLE, // The instance is |MojoHandleAttachment|. + TYPE_WIN_HANDLE, // The instance is |HandleAttachmentWin|. }; virtual Type GetType() const = 0; diff --git a/ipc/mojo/ipc_channel_mojo.cc b/ipc/mojo/ipc_channel_mojo.cc index d4e5260..62fcb19 100644 --- a/ipc/mojo/ipc_channel_mojo.cc +++ b/ipc/mojo/ipc_channel_mojo.cc @@ -532,6 +532,9 @@ MojoResult ChannelMojo::ReadFromMessageAttachmentSet( attachment.get())->TakeHandle(); handles->push_back(handle.release().value()); } break; + case MessageAttachment::TYPE_WIN_HANDLE: + NOTREACHED(); + break; } } |