| 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" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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 "build/build_config.h" | 23 #include "build/build_config.h" |
| 24 #include "content/common/child_process_messages.h" | 24 #include "content/common/child_process_messages.h" |
| 25 #include "content/public/common/child_process_host_delegate.h" | 25 #include "content/public/common/child_process_host_delegate.h" |
| 26 #include "content/public/common/content_paths.h" | 26 #include "content/public/common/content_paths.h" |
| 27 #include "content/public/common/content_switches.h" | 27 #include "content/public/common/content_switches.h" |
| 28 #include "gpu/ipc/client/gpu_memory_buffer_impl_shared_memory.h" | 28 #include "gpu/ipc/client/gpu_memory_buffer_impl_shared_memory.h" |
| 29 #include "ipc/attachment_broker.h" | 29 #include "ipc/attachment_broker.h" |
| 30 #include "ipc/attachment_broker_privileged.h" | 30 #include "ipc/attachment_broker_privileged.h" |
| 31 #include "ipc/ipc.mojom.h" | |
| 32 #include "ipc/ipc_channel.h" | 31 #include "ipc/ipc_channel.h" |
| 33 #include "ipc/ipc_channel_mojo.h" | 32 #include "ipc/ipc_channel_mojo.h" |
| 34 #include "ipc/ipc_logging.h" | 33 #include "ipc/ipc_logging.h" |
| 35 #include "ipc/message_filter.h" | 34 #include "ipc/message_filter.h" |
| 36 #include "mojo/edk/embedder/embedder.h" | 35 #include "mojo/edk/embedder/embedder.h" |
| 37 #include "services/shell/public/cpp/interface_provider.h" | |
| 38 | 36 |
| 39 #if defined(OS_LINUX) | 37 #if defined(OS_LINUX) |
| 40 #include "base/linux_util.h" | 38 #include "base/linux_util.h" |
| 41 #elif defined(OS_WIN) | 39 #elif defined(OS_WIN) |
| 42 #include "content/common/font_cache_dispatcher_win.h" | 40 #include "content/common/font_cache_dispatcher_win.h" |
| 43 #endif // OS_LINUX | 41 #endif // OS_LINUX |
| 44 | 42 |
| 45 namespace { | 43 namespace { |
| 46 | 44 |
| 47 // Global atomic to generate child process unique IDs. | 45 // Global atomic to generate child process unique IDs. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 } | 121 } |
| 124 } | 122 } |
| 125 | 123 |
| 126 void ChildProcessHostImpl::AddFilter(IPC::MessageFilter* filter) { | 124 void ChildProcessHostImpl::AddFilter(IPC::MessageFilter* filter) { |
| 127 filters_.push_back(filter); | 125 filters_.push_back(filter); |
| 128 | 126 |
| 129 if (channel_) | 127 if (channel_) |
| 130 filter->OnFilterAdded(channel_.get()); | 128 filter->OnFilterAdded(channel_.get()); |
| 131 } | 129 } |
| 132 | 130 |
| 133 shell::InterfaceProvider* ChildProcessHostImpl::GetRemoteInterfaces() { | |
| 134 return delegate_->GetRemoteInterfaces(); | |
| 135 } | |
| 136 | |
| 137 void ChildProcessHostImpl::ForceShutdown() { | 131 void ChildProcessHostImpl::ForceShutdown() { |
| 138 Send(new ChildProcessMsg_Shutdown()); | 132 Send(new ChildProcessMsg_Shutdown()); |
| 139 } | 133 } |
| 140 | 134 |
| 141 std::string ChildProcessHostImpl::CreateChannelMojo( | 135 std::string ChildProcessHostImpl::CreateChannelMojo( |
| 142 const std::string& child_token) { | 136 const std::string& child_token) { |
| 143 DCHECK(channel_id_.empty()); | 137 DCHECK(channel_id_.empty()); |
| 144 channel_id_ = mojo::edk::GenerateRandomToken(); | 138 channel_id_ = mojo::edk::GenerateRandomToken(); |
| 145 mojo::ScopedMessagePipeHandle host_handle = | 139 mojo::ScopedMessagePipeHandle host_handle = |
| 146 mojo::edk::CreateParentMessagePipe(channel_id_, child_token); | 140 mojo::edk::CreateParentMessagePipe(channel_id_, child_token); |
| 147 channel_ = IPC::ChannelMojo::Create(std::move(host_handle), | 141 channel_ = IPC::ChannelMojo::Create(std::move(host_handle), |
| 148 IPC::Channel::MODE_SERVER, this); | 142 IPC::Channel::MODE_SERVER, this); |
| 149 if (!channel_ || !InitChannel()) | 143 if (!channel_ || !InitChannel()) |
| 150 return std::string(); | 144 return std::string(); |
| 151 | 145 |
| 152 return channel_id_; | 146 return channel_id_; |
| 153 } | 147 } |
| 154 | 148 |
| 155 void ChildProcessHostImpl::CreateChannelMojo() { | |
| 156 // TODO(rockot): Remove |channel_id_| once this is the only code path by which | |
| 157 // the Channel is created. For now it serves to at least mutually exclude | |
| 158 // different CreateChannel* calls. | |
| 159 DCHECK(channel_id_.empty()); | |
| 160 channel_id_ = "ChannelMojo"; | |
| 161 | |
| 162 shell::InterfaceProvider* remote_interfaces = GetRemoteInterfaces(); | |
| 163 DCHECK(remote_interfaces); | |
| 164 | |
| 165 IPC::mojom::ChannelBootstrapPtr bootstrap; | |
| 166 remote_interfaces->GetInterface(&bootstrap); | |
| 167 channel_ = IPC::ChannelMojo::Create(bootstrap.PassInterface().PassHandle(), | |
| 168 IPC::Channel::MODE_SERVER, this); | |
| 169 DCHECK(channel_); | |
| 170 | |
| 171 bool initialized = InitChannel(); | |
| 172 DCHECK(initialized); | |
| 173 } | |
| 174 | |
| 175 std::string ChildProcessHostImpl::CreateChannel() { | 149 std::string ChildProcessHostImpl::CreateChannel() { |
| 176 DCHECK(channel_id_.empty()); | 150 DCHECK(channel_id_.empty()); |
| 177 channel_id_ = IPC::Channel::GenerateVerifiedChannelID(std::string()); | 151 channel_id_ = IPC::Channel::GenerateVerifiedChannelID(std::string()); |
| 178 channel_ = IPC::Channel::CreateServer(channel_id_, this); | 152 channel_ = IPC::Channel::CreateServer(channel_id_, this); |
| 179 if (!channel_ || !InitChannel()) | 153 if (!channel_ || !InitChannel()) |
| 180 return std::string(); | 154 return std::string(); |
| 181 | 155 |
| 182 return channel_id_; | 156 return channel_id_; |
| 183 } | 157 } |
| 184 | 158 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 } | 353 } |
| 380 | 354 |
| 381 void ChildProcessHostImpl::OnDeletedGpuMemoryBuffer( | 355 void ChildProcessHostImpl::OnDeletedGpuMemoryBuffer( |
| 382 gfx::GpuMemoryBufferId id, | 356 gfx::GpuMemoryBufferId id, |
| 383 const gpu::SyncToken& sync_token) { | 357 const gpu::SyncToken& sync_token) { |
| 384 // Note: Nothing to do here as ownership of shared memory backed | 358 // Note: Nothing to do here as ownership of shared memory backed |
| 385 // GpuMemoryBuffers is passed with IPC. | 359 // GpuMemoryBuffers is passed with IPC. |
| 386 } | 360 } |
| 387 | 361 |
| 388 } // namespace content | 362 } // namespace content |
| OLD | NEW |