diff options
Diffstat (limited to 'ipc')
-rw-r--r-- | ipc/attachment_broker_privileged.cc | 25 | ||||
-rw-r--r-- | ipc/attachment_broker_privileged.h | 5 |
2 files changed, 30 insertions, 0 deletions
diff --git a/ipc/attachment_broker_privileged.cc b/ipc/attachment_broker_privileged.cc index 2b14217..85c1ac9 100644 --- a/ipc/attachment_broker_privileged.cc +++ b/ipc/attachment_broker_privileged.cc @@ -16,6 +16,9 @@ #endif #if defined(OS_MACOSX) && !defined(OS_IOS) +#include <mach/mach.h> + +#include "base/process/port_provider_mac.h" #include "ipc/attachment_broker_privileged_mac.h" #endif @@ -24,6 +27,19 @@ namespace IPC { namespace { #if defined(OS_MACOSX) && !defined(OS_IOS) + +// A fake port provider that does nothing. Intended for single process unit +// tests. +class FakePortProvider : public base::PortProvider { + mach_port_t TaskForPid(base::ProcessHandle process) const override { + DCHECK_EQ(process, getpid()); + return mach_task_self(); + } +}; + +base::LazyInstance<FakePortProvider>::Leaky + g_fake_port_provider = LAZY_INSTANCE_INITIALIZER; + // Passed as a constructor parameter to AttachmentBrokerPrivilegedMac. base::PortProvider* g_port_provider = nullptr; #endif // defined(OS_MACOSX) && !defined(OS_IOS) @@ -86,6 +102,15 @@ void AttachmentBrokerPrivileged::CreateBrokerIfNeeded() { } #endif // defined(OS_MACOSX) && !defined(OS_IOS) +// static +void AttachmentBrokerPrivileged::CreateBrokerForSingleProcessTests() { +#if defined(OS_MACOSX) && !defined(OS_IOS) + CreateBrokerIfNeeded(&g_fake_port_provider.Get()); +#else + CreateBrokerIfNeeded(); +#endif // defined(OS_MACOSX) && !defined(OS_IOS) +} + void AttachmentBrokerPrivileged::RegisterCommunicationChannel( Endpoint* endpoint) { base::AutoLock auto_lock(*get_lock()); diff --git a/ipc/attachment_broker_privileged.h b/ipc/attachment_broker_privileged.h index ec600b7..686bb9d 100644 --- a/ipc/attachment_broker_privileged.h +++ b/ipc/attachment_broker_privileged.h @@ -42,6 +42,11 @@ class IPC_EXPORT AttachmentBrokerPrivileged : public IPC::AttachmentBroker { static void CreateBrokerIfNeeded(); #endif // defined(OS_MACOSX) && !defined(OS_IOS) + // Similar to CreateBrokerIfNeeded(), but useful for single process unit tests + // that don't need real attachment brokering, and don't want to deal with + // setting up a fake PortProvider. + static void CreateBrokerForSingleProcessTests(); + // AttachmentBroker overrides. void RegisterCommunicationChannel(Endpoint* endpoint) override; void DeregisterCommunicationChannel(Endpoint* endpoint) override; |