OLD | NEW |
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(); |
| 59 } |
| 60 #endif // USE_ATTACHMENT_BROKER |
44 | 61 |
45 #if defined(OS_MACOSX) | 62 #if defined(OS_MACOSX) |
46 // Given |path| identifying a Mac-style child process executable path, adjusts | 63 // Given |path| identifying a Mac-style child process executable path, adjusts |
47 // it to correspond to |feature|. For a child process path such as | 64 // it to correspond to |feature|. For a child process path such as |
48 // ".../Chromium Helper.app/Contents/MacOS/Chromium Helper", the transformed | 65 // ".../Chromium Helper.app/Contents/MacOS/Chromium Helper", the transformed |
49 // path for feature "NP" would be | 66 // path for feature "NP" would be |
50 // ".../Chromium Helper NP.app/Contents/MacOS/Chromium Helper NP". The new | 67 // ".../Chromium Helper NP.app/Contents/MacOS/Chromium Helper NP". The new |
51 // path is returned. | 68 // path is returned. |
52 base::FilePath TransformPathForFeature(const base::FilePath& path, | 69 base::FilePath TransformPathForFeature(const base::FilePath& path, |
53 const std::string& feature) { | 70 const std::string& feature) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 // non-executable heap, but the "EH" feature is provided to allow code | 155 // non-executable heap, but the "EH" feature is provided to allow code |
139 // intolerant of a non-executable heap to work properly on 10.7. This | 156 // intolerant of a non-executable heap to work properly on 10.7. This |
140 // results in Chromium Helper EH.app or Google Chrome Helper EH.app. | 157 // results in Chromium Helper EH.app or Google Chrome Helper EH.app. |
141 child_path = TransformPathForFeature(child_path, "EH"); | 158 child_path = TransformPathForFeature(child_path, "EH"); |
142 } | 159 } |
143 #endif | 160 #endif |
144 | 161 |
145 return child_path; | 162 return child_path; |
146 } | 163 } |
147 | 164 |
148 // static | |
149 IPC::AttachmentBrokerPrivileged* ChildProcessHost::GetAttachmentBroker() { | |
150 #if USE_ATTACHMENT_BROKER | |
151 return &g_attachment_broker.Get(); | |
152 #else | |
153 return nullptr; | |
154 #endif // USE_ATTACHMENT_BROKER | |
155 } | |
156 | |
157 ChildProcessHostImpl::ChildProcessHostImpl(ChildProcessHostDelegate* delegate) | 165 ChildProcessHostImpl::ChildProcessHostImpl(ChildProcessHostDelegate* delegate) |
158 : delegate_(delegate), | 166 : delegate_(delegate), |
159 opening_channel_(false) { | 167 opening_channel_(false) { |
160 #if defined(OS_WIN) | 168 #if defined(OS_WIN) |
161 AddFilter(new FontCacheDispatcher()); | 169 AddFilter(new FontCacheDispatcher()); |
162 #endif | 170 #endif |
163 } | 171 } |
164 | 172 |
165 ChildProcessHostImpl::~ChildProcessHostImpl() { | 173 ChildProcessHostImpl::~ChildProcessHostImpl() { |
166 #if USE_ATTACHMENT_BROKER | 174 #if USE_ATTACHMENT_BROKER |
167 g_attachment_broker.Get().DeregisterCommunicationChannel(channel_.get()); | 175 GetAttachmentBroker()->DeregisterCommunicationChannel(channel_.get()); |
168 #endif | 176 #endif |
169 for (size_t i = 0; i < filters_.size(); ++i) { | 177 for (size_t i = 0; i < filters_.size(); ++i) { |
170 filters_[i]->OnChannelClosing(); | 178 filters_[i]->OnChannelClosing(); |
171 filters_[i]->OnFilterRemoved(); | 179 filters_[i]->OnFilterRemoved(); |
172 } | 180 } |
173 } | 181 } |
174 | 182 |
175 void ChildProcessHostImpl::AddFilter(IPC::MessageFilter* filter) { | 183 void ChildProcessHostImpl::AddFilter(IPC::MessageFilter* filter) { |
176 filters_.push_back(filter); | 184 filters_.push_back(filter); |
177 | 185 |
178 if (channel_) | 186 if (channel_) |
179 filter->OnFilterAdded(channel_.get()); | 187 filter->OnFilterAdded(channel_.get()); |
180 } | 188 } |
181 | 189 |
182 void ChildProcessHostImpl::ForceShutdown() { | 190 void ChildProcessHostImpl::ForceShutdown() { |
183 Send(new ChildProcessMsg_Shutdown()); | 191 Send(new ChildProcessMsg_Shutdown()); |
184 } | 192 } |
185 | 193 |
186 std::string ChildProcessHostImpl::CreateChannel() { | 194 std::string ChildProcessHostImpl::CreateChannel() { |
187 channel_id_ = IPC::Channel::GenerateVerifiedChannelID(std::string()); | 195 channel_id_ = IPC::Channel::GenerateVerifiedChannelID(std::string()); |
188 channel_ = | 196 channel_ = IPC::Channel::CreateServer(channel_id_, this); |
189 IPC::Channel::CreateServer(channel_id_, this, GetAttachmentBroker()); | |
190 if (!channel_->Connect()) | 197 if (!channel_->Connect()) |
191 return std::string(); | 198 return std::string(); |
192 #if USE_ATTACHMENT_BROKER | 199 #if USE_ATTACHMENT_BROKER |
193 g_attachment_broker.Get().RegisterCommunicationChannel(channel_.get()); | 200 GetAttachmentBroker()->RegisterCommunicationChannel(channel_.get()); |
194 #endif | 201 #endif |
195 | 202 |
196 for (size_t i = 0; i < filters_.size(); ++i) | 203 for (size_t i = 0; i < filters_.size(); ++i) |
197 filters_[i]->OnFilterAdded(channel_.get()); | 204 filters_[i]->OnFilterAdded(channel_.get()); |
198 | 205 |
199 // Make sure these messages get sent first. | 206 // Make sure these messages get sent first. |
200 #if defined(IPC_MESSAGE_LOG_ENABLED) | 207 #if defined(IPC_MESSAGE_LOG_ENABLED) |
201 bool enabled = IPC::Logging::GetInstance()->Enabled(); | 208 bool enabled = IPC::Logging::GetInstance()->Enabled(); |
202 Send(new ChildProcessMsg_SetIPCLoggingEnabled(enabled)); | 209 Send(new ChildProcessMsg_SetIPCLoggingEnabled(enabled)); |
203 #endif | 210 #endif |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 } | 381 } |
375 | 382 |
376 void ChildProcessHostImpl::OnDeletedGpuMemoryBuffer( | 383 void ChildProcessHostImpl::OnDeletedGpuMemoryBuffer( |
377 gfx::GpuMemoryBufferId id, | 384 gfx::GpuMemoryBufferId id, |
378 uint32 sync_point) { | 385 uint32 sync_point) { |
379 // Note: Nothing to do here as ownership of shared memory backed | 386 // Note: Nothing to do here as ownership of shared memory backed |
380 // GpuMemoryBuffers is passed with IPC. | 387 // GpuMemoryBuffers is passed with IPC. |
381 } | 388 } |
382 | 389 |
383 } // namespace content | 390 } // namespace content |
OLD | NEW |