| 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 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 VLOG(1) << "Mojo is disabled on child"; | 397 VLOG(1) << "Mojo is disabled on child"; |
| 398 channel_->Init(channel_name_, IPC::Channel::MODE_CLIENT, create_pipe_now); | 398 channel_->Init(channel_name_, IPC::Channel::MODE_CLIENT, create_pipe_now); |
| 399 } | 399 } |
| 400 | 400 |
| 401 void ChildThreadImpl::Init(const Options& options) { | 401 void ChildThreadImpl::Init(const Options& options) { |
| 402 channel_name_ = options.channel_name; | 402 channel_name_ = options.channel_name; |
| 403 | 403 |
| 404 g_lazy_tls.Pointer()->Set(this); | 404 g_lazy_tls.Pointer()->Set(this); |
| 405 on_channel_error_called_ = false; | 405 on_channel_error_called_ = false; |
| 406 message_loop_ = base::MessageLoop::current(); | 406 message_loop_ = base::MessageLoop::current(); |
| 407 main_task_runner_ = message_loop_->task_runner(); |
| 407 #ifdef IPC_MESSAGE_LOG_ENABLED | 408 #ifdef IPC_MESSAGE_LOG_ENABLED |
| 408 // We must make sure to instantiate the IPC Logger *before* we create the | 409 // We must make sure to instantiate the IPC Logger *before* we create the |
| 409 // channel, otherwise we can get a callback on the IO thread which creates | 410 // channel, otherwise we can get a callback on the IO thread which creates |
| 410 // the logger, and the logger does not like being created on the IO thread. | 411 // the logger, and the logger does not like being created on the IO thread. |
| 411 IPC::Logging::GetInstance(); | 412 IPC::Logging::GetInstance(); |
| 412 #endif | 413 #endif |
| 413 | 414 |
| 414 IPC::AttachmentBrokerUnprivileged::CreateBrokerIfNeeded(); | 415 IPC::AttachmentBrokerUnprivileged::CreateBrokerIfNeeded(); |
| 415 | 416 |
| 416 channel_ = | 417 channel_ = |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 // ConnectionFilter. | 460 // ConnectionFilter. |
| 460 mojo_shell_connection_->SetupInterfaceRequestProxies( | 461 mojo_shell_connection_->SetupInterfaceRequestProxies( |
| 461 GetInterfaceRegistry(), remote_interfaces); | 462 GetInterfaceRegistry(), remote_interfaces); |
| 462 | 463 |
| 463 if (options.auto_start_mojo_shell_connection) | 464 if (options.auto_start_mojo_shell_connection) |
| 464 StartMojoShellConnection(); | 465 StartMojoShellConnection(); |
| 465 } | 466 } |
| 466 | 467 |
| 467 sync_message_filter_ = channel_->CreateSyncMessageFilter(); | 468 sync_message_filter_ = channel_->CreateSyncMessageFilter(); |
| 468 thread_safe_sender_ = new ThreadSafeSender( | 469 thread_safe_sender_ = new ThreadSafeSender( |
| 469 message_loop_->task_runner(), sync_message_filter_.get()); | 470 main_task_runner_, sync_message_filter_.get()); |
| 470 | 471 |
| 471 resource_dispatcher_.reset(new ResourceDispatcher( | 472 resource_dispatcher_.reset(new ResourceDispatcher( |
| 472 this, message_loop()->task_runner())); | 473 this, message_loop()->task_runner())); |
| 473 websocket_dispatcher_.reset(new WebSocketDispatcher); | 474 websocket_dispatcher_.reset(new WebSocketDispatcher); |
| 474 file_system_dispatcher_.reset(new FileSystemDispatcher()); | 475 file_system_dispatcher_.reset(new FileSystemDispatcher()); |
| 475 | 476 |
| 476 histogram_message_filter_ = new ChildHistogramMessageFilter(); | 477 histogram_message_filter_ = new ChildHistogramMessageFilter(); |
| 477 resource_message_filter_ = | 478 resource_message_filter_ = |
| 478 new ChildResourceMessageFilter(resource_dispatcher()); | 479 new ChildResourceMessageFilter(resource_dispatcher()); |
| 479 | 480 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 int connection_timeout = kConnectionTimeoutS; | 538 int connection_timeout = kConnectionTimeoutS; |
| 538 std::string connection_override = | 539 std::string connection_override = |
| 539 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 540 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 540 switches::kIPCConnectionTimeout); | 541 switches::kIPCConnectionTimeout); |
| 541 if (!connection_override.empty()) { | 542 if (!connection_override.empty()) { |
| 542 int temp; | 543 int temp; |
| 543 if (base::StringToInt(connection_override, &temp)) | 544 if (base::StringToInt(connection_override, &temp)) |
| 544 connection_timeout = temp; | 545 connection_timeout = temp; |
| 545 } | 546 } |
| 546 | 547 |
| 547 message_loop_->task_runner()->PostDelayedTask( | 548 main_task_runner_->PostDelayedTask( |
| 548 FROM_HERE, base::Bind(&ChildThreadImpl::EnsureConnected, | 549 FROM_HERE, base::Bind(&ChildThreadImpl::EnsureConnected, |
| 549 channel_connected_factory_->GetWeakPtr()), | 550 channel_connected_factory_->GetWeakPtr()), |
| 550 base::TimeDelta::FromSeconds(connection_timeout)); | 551 base::TimeDelta::FromSeconds(connection_timeout)); |
| 551 | 552 |
| 552 #if defined(OS_ANDROID) | 553 #if defined(OS_ANDROID) |
| 553 g_quit_closure.Get().BindToMainThread(); | 554 g_quit_closure.Get().BindToMainThread(); |
| 554 #endif | 555 #endif |
| 555 | 556 |
| 556 shared_bitmap_manager_.reset( | 557 shared_bitmap_manager_.reset( |
| 557 new ChildSharedBitmapManager(thread_safe_sender())); | 558 new ChildSharedBitmapManager(thread_safe_sender())); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 586 channel_->ClearIPCTaskRunner(); | 587 channel_->ClearIPCTaskRunner(); |
| 587 g_lazy_tls.Pointer()->Set(NULL); | 588 g_lazy_tls.Pointer()->Set(NULL); |
| 588 } | 589 } |
| 589 | 590 |
| 590 void ChildThreadImpl::Shutdown() { | 591 void ChildThreadImpl::Shutdown() { |
| 591 // Delete objects that hold references to blink so derived classes can | 592 // Delete objects that hold references to blink so derived classes can |
| 592 // safely shutdown blink in their Shutdown implementation. | 593 // safely shutdown blink in their Shutdown implementation. |
| 593 file_system_dispatcher_.reset(); | 594 file_system_dispatcher_.reset(); |
| 594 quota_dispatcher_.reset(); | 595 quota_dispatcher_.reset(); |
| 595 WebFileSystemImpl::DeleteThreadSpecificInstance(); | 596 WebFileSystemImpl::DeleteThreadSpecificInstance(); |
| 597 message_loop_ = nullptr; |
| 596 } | 598 } |
| 597 | 599 |
| 598 void ChildThreadImpl::ShutdownDiscardableSharedMemoryManager() { | 600 void ChildThreadImpl::ShutdownDiscardableSharedMemoryManager() { |
| 599 discardable_shared_memory_manager_.reset(); | 601 discardable_shared_memory_manager_.reset(); |
| 600 } | 602 } |
| 601 | 603 |
| 602 void ChildThreadImpl::OnChannelConnected(int32_t peer_pid) { | 604 void ChildThreadImpl::OnChannelConnected(int32_t peer_pid) { |
| 603 channel_connected_factory_.reset(); | 605 channel_connected_factory_.reset(); |
| 604 } | 606 } |
| 605 | 607 |
| 606 void ChildThreadImpl::OnChannelError() { | 608 void ChildThreadImpl::OnChannelError() { |
| 607 on_channel_error_called_ = true; | 609 on_channel_error_called_ = true; |
| 608 base::MessageLoop::current()->QuitWhenIdle(); | 610 base::MessageLoop::current()->QuitWhenIdle(); |
| 609 } | 611 } |
| 610 | 612 |
| 611 bool ChildThreadImpl::Send(IPC::Message* msg) { | 613 bool ChildThreadImpl::Send(IPC::Message* msg) { |
| 612 DCHECK(message_loop_->task_runner()->BelongsToCurrentThread()); | 614 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 613 if (!channel_) { | 615 if (!channel_) { |
| 614 delete msg; | 616 delete msg; |
| 615 return false; | 617 return false; |
| 616 } | 618 } |
| 617 | 619 |
| 618 return channel_->Send(msg); | 620 return channel_->Send(msg); |
| 619 } | 621 } |
| 620 | 622 |
| 621 #if defined(OS_WIN) | 623 #if defined(OS_WIN) |
| 622 void ChildThreadImpl::PreCacheFont(const LOGFONT& log_font) { | 624 void ChildThreadImpl::PreCacheFont(const LOGFONT& log_font) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 649 shell::InterfaceProvider* ChildThreadImpl::GetRemoteInterfaces() { | 651 shell::InterfaceProvider* ChildThreadImpl::GetRemoteInterfaces() { |
| 650 if (browser_connection_) | 652 if (browser_connection_) |
| 651 return browser_connection_->GetRemoteInterfaces(); | 653 return browser_connection_->GetRemoteInterfaces(); |
| 652 | 654 |
| 653 if (!remote_interfaces_.get()) | 655 if (!remote_interfaces_.get()) |
| 654 remote_interfaces_.reset(new shell::InterfaceProvider); | 656 remote_interfaces_.reset(new shell::InterfaceProvider); |
| 655 return remote_interfaces_.get(); | 657 return remote_interfaces_.get(); |
| 656 } | 658 } |
| 657 | 659 |
| 658 IPC::MessageRouter* ChildThreadImpl::GetRouter() { | 660 IPC::MessageRouter* ChildThreadImpl::GetRouter() { |
| 659 DCHECK(message_loop_->task_runner()->BelongsToCurrentThread()); | 661 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 660 return &router_; | 662 return &router_; |
| 661 } | 663 } |
| 662 | 664 |
| 663 std::unique_ptr<base::SharedMemory> ChildThreadImpl::AllocateSharedMemory( | 665 std::unique_ptr<base::SharedMemory> ChildThreadImpl::AllocateSharedMemory( |
| 664 size_t buf_size) { | 666 size_t buf_size) { |
| 665 DCHECK(message_loop_->task_runner()->BelongsToCurrentThread()); | 667 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 666 return AllocateSharedMemory(buf_size, this, nullptr); | 668 return AllocateSharedMemory(buf_size, this, nullptr); |
| 667 } | 669 } |
| 668 | 670 |
| 669 // static | 671 // static |
| 670 std::unique_ptr<base::SharedMemory> ChildThreadImpl::AllocateSharedMemory( | 672 std::unique_ptr<base::SharedMemory> ChildThreadImpl::AllocateSharedMemory( |
| 671 size_t buf_size, | 673 size_t buf_size, |
| 672 IPC::Sender* sender, | 674 IPC::Sender* sender, |
| 673 bool* out_of_memory) { | 675 bool* out_of_memory) { |
| 674 std::unique_ptr<base::SharedMemory> shared_buf; | 676 std::unique_ptr<base::SharedMemory> shared_buf; |
| 675 // Ask the browser to create the shared memory, since this is blocked by the | 677 // Ask the browser to create the shared memory, since this is blocked by the |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 void ChildThreadImpl::EnsureConnected() { | 812 void ChildThreadImpl::EnsureConnected() { |
| 811 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; | 813 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; |
| 812 base::Process::Current().Terminate(0, false); | 814 base::Process::Current().Terminate(0, false); |
| 813 } | 815 } |
| 814 | 816 |
| 815 bool ChildThreadImpl::IsInBrowserProcess() const { | 817 bool ChildThreadImpl::IsInBrowserProcess() const { |
| 816 return static_cast<bool>(browser_process_io_runner_); | 818 return static_cast<bool>(browser_process_io_runner_); |
| 817 } | 819 } |
| 818 | 820 |
| 819 } // namespace content | 821 } // namespace content |
| OLD | NEW |