OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 // Represents the browser side of the browser <--> renderer communication | 5 // Represents the browser side of the browser <--> renderer communication |
6 // channel. There will be one RenderProcessHost per renderer process. | 6 // channel. There will be one RenderProcessHost per renderer process. |
7 | 7 |
8 #include "content/browser/renderer_host/render_process_host_impl.h" | 8 #include "content/browser/renderer_host/render_process_host_impl.h" |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 #include "content/public/common/url_constants.h" | 157 #include "content/public/common/url_constants.h" |
158 #include "device/battery/battery_monitor_impl.h" | 158 #include "device/battery/battery_monitor_impl.h" |
159 #include "gpu/GLES2/gl2extchromium.h" | 159 #include "gpu/GLES2/gl2extchromium.h" |
160 #include "gpu/command_buffer/client/gpu_switches.h" | 160 #include "gpu/command_buffer/client/gpu_switches.h" |
161 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 161 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
162 #include "gpu/command_buffer/service/gpu_switches.h" | 162 #include "gpu/command_buffer/service/gpu_switches.h" |
163 #include "ipc/attachment_broker.h" | 163 #include "ipc/attachment_broker.h" |
164 #include "ipc/attachment_broker_privileged.h" | 164 #include "ipc/attachment_broker_privileged.h" |
165 #include "ipc/ipc_channel.h" | 165 #include "ipc/ipc_channel.h" |
166 #include "ipc/ipc_logging.h" | 166 #include "ipc/ipc_logging.h" |
| 167 #include "ipc/ipc_sender.h" |
167 #include "ipc/ipc_switches.h" | 168 #include "ipc/ipc_switches.h" |
168 #include "ipc/mojo/ipc_channel_mojo.h" | 169 #include "ipc/mojo/ipc_channel_mojo.h" |
169 #include "media/base/media_switches.h" | 170 #include "media/base/media_switches.h" |
170 #include "mojo/edk/embedder/embedder.h" | 171 #include "mojo/edk/embedder/embedder.h" |
171 #include "net/url_request/url_request_context_getter.h" | 172 #include "net/url_request/url_request_context_getter.h" |
172 #include "ppapi/shared_impl/ppapi_switches.h" | 173 #include "ppapi/shared_impl/ppapi_switches.h" |
173 #include "services/shell/runner/common/switches.h" | 174 #include "services/shell/runner/common/switches.h" |
174 #include "storage/browser/fileapi/sandbox_file_system_backend.h" | 175 #include "storage/browser/fileapi/sandbox_file_system_backend.h" |
175 #include "third_party/skia/include/core/SkBitmap.h" | 176 #include "third_party/skia/include/core/SkBitmap.h" |
176 #include "ui/base/ui_base_switches.h" | 177 #include "ui/base/ui_base_switches.h" |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 for (auto it : vector) { | 441 for (auto it : vector) { |
441 if (!str.empty()) | 442 if (!str.empty()) |
442 str += ","; | 443 str += ","; |
443 str += base::UintToString(it); | 444 str += base::UintToString(it); |
444 } | 445 } |
445 return str; | 446 return str; |
446 } | 447 } |
447 | 448 |
448 } // namespace | 449 } // namespace |
449 | 450 |
| 451 class RenderProcessHostImpl::SafeSenderProxy : public IPC::Sender { |
| 452 public: |
| 453 // |process| must outlive this object. |
| 454 explicit SafeSenderProxy(RenderProcessHostImpl* process, bool send_now) |
| 455 : process_(process), send_now_(send_now) {} |
| 456 ~SafeSenderProxy() override {} |
| 457 |
| 458 // IPC::Sender: |
| 459 bool Send(IPC::Message* message) override { |
| 460 return process_->SendImpl(base::WrapUnique(message), send_now_); |
| 461 } |
| 462 |
| 463 private: |
| 464 RenderProcessHostImpl* const process_; |
| 465 const bool send_now_; |
| 466 |
| 467 DISALLOW_COPY_AND_ASSIGN(SafeSenderProxy); |
| 468 }; |
| 469 |
450 RendererMainThreadFactoryFunction g_renderer_main_thread_factory = NULL; | 470 RendererMainThreadFactoryFunction g_renderer_main_thread_factory = NULL; |
451 | 471 |
452 base::MessageLoop* g_in_process_thread; | 472 base::MessageLoop* g_in_process_thread; |
453 | 473 |
454 base::MessageLoop* | 474 base::MessageLoop* |
455 RenderProcessHostImpl::GetInProcessRendererThreadForTesting() { | 475 RenderProcessHostImpl::GetInProcessRendererThreadForTesting() { |
456 return g_in_process_thread; | 476 return g_in_process_thread; |
457 } | 477 } |
458 | 478 |
459 // Stores the maximum number of renderer processes the content module can | 479 // Stores the maximum number of renderer processes the content module can |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 RenderProcessHostImpl::RenderProcessHostImpl( | 549 RenderProcessHostImpl::RenderProcessHostImpl( |
530 BrowserContext* browser_context, | 550 BrowserContext* browser_context, |
531 StoragePartitionImpl* storage_partition_impl, | 551 StoragePartitionImpl* storage_partition_impl, |
532 bool is_for_guests_only) | 552 bool is_for_guests_only) |
533 : fast_shutdown_started_(false), | 553 : fast_shutdown_started_(false), |
534 deleting_soon_(false), | 554 deleting_soon_(false), |
535 #ifndef NDEBUG | 555 #ifndef NDEBUG |
536 is_self_deleted_(false), | 556 is_self_deleted_(false), |
537 #endif | 557 #endif |
538 pending_views_(0), | 558 pending_views_(0), |
| 559 immediate_sender_(new SafeSenderProxy(this, true)), |
| 560 io_thread_sender_(new SafeSenderProxy(this, false)), |
539 mojo_application_host_(new MojoApplicationHost), | 561 mojo_application_host_(new MojoApplicationHost), |
540 visible_widgets_(0), | 562 visible_widgets_(0), |
541 is_process_backgrounded_(false), | 563 is_process_backgrounded_(false), |
542 is_initialized_(false), | 564 is_initialized_(false), |
543 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), | 565 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), |
544 browser_context_(browser_context), | 566 browser_context_(browser_context), |
545 storage_partition_impl_(storage_partition_impl), | 567 storage_partition_impl_(storage_partition_impl), |
546 sudden_termination_allowed_(true), | 568 sudden_termination_allowed_(true), |
547 ignore_input_events_(false), | 569 ignore_input_events_(false), |
548 is_for_guests_only_(is_for_guests_only), | 570 is_for_guests_only_(is_for_guests_only), |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 ui::GpuSwitchingManager::GetInstance()->RemoveObserver(this); | 663 ui::GpuSwitchingManager::GetInstance()->RemoveObserver(this); |
642 gpu_observer_registered_ = false; | 664 gpu_observer_registered_ = false; |
643 } | 665 } |
644 | 666 |
645 #if USE_ATTACHMENT_BROKER | 667 #if USE_ATTACHMENT_BROKER |
646 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( | 668 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( |
647 channel_.get()); | 669 channel_.get()); |
648 #endif | 670 #endif |
649 // We may have some unsent messages at this point, but that's OK. | 671 // We may have some unsent messages at this point, but that's OK. |
650 channel_.reset(); | 672 channel_.reset(); |
651 while (!queued_messages_.empty()) { | 673 while (!queued_messages_.empty()) |
652 delete queued_messages_.front(); | |
653 queued_messages_.pop(); | 674 queued_messages_.pop(); |
654 } | |
655 | 675 |
656 UnregisterHost(GetID()); | 676 UnregisterHost(GetID()); |
657 | 677 |
658 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 678 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
659 switches::kDisableGpuShaderDiskCache)) { | 679 switches::kDisableGpuShaderDiskCache)) { |
660 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 680 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
661 base::Bind(&RemoveShaderInfo, GetID())); | 681 base::Bind(&RemoveShaderInfo, GetID())); |
662 } | 682 } |
663 } | 683 } |
664 | 684 |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1010 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) | 1030 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
1011 enable_web_bluetooth = true; | 1031 enable_web_bluetooth = true; |
1012 #endif | 1032 #endif |
1013 | 1033 |
1014 if (enable_web_bluetooth) { | 1034 if (enable_web_bluetooth) { |
1015 bluetooth_dispatcher_host_ = new BluetoothDispatcherHost(GetID()); | 1035 bluetooth_dispatcher_host_ = new BluetoothDispatcherHost(GetID()); |
1016 AddFilter(bluetooth_dispatcher_host_.get()); | 1036 AddFilter(bluetooth_dispatcher_host_.get()); |
1017 } | 1037 } |
1018 } | 1038 } |
1019 | 1039 |
| 1040 bool RenderProcessHostImpl::SendImpl(std::unique_ptr<IPC::Message> msg, |
| 1041 bool send_now) { |
| 1042 TRACE_EVENT0("renderer_host", "RenderProcessHostImpl::SendImpl"); |
| 1043 #if !defined(OS_ANDROID) |
| 1044 DCHECK(!msg->is_sync()); |
| 1045 #endif |
| 1046 |
| 1047 if (!channel_) { |
| 1048 #if defined(OS_ANDROID) |
| 1049 if (msg->is_sync()) |
| 1050 return false; |
| 1051 #endif |
| 1052 if (!is_initialized_) { |
| 1053 queued_messages_.emplace(std::move(msg)); |
| 1054 return true; |
| 1055 } else { |
| 1056 return false; |
| 1057 } |
| 1058 } |
| 1059 |
| 1060 if (child_process_launcher_.get() && child_process_launcher_->IsStarting()) { |
| 1061 #if defined(OS_ANDROID) |
| 1062 if (msg->is_sync()) |
| 1063 return false; |
| 1064 #endif |
| 1065 queued_messages_.emplace(std::move(msg)); |
| 1066 return true; |
| 1067 } |
| 1068 |
| 1069 if (send_now) |
| 1070 return channel_->SendNow(std::move(msg)); |
| 1071 |
| 1072 return channel_->SendOnIPCThread(std::move(msg)); |
| 1073 } |
| 1074 |
1020 void RenderProcessHostImpl::RegisterMojoServices() { | 1075 void RenderProcessHostImpl::RegisterMojoServices() { |
1021 #if !defined(OS_ANDROID) | 1076 #if !defined(OS_ANDROID) |
1022 mojo_application_host_->service_registry()->AddService( | 1077 mojo_application_host_->service_registry()->AddService( |
1023 base::Bind(&device::BatteryMonitorImpl::Create)); | 1078 base::Bind(&device::BatteryMonitorImpl::Create)); |
1024 #endif | 1079 #endif |
1025 | 1080 |
1026 mojo_application_host_->service_registry()->AddService( | 1081 mojo_application_host_->service_registry()->AddService( |
1027 base::Bind(&PermissionServiceContext::CreateService, | 1082 base::Bind(&PermissionServiceContext::CreateService, |
1028 base::Unretained(permission_service_context_.get()))); | 1083 base::Unretained(permission_service_context_.get()))); |
1029 | 1084 |
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1638 | 1693 |
1639 // Set this before ProcessDied() so observers can tell if the render process | 1694 // Set this before ProcessDied() so observers can tell if the render process |
1640 // died due to fast shutdown versus another cause. | 1695 // died due to fast shutdown versus another cause. |
1641 fast_shutdown_started_ = true; | 1696 fast_shutdown_started_ = true; |
1642 | 1697 |
1643 ProcessDied(false /* already_dead */, nullptr); | 1698 ProcessDied(false /* already_dead */, nullptr); |
1644 return true; | 1699 return true; |
1645 } | 1700 } |
1646 | 1701 |
1647 bool RenderProcessHostImpl::Send(IPC::Message* msg) { | 1702 bool RenderProcessHostImpl::Send(IPC::Message* msg) { |
1648 TRACE_EVENT0("renderer_host", "RenderProcessHostImpl::Send"); | 1703 return SendImpl(base::WrapUnique(msg), false /* send_now */); |
1649 #if !defined(OS_ANDROID) | |
1650 DCHECK(!msg->is_sync()); | |
1651 #endif | |
1652 | |
1653 if (!channel_) { | |
1654 #if defined(OS_ANDROID) | |
1655 if (msg->is_sync()) { | |
1656 delete msg; | |
1657 return false; | |
1658 } | |
1659 #endif | |
1660 if (!is_initialized_) { | |
1661 queued_messages_.push(msg); | |
1662 return true; | |
1663 } else { | |
1664 delete msg; | |
1665 return false; | |
1666 } | |
1667 } | |
1668 | |
1669 if (child_process_launcher_.get() && child_process_launcher_->IsStarting()) { | |
1670 #if defined(OS_ANDROID) | |
1671 if (msg->is_sync()) { | |
1672 delete msg; | |
1673 return false; | |
1674 } | |
1675 #endif | |
1676 queued_messages_.push(msg); | |
1677 return true; | |
1678 } | |
1679 | |
1680 return channel_->Send(msg); | |
1681 } | 1704 } |
1682 | 1705 |
1683 bool RenderProcessHostImpl::OnMessageReceived(const IPC::Message& msg) { | 1706 bool RenderProcessHostImpl::OnMessageReceived(const IPC::Message& msg) { |
1684 // If we're about to be deleted, or have initiated the fast shutdown sequence, | 1707 // If we're about to be deleted, or have initiated the fast shutdown sequence, |
1685 // we ignore incoming messages. | 1708 // we ignore incoming messages. |
1686 | 1709 |
1687 if (deleting_soon_ || fast_shutdown_started_) | 1710 if (deleting_soon_ || fast_shutdown_started_) |
1688 return false; | 1711 return false; |
1689 | 1712 |
1690 mark_child_process_activity_time(); | 1713 mark_child_process_activity_time(); |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2026 p2p_socket_dispatcher_host_); | 2049 p2p_socket_dispatcher_host_); |
2027 } | 2050 } |
2028 return stop_rtp_dump_callback_; | 2051 return stop_rtp_dump_callback_; |
2029 } | 2052 } |
2030 #endif | 2053 #endif |
2031 | 2054 |
2032 IPC::ChannelProxy* RenderProcessHostImpl::GetChannel() { | 2055 IPC::ChannelProxy* RenderProcessHostImpl::GetChannel() { |
2033 return channel_.get(); | 2056 return channel_.get(); |
2034 } | 2057 } |
2035 | 2058 |
| 2059 IPC::Sender* RenderProcessHostImpl::GetImmediateSender() { |
| 2060 return immediate_sender_.get(); |
| 2061 } |
| 2062 |
| 2063 IPC::Sender* RenderProcessHostImpl::GetIOThreadSender() { |
| 2064 return io_thread_sender_.get(); |
| 2065 } |
| 2066 |
2036 void RenderProcessHostImpl::AddFilter(BrowserMessageFilter* filter) { | 2067 void RenderProcessHostImpl::AddFilter(BrowserMessageFilter* filter) { |
2037 channel_->AddFilter(filter->GetFilter()); | 2068 channel_->AddFilter(filter->GetFilter()); |
2038 } | 2069 } |
2039 | 2070 |
2040 bool RenderProcessHostImpl::FastShutdownForPageCount(size_t count) { | 2071 bool RenderProcessHostImpl::FastShutdownForPageCount(size_t count) { |
2041 if (GetActiveViewCount() == count) | 2072 if (GetActiveViewCount() == count) |
2042 return FastShutdownIfPossible(); | 2073 return FastShutdownIfPossible(); |
2043 return false; | 2074 return false; |
2044 } | 2075 } |
2045 | 2076 |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2371 } | 2402 } |
2372 | 2403 |
2373 RendererClosedDetails details(status, exit_code); | 2404 RendererClosedDetails details(status, exit_code); |
2374 | 2405 |
2375 child_process_launcher_.reset(); | 2406 child_process_launcher_.reset(); |
2376 #if USE_ATTACHMENT_BROKER | 2407 #if USE_ATTACHMENT_BROKER |
2377 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( | 2408 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( |
2378 channel_.get()); | 2409 channel_.get()); |
2379 #endif | 2410 #endif |
2380 channel_.reset(); | 2411 channel_.reset(); |
2381 while (!queued_messages_.empty()) { | 2412 while (!queued_messages_.empty()) |
2382 delete queued_messages_.front(); | |
2383 queued_messages_.pop(); | 2413 queued_messages_.pop(); |
2384 } | |
2385 UpdateProcessPriority(); | 2414 UpdateProcessPriority(); |
2386 DCHECK(!is_process_backgrounded_); | 2415 DCHECK(!is_process_backgrounded_); |
2387 | 2416 |
2388 // RenderProcessExited observers and RenderProcessGone handlers might | 2417 // RenderProcessExited observers and RenderProcessGone handlers might |
2389 // navigate or perform other actions that require a connection. Ensure that | 2418 // navigate or perform other actions that require a connection. Ensure that |
2390 // there is one before calling them. | 2419 // there is one before calling them. |
2391 mojo_application_host_.reset(new MojoApplicationHost); | 2420 mojo_application_host_.reset(new MojoApplicationHost); |
2392 | 2421 |
2393 within_process_died_observer_ = true; | 2422 within_process_died_observer_ = true; |
2394 NotificationService::current()->Notify( | 2423 NotificationService::current()->Notify( |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2551 // with state that must be there before any JavaScript executes. | 2580 // with state that must be there before any JavaScript executes. |
2552 // | 2581 // |
2553 // The queued messages contain such things as "navigate". If this notification | 2582 // The queued messages contain such things as "navigate". If this notification |
2554 // was after, we can end up executing JavaScript before the initialization | 2583 // was after, we can end up executing JavaScript before the initialization |
2555 // happens. | 2584 // happens. |
2556 NotificationService::current()->Notify(NOTIFICATION_RENDERER_PROCESS_CREATED, | 2585 NotificationService::current()->Notify(NOTIFICATION_RENDERER_PROCESS_CREATED, |
2557 Source<RenderProcessHost>(this), | 2586 Source<RenderProcessHost>(this), |
2558 NotificationService::NoDetails()); | 2587 NotificationService::NoDetails()); |
2559 | 2588 |
2560 while (!queued_messages_.empty()) { | 2589 while (!queued_messages_.empty()) { |
2561 Send(queued_messages_.front()); | 2590 Send(queued_messages_.front().release()); |
2562 queued_messages_.pop(); | 2591 queued_messages_.pop(); |
2563 } | 2592 } |
2564 | 2593 |
2565 if (IsReady()) { | 2594 if (IsReady()) { |
2566 DCHECK(!sent_render_process_ready_); | 2595 DCHECK(!sent_render_process_ready_); |
2567 sent_render_process_ready_ = true; | 2596 sent_render_process_ready_ = true; |
2568 // Send RenderProcessReady only if the channel is already connected. | 2597 // Send RenderProcessReady only if the channel is already connected. |
2569 FOR_EACH_OBSERVER(RenderProcessHostObserver, | 2598 FOR_EACH_OBSERVER(RenderProcessHostObserver, |
2570 observers_, | 2599 observers_, |
2571 RenderProcessReady(this)); | 2600 RenderProcessReady(this)); |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2763 | 2792 |
2764 // Skip widgets in other processes. | 2793 // Skip widgets in other processes. |
2765 if (rvh->GetProcess()->GetID() != GetID()) | 2794 if (rvh->GetProcess()->GetID() != GetID()) |
2766 continue; | 2795 continue; |
2767 | 2796 |
2768 rvh->OnWebkitPreferencesChanged(); | 2797 rvh->OnWebkitPreferencesChanged(); |
2769 } | 2798 } |
2770 } | 2799 } |
2771 | 2800 |
2772 } // namespace content | 2801 } // namespace content |
OLD | NEW |