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

Side by Side 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: Rebase errors. Created 5 years, 3 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 unified diff | Download patch
« no previous file with comments | « content/child/npapi/np_channel_base.cc ('k') | content/common/gpu/client/gpu_channel_host.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/common/child_process_host_impl.h" 5 #include "content/common/child_process_host_impl.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/atomic_sequence_num.h" 9 #include "base/atomic_sequence_num.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/hash.h" 12 #include "base/hash.h"
13 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
16 #include "base/numerics/safe_math.h" 16 #include "base/numerics/safe_math.h"
17 #include "base/path_service.h" 17 #include "base/path_service.h"
18 #include "base/process/process_metrics.h" 18 #include "base/process/process_metrics.h"
19 #include "base/rand_util.h" 19 #include "base/rand_util.h"
20 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
21 #include "base/synchronization/lock.h"
21 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" 22 #include "base/third_party/dynamic_annotations/dynamic_annotations.h"
22 #include "content/common/child_process_messages.h" 23 #include "content/common/child_process_messages.h"
23 #include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" 24 #include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h"
24 #include "content/public/common/child_process_host_delegate.h" 25 #include "content/public/common/child_process_host_delegate.h"
25 #include "content/public/common/content_paths.h" 26 #include "content/public/common/content_paths.h"
26 #include "content/public/common/content_switches.h" 27 #include "content/public/common/content_switches.h"
27 #include "ipc/ipc_channel.h" 28 #include "ipc/ipc_channel.h"
28 #include "ipc/ipc_logging.h" 29 #include "ipc/ipc_logging.h"
29 #include "ipc/message_filter.h" 30 #include "ipc/message_filter.h"
30 31
31 #if defined(OS_LINUX) 32 #if defined(OS_LINUX)
32 #include "base/linux_util.h" 33 #include "base/linux_util.h"
33 #elif defined(OS_WIN) 34 #elif defined(OS_WIN)
34 #include "content/common/font_cache_dispatcher_win.h" 35 #include "content/common/font_cache_dispatcher_win.h"
35 #include "ipc/attachment_broker_privileged_win.h" 36 #include "ipc/attachment_broker_privileged_win.h"
36 #endif // OS_LINUX 37 #endif // OS_LINUX
37 38
39 namespace {
40
38 #if defined(OS_WIN) 41 #if defined(OS_WIN)
39 base::LazyInstance<IPC::AttachmentBrokerPrivilegedWin>::Leaky 42 base::LazyInstance<IPC::AttachmentBrokerPrivilegedWin>::Leaky
40 g_attachment_broker = LAZY_INSTANCE_INITIALIZER; 43 g_attachment_broker = LAZY_INSTANCE_INITIALIZER;
44 base::LazyInstance<base::Lock>::Leaky
45 g_attachment_broker_lock = LAZY_INSTANCE_INITIALIZER;
46 static bool g_attachment_broker_initialized = false;
41 #endif // defined(OS_WIN) 47 #endif // defined(OS_WIN)
42 48
43 namespace { 49 #if USE_ATTACHMENT_BROKER
50 IPC::AttachmentBrokerPrivileged* GetAttachmentBroker() {
51 if (!g_attachment_broker_initialized) {
52 base::AutoLock l(g_attachment_broker_lock.Get());
53 if (!g_attachment_broker_initialized) {
54 IPC::AttachmentBroker::SetGlobal(&g_attachment_broker.Get());
55 g_attachment_broker_initialized = true;
56 }
57 }
58 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
59 }
60 #endif // USE_ATTACHMENT_BROKER
44 61
45 // Global atomic to generate child process unique IDs. 62 // Global atomic to generate child process unique IDs.
46 base::StaticAtomicSequenceNumber g_unique_id; 63 base::StaticAtomicSequenceNumber g_unique_id;
47 64
48 } // namespace 65 } // namespace
49 66
50 namespace content { 67 namespace content {
51 68
52 int ChildProcessHost::kInvalidUniqueID = -1; 69 int ChildProcessHost::kInvalidUniqueID = -1;
53 70
(...skipping 22 matching lines...) Expand all
76 child_path = base::FilePath(base::kProcSelfExe); 93 child_path = base::FilePath(base::kProcSelfExe);
77 #endif 94 #endif
78 95
79 // On most platforms, the child executable is the same as the current 96 // On most platforms, the child executable is the same as the current
80 // executable. 97 // executable.
81 if (child_path.empty()) 98 if (child_path.empty())
82 PathService::Get(CHILD_PROCESS_EXE, &child_path); 99 PathService::Get(CHILD_PROCESS_EXE, &child_path);
83 return child_path; 100 return child_path;
84 } 101 }
85 102
86 // static
87 IPC::AttachmentBrokerPrivileged* ChildProcessHost::GetAttachmentBroker() {
88 #if USE_ATTACHMENT_BROKER
89 return &g_attachment_broker.Get();
90 #else
91 return nullptr;
92 #endif // USE_ATTACHMENT_BROKER
93 }
94
95 ChildProcessHostImpl::ChildProcessHostImpl(ChildProcessHostDelegate* delegate) 103 ChildProcessHostImpl::ChildProcessHostImpl(ChildProcessHostDelegate* delegate)
96 : delegate_(delegate), 104 : delegate_(delegate),
97 opening_channel_(false) { 105 opening_channel_(false) {
98 #if defined(OS_WIN) 106 #if defined(OS_WIN)
99 AddFilter(new FontCacheDispatcher()); 107 AddFilter(new FontCacheDispatcher());
100 #endif 108 #endif
101 } 109 }
102 110
103 ChildProcessHostImpl::~ChildProcessHostImpl() { 111 ChildProcessHostImpl::~ChildProcessHostImpl() {
104 #if USE_ATTACHMENT_BROKER 112 #if USE_ATTACHMENT_BROKER
105 g_attachment_broker.Get().DeregisterCommunicationChannel(channel_.get()); 113 GetAttachmentBroker()->DeregisterCommunicationChannel(channel_.get());
106 #endif 114 #endif
107 for (size_t i = 0; i < filters_.size(); ++i) { 115 for (size_t i = 0; i < filters_.size(); ++i) {
108 filters_[i]->OnChannelClosing(); 116 filters_[i]->OnChannelClosing();
109 filters_[i]->OnFilterRemoved(); 117 filters_[i]->OnFilterRemoved();
110 } 118 }
111 } 119 }
112 120
113 void ChildProcessHostImpl::AddFilter(IPC::MessageFilter* filter) { 121 void ChildProcessHostImpl::AddFilter(IPC::MessageFilter* filter) {
114 filters_.push_back(filter); 122 filters_.push_back(filter);
115 123
116 if (channel_) 124 if (channel_)
117 filter->OnFilterAdded(channel_.get()); 125 filter->OnFilterAdded(channel_.get());
118 } 126 }
119 127
120 void ChildProcessHostImpl::ForceShutdown() { 128 void ChildProcessHostImpl::ForceShutdown() {
121 Send(new ChildProcessMsg_Shutdown()); 129 Send(new ChildProcessMsg_Shutdown());
122 } 130 }
123 131
124 std::string ChildProcessHostImpl::CreateChannel() { 132 std::string ChildProcessHostImpl::CreateChannel() {
125 channel_id_ = IPC::Channel::GenerateVerifiedChannelID(std::string()); 133 channel_id_ = IPC::Channel::GenerateVerifiedChannelID(std::string());
126 channel_ = 134 channel_ = IPC::Channel::CreateServer(channel_id_, this);
127 IPC::Channel::CreateServer(channel_id_, this, GetAttachmentBroker());
128 if (!channel_->Connect()) 135 if (!channel_->Connect())
129 return std::string(); 136 return std::string();
130 #if USE_ATTACHMENT_BROKER 137 #if USE_ATTACHMENT_BROKER
131 g_attachment_broker.Get().RegisterCommunicationChannel(channel_.get()); 138 GetAttachmentBroker()->RegisterCommunicationChannel(channel_.get());
132 #endif 139 #endif
133 140
134 for (size_t i = 0; i < filters_.size(); ++i) 141 for (size_t i = 0; i < filters_.size(); ++i)
135 filters_[i]->OnFilterAdded(channel_.get()); 142 filters_[i]->OnFilterAdded(channel_.get());
136 143
137 // Make sure these messages get sent first. 144 // Make sure these messages get sent first.
138 #if defined(IPC_MESSAGE_LOG_ENABLED) 145 #if defined(IPC_MESSAGE_LOG_ENABLED)
139 bool enabled = IPC::Logging::GetInstance()->Enabled(); 146 bool enabled = IPC::Logging::GetInstance()->Enabled();
140 Send(new ChildProcessMsg_SetIPCLoggingEnabled(enabled)); 147 Send(new ChildProcessMsg_SetIPCLoggingEnabled(enabled));
141 #endif 148 #endif
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 } 319 }
313 320
314 void ChildProcessHostImpl::OnDeletedGpuMemoryBuffer( 321 void ChildProcessHostImpl::OnDeletedGpuMemoryBuffer(
315 gfx::GpuMemoryBufferId id, 322 gfx::GpuMemoryBufferId id,
316 uint32 sync_point) { 323 uint32 sync_point) {
317 // Note: Nothing to do here as ownership of shared memory backed 324 // Note: Nothing to do here as ownership of shared memory backed
318 // GpuMemoryBuffers is passed with IPC. 325 // GpuMemoryBuffers is passed with IPC.
319 } 326 }
320 327
321 } // namespace content 328 } // namespace content
OLDNEW
« no previous file with comments | « content/child/npapi/np_channel_base.cc ('k') | content/common/gpu/client/gpu_channel_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698