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 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 } | 576 } |
577 | 577 |
578 IPC::MessageRouter* ChildThreadImpl::GetRouter() { | 578 IPC::MessageRouter* ChildThreadImpl::GetRouter() { |
579 DCHECK(base::MessageLoop::current() == message_loop()); | 579 DCHECK(base::MessageLoop::current() == message_loop()); |
580 return &router_; | 580 return &router_; |
581 } | 581 } |
582 | 582 |
583 std::unique_ptr<base::SharedMemory> ChildThreadImpl::AllocateSharedMemory( | 583 std::unique_ptr<base::SharedMemory> ChildThreadImpl::AllocateSharedMemory( |
584 size_t buf_size) { | 584 size_t buf_size) { |
585 DCHECK(base::MessageLoop::current() == message_loop()); | 585 DCHECK(base::MessageLoop::current() == message_loop()); |
586 return AllocateSharedMemory(buf_size, this); | 586 return AllocateSharedMemory(buf_size, this, nullptr); |
587 } | 587 } |
588 | 588 |
589 // static | 589 // static |
590 std::unique_ptr<base::SharedMemory> ChildThreadImpl::AllocateSharedMemory( | 590 std::unique_ptr<base::SharedMemory> ChildThreadImpl::AllocateSharedMemory( |
591 size_t buf_size, | 591 size_t buf_size, |
592 IPC::Sender* sender) { | 592 IPC::Sender* sender, |
| 593 bool* out_of_memory) { |
593 std::unique_ptr<base::SharedMemory> shared_buf; | 594 std::unique_ptr<base::SharedMemory> shared_buf; |
594 // Ask the browser to create the shared memory, since this is blocked by the | 595 // Ask the browser to create the shared memory, since this is blocked by the |
595 // sandbox on most platforms. | 596 // sandbox on most platforms. |
596 base::SharedMemoryHandle shared_mem_handle; | 597 base::SharedMemoryHandle shared_mem_handle; |
597 if (sender->Send(new ChildProcessHostMsg_SyncAllocateSharedMemory( | 598 if (sender->Send(new ChildProcessHostMsg_SyncAllocateSharedMemory( |
598 buf_size, &shared_mem_handle))) { | 599 buf_size, &shared_mem_handle))) { |
599 if (base::SharedMemory::IsHandleValid(shared_mem_handle)) { | 600 if (base::SharedMemory::IsHandleValid(shared_mem_handle)) { |
600 shared_buf.reset(new base::SharedMemory(shared_mem_handle, false)); | 601 shared_buf.reset(new base::SharedMemory(shared_mem_handle, false)); |
601 } else { | 602 } else { |
602 NOTREACHED() << "Browser failed to allocate shared memory"; | 603 LOG(WARNING) << "Browser failed to allocate shared memory"; |
| 604 if (out_of_memory) |
| 605 *out_of_memory = true; |
603 return nullptr; | 606 return nullptr; |
604 } | 607 } |
605 } else { | 608 } else { |
606 // Send is allowed to fail during shutdown. Return null in this case. | 609 // Send is allowed to fail during shutdown. Return null in this case. |
| 610 if (out_of_memory) |
| 611 *out_of_memory = false; |
607 return nullptr; | 612 return nullptr; |
608 } | 613 } |
609 return shared_buf; | 614 return shared_buf; |
610 } | 615 } |
611 | 616 |
612 bool ChildThreadImpl::OnMessageReceived(const IPC::Message& msg) { | 617 bool ChildThreadImpl::OnMessageReceived(const IPC::Message& msg) { |
613 // Resource responses are sent to the resource dispatcher. | 618 // Resource responses are sent to the resource dispatcher. |
614 if (resource_dispatcher_->OnMessageReceived(msg)) | 619 if (resource_dispatcher_->OnMessageReceived(msg)) |
615 return true; | 620 return true; |
616 if (websocket_dispatcher_->OnMessageReceived(msg)) | 621 if (websocket_dispatcher_->OnMessageReceived(msg)) |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 void ChildThreadImpl::EnsureConnected() { | 727 void ChildThreadImpl::EnsureConnected() { |
723 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; | 728 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; |
724 base::Process::Current().Terminate(0, false); | 729 base::Process::Current().Terminate(0, false); |
725 } | 730 } |
726 | 731 |
727 bool ChildThreadImpl::IsInBrowserProcess() const { | 732 bool ChildThreadImpl::IsInBrowserProcess() const { |
728 return static_cast<bool>(browser_process_io_runner_); | 733 return static_cast<bool>(browser_process_io_runner_); |
729 } | 734 } |
730 | 735 |
731 } // namespace content | 736 } // namespace content |
OLD | NEW |