Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(366)

Unified Diff: content/common/child_process_host_impl.cc

Issue 1292263003: ipc: Use a global for the process's attachment broker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ipc_message2
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 3aad503d6c424ca50db5096ffe8a2fad90ae7ec4..397a690e4ce60dcbe2a81c24dce8870451aeaf21 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();
+}
+#endif // USE_ATTACHMENT_BROKER
#if defined(OS_MACOSX)
// Given |path| identifying a Mac-style child process executable path, adjusts
@@ -145,15 +162,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) {
@@ -164,7 +172,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();
@@ -185,12 +193,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)

Powered by Google App Engine
This is Rietveld 408576698