Index: content/common/child_process_host_impl.cc |
diff --git a/content/common/child_process_host_impl.cc b/content/common/child_process_host_impl.cc |
index 2341db13083705eb14995038787566d4bf9e5c02..b3f3764a6f54d6f33c92dfd3bf22b65f61cecf16 100644 |
--- a/content/common/child_process_host_impl.cc |
+++ b/content/common/child_process_host_impl.cc |
@@ -18,6 +18,7 @@ |
#include "base/process/process_metrics.h" |
#include "base/rand_util.h" |
#include "base/strings/stringprintf.h" |
+#include "base/synchronization/lock.h" |
#include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
#include "content/common/child_process_messages.h" |
#include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" |
@@ -35,12 +36,28 @@ |
#include "ipc/attachment_broker_privileged_win.h" |
#endif // OS_LINUX |
+namespace { |
+ |
#if defined(OS_WIN) |
base::LazyInstance<IPC::AttachmentBrokerPrivilegedWin>::Leaky |
g_attachment_broker = LAZY_INSTANCE_INITIALIZER; |
+base::LazyInstance<base::Lock>::Leaky |
+ g_attachment_broker_lock = LAZY_INSTANCE_INITIALIZER; |
+static bool g_attachment_broker_initialized = false; |
#endif // defined(OS_WIN) |
-namespace { |
+#if USE_ATTACHMENT_BROKER |
+IPC::AttachmentBrokerPrivileged* GetAttachmentBroker() { |
+ if (!g_attachment_broker_initialized) { |
+ base::AutoLock l(g_attachment_broker_lock.Get()); |
+ if (!g_attachment_broker_initialized) { |
+ IPC::AttachmentBroker::SetGlobal(&g_attachment_broker.Get()); |
+ g_attachment_broker_initialized = true; |
+ } |
+ } |
+ return &g_attachment_broker.Get(); |
Avi (use Gerrit)
2015/09/11 23:24:40
What? This is literally a double-checked lock, and
erikchen
2015/09/12 01:06:31
What I need is a cross-platform version of pthread
|
+} |
+#endif // USE_ATTACHMENT_BROKER |
// Global atomic to generate child process unique IDs. |
base::StaticAtomicSequenceNumber g_unique_id; |
@@ -83,15 +100,6 @@ base::FilePath ChildProcessHost::GetChildPath(int flags) { |
return child_path; |
} |
-// static |
-IPC::AttachmentBrokerPrivileged* ChildProcessHost::GetAttachmentBroker() { |
-#if USE_ATTACHMENT_BROKER |
- return &g_attachment_broker.Get(); |
-#else |
- return nullptr; |
-#endif // USE_ATTACHMENT_BROKER |
-} |
- |
ChildProcessHostImpl::ChildProcessHostImpl(ChildProcessHostDelegate* delegate) |
: delegate_(delegate), |
opening_channel_(false) { |
@@ -102,7 +110,7 @@ ChildProcessHostImpl::ChildProcessHostImpl(ChildProcessHostDelegate* delegate) |
ChildProcessHostImpl::~ChildProcessHostImpl() { |
#if USE_ATTACHMENT_BROKER |
- g_attachment_broker.Get().DeregisterCommunicationChannel(channel_.get()); |
+ GetAttachmentBroker()->DeregisterCommunicationChannel(channel_.get()); |
#endif |
for (size_t i = 0; i < filters_.size(); ++i) { |
filters_[i]->OnChannelClosing(); |
@@ -123,12 +131,11 @@ void ChildProcessHostImpl::ForceShutdown() { |
std::string ChildProcessHostImpl::CreateChannel() { |
channel_id_ = IPC::Channel::GenerateVerifiedChannelID(std::string()); |
- channel_ = |
- IPC::Channel::CreateServer(channel_id_, this, GetAttachmentBroker()); |
+ channel_ = IPC::Channel::CreateServer(channel_id_, this); |
if (!channel_->Connect()) |
return std::string(); |
#if USE_ATTACHMENT_BROKER |
- g_attachment_broker.Get().RegisterCommunicationChannel(channel_.get()); |
+ GetAttachmentBroker()->RegisterCommunicationChannel(channel_.get()); |
#endif |
for (size_t i = 0; i < filters_.size(); ++i) |