| 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 14 matching lines...) Expand all Loading... |
| 25 #include "base/single_thread_task_runner.h" | 25 #include "base/single_thread_task_runner.h" |
| 26 #include "base/strings/string_number_conversions.h" | 26 #include "base/strings/string_number_conversions.h" |
| 27 #include "base/strings/string_util.h" | 27 #include "base/strings/string_util.h" |
| 28 #include "base/synchronization/condition_variable.h" | 28 #include "base/synchronization/condition_variable.h" |
| 29 #include "base/synchronization/lock.h" | 29 #include "base/synchronization/lock.h" |
| 30 #include "base/threading/thread_local.h" | 30 #include "base/threading/thread_local.h" |
| 31 #include "base/threading/thread_task_runner_handle.h" | 31 #include "base/threading/thread_task_runner_handle.h" |
| 32 #include "base/timer/elapsed_timer.h" | 32 #include "base/timer/elapsed_timer.h" |
| 33 #include "base/tracked_objects.h" | 33 #include "base/tracked_objects.h" |
| 34 #include "build/build_config.h" | 34 #include "build/build_config.h" |
| 35 #include "components/discardable_memory/client/client_discardable_shared_memory_
manager.h" | |
| 36 #include "components/tracing/child/child_trace_message_filter.h" | 35 #include "components/tracing/child/child_trace_message_filter.h" |
| 37 #include "content/child/child_histogram_message_filter.h" | 36 #include "content/child/child_histogram_message_filter.h" |
| 38 #include "content/child/child_process.h" | 37 #include "content/child/child_process.h" |
| 39 #include "content/child/child_resource_message_filter.h" | 38 #include "content/child/child_resource_message_filter.h" |
| 40 #include "content/child/child_shared_bitmap_manager.h" | 39 #include "content/child/child_shared_bitmap_manager.h" |
| 41 #include "content/child/fileapi/file_system_dispatcher.h" | 40 #include "content/child/fileapi/file_system_dispatcher.h" |
| 42 #include "content/child/fileapi/webfilesystem_impl.h" | 41 #include "content/child/fileapi/webfilesystem_impl.h" |
| 43 #include "content/child/memory/child_memory_message_filter.h" | 42 #include "content/child/memory/child_memory_message_filter.h" |
| 44 #include "content/child/notifications/notification_dispatcher.h" | 43 #include "content/child/notifications/notification_dispatcher.h" |
| 45 #include "content/child/push_messaging/push_dispatcher.h" | 44 #include "content/child/push_messaging/push_dispatcher.h" |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 } | 310 } |
| 312 | 311 |
| 313 ChildThreadImpl::Options::Builder& | 312 ChildThreadImpl::Options::Builder& |
| 314 ChildThreadImpl::Options::Builder::AutoStartServiceManagerConnection( | 313 ChildThreadImpl::Options::Builder::AutoStartServiceManagerConnection( |
| 315 bool auto_start) { | 314 bool auto_start) { |
| 316 options_.auto_start_service_manager_connection = auto_start; | 315 options_.auto_start_service_manager_connection = auto_start; |
| 317 return *this; | 316 return *this; |
| 318 } | 317 } |
| 319 | 318 |
| 320 ChildThreadImpl::Options::Builder& | 319 ChildThreadImpl::Options::Builder& |
| 321 ChildThreadImpl::Options::Builder::ConnectToBrowser( | 320 ChildThreadImpl::Options::Builder::ConnectToBrowser(bool connect_to_browser) { |
| 322 bool connect_to_browser) { | |
| 323 options_.connect_to_browser = connect_to_browser; | 321 options_.connect_to_browser = connect_to_browser; |
| 324 return *this; | 322 return *this; |
| 325 } | 323 } |
| 326 | 324 |
| 327 ChildThreadImpl::Options::Builder& | 325 ChildThreadImpl::Options::Builder& |
| 328 ChildThreadImpl::Options::Builder::AddStartupFilter( | 326 ChildThreadImpl::Options::Builder::AddStartupFilter( |
| 329 IPC::MessageFilter* filter) { | 327 IPC::MessageFilter* filter) { |
| 330 options_.startup_filters.push_back(filter); | 328 options_.startup_filters.push_back(filter); |
| 331 return *this; | 329 return *this; |
| 332 } | 330 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 349 #if defined(OS_ANDROID) | 347 #if defined(OS_ANDROID) |
| 350 if (!handled && msg.is_sync()) { | 348 if (!handled && msg.is_sync()) { |
| 351 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg); | 349 IPC::Message* reply = IPC::SyncMessage::GenerateReply(&msg); |
| 352 reply->set_reply_error(); | 350 reply->set_reply_error(); |
| 353 Send(reply); | 351 Send(reply); |
| 354 } | 352 } |
| 355 #endif | 353 #endif |
| 356 return handled; | 354 return handled; |
| 357 } | 355 } |
| 358 | 356 |
| 359 class ChildThreadImpl::ClientDiscardableSharedMemoryManagerDelegate | |
| 360 : public discardable_memory::ClientDiscardableSharedMemoryManager:: | |
| 361 Delegate { | |
| 362 public: | |
| 363 explicit ClientDiscardableSharedMemoryManagerDelegate( | |
| 364 scoped_refptr<ThreadSafeSender> sender) | |
| 365 : sender_(sender) {} | |
| 366 ~ClientDiscardableSharedMemoryManagerDelegate() override {} | |
| 367 | |
| 368 void AllocateLockedDiscardableSharedMemory( | |
| 369 size_t size, | |
| 370 discardable_memory::DiscardableSharedMemoryId id, | |
| 371 base::SharedMemoryHandle* handle) override { | |
| 372 sender_->Send( | |
| 373 new ChildProcessHostMsg_SyncAllocateLockedDiscardableSharedMemory( | |
| 374 size, id, handle)); | |
| 375 } | |
| 376 | |
| 377 void DeletedDiscardableSharedMemory( | |
| 378 discardable_memory::DiscardableSharedMemoryId id) override { | |
| 379 sender_->Send(new ChildProcessHostMsg_DeletedDiscardableSharedMemory(id)); | |
| 380 } | |
| 381 | |
| 382 private: | |
| 383 scoped_refptr<ThreadSafeSender> sender_; | |
| 384 }; | |
| 385 | |
| 386 ChildThreadImpl::ChildThreadImpl() | 357 ChildThreadImpl::ChildThreadImpl() |
| 387 : route_provider_binding_(this), | 358 : route_provider_binding_(this), |
| 388 associated_interface_provider_bindings_( | 359 associated_interface_provider_bindings_( |
| 389 mojo::BindingSetDispatchMode::WITH_CONTEXT), | 360 mojo::BindingSetDispatchMode::WITH_CONTEXT), |
| 390 router_(this), | 361 router_(this), |
| 391 channel_connected_factory_( | 362 channel_connected_factory_( |
| 392 new base::WeakPtrFactory<ChildThreadImpl>(this)), | 363 new base::WeakPtrFactory<ChildThreadImpl>(this)), |
| 393 weak_factory_(this) { | 364 weak_factory_(this) { |
| 394 Init(Options::Builder().Build()); | 365 Init(Options::Builder().Build()); |
| 395 } | 366 } |
| 396 | 367 |
| 397 ChildThreadImpl::ChildThreadImpl(const Options& options) | 368 ChildThreadImpl::ChildThreadImpl(const Options& options) |
| 398 : route_provider_binding_(this), | 369 : route_provider_binding_(this), |
| 399 associated_interface_provider_bindings_( | 370 associated_interface_provider_bindings_( |
| 400 mojo::BindingSetDispatchMode::WITH_CONTEXT), | 371 mojo::BindingSetDispatchMode::WITH_CONTEXT), |
| 401 router_(this), | 372 router_(this), |
| 402 browser_process_io_runner_(options.browser_process_io_runner), | 373 browser_process_io_runner_(options.browser_process_io_runner), |
| 403 channel_connected_factory_( | 374 channel_connected_factory_( |
| 404 new base::WeakPtrFactory<ChildThreadImpl>(this)), | 375 new base::WeakPtrFactory<ChildThreadImpl>(this)), |
| 405 weak_factory_(this) { | 376 weak_factory_(this) { |
| 406 Init(options); | 377 Init(options); |
| 407 } | 378 } |
| 408 | 379 |
| 409 scoped_refptr<base::SequencedTaskRunner> ChildThreadImpl::GetIOTaskRunner() { | 380 scoped_refptr<base::SingleThreadTaskRunner> ChildThreadImpl::GetIOTaskRunner() { |
| 410 if (IsInBrowserProcess()) | 381 if (IsInBrowserProcess()) |
| 411 return browser_process_io_runner_; | 382 return browser_process_io_runner_; |
| 412 return ChildProcess::current()->io_task_runner(); | 383 return ChildProcess::current()->io_task_runner(); |
| 413 } | 384 } |
| 414 | 385 |
| 415 void ChildThreadImpl::ConnectChannel() { | 386 void ChildThreadImpl::ConnectChannel() { |
| 416 std::string channel_token; | 387 std::string channel_token; |
| 417 mojo::ScopedMessagePipeHandle handle; | 388 mojo::ScopedMessagePipeHandle handle; |
| 418 if (!IsInBrowserProcess()) { | 389 if (!IsInBrowserProcess()) { |
| 419 channel_token = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 390 channel_token = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 FROM_HERE, base::Bind(&ChildThreadImpl::EnsureConnected, | 557 FROM_HERE, base::Bind(&ChildThreadImpl::EnsureConnected, |
| 587 channel_connected_factory_->GetWeakPtr()), | 558 channel_connected_factory_->GetWeakPtr()), |
| 588 base::TimeDelta::FromSeconds(connection_timeout)); | 559 base::TimeDelta::FromSeconds(connection_timeout)); |
| 589 | 560 |
| 590 #if defined(OS_ANDROID) | 561 #if defined(OS_ANDROID) |
| 591 g_quit_closure.Get().BindToMainThread(); | 562 g_quit_closure.Get().BindToMainThread(); |
| 592 #endif | 563 #endif |
| 593 | 564 |
| 594 shared_bitmap_manager_.reset( | 565 shared_bitmap_manager_.reset( |
| 595 new ChildSharedBitmapManager(thread_safe_sender())); | 566 new ChildSharedBitmapManager(thread_safe_sender())); |
| 596 | |
| 597 client_discardable_shared_memory_manager_delegate_ = | |
| 598 base::MakeUnique<ClientDiscardableSharedMemoryManagerDelegate>( | |
| 599 thread_safe_sender()); | |
| 600 discardable_shared_memory_manager_ = base::MakeUnique< | |
| 601 discardable_memory::ClientDiscardableSharedMemoryManager>( | |
| 602 client_discardable_shared_memory_manager_delegate_.get()); | |
| 603 } | 567 } |
| 604 | 568 |
| 605 ChildThreadImpl::~ChildThreadImpl() { | 569 ChildThreadImpl::~ChildThreadImpl() { |
| 606 #ifdef IPC_MESSAGE_LOG_ENABLED | 570 #ifdef IPC_MESSAGE_LOG_ENABLED |
| 607 IPC::Logging::GetInstance()->SetIPCSender(NULL); | 571 IPC::Logging::GetInstance()->SetIPCSender(NULL); |
| 608 #endif | 572 #endif |
| 609 | 573 |
| 610 channel_->RemoveFilter(histogram_message_filter_.get()); | 574 channel_->RemoveFilter(histogram_message_filter_.get()); |
| 611 channel_->RemoveFilter(sync_message_filter_.get()); | 575 channel_->RemoveFilter(sync_message_filter_.get()); |
| 612 | 576 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 623 } | 587 } |
| 624 | 588 |
| 625 void ChildThreadImpl::Shutdown() { | 589 void ChildThreadImpl::Shutdown() { |
| 626 // Delete objects that hold references to blink so derived classes can | 590 // Delete objects that hold references to blink so derived classes can |
| 627 // safely shutdown blink in their Shutdown implementation. | 591 // safely shutdown blink in their Shutdown implementation. |
| 628 file_system_dispatcher_.reset(); | 592 file_system_dispatcher_.reset(); |
| 629 quota_dispatcher_.reset(); | 593 quota_dispatcher_.reset(); |
| 630 WebFileSystemImpl::DeleteThreadSpecificInstance(); | 594 WebFileSystemImpl::DeleteThreadSpecificInstance(); |
| 631 } | 595 } |
| 632 | 596 |
| 633 void ChildThreadImpl::ShutdownDiscardableSharedMemoryManager() { | |
| 634 discardable_shared_memory_manager_.reset(); | |
| 635 } | |
| 636 | |
| 637 void ChildThreadImpl::OnChannelConnected(int32_t peer_pid) { | 597 void ChildThreadImpl::OnChannelConnected(int32_t peer_pid) { |
| 638 channel_connected_factory_.reset(); | 598 channel_connected_factory_.reset(); |
| 639 } | 599 } |
| 640 | 600 |
| 641 void ChildThreadImpl::OnChannelError() { | 601 void ChildThreadImpl::OnChannelError() { |
| 642 on_channel_error_called_ = true; | 602 on_channel_error_called_ = true; |
| 643 base::MessageLoop::current()->QuitWhenIdle(); | 603 base::MessageLoop::current()->QuitWhenIdle(); |
| 644 } | 604 } |
| 645 | 605 |
| 646 bool ChildThreadImpl::Send(IPC::Message* msg) { | 606 bool ChildThreadImpl::Send(IPC::Message* msg) { |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 916 connected_to_browser_ = true; | 876 connected_to_browser_ = true; |
| 917 child_info_ = local_info; | 877 child_info_ = local_info; |
| 918 browser_info_ = remote_info; | 878 browser_info_ = remote_info; |
| 919 } | 879 } |
| 920 | 880 |
| 921 bool ChildThreadImpl::IsInBrowserProcess() const { | 881 bool ChildThreadImpl::IsInBrowserProcess() const { |
| 922 return static_cast<bool>(browser_process_io_runner_); | 882 return static_cast<bool>(browser_process_io_runner_); |
| 923 } | 883 } |
| 924 | 884 |
| 925 } // namespace content | 885 } // namespace content |
| OLD | NEW |