summaryrefslogtreecommitdiffstats
path: root/ipc
diff options
context:
space:
mode:
authorerikchen <erikchen@chromium.org>2015-10-06 18:23:56 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-07 01:26:16 +0000
commitcdc80b06d5c210d040d7b41700a1161d310d4485 (patch)
tree4a2204377d20aeb7b4a72d340110a72fa6d0c8d7 /ipc
parentc34797eef3845a14cd4b47b51aa3491f5b3ea002 (diff)
downloadchromium_src-cdc80b06d5c210d040d7b41700a1161d310d4485.zip
chromium_src-cdc80b06d5c210d040d7b41700a1161d310d4485.tar.gz
chromium_src-cdc80b06d5c210d040d7b41700a1161d310d4485.tar.bz2
ipc: Make factory methods for attachment brokers.
This is a refactor with no intended functional effects. BUG=535711 Review URL: https://codereview.chromium.org/1382303003 Cr-Commit-Position: refs/heads/master@{#352735}
Diffstat (limited to 'ipc')
-rw-r--r--ipc/attachment_broker.cc5
-rw-r--r--ipc/attachment_broker_privileged.cc23
-rw-r--r--ipc/attachment_broker_privileged.h9
-rw-r--r--ipc/attachment_broker_privileged_win_unittest.cc2
-rw-r--r--ipc/attachment_broker_unprivileged.cc23
-rw-r--r--ipc/attachment_broker_unprivileged.h9
6 files changed, 63 insertions, 8 deletions
diff --git a/ipc/attachment_broker.cc b/ipc/attachment_broker.cc
index 2fc4fb4..dac046b 100644
--- a/ipc/attachment_broker.cc
+++ b/ipc/attachment_broker.cc
@@ -14,8 +14,9 @@ namespace IPC {
// static
void AttachmentBroker::SetGlobal(AttachmentBroker* broker) {
- CHECK(!g_attachment_broker)
- << "An attachment broker already exists with memory address: " << broker;
+ CHECK(!g_attachment_broker || !broker)
+ << "Global attachment broker address: " << broker
+ << ". New attachment broker address: " << broker;
g_attachment_broker = broker;
}
diff --git a/ipc/attachment_broker_privileged.cc b/ipc/attachment_broker_privileged.cc
index 0f3ac48..d040392 100644
--- a/ipc/attachment_broker_privileged.cc
+++ b/ipc/attachment_broker_privileged.cc
@@ -9,11 +9,30 @@
#include "base/metrics/histogram_macros.h"
#include "ipc/ipc_endpoint.h"
+#if defined(OS_WIN)
+#include "ipc/attachment_broker_privileged_win.h"
+#endif
+
namespace IPC {
-AttachmentBrokerPrivileged::AttachmentBrokerPrivileged() {}
+AttachmentBrokerPrivileged::AttachmentBrokerPrivileged() {
+ IPC::AttachmentBroker::SetGlobal(this);
+}
-AttachmentBrokerPrivileged::~AttachmentBrokerPrivileged() {}
+AttachmentBrokerPrivileged::~AttachmentBrokerPrivileged() {
+ IPC::AttachmentBroker::SetGlobal(nullptr);
+}
+
+// static
+scoped_ptr<AttachmentBrokerPrivileged>
+AttachmentBrokerPrivileged::CreateBroker() {
+#if defined(OS_WIN)
+ return scoped_ptr<AttachmentBrokerPrivileged>(
+ new IPC::AttachmentBrokerPrivilegedWin);
+#else
+ return nullptr;
+#endif
+}
void AttachmentBrokerPrivileged::RegisterCommunicationChannel(
Endpoint* endpoint) {
diff --git a/ipc/attachment_broker_privileged.h b/ipc/attachment_broker_privileged.h
index 7b3975a..0d5f4a8 100644
--- a/ipc/attachment_broker_privileged.h
+++ b/ipc/attachment_broker_privileged.h
@@ -7,6 +7,7 @@
#include <vector>
+#include "base/memory/scoped_ptr.h"
#include "ipc/attachment_broker.h"
#include "ipc/ipc_export.h"
@@ -24,6 +25,14 @@ class IPC_EXPORT AttachmentBrokerPrivileged : public IPC::AttachmentBroker {
AttachmentBrokerPrivileged();
~AttachmentBrokerPrivileged() override;
+ // On platforms that support attachment brokering, returns a new instance of
+ // a platform-specific attachment broker. Otherwise returns |nullptr|.
+ // The caller takes ownership of the newly created instance, and is
+ // responsible for ensuring that the attachment broker lives longer than
+ // every IPC::Channel. The new instance automatically registers itself as the
+ // global attachment broker.
+ static scoped_ptr<AttachmentBrokerPrivileged> CreateBroker();
+
// Each unprivileged process should have one IPC channel on which it
// communicates attachment information with the broker process. In the broker
// process, these channels must be registered and deregistered with the
diff --git a/ipc/attachment_broker_privileged_win_unittest.cc b/ipc/attachment_broker_privileged_win_unittest.cc
index 9c4a1195..25cadcb 100644
--- a/ipc/attachment_broker_privileged_win_unittest.cc
+++ b/ipc/attachment_broker_privileged_win_unittest.cc
@@ -220,7 +220,6 @@ class IPCAttachmentBrokerPrivilegedWinTest : public IPCTestBase {
// Takes ownership of |broker|. Has no effect if called after CommonSetUp().
void set_broker(IPC::AttachmentBrokerUnprivilegedWin* broker) {
broker_.reset(broker);
- IPC::AttachmentBroker::SetGlobal(broker);
}
void CommonSetUp() {
@@ -427,7 +426,6 @@ int CommonPrivilegedProcessMain(OnMessageReceivedCallback callback,
// Set up IPC channel.
IPC::AttachmentBrokerPrivilegedWin broker;
- IPC::AttachmentBroker::SetGlobal(&broker);
scoped_ptr<IPC::Channel> channel(IPC::Channel::CreateClient(
IPCTestBase::GetChannelName(channel_name), &listener));
broker.RegisterCommunicationChannel(channel.get());
diff --git a/ipc/attachment_broker_unprivileged.cc b/ipc/attachment_broker_unprivileged.cc
index ce4e8ab..75f61e4 100644
--- a/ipc/attachment_broker_unprivileged.cc
+++ b/ipc/attachment_broker_unprivileged.cc
@@ -8,12 +8,31 @@
#include "ipc/ipc_channel.h"
#include "ipc/ipc_endpoint.h"
+#if defined(OS_WIN)
+#include "ipc/attachment_broker_unprivileged_win.h"
+#endif
+
namespace IPC {
AttachmentBrokerUnprivileged::AttachmentBrokerUnprivileged()
- : sender_(nullptr) {}
+ : sender_(nullptr) {
+ IPC::AttachmentBroker::SetGlobal(this);
+}
-AttachmentBrokerUnprivileged::~AttachmentBrokerUnprivileged() {}
+AttachmentBrokerUnprivileged::~AttachmentBrokerUnprivileged() {
+ IPC::AttachmentBroker::SetGlobal(nullptr);
+}
+
+// static
+scoped_ptr<AttachmentBrokerUnprivileged>
+AttachmentBrokerUnprivileged::CreateBroker() {
+#if defined(OS_WIN)
+ return scoped_ptr<AttachmentBrokerUnprivileged>(
+ new IPC::AttachmentBrokerUnprivilegedWin);
+#else
+ return nullptr;
+#endif
+}
void AttachmentBrokerUnprivileged::DesignateBrokerCommunicationChannel(
Endpoint* endpoint) {
diff --git a/ipc/attachment_broker_unprivileged.h b/ipc/attachment_broker_unprivileged.h
index 4f847a6..26cc1bf 100644
--- a/ipc/attachment_broker_unprivileged.h
+++ b/ipc/attachment_broker_unprivileged.h
@@ -5,6 +5,7 @@
#ifndef IPC_ATTACHMENT_BROKER_UNPRIVILEGED_H_
#define IPC_ATTACHMENT_BROKER_UNPRIVILEGED_H_
+#include "base/memory/scoped_ptr.h"
#include "ipc/attachment_broker.h"
#include "ipc/ipc_export.h"
@@ -20,6 +21,14 @@ class IPC_EXPORT AttachmentBrokerUnprivileged : public IPC::AttachmentBroker {
AttachmentBrokerUnprivileged();
~AttachmentBrokerUnprivileged() override;
+ // On platforms that support attachment brokering, returns a new instance of
+ // a platform-specific attachment broker. Otherwise returns |nullptr|.
+ // The caller takes ownership of the newly created instance, and is
+ // responsible for ensuring that the attachment broker lives longer than
+ // every IPC::Channel. The new instance automatically registers itself as the
+ // global attachment broker.
+ static scoped_ptr<AttachmentBrokerUnprivileged> CreateBroker();
+
// In each unprivileged process, exactly one channel should be used to
// communicate brokerable attachments with the broker process.
void DesignateBrokerCommunicationChannel(Endpoint* endpoint);