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