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