| 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/debug/leak_annotations.h" |
| 11 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/lazy_instance.h" |
| 12 #include "base/logging.h" | 14 #include "base/logging.h" |
| 13 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 14 #include "base/numerics/safe_math.h" | 16 #include "base/numerics/safe_math.h" |
| 15 #include "base/path_service.h" | 17 #include "base/path_service.h" |
| 16 #include "base/process/process_metrics.h" | 18 #include "base/process/process_metrics.h" |
| 17 #include "base/rand_util.h" | 19 #include "base/rand_util.h" |
| 18 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 21 #include "base/synchronization/lock.h" |
| 19 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 22 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| 20 #include "content/common/child_process_messages.h" | 23 #include "content/common/child_process_messages.h" |
| 21 #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" |
| 22 #include "content/public/common/child_process_host_delegate.h" | 25 #include "content/public/common/child_process_host_delegate.h" |
| 23 #include "content/public/common/content_paths.h" | 26 #include "content/public/common/content_paths.h" |
| 24 #include "content/public/common/content_switches.h" | 27 #include "content/public/common/content_switches.h" |
| 28 #include "ipc/attachment_broker.h" |
| 25 #include "ipc/ipc_channel.h" | 29 #include "ipc/ipc_channel.h" |
| 26 #include "ipc/ipc_logging.h" | 30 #include "ipc/ipc_logging.h" |
| 27 #include "ipc/message_filter.h" | 31 #include "ipc/message_filter.h" |
| 28 | 32 |
| 29 #if defined(OS_LINUX) | 33 #if defined(OS_LINUX) |
| 30 #include "base/linux_util.h" | 34 #include "base/linux_util.h" |
| 31 #elif defined(OS_WIN) | 35 #elif defined(OS_WIN) |
| 32 #include "content/common/font_cache_dispatcher_win.h" | 36 #include "content/common/font_cache_dispatcher_win.h" |
| 37 #include "ipc/attachment_broker_win.h" |
| 33 #endif // OS_LINUX | 38 #endif // OS_LINUX |
| 34 | 39 |
| 40 base::LazyInstance<base::Lock>::Leaky g_attachment_broker_lock = |
| 41 LAZY_INSTANCE_INITIALIZER; |
| 42 IPC::AttachmentBroker* g_attachment_broker = nullptr; |
| 43 |
| 35 namespace { | 44 namespace { |
| 36 | 45 |
| 46 // Makes a platform specific AttachmentBroker. |
| 47 IPC::AttachmentBroker* CreateAttachmentBroker() { |
| 48 #if defined(OS_WIN) |
| 49 IPC::AttachmentBrokerWin* attachment_broker = new IPC::AttachmentBrokerWin; |
| 50 ANNOTATE_LEAKING_OBJECT_PTR(attachment_broker); |
| 51 return attachment_broker; |
| 52 #else |
| 53 return nullptr; |
| 54 #endif // defined(OS_WIN) |
| 55 } |
| 56 |
| 37 #if defined(OS_MACOSX) | 57 #if defined(OS_MACOSX) |
| 38 // Given |path| identifying a Mac-style child process executable path, adjusts | 58 // Given |path| identifying a Mac-style child process executable path, adjusts |
| 39 // it to correspond to |feature|. For a child process path such as | 59 // it to correspond to |feature|. For a child process path such as |
| 40 // ".../Chromium Helper.app/Contents/MacOS/Chromium Helper", the transformed | 60 // ".../Chromium Helper.app/Contents/MacOS/Chromium Helper", the transformed |
| 41 // path for feature "NP" would be | 61 // path for feature "NP" would be |
| 42 // ".../Chromium Helper NP.app/Contents/MacOS/Chromium Helper NP". The new | 62 // ".../Chromium Helper NP.app/Contents/MacOS/Chromium Helper NP". The new |
| 43 // path is returned. | 63 // path is returned. |
| 44 base::FilePath TransformPathForFeature(const base::FilePath& path, | 64 base::FilePath TransformPathForFeature(const base::FilePath& path, |
| 45 const std::string& feature) { | 65 const std::string& feature) { |
| 46 std::string basename = path.BaseName().value(); | 66 std::string basename = path.BaseName().value(); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 // non-executable heap, but the "EH" feature is provided to allow code | 150 // non-executable heap, but the "EH" feature is provided to allow code |
| 131 // intolerant of a non-executable heap to work properly on 10.7. This | 151 // intolerant of a non-executable heap to work properly on 10.7. This |
| 132 // results in Chromium Helper EH.app or Google Chrome Helper EH.app. | 152 // results in Chromium Helper EH.app or Google Chrome Helper EH.app. |
| 133 child_path = TransformPathForFeature(child_path, "EH"); | 153 child_path = TransformPathForFeature(child_path, "EH"); |
| 134 } | 154 } |
| 135 #endif | 155 #endif |
| 136 | 156 |
| 137 return child_path; | 157 return child_path; |
| 138 } | 158 } |
| 139 | 159 |
| 160 // static |
| 161 IPC::AttachmentBroker* ChildProcessHost::GetAttachmentBroker() { |
| 162 base::AutoLock lock(g_attachment_broker_lock.Get()); |
| 163 if (!g_attachment_broker) |
| 164 g_attachment_broker = CreateAttachmentBroker(); |
| 165 |
| 166 return g_attachment_broker; |
| 167 } |
| 168 |
| 140 ChildProcessHostImpl::ChildProcessHostImpl(ChildProcessHostDelegate* delegate) | 169 ChildProcessHostImpl::ChildProcessHostImpl(ChildProcessHostDelegate* delegate) |
| 141 : delegate_(delegate), | 170 : delegate_(delegate), |
| 142 opening_channel_(false) { | 171 opening_channel_(false) { |
| 143 #if defined(OS_WIN) | 172 #if defined(OS_WIN) |
| 144 AddFilter(new FontCacheDispatcher()); | 173 AddFilter(new FontCacheDispatcher()); |
| 145 #endif | 174 #endif |
| 146 } | 175 } |
| 147 | 176 |
| 148 ChildProcessHostImpl::~ChildProcessHostImpl() { | 177 ChildProcessHostImpl::~ChildProcessHostImpl() { |
| 149 for (size_t i = 0; i < filters_.size(); ++i) { | 178 for (size_t i = 0; i < filters_.size(); ++i) { |
| 150 filters_[i]->OnChannelClosing(); | 179 filters_[i]->OnChannelClosing(); |
| 151 filters_[i]->OnFilterRemoved(); | 180 filters_[i]->OnFilterRemoved(); |
| 152 } | 181 } |
| 153 } | 182 } |
| 154 | 183 |
| 155 void ChildProcessHostImpl::AddFilter(IPC::MessageFilter* filter) { | 184 void ChildProcessHostImpl::AddFilter(IPC::MessageFilter* filter) { |
| 156 filters_.push_back(filter); | 185 filters_.push_back(filter); |
| 157 | 186 |
| 158 if (channel_) | 187 if (channel_) |
| 159 filter->OnFilterAdded(channel_.get()); | 188 filter->OnFilterAdded(channel_.get()); |
| 160 } | 189 } |
| 161 | 190 |
| 162 void ChildProcessHostImpl::ForceShutdown() { | 191 void ChildProcessHostImpl::ForceShutdown() { |
| 163 Send(new ChildProcessMsg_Shutdown()); | 192 Send(new ChildProcessMsg_Shutdown()); |
| 164 } | 193 } |
| 165 | 194 |
| 166 std::string ChildProcessHostImpl::CreateChannel() { | 195 std::string ChildProcessHostImpl::CreateChannel() { |
| 167 channel_id_ = IPC::Channel::GenerateVerifiedChannelID(std::string()); | 196 channel_id_ = IPC::Channel::GenerateVerifiedChannelID(std::string()); |
| 168 channel_ = IPC::Channel::CreateServer(channel_id_, this); | 197 channel_ = |
| 198 IPC::Channel::CreateServer(channel_id_, this, GetAttachmentBroker()); |
| 169 if (!channel_->Connect()) | 199 if (!channel_->Connect()) |
| 170 return std::string(); | 200 return std::string(); |
| 171 | 201 |
| 172 for (size_t i = 0; i < filters_.size(); ++i) | 202 for (size_t i = 0; i < filters_.size(); ++i) |
| 173 filters_[i]->OnFilterAdded(channel_.get()); | 203 filters_[i]->OnFilterAdded(channel_.get()); |
| 174 | 204 |
| 175 // Make sure these messages get sent first. | 205 // Make sure these messages get sent first. |
| 176 #if defined(IPC_MESSAGE_LOG_ENABLED) | 206 #if defined(IPC_MESSAGE_LOG_ENABLED) |
| 177 bool enabled = IPC::Logging::GetInstance()->Enabled(); | 207 bool enabled = IPC::Logging::GetInstance()->Enabled(); |
| 178 Send(new ChildProcessMsg_SetIPCLoggingEnabled(enabled)); | 208 Send(new ChildProcessMsg_SetIPCLoggingEnabled(enabled)); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 } | 361 } |
| 332 | 362 |
| 333 void ChildProcessHostImpl::OnDeletedGpuMemoryBuffer( | 363 void ChildProcessHostImpl::OnDeletedGpuMemoryBuffer( |
| 334 gfx::GpuMemoryBufferId id, | 364 gfx::GpuMemoryBufferId id, |
| 335 uint32 sync_point) { | 365 uint32 sync_point) { |
| 336 // Note: Nothing to do here as ownership of shared memory backed | 366 // Note: Nothing to do here as ownership of shared memory backed |
| 337 // GpuMemoryBuffers is passed with IPC. | 367 // GpuMemoryBuffers is passed with IPC. |
| 338 } | 368 } |
| 339 | 369 |
| 340 } // namespace content | 370 } // namespace content |
| OLD | NEW |