| 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/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.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/synchronization/lock.h" |
| 22 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 22 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| 23 #include "base/threading/thread_task_runner_handle.h" | 23 #include "base/threading/thread_task_runner_handle.h" |
| 24 #include "build/build_config.h" | 24 #include "build/build_config.h" |
| 25 #include "content/common/child_process_messages.h" | 25 #include "content/common/child_process_messages.h" |
| 26 #include "content/public/common/child_process_host_delegate.h" | 26 #include "content/public/common/child_process_host_delegate.h" |
| 27 #include "content/public/common/content_paths.h" | 27 #include "content/public/common/content_paths.h" |
| 28 #include "content/public/common/content_switches.h" | 28 #include "content/public/common/content_switches.h" |
| 29 #include "gpu/ipc/client/gpu_memory_buffer_impl_shared_memory.h" | 29 #include "gpu/ipc/client/gpu_memory_buffer_impl_shared_memory.h" |
| 30 #include "ipc/attachment_broker.h" | |
| 31 #include "ipc/attachment_broker_privileged.h" | |
| 32 #include "ipc/ipc.mojom.h" | 30 #include "ipc/ipc.mojom.h" |
| 33 #include "ipc/ipc_channel.h" | 31 #include "ipc/ipc_channel.h" |
| 34 #include "ipc/ipc_channel_mojo.h" | 32 #include "ipc/ipc_channel_mojo.h" |
| 35 #include "ipc/ipc_logging.h" | 33 #include "ipc/ipc_logging.h" |
| 36 #include "ipc/message_filter.h" | 34 #include "ipc/message_filter.h" |
| 37 #include "mojo/edk/embedder/embedder.h" | 35 #include "mojo/edk/embedder/embedder.h" |
| 38 #include "services/service_manager/public/cpp/interface_provider.h" | 36 #include "services/service_manager/public/cpp/interface_provider.h" |
| 39 | 37 |
| 40 #if defined(OS_LINUX) | 38 #if defined(OS_LINUX) |
| 41 #include "base/linux_util.h" | 39 #include "base/linux_util.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 PathService::Get(CHILD_PROCESS_EXE, &child_path); | 83 PathService::Get(CHILD_PROCESS_EXE, &child_path); |
| 86 return child_path; | 84 return child_path; |
| 87 } | 85 } |
| 88 | 86 |
| 89 ChildProcessHostImpl::ChildProcessHostImpl(ChildProcessHostDelegate* delegate) | 87 ChildProcessHostImpl::ChildProcessHostImpl(ChildProcessHostDelegate* delegate) |
| 90 : delegate_(delegate), | 88 : delegate_(delegate), |
| 91 opening_channel_(false) { | 89 opening_channel_(false) { |
| 92 #if defined(OS_WIN) | 90 #if defined(OS_WIN) |
| 93 AddFilter(new FontCacheDispatcher()); | 91 AddFilter(new FontCacheDispatcher()); |
| 94 #endif | 92 #endif |
| 95 | |
| 96 #if USE_ATTACHMENT_BROKER | |
| 97 #if defined(OS_MACOSX) | |
| 98 // On Mac, the privileged AttachmentBroker needs a reference to the Mach port | |
| 99 // Provider, which is only available in the chrome/ module. The attachment | |
| 100 // broker must already be created. | |
| 101 DCHECK(IPC::AttachmentBroker::GetGlobal()); | |
| 102 #else | |
| 103 // Construct the privileged attachment broker early in the life cycle of a | |
| 104 // child process. | |
| 105 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded(); | |
| 106 #endif // defined(OS_MACOSX) | |
| 107 #endif // USE_ATTACHMENT_BROKER | |
| 108 } | 93 } |
| 109 | 94 |
| 110 ChildProcessHostImpl::~ChildProcessHostImpl() { | 95 ChildProcessHostImpl::~ChildProcessHostImpl() { |
| 111 // If a channel was never created than it wasn't registered and the filters | 96 // If a channel was never created than it wasn't registered and the filters |
| 112 // weren't notified. For the sake of symmetry don't call the matching teardown | 97 // weren't notified. For the sake of symmetry don't call the matching teardown |
| 113 // functions. This is analogous to how RenderProcessHostImpl handles things. | 98 // functions. This is analogous to how RenderProcessHostImpl handles things. |
| 114 if (!channel_) | 99 if (!channel_) |
| 115 return; | 100 return; |
| 116 | 101 |
| 117 #if USE_ATTACHMENT_BROKER | |
| 118 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( | |
| 119 channel_.get()); | |
| 120 #endif | |
| 121 for (size_t i = 0; i < filters_.size(); ++i) { | 102 for (size_t i = 0; i < filters_.size(); ++i) { |
| 122 filters_[i]->OnChannelClosing(); | 103 filters_[i]->OnChannelClosing(); |
| 123 filters_[i]->OnFilterRemoved(); | 104 filters_[i]->OnFilterRemoved(); |
| 124 } | 105 } |
| 125 } | 106 } |
| 126 | 107 |
| 127 void ChildProcessHostImpl::AddFilter(IPC::MessageFilter* filter) { | 108 void ChildProcessHostImpl::AddFilter(IPC::MessageFilter* filter) { |
| 128 filters_.push_back(filter); | 109 filters_.push_back(filter); |
| 129 | 110 |
| 130 if (channel_) | 111 if (channel_) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 remote_interfaces->GetInterface(&bootstrap); | 149 remote_interfaces->GetInterface(&bootstrap); |
| 169 channel_ = IPC::ChannelMojo::Create(bootstrap.PassInterface().PassHandle(), | 150 channel_ = IPC::ChannelMojo::Create(bootstrap.PassInterface().PassHandle(), |
| 170 IPC::Channel::MODE_SERVER, this); | 151 IPC::Channel::MODE_SERVER, this); |
| 171 DCHECK(channel_); | 152 DCHECK(channel_); |
| 172 | 153 |
| 173 bool initialized = InitChannel(); | 154 bool initialized = InitChannel(); |
| 174 DCHECK(initialized); | 155 DCHECK(initialized); |
| 175 } | 156 } |
| 176 | 157 |
| 177 bool ChildProcessHostImpl::InitChannel() { | 158 bool ChildProcessHostImpl::InitChannel() { |
| 178 #if USE_ATTACHMENT_BROKER | 159 if (!channel_->Connect()) |
| 179 DCHECK(base::MessageLoopForIO::IsCurrent()); | |
| 180 IPC::AttachmentBroker::GetGlobal()->RegisterCommunicationChannel( | |
| 181 channel_.get(), base::ThreadTaskRunnerHandle::Get()); | |
| 182 #endif | |
| 183 if (!channel_->Connect()) { | |
| 184 #if USE_ATTACHMENT_BROKER | |
| 185 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( | |
| 186 channel_.get()); | |
| 187 #endif | |
| 188 return false; | 160 return false; |
| 189 } | |
| 190 | 161 |
| 191 for (size_t i = 0; i < filters_.size(); ++i) | 162 for (size_t i = 0; i < filters_.size(); ++i) |
| 192 filters_[i]->OnFilterAdded(channel_.get()); | 163 filters_[i]->OnFilterAdded(channel_.get()); |
| 193 | 164 |
| 194 // Make sure these messages get sent first. | 165 // Make sure these messages get sent first. |
| 195 #if defined(IPC_MESSAGE_LOG_ENABLED) | 166 #if defined(IPC_MESSAGE_LOG_ENABLED) |
| 196 bool enabled = IPC::Logging::GetInstance()->Enabled(); | 167 bool enabled = IPC::Logging::GetInstance()->Enabled(); |
| 197 Send(new ChildProcessMsg_SetIPCLoggingEnabled(enabled)); | 168 Send(new ChildProcessMsg_SetIPCLoggingEnabled(enabled)); |
| 198 #endif | 169 #endif |
| 199 | 170 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 } | 343 } |
| 373 | 344 |
| 374 void ChildProcessHostImpl::OnDeletedGpuMemoryBuffer( | 345 void ChildProcessHostImpl::OnDeletedGpuMemoryBuffer( |
| 375 gfx::GpuMemoryBufferId id, | 346 gfx::GpuMemoryBufferId id, |
| 376 const gpu::SyncToken& sync_token) { | 347 const gpu::SyncToken& sync_token) { |
| 377 // Note: Nothing to do here as ownership of shared memory backed | 348 // Note: Nothing to do here as ownership of shared memory backed |
| 378 // GpuMemoryBuffers is passed with IPC. | 349 // GpuMemoryBuffers is passed with IPC. |
| 379 } | 350 } |
| 380 | 351 |
| 381 } // namespace content | 352 } // namespace content |
| OLD | NEW |