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::ShellClient>(std::move(handle))); | 422 mojo::MakeRequest<shell::mojom::ShellClient>(std::move(handle)), |
417 mojo_shell_connection_->AddEmbeddedShellClient(this); | 423 GetIOTaskRunner()); |
418 } | 424 } |
419 | 425 |
420 sync_message_filter_ = channel_->CreateSyncMessageFilter(); | 426 sync_message_filter_ = channel_->CreateSyncMessageFilter(); |
421 thread_safe_sender_ = new ThreadSafeSender( | 427 thread_safe_sender_ = new ThreadSafeSender( |
422 message_loop_->task_runner(), sync_message_filter_.get()); | 428 message_loop_->task_runner(), sync_message_filter_.get()); |
423 | 429 |
424 resource_dispatcher_.reset(new ResourceDispatcher( | 430 resource_dispatcher_.reset(new ResourceDispatcher( |
425 this, message_loop()->task_runner())); | 431 this, message_loop()->task_runner())); |
426 websocket_dispatcher_.reset(new WebSocketDispatcher); | 432 websocket_dispatcher_.reset(new WebSocketDispatcher); |
427 file_system_dispatcher_.reset(new FileSystemDispatcher()); | 433 file_system_dispatcher_.reset(new FileSystemDispatcher()); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 498 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
493 switches::kIPCConnectionTimeout); | 499 switches::kIPCConnectionTimeout); |
494 if (!connection_override.empty()) { | 500 if (!connection_override.empty()) { |
495 int temp; | 501 int temp; |
496 if (base::StringToInt(connection_override, &temp)) | 502 if (base::StringToInt(connection_override, &temp)) |
497 connection_timeout = temp; | 503 connection_timeout = temp; |
498 } | 504 } |
499 | 505 |
500 message_loop_->task_runner()->PostDelayedTask( | 506 message_loop_->task_runner()->PostDelayedTask( |
501 FROM_HERE, base::Bind(&ChildThreadImpl::EnsureConnected, | 507 FROM_HERE, base::Bind(&ChildThreadImpl::EnsureConnected, |
502 channel_connected_factory_.GetWeakPtr()), | 508 channel_connected_factory_->GetWeakPtr()), |
503 base::TimeDelta::FromSeconds(connection_timeout)); | 509 base::TimeDelta::FromSeconds(connection_timeout)); |
504 | 510 |
505 #if defined(OS_ANDROID) | 511 #if defined(OS_ANDROID) |
506 g_quit_closure.Get().BindToMainThread(); | 512 g_quit_closure.Get().BindToMainThread(); |
507 #endif | 513 #endif |
508 | 514 |
509 shared_bitmap_manager_.reset( | 515 shared_bitmap_manager_.reset( |
510 new ChildSharedBitmapManager(thread_safe_sender())); | 516 new ChildSharedBitmapManager(thread_safe_sender())); |
511 | 517 |
512 gpu_memory_buffer_manager_.reset( | 518 gpu_memory_buffer_manager_.reset( |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 file_system_dispatcher_.reset(); | 555 file_system_dispatcher_.reset(); |
550 quota_dispatcher_.reset(); | 556 quota_dispatcher_.reset(); |
551 WebFileSystemImpl::DeleteThreadSpecificInstance(); | 557 WebFileSystemImpl::DeleteThreadSpecificInstance(); |
552 } | 558 } |
553 | 559 |
554 void ChildThreadImpl::ShutdownDiscardableSharedMemoryManager() { | 560 void ChildThreadImpl::ShutdownDiscardableSharedMemoryManager() { |
555 discardable_shared_memory_manager_.reset(); | 561 discardable_shared_memory_manager_.reset(); |
556 } | 562 } |
557 | 563 |
558 void ChildThreadImpl::OnChannelConnected(int32_t peer_pid) { | 564 void ChildThreadImpl::OnChannelConnected(int32_t peer_pid) { |
559 channel_connected_factory_.InvalidateWeakPtrs(); | 565 channel_connected_factory_.reset(); |
560 } | 566 } |
561 | 567 |
562 void ChildThreadImpl::OnChannelError() { | 568 void ChildThreadImpl::OnChannelError() { |
563 on_channel_error_called_ = true; | 569 on_channel_error_called_ = true; |
564 base::MessageLoop::current()->QuitWhenIdle(); | 570 base::MessageLoop::current()->QuitWhenIdle(); |
565 } | 571 } |
566 | 572 |
567 bool ChildThreadImpl::Send(IPC::Message* msg) { | 573 bool ChildThreadImpl::Send(IPC::Message* msg) { |
568 DCHECK(base::MessageLoop::current() == message_loop()); | 574 DCHECK(base::MessageLoop::current() == message_loop()); |
569 if (!channel_) { | 575 if (!channel_) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 interface_registry_.reset(new shell::InterfaceRegistry(nullptr)); | 607 interface_registry_.reset(new shell::InterfaceRegistry(nullptr)); |
602 return interface_registry_.get(); | 608 return interface_registry_.get(); |
603 } | 609 } |
604 | 610 |
605 shell::InterfaceProvider* ChildThreadImpl::GetRemoteInterfaces() { | 611 shell::InterfaceProvider* ChildThreadImpl::GetRemoteInterfaces() { |
606 if (!remote_interfaces_.get()) | 612 if (!remote_interfaces_.get()) |
607 remote_interfaces_.reset(new shell::InterfaceProvider); | 613 remote_interfaces_.reset(new shell::InterfaceProvider); |
608 return remote_interfaces_.get(); | 614 return remote_interfaces_.get(); |
609 } | 615 } |
610 | 616 |
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() { | 617 IPC::MessageRouter* ChildThreadImpl::GetRouter() { |
620 DCHECK(base::MessageLoop::current() == message_loop()); | 618 DCHECK(base::MessageLoop::current() == message_loop()); |
621 return &router_; | 619 return &router_; |
622 } | 620 } |
623 | 621 |
624 std::unique_ptr<base::SharedMemory> ChildThreadImpl::AllocateSharedMemory( | 622 std::unique_ptr<base::SharedMemory> ChildThreadImpl::AllocateSharedMemory( |
625 size_t buf_size) { | 623 size_t buf_size) { |
626 DCHECK(base::MessageLoop::current() == message_loop()); | 624 DCHECK(base::MessageLoop::current() == message_loop()); |
627 return AllocateSharedMemory(buf_size, this, nullptr); | 625 return AllocateSharedMemory(buf_size, this, nullptr); |
628 } | 626 } |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 void ChildThreadImpl::EnsureConnected() { | 764 void ChildThreadImpl::EnsureConnected() { |
767 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; | 765 VLOG(0) << "ChildThreadImpl::EnsureConnected()"; |
768 base::Process::Current().Terminate(0, false); | 766 base::Process::Current().Terminate(0, false); |
769 } | 767 } |
770 | 768 |
771 bool ChildThreadImpl::IsInBrowserProcess() const { | 769 bool ChildThreadImpl::IsInBrowserProcess() const { |
772 return static_cast<bool>(browser_process_io_runner_); | 770 return static_cast<bool>(browser_process_io_runner_); |
773 } | 771 } |
774 | 772 |
775 } // namespace content | 773 } // namespace content |
OLD | NEW |