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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 #include "ipc/ipc_channel_mojo.h" | 61 #include "ipc/ipc_channel_mojo.h" |
62 #include "ipc/ipc_logging.h" | 62 #include "ipc/ipc_logging.h" |
63 #include "ipc/ipc_platform_file.h" | 63 #include "ipc/ipc_platform_file.h" |
64 #include "ipc/ipc_switches.h" | 64 #include "ipc/ipc_switches.h" |
65 #include "ipc/ipc_sync_channel.h" | 65 #include "ipc/ipc_sync_channel.h" |
66 #include "ipc/ipc_sync_message_filter.h" | 66 #include "ipc/ipc_sync_message_filter.h" |
67 #include "mojo/edk/embedder/embedder.h" | 67 #include "mojo/edk/embedder/embedder.h" |
68 #include "mojo/edk/embedder/named_platform_channel_pair.h" | 68 #include "mojo/edk/embedder/named_platform_channel_pair.h" |
69 #include "mojo/edk/embedder/platform_channel_pair.h" | 69 #include "mojo/edk/embedder/platform_channel_pair.h" |
70 #include "mojo/edk/embedder/scoped_ipc_support.h" | 70 #include "mojo/edk/embedder/scoped_ipc_support.h" |
| 71 #include "services/shell/public/cpp/interface_provider.h" |
| 72 #include "services/shell/public/cpp/interface_registry.h" |
71 #include "services/shell/runner/common/client_util.h" | 73 #include "services/shell/runner/common/client_util.h" |
72 | 74 |
73 #if defined(OS_POSIX) | 75 #if defined(OS_POSIX) |
74 #include "base/posix/global_descriptors.h" | 76 #include "base/posix/global_descriptors.h" |
75 #include "content/public/common/content_descriptors.h" | 77 #include "content/public/common/content_descriptors.h" |
76 #endif | 78 #endif |
77 | 79 |
78 using tracked_objects::ThreadData; | 80 using tracked_objects::ThreadData; |
79 | 81 |
80 namespace content { | 82 namespace content { |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg); | 326 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg); |
325 reply->set_reply_error(); | 327 reply->set_reply_error(); |
326 Send(reply); | 328 Send(reply); |
327 } | 329 } |
328 #endif | 330 #endif |
329 return handled; | 331 return handled; |
330 } | 332 } |
331 | 333 |
332 ChildThreadImpl::ChildThreadImpl() | 334 ChildThreadImpl::ChildThreadImpl() |
333 : router_(this), | 335 : router_(this), |
334 channel_connected_factory_(this) { | 336 channel_connected_factory_( |
| 337 new base::WeakPtrFactory<ChildThreadImpl>(this)), |
| 338 weak_factory_(this) { |
335 Init(Options::Builder().Build()); | 339 Init(Options::Builder().Build()); |
336 } | 340 } |
337 | 341 |
338 ChildThreadImpl::ChildThreadImpl(const Options& options) | 342 ChildThreadImpl::ChildThreadImpl(const Options& options) |
339 : router_(this), | 343 : router_(this), |
340 browser_process_io_runner_(options.browser_process_io_runner), | 344 browser_process_io_runner_(options.browser_process_io_runner), |
341 channel_connected_factory_(this) { | 345 channel_connected_factory_( |
| 346 new base::WeakPtrFactory<ChildThreadImpl>(this)), |
| 347 weak_factory_(this) { |
342 Init(options); | 348 Init(options); |
343 } | 349 } |
344 | 350 |
345 scoped_refptr<base::SequencedTaskRunner> ChildThreadImpl::GetIOTaskRunner() { | 351 scoped_refptr<base::SequencedTaskRunner> ChildThreadImpl::GetIOTaskRunner() { |
346 if (IsInBrowserProcess()) | 352 if (IsInBrowserProcess()) |
347 return browser_process_io_runner_; | 353 return browser_process_io_runner_; |
348 return ChildProcess::current()->io_task_runner(); | 354 return ChildProcess::current()->io_task_runner(); |
349 } | 355 } |
350 | 356 |
351 void ChildThreadImpl::ConnectChannel(bool use_mojo_channel, | 357 void ChildThreadImpl::ConnectChannel(bool use_mojo_channel, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 412 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
407 switches::kMojoApplicationChannelToken); | 413 switches::kMojoApplicationChannelToken); |
408 } else { | 414 } else { |
409 mojo_application_token = options.in_process_application_token; | 415 mojo_application_token = options.in_process_application_token; |
410 } | 416 } |
411 if (!mojo_application_token.empty()) { | 417 if (!mojo_application_token.empty()) { |
412 mojo::ScopedMessagePipeHandle handle = | 418 mojo::ScopedMessagePipeHandle handle = |
413 mojo::edk::CreateChildMessagePipe(mojo_application_token); | 419 mojo::edk::CreateChildMessagePipe(mojo_application_token); |
414 DCHECK(handle.is_valid()); | 420 DCHECK(handle.is_valid()); |
415 mojo_shell_connection_ = MojoShellConnection::Create( | 421 mojo_shell_connection_ = MojoShellConnection::Create( |
416 mojo::MakeRequest<shell::mojom::Service>(std::move(handle))); | 422 mojo::MakeRequest<shell::mojom::Service>(std::move(handle)), |
417 mojo_shell_connection_->MergeService(this); | 423 GetIOTaskRunner()); |
| 424 |
| 425 // TODO(rockot): Remove this once all child-to-browser interface connections |
| 426 // are made via a Connector rather than directly through an |
| 427 // InterfaceProvider, and all exposed interfaces are exposed via a |
| 428 // ConnectionFilter. |
| 429 mojo_shell_connection_->SetupInterfaceRequestProxies( |
| 430 GetInterfaceRegistry(), GetRemoteInterfaces()); |
| 431 |
| 432 AddConnectionFilters(mojo_shell_connection_.get()); |
| 433 mojo_shell_connection_->Start(); |
418 } | 434 } |
419 | 435 |
420 sync_message_filter_ = channel_->CreateSyncMessageFilter(); | 436 sync_message_filter_ = channel_->CreateSyncMessageFilter(); |
421 thread_safe_sender_ = new ThreadSafeSender( | 437 thread_safe_sender_ = new ThreadSafeSender( |
422 message_loop_->task_runner(), sync_message_filter_.get()); | 438 message_loop_->task_runner(), sync_message_filter_.get()); |
423 | 439 |
424 resource_dispatcher_.reset(new ResourceDispatcher( | 440 resource_dispatcher_.reset(new ResourceDispatcher( |
425 this, message_loop()->task_runner())); | 441 this, message_loop()->task_runner())); |
426 websocket_dispatcher_.reset(new WebSocketDispatcher); | 442 websocket_dispatcher_.reset(new WebSocketDispatcher); |
427 file_system_dispatcher_.reset(new FileSystemDispatcher()); | 443 file_system_dispatcher_.reset(new FileSystemDispatcher()); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 508 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
493 switches::kIPCConnectionTimeout); | 509 switches::kIPCConnectionTimeout); |
494 if (!connection_override.empty()) { | 510 if (!connection_override.empty()) { |
495 int temp; | 511 int temp; |
496 if (base::StringToInt(connection_override, &temp)) | 512 if (base::StringToInt(connection_override, &temp)) |
497 connection_timeout = temp; | 513 connection_timeout = temp; |
498 } | 514 } |
499 | 515 |
500 message_loop_->task_runner()->PostDelayedTask( | 516 message_loop_->task_runner()->PostDelayedTask( |
501 FROM_HERE, base::Bind(&ChildThreadImpl::EnsureConnected, | 517 FROM_HERE, base::Bind(&ChildThreadImpl::EnsureConnected, |
502 channel_connected_factory_.GetWeakPtr()), | 518 channel_connected_factory_->GetWeakPtr()), |
503 base::TimeDelta::FromSeconds(connection_timeout)); | 519 base::TimeDelta::FromSeconds(connection_timeout)); |
504 | 520 |
505 #if defined(OS_ANDROID) | 521 #if defined(OS_ANDROID) |
506 g_quit_closure.Get().BindToMainThread(); | 522 g_quit_closure.Get().BindToMainThread(); |
507 #endif | 523 #endif |
508 | 524 |
509 shared_bitmap_manager_.reset( | 525 shared_bitmap_manager_.reset( |
510 new ChildSharedBitmapManager(thread_safe_sender())); | 526 new ChildSharedBitmapManager(thread_safe_sender())); |
511 | 527 |
512 gpu_memory_buffer_manager_.reset( | 528 gpu_memory_buffer_manager_.reset( |
513 new ChildGpuMemoryBufferManager(thread_safe_sender())); | 529 new ChildGpuMemoryBufferManager(thread_safe_sender())); |
514 | 530 |
515 discardable_shared_memory_manager_.reset( | 531 discardable_shared_memory_manager_.reset( |
516 new ChildDiscardableSharedMemoryManager(thread_safe_sender())); | 532 new ChildDiscardableSharedMemoryManager(thread_safe_sender())); |
517 } | 533 } |
518 | 534 |
519 ChildThreadImpl::~ChildThreadImpl() { | 535 ChildThreadImpl::~ChildThreadImpl() { |
520 if (MojoShellConnection::GetForProcess()) | |
521 MojoShellConnection::DestroyForProcess(); | |
522 | |
523 #ifdef IPC_MESSAGE_LOG_ENABLED | 536 #ifdef IPC_MESSAGE_LOG_ENABLED |
524 IPC::Logging::GetInstance()->SetIPCSender(NULL); | 537 IPC::Logging::GetInstance()->SetIPCSender(NULL); |
525 #endif | 538 #endif |
526 | 539 |
527 IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal(); | 540 IPC::AttachmentBroker* broker = IPC::AttachmentBroker::GetGlobal(); |
528 if (broker && !broker->IsPrivilegedBroker()) | 541 if (broker && !broker->IsPrivilegedBroker()) |
529 broker->DeregisterBrokerCommunicationChannel(channel_.get()); | 542 broker->DeregisterBrokerCommunicationChannel(channel_.get()); |
530 | 543 |
531 channel_->RemoveFilter(histogram_message_filter_.get()); | 544 channel_->RemoveFilter(histogram_message_filter_.get()); |
532 channel_->RemoveFilter(sync_message_filter_.get()); | 545 channel_->RemoveFilter(sync_message_filter_.get()); |
(...skipping 16 matching lines...) Expand all Loading... |
549 file_system_dispatcher_.reset(); | 562 file_system_dispatcher_.reset(); |
550 quota_dispatcher_.reset(); | 563 quota_dispatcher_.reset(); |
551 WebFileSystemImpl::DeleteThreadSpecificInstance(); | 564 WebFileSystemImpl::DeleteThreadSpecificInstance(); |
552 } | 565 } |
553 | 566 |
554 void ChildThreadImpl::ShutdownDiscardableSharedMemoryManager() { | 567 void ChildThreadImpl::ShutdownDiscardableSharedMemoryManager() { |
555 discardable_shared_memory_manager_.reset(); | 568 discardable_shared_memory_manager_.reset(); |
556 } | 569 } |
557 | 570 |
558 void ChildThreadImpl::OnChannelConnected(int32_t peer_pid) { | 571 void ChildThreadImpl::OnChannelConnected(int32_t peer_pid) { |
559 channel_connected_factory_.InvalidateWeakPtrs(); | 572 channel_connected_factory_.reset(); |
560 } | 573 } |
561 | 574 |
562 void ChildThreadImpl::OnChannelError() { | 575 void ChildThreadImpl::OnChannelError() { |
563 on_channel_error_called_ = true; | 576 on_channel_error_called_ = true; |
564 base::MessageLoop::current()->QuitWhenIdle(); | 577 base::MessageLoop::current()->QuitWhenIdle(); |
565 } | 578 } |
566 | 579 |
567 bool ChildThreadImpl::Send(IPC::Message* msg) { | 580 bool ChildThreadImpl::Send(IPC::Message* msg) { |
568 DCHECK(message_loop_->task_runner()->BelongsToCurrentThread()); | 581 DCHECK(message_loop_->task_runner()->BelongsToCurrentThread()); |
569 if (!channel_) { | 582 if (!channel_) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 interface_registry_.reset(new shell::InterfaceRegistry(nullptr)); | 614 interface_registry_.reset(new shell::InterfaceRegistry(nullptr)); |
602 return interface_registry_.get(); | 615 return interface_registry_.get(); |
603 } | 616 } |
604 | 617 |
605 shell::InterfaceProvider* ChildThreadImpl::GetRemoteInterfaces() { | 618 shell::InterfaceProvider* ChildThreadImpl::GetRemoteInterfaces() { |
606 if (!remote_interfaces_.get()) | 619 if (!remote_interfaces_.get()) |
607 remote_interfaces_.reset(new shell::InterfaceProvider); | 620 remote_interfaces_.reset(new shell::InterfaceProvider); |
608 return remote_interfaces_.get(); | 621 return remote_interfaces_.get(); |
609 } | 622 } |
610 | 623 |
611 shell::InterfaceRegistry* ChildThreadImpl::GetInterfaceRegistryForConnection() { | |
612 return GetInterfaceRegistry(); | |
613 } | |
614 | |
615 shell::InterfaceProvider* ChildThreadImpl::GetInterfaceProviderForConnection() { | |
616 return GetRemoteInterfaces(); | |
617 } | |
618 | |
619 IPC::MessageRouter* ChildThreadImpl::GetRouter() { | 624 IPC::MessageRouter* ChildThreadImpl::GetRouter() { |
620 DCHECK(message_loop_->task_runner()->BelongsToCurrentThread()); | 625 DCHECK(message_loop_->task_runner()->BelongsToCurrentThread()); |
621 return &router_; | 626 return &router_; |
622 } | 627 } |
623 | 628 |
624 std::unique_ptr<base::SharedMemory> ChildThreadImpl::AllocateSharedMemory( | 629 std::unique_ptr<base::SharedMemory> ChildThreadImpl::AllocateSharedMemory( |
625 size_t buf_size) { | 630 size_t buf_size) { |
626 DCHECK(message_loop_->task_runner()->BelongsToCurrentThread()); | 631 DCHECK(message_loop_->task_runner()->BelongsToCurrentThread()); |
627 return AllocateSharedMemory(buf_size, this, nullptr); | 632 return AllocateSharedMemory(buf_size, this, nullptr); |
628 } | 633 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 | 689 |
685 if (handled) | 690 if (handled) |
686 return true; | 691 return true; |
687 | 692 |
688 if (msg.routing_id() == MSG_ROUTING_CONTROL) | 693 if (msg.routing_id() == MSG_ROUTING_CONTROL) |
689 return OnControlMessageReceived(msg); | 694 return OnControlMessageReceived(msg); |
690 | 695 |
691 return router_.OnMessageReceived(msg); | 696 return router_.OnMessageReceived(msg); |
692 } | 697 } |
693 | 698 |
| 699 void ChildThreadImpl::AddConnectionFilters(MojoShellConnection* connection) {} |
| 700 |
694 bool ChildThreadImpl::OnControlMessageReceived(const IPC::Message& msg) { | 701 bool ChildThreadImpl::OnControlMessageReceived(const IPC::Message& msg) { |
695 return false; | 702 return false; |
696 } | 703 } |
697 | 704 |
698 void ChildThreadImpl::OnProcessBackgrounded(bool backgrounded) { | 705 void ChildThreadImpl::OnProcessBackgrounded(bool backgrounded) { |
699 // Set timer slack to maximum on main thread when in background. | 706 // Set timer slack to maximum on main thread when in background. |
700 base::TimerSlack timer_slack = base::TIMER_SLACK_NONE; | 707 base::TimerSlack timer_slack = base::TIMER_SLACK_NONE; |
701 if (backgrounded) | 708 if (backgrounded) |
702 timer_slack = base::TIMER_SLACK_MAXIMUM; | 709 timer_slack = base::TIMER_SLACK_MAXIMUM; |
703 base::MessageLoop::current()->SetTimerSlack(timer_slack); | 710 base::MessageLoop::current()->SetTimerSlack(timer_slack); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 void ChildThreadImpl::EnsureConnected() { | 773 void ChildThreadImpl::EnsureConnected() { |
767 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; | 774 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; |
768 base::Process::Current().Terminate(0, false); | 775 base::Process::Current().Terminate(0, false); |
769 } | 776 } |
770 | 777 |
771 bool ChildThreadImpl::IsInBrowserProcess() const { | 778 bool ChildThreadImpl::IsInBrowserProcess() const { |
772 return static_cast<bool>(browser_process_io_runner_); | 779 return static_cast<bool>(browser_process_io_runner_); |
773 } | 780 } |
774 | 781 |
775 } // namespace content | 782 } // namespace content |
OLD | NEW |