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/child/child_thread_impl.h" | 5 #include "content/child/child_thread_impl.h" |
6 | 6 |
7 #include <signal.h> | 7 #include <signal.h> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 size_t buf_size) { | 562 size_t buf_size) { |
563 DCHECK(base::MessageLoop::current() == message_loop()); | 563 DCHECK(base::MessageLoop::current() == message_loop()); |
564 return AllocateSharedMemory(buf_size, this); | 564 return AllocateSharedMemory(buf_size, this); |
565 } | 565 } |
566 | 566 |
567 // static | 567 // static |
568 scoped_ptr<base::SharedMemory> ChildThreadImpl::AllocateSharedMemory( | 568 scoped_ptr<base::SharedMemory> ChildThreadImpl::AllocateSharedMemory( |
569 size_t buf_size, | 569 size_t buf_size, |
570 IPC::Sender* sender) { | 570 IPC::Sender* sender) { |
571 scoped_ptr<base::SharedMemory> shared_buf; | 571 scoped_ptr<base::SharedMemory> shared_buf; |
572 #if defined(OS_WIN) | 572 // Ask the browser to create the shared memory, since this is blocked by the |
573 shared_buf.reset(new base::SharedMemory); | 573 // sandbox on most platforms. |
574 if (!shared_buf->CreateAnonymous(buf_size)) { | |
575 NOTREACHED(); | |
576 return nullptr; | |
577 } | |
578 #else | |
579 // On POSIX, we need to ask the browser to create the shared memory for us, | |
580 // since this is blocked by the sandbox. | |
581 base::SharedMemoryHandle shared_mem_handle; | 574 base::SharedMemoryHandle shared_mem_handle; |
582 if (sender->Send(new ChildProcessHostMsg_SyncAllocateSharedMemory( | 575 if (sender->Send(new ChildProcessHostMsg_SyncAllocateSharedMemory( |
583 buf_size, &shared_mem_handle))) { | 576 buf_size, &shared_mem_handle))) { |
584 if (base::SharedMemory::IsHandleValid(shared_mem_handle)) { | 577 if (base::SharedMemory::IsHandleValid(shared_mem_handle)) { |
585 shared_buf.reset(new base::SharedMemory(shared_mem_handle, false)); | 578 shared_buf.reset(new base::SharedMemory(shared_mem_handle, false)); |
586 } else { | 579 } else { |
587 NOTREACHED() << "Browser failed to allocate shared memory"; | 580 NOTREACHED() << "Browser failed to allocate shared memory"; |
588 return nullptr; | 581 return nullptr; |
589 } | 582 } |
590 } else { | 583 } else { |
591 // Send is allowed to fail during shutdown. Return null in this case. | 584 // Send is allowed to fail during shutdown. Return null in this case. |
592 return nullptr; | 585 return nullptr; |
593 } | 586 } |
594 #endif | |
595 return shared_buf; | 587 return shared_buf; |
596 } | 588 } |
597 | 589 |
598 bool ChildThreadImpl::OnMessageReceived(const IPC::Message& msg) { | 590 bool ChildThreadImpl::OnMessageReceived(const IPC::Message& msg) { |
599 if (mojo_application_->OnMessageReceived(msg)) | 591 if (mojo_application_->OnMessageReceived(msg)) |
600 return true; | 592 return true; |
601 | 593 |
602 // Resource responses are sent to the resource dispatcher. | 594 // Resource responses are sent to the resource dispatcher. |
603 if (resource_dispatcher_->OnMessageReceived(msg)) | 595 if (resource_dispatcher_->OnMessageReceived(msg)) |
604 return true; | 596 return true; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
731 void ChildThreadImpl::EnsureConnected() { | 723 void ChildThreadImpl::EnsureConnected() { |
732 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; | 724 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; |
733 base::Process::Current().Terminate(0, false); | 725 base::Process::Current().Terminate(0, false); |
734 } | 726 } |
735 | 727 |
736 bool ChildThreadImpl::IsInBrowserProcess() const { | 728 bool ChildThreadImpl::IsInBrowserProcess() const { |
737 return browser_process_io_runner_; | 729 return browser_process_io_runner_; |
738 } | 730 } |
739 | 731 |
740 } // namespace content | 732 } // namespace content |
OLD | NEW |