| 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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 | 185 |
| 186 bool ChildProcessHostImpl::Send(IPC::Message* message) { | 186 bool ChildProcessHostImpl::Send(IPC::Message* message) { |
| 187 if (!channel_) { | 187 if (!channel_) { |
| 188 delete message; | 188 delete message; |
| 189 return false; | 189 return false; |
| 190 } | 190 } |
| 191 return channel_->Send(message); | 191 return channel_->Send(message); |
| 192 } | 192 } |
| 193 | 193 |
| 194 void ChildProcessHostImpl::AllocateSharedMemory( | 194 void ChildProcessHostImpl::AllocateSharedMemory( |
| 195 size_t buffer_size, base::ProcessHandle child_process_handle, | 195 size_t buffer_size, |
| 196 base::SharedMemoryHandle* shared_memory_handle) { | 196 base::SharedMemoryHandle* shared_memory_handle) { |
| 197 base::SharedMemory shared_buf; | 197 base::SharedMemory shared_buf; |
| 198 if (!shared_buf.CreateAnonymous(buffer_size)) { | 198 if (!shared_buf.CreateAnonymous(buffer_size)) { |
| 199 *shared_memory_handle = base::SharedMemory::NULLHandle(); | 199 *shared_memory_handle = base::SharedMemory::NULLHandle(); |
| 200 NOTREACHED() << "Cannot create shared memory buffer"; | 200 NOTREACHED() << "Cannot create shared memory buffer"; |
| 201 return; | 201 return; |
| 202 } | 202 } |
| 203 shared_buf.GiveToProcess(child_process_handle, shared_memory_handle); | 203 *shared_memory_handle = shared_buf.TakeHandle(); |
| 204 } | 204 } |
| 205 | 205 |
| 206 int ChildProcessHostImpl::GenerateChildProcessUniqueId() { | 206 int ChildProcessHostImpl::GenerateChildProcessUniqueId() { |
| 207 // This function must be threadsafe. | 207 // This function must be threadsafe. |
| 208 // | 208 // |
| 209 // Historically, this function returned ids started with 1, so in several | 209 // Historically, this function returned ids started with 1, so in several |
| 210 // places in the code a value of 0 (rather than kInvalidUniqueID) was used as | 210 // places in the code a value of 0 (rather than kInvalidUniqueID) was used as |
| 211 // an invalid value. So we retain those semantics. | 211 // an invalid value. So we retain those semantics. |
| 212 int id = g_unique_id.GetNext() + 1; | 212 int id = g_unique_id.GetNext() + 1; |
| 213 | 213 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 delegate_->OnChildDisconnected(); | 309 delegate_->OnChildDisconnected(); |
| 310 } | 310 } |
| 311 | 311 |
| 312 void ChildProcessHostImpl::OnBadMessageReceived(const IPC::Message& message) { | 312 void ChildProcessHostImpl::OnBadMessageReceived(const IPC::Message& message) { |
| 313 delegate_->OnBadMessageReceived(message); | 313 delegate_->OnBadMessageReceived(message); |
| 314 } | 314 } |
| 315 | 315 |
| 316 void ChildProcessHostImpl::OnAllocateSharedMemory( | 316 void ChildProcessHostImpl::OnAllocateSharedMemory( |
| 317 uint32_t buffer_size, | 317 uint32_t buffer_size, |
| 318 base::SharedMemoryHandle* handle) { | 318 base::SharedMemoryHandle* handle) { |
| 319 AllocateSharedMemory(buffer_size, peer_process_.Handle(), handle); | 319 AllocateSharedMemory(buffer_size, handle); |
| 320 } | 320 } |
| 321 | 321 |
| 322 void ChildProcessHostImpl::OnShutdownRequest() { | 322 void ChildProcessHostImpl::OnShutdownRequest() { |
| 323 if (delegate_->CanShutdown()) | 323 if (delegate_->CanShutdown()) |
| 324 Send(new ChildProcessMsg_Shutdown()); | 324 Send(new ChildProcessMsg_Shutdown()); |
| 325 } | 325 } |
| 326 | 326 |
| 327 void ChildProcessHostImpl::OnAllocateGpuMemoryBuffer( | 327 void ChildProcessHostImpl::OnAllocateGpuMemoryBuffer( |
| 328 gfx::GpuMemoryBufferId id, | 328 gfx::GpuMemoryBufferId id, |
| 329 uint32_t width, | 329 uint32_t width, |
| 330 uint32_t height, | 330 uint32_t height, |
| 331 gfx::BufferFormat format, | 331 gfx::BufferFormat format, |
| 332 gfx::BufferUsage usage, | 332 gfx::BufferUsage usage, |
| 333 gfx::GpuMemoryBufferHandle* handle) { | 333 gfx::GpuMemoryBufferHandle* handle) { |
| 334 // TODO(reveman): Add support for other types of GpuMemoryBuffers. | 334 // TODO(reveman): Add support for other types of GpuMemoryBuffers. |
| 335 | 335 |
| 336 // AllocateForChildProcess() will check if |width| and |height| are valid | 336 // AllocateForChildProcess() will check if |width| and |height| are valid |
| 337 // and handle failure in a controlled way when not. We just need to make | 337 // and handle failure in a controlled way when not. We just need to make |
| 338 // sure |usage| is supported here. | 338 // sure |usage| is supported here. |
| 339 if (gpu::GpuMemoryBufferImplSharedMemory::IsUsageSupported(usage)) { | 339 if (gpu::GpuMemoryBufferImplSharedMemory::IsUsageSupported(usage)) { |
| 340 *handle = gpu::GpuMemoryBufferImplSharedMemory::AllocateForChildProcess( | 340 *handle = gpu::GpuMemoryBufferImplSharedMemory::AllocateForChildProcess( |
| 341 id, gfx::Size(width, height), format, peer_process_.Handle()); | 341 id, gfx::Size(width, height), format); |
| 342 } | 342 } |
| 343 } | 343 } |
| 344 | 344 |
| 345 void ChildProcessHostImpl::OnDeletedGpuMemoryBuffer( | 345 void ChildProcessHostImpl::OnDeletedGpuMemoryBuffer( |
| 346 gfx::GpuMemoryBufferId id, | 346 gfx::GpuMemoryBufferId id, |
| 347 const gpu::SyncToken& sync_token) { | 347 const gpu::SyncToken& sync_token) { |
| 348 // Note: Nothing to do here as ownership of shared memory backed | 348 // Note: Nothing to do here as ownership of shared memory backed |
| 349 // GpuMemoryBuffers is passed with IPC. | 349 // GpuMemoryBuffers is passed with IPC. |
| 350 } | 350 } |
| 351 | 351 |
| 352 } // namespace content | 352 } // namespace content |
| OLD | NEW |