| 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 // results in Chromium Helper EH.app or Google Chrome Helper EH.app. | 132 // results in Chromium Helper EH.app or Google Chrome Helper EH.app. |
| 133 child_path = TransformPathForFeature(child_path, "EH"); | 133 child_path = TransformPathForFeature(child_path, "EH"); |
| 134 } | 134 } |
| 135 #endif | 135 #endif |
| 136 | 136 |
| 137 return child_path; | 137 return child_path; |
| 138 } | 138 } |
| 139 | 139 |
| 140 ChildProcessHostImpl::ChildProcessHostImpl(ChildProcessHostDelegate* delegate) | 140 ChildProcessHostImpl::ChildProcessHostImpl(ChildProcessHostDelegate* delegate) |
| 141 : delegate_(delegate), | 141 : delegate_(delegate), |
| 142 peer_handle_(base::kNullProcessHandle), | |
| 143 opening_channel_(false) { | 142 opening_channel_(false) { |
| 144 #if defined(OS_WIN) | 143 #if defined(OS_WIN) |
| 145 AddFilter(new FontCacheDispatcher()); | 144 AddFilter(new FontCacheDispatcher()); |
| 146 #endif | 145 #endif |
| 147 } | 146 } |
| 148 | 147 |
| 149 ChildProcessHostImpl::~ChildProcessHostImpl() { | 148 ChildProcessHostImpl::~ChildProcessHostImpl() { |
| 150 for (size_t i = 0; i < filters_.size(); ++i) { | 149 for (size_t i = 0; i < filters_.size(); ++i) { |
| 151 filters_[i]->OnChannelClosing(); | 150 filters_[i]->OnChannelClosing(); |
| 152 filters_[i]->OnFilterRemoved(); | 151 filters_[i]->OnFilterRemoved(); |
| 153 } | 152 } |
| 154 | |
| 155 base::CloseProcessHandle(peer_handle_); | |
| 156 } | 153 } |
| 157 | 154 |
| 158 void ChildProcessHostImpl::AddFilter(IPC::MessageFilter* filter) { | 155 void ChildProcessHostImpl::AddFilter(IPC::MessageFilter* filter) { |
| 159 filters_.push_back(filter); | 156 filters_.push_back(filter); |
| 160 | 157 |
| 161 if (channel_) | 158 if (channel_) |
| 162 filter->OnFilterAdded(channel_.get()); | 159 filter->OnFilterAdded(channel_.get()); |
| 163 } | 160 } |
| 164 | 161 |
| 165 void ChildProcessHostImpl::ForceShutdown() { | 162 void ChildProcessHostImpl::ForceShutdown() { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 } | 267 } |
| 271 | 268 |
| 272 #ifdef IPC_MESSAGE_LOG_ENABLED | 269 #ifdef IPC_MESSAGE_LOG_ENABLED |
| 273 if (logger->Enabled()) | 270 if (logger->Enabled()) |
| 274 logger->OnPostDispatchMessage(msg, channel_id_); | 271 logger->OnPostDispatchMessage(msg, channel_id_); |
| 275 #endif | 272 #endif |
| 276 return handled; | 273 return handled; |
| 277 } | 274 } |
| 278 | 275 |
| 279 void ChildProcessHostImpl::OnChannelConnected(int32 peer_pid) { | 276 void ChildProcessHostImpl::OnChannelConnected(int32 peer_pid) { |
| 280 if (!peer_handle_ && | 277 if (!peer_process_.IsValid()) { |
| 281 !base::OpenPrivilegedProcessHandle(peer_pid, &peer_handle_)) { | 278 base::ProcessHandle peer_handle_; |
| 282 peer_handle_ = delegate_->GetHandle(); | 279 if (base::OpenPrivilegedProcessHandle(peer_pid, &peer_handle_)) { |
| 283 DCHECK(peer_handle_); | 280 // TODO(rvargas) crbug.com/417532: don't go through a ProcessHandle. |
| 281 if (peer_handle_ == base::GetCurrentProcessHandle()) |
| 282 peer_process_ = base::Process::Current(); |
| 283 else |
| 284 peer_process_ = base::Process(peer_handle_); |
| 285 } else { |
| 286 peer_process_ = delegate_->GetProcess().Duplicate(); |
| 287 } |
| 288 DCHECK(peer_process_.IsValid()); |
| 284 } | 289 } |
| 285 opening_channel_ = false; | 290 opening_channel_ = false; |
| 286 delegate_->OnChannelConnected(peer_pid); | 291 delegate_->OnChannelConnected(peer_pid); |
| 287 for (size_t i = 0; i < filters_.size(); ++i) | 292 for (size_t i = 0; i < filters_.size(); ++i) |
| 288 filters_[i]->OnChannelConnected(peer_pid); | 293 filters_[i]->OnChannelConnected(peer_pid); |
| 289 } | 294 } |
| 290 | 295 |
| 291 void ChildProcessHostImpl::OnChannelError() { | 296 void ChildProcessHostImpl::OnChannelError() { |
| 292 opening_channel_ = false; | 297 opening_channel_ = false; |
| 293 delegate_->OnChannelError(); | 298 delegate_->OnChannelError(); |
| 294 | 299 |
| 295 for (size_t i = 0; i < filters_.size(); ++i) | 300 for (size_t i = 0; i < filters_.size(); ++i) |
| 296 filters_[i]->OnChannelError(); | 301 filters_[i]->OnChannelError(); |
| 297 | 302 |
| 298 // This will delete host_, which will also destroy this! | 303 // This will delete host_, which will also destroy this! |
| 299 delegate_->OnChildDisconnected(); | 304 delegate_->OnChildDisconnected(); |
| 300 } | 305 } |
| 301 | 306 |
| 302 void ChildProcessHostImpl::OnBadMessageReceived(const IPC::Message& message) { | 307 void ChildProcessHostImpl::OnBadMessageReceived(const IPC::Message& message) { |
| 303 delegate_->OnBadMessageReceived(message); | 308 delegate_->OnBadMessageReceived(message); |
| 304 } | 309 } |
| 305 | 310 |
| 306 void ChildProcessHostImpl::OnAllocateSharedMemory( | 311 void ChildProcessHostImpl::OnAllocateSharedMemory( |
| 307 uint32 buffer_size, | 312 uint32 buffer_size, |
| 308 base::SharedMemoryHandle* handle) { | 313 base::SharedMemoryHandle* handle) { |
| 309 AllocateSharedMemory(buffer_size, peer_handle_, handle); | 314 AllocateSharedMemory(buffer_size, peer_process_.Handle(), handle); |
| 310 } | 315 } |
| 311 | 316 |
| 312 void ChildProcessHostImpl::OnShutdownRequest() { | 317 void ChildProcessHostImpl::OnShutdownRequest() { |
| 313 if (delegate_->CanShutdown()) | 318 if (delegate_->CanShutdown()) |
| 314 Send(new ChildProcessMsg_Shutdown()); | 319 Send(new ChildProcessMsg_Shutdown()); |
| 315 } | 320 } |
| 316 | 321 |
| 317 void ChildProcessHostImpl::OnAllocateGpuMemoryBuffer( | 322 void ChildProcessHostImpl::OnAllocateGpuMemoryBuffer( |
| 318 uint32 width, | 323 uint32 width, |
| 319 uint32 height, | 324 uint32 height, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 333 GpuMemoryBufferAllocated(reply, gfx::GpuMemoryBufferHandle()); | 338 GpuMemoryBufferAllocated(reply, gfx::GpuMemoryBufferHandle()); |
| 334 return; | 339 return; |
| 335 } | 340 } |
| 336 | 341 |
| 337 // Note: It is safe to use base::Unretained here as the shared memory | 342 // Note: It is safe to use base::Unretained here as the shared memory |
| 338 // implementation of AllocateForChildProcess() calls this synchronously. | 343 // implementation of AllocateForChildProcess() calls this synchronously. |
| 339 GpuMemoryBufferImplSharedMemory::AllocateForChildProcess( | 344 GpuMemoryBufferImplSharedMemory::AllocateForChildProcess( |
| 340 g_next_gpu_memory_buffer_id.GetNext(), | 345 g_next_gpu_memory_buffer_id.GetNext(), |
| 341 gfx::Size(width, height), | 346 gfx::Size(width, height), |
| 342 format, | 347 format, |
| 343 peer_handle_, | 348 peer_process_.Handle(), |
| 344 base::Bind(&ChildProcessHostImpl::GpuMemoryBufferAllocated, | 349 base::Bind(&ChildProcessHostImpl::GpuMemoryBufferAllocated, |
| 345 base::Unretained(this), | 350 base::Unretained(this), |
| 346 reply)); | 351 reply)); |
| 347 } | 352 } |
| 348 | 353 |
| 349 void ChildProcessHostImpl::OnDeletedGpuMemoryBuffer( | 354 void ChildProcessHostImpl::OnDeletedGpuMemoryBuffer( |
| 350 gfx::GpuMemoryBufferId id, | 355 gfx::GpuMemoryBufferId id, |
| 351 uint32 sync_point) { | 356 uint32 sync_point) { |
| 352 // Note: Nothing to do here as ownership of shared memory backed | 357 // Note: Nothing to do here as ownership of shared memory backed |
| 353 // GpuMemoryBuffers is passed with IPC. | 358 // GpuMemoryBuffers is passed with IPC. |
| 354 } | 359 } |
| 355 | 360 |
| 356 void ChildProcessHostImpl::GpuMemoryBufferAllocated( | 361 void ChildProcessHostImpl::GpuMemoryBufferAllocated( |
| 357 IPC::Message* reply, | 362 IPC::Message* reply, |
| 358 const gfx::GpuMemoryBufferHandle& handle) { | 363 const gfx::GpuMemoryBufferHandle& handle) { |
| 359 ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer::WriteReplyParams(reply, | 364 ChildProcessHostMsg_SyncAllocateGpuMemoryBuffer::WriteReplyParams(reply, |
| 360 handle); | 365 handle); |
| 361 Send(reply); | 366 Send(reply); |
| 362 } | 367 } |
| 363 | 368 |
| 364 } // namespace content | 369 } // namespace content |
| OLD | NEW |