Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Side by Side Diff: content/browser/renderer_host/render_process_host_impl.cc

Issue 1991323002: Send input event IPCs directly from the UI thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 // SafeSenderProxy owns two IPC::Sender implementations which proxy to the
452 // RPH's own ChannelProxy. One enables immediate sends while the other enables
453 // IO-thread sends. These are both implemented via RPHI's SendImpl which safely
454 // avoids dereferencing the underlying ChannelProxy if it's been reset (e.g.
455 // after process death.)
456 class RenderProcessHostImpl::SafeSenderProxy {
457 public:
458 // |process| must outlive this object.
459 explicit SafeSenderProxy(RenderProcessHostImpl* process)
460 : immediate_sender_(process, true /* send_now */),
461 io_thread_sender_(process, false /* send_now */) {}
462 ~SafeSenderProxy() {}
463
464 IPC::Sender* immediate_sender() { return &immediate_sender_; }
465 IPC::Sender* io_thread_sender() { return &io_thread_sender_; }
466
467 private:
468 class SenderProxy : public IPC::Sender {
469 public:
470 SenderProxy(RenderProcessHostImpl* process, bool send_now)
471 : process_(process), send_now_(send_now) {}
472 ~SenderProxy() override {}
473
474 // IPC::Sender:
475 bool Send(IPC::Message* message) override {
476 return process_->SendImpl(base::WrapUnique(message), send_now_);
477 }
478
479 private:
480 RenderProcessHostImpl* const process_;
481 const bool send_now_;
482
483 DISALLOW_COPY_AND_ASSIGN(SenderProxy);
484 };
485
486 SenderProxy immediate_sender_;
487 SenderProxy io_thread_sender_;
Charlie Reis 2016/05/24 18:11:55 We could just put these straight on RPHI and skip
piman 2016/05/24 19:00:26 This sounds like a good idea. We can keep encapsul
Ken Rockot(use gerrit already) 2016/05/24 19:15:38 Agreed, and done
488
489 DISALLOW_COPY_AND_ASSIGN(SafeSenderProxy);
490 };
491
450 RendererMainThreadFactoryFunction g_renderer_main_thread_factory = NULL; 492 RendererMainThreadFactoryFunction g_renderer_main_thread_factory = NULL;
451 493
452 base::MessageLoop* g_in_process_thread; 494 base::MessageLoop* g_in_process_thread;
453 495
454 base::MessageLoop* 496 base::MessageLoop*
455 RenderProcessHostImpl::GetInProcessRendererThreadForTesting() { 497 RenderProcessHostImpl::GetInProcessRendererThreadForTesting() {
456 return g_in_process_thread; 498 return g_in_process_thread;
457 } 499 }
458 500
459 // Stores the maximum number of renderer processes the content module can 501 // Stores the maximum number of renderer processes the content module can
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 RenderProcessHostImpl::RenderProcessHostImpl( 571 RenderProcessHostImpl::RenderProcessHostImpl(
530 BrowserContext* browser_context, 572 BrowserContext* browser_context,
531 StoragePartitionImpl* storage_partition_impl, 573 StoragePartitionImpl* storage_partition_impl,
532 bool is_for_guests_only) 574 bool is_for_guests_only)
533 : fast_shutdown_started_(false), 575 : fast_shutdown_started_(false),
534 deleting_soon_(false), 576 deleting_soon_(false),
535 #ifndef NDEBUG 577 #ifndef NDEBUG
536 is_self_deleted_(false), 578 is_self_deleted_(false),
537 #endif 579 #endif
538 pending_views_(0), 580 pending_views_(0),
581 safe_sender_(new SafeSenderProxy(this)),
539 mojo_application_host_(new MojoApplicationHost), 582 mojo_application_host_(new MojoApplicationHost),
540 visible_widgets_(0), 583 visible_widgets_(0),
541 is_process_backgrounded_(false), 584 is_process_backgrounded_(false),
542 is_initialized_(false), 585 is_initialized_(false),
543 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), 586 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()),
544 browser_context_(browser_context), 587 browser_context_(browser_context),
545 storage_partition_impl_(storage_partition_impl), 588 storage_partition_impl_(storage_partition_impl),
546 sudden_termination_allowed_(true), 589 sudden_termination_allowed_(true),
547 ignore_input_events_(false), 590 ignore_input_events_(false),
548 is_for_guests_only_(is_for_guests_only), 591 is_for_guests_only_(is_for_guests_only),
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 ui::GpuSwitchingManager::GetInstance()->RemoveObserver(this); 684 ui::GpuSwitchingManager::GetInstance()->RemoveObserver(this);
642 gpu_observer_registered_ = false; 685 gpu_observer_registered_ = false;
643 } 686 }
644 687
645 #if USE_ATTACHMENT_BROKER 688 #if USE_ATTACHMENT_BROKER
646 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( 689 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel(
647 channel_.get()); 690 channel_.get());
648 #endif 691 #endif
649 // We may have some unsent messages at this point, but that's OK. 692 // We may have some unsent messages at this point, but that's OK.
650 channel_.reset(); 693 channel_.reset();
651 while (!queued_messages_.empty()) { 694 while (!queued_messages_.empty())
652 delete queued_messages_.front();
653 queued_messages_.pop(); 695 queued_messages_.pop();
654 }
655 696
656 UnregisterHost(GetID()); 697 UnregisterHost(GetID());
657 698
658 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 699 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
659 switches::kDisableGpuShaderDiskCache)) { 700 switches::kDisableGpuShaderDiskCache)) {
660 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 701 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
661 base::Bind(&RemoveShaderInfo, GetID())); 702 base::Bind(&RemoveShaderInfo, GetID()));
662 } 703 }
663 } 704 }
664 705
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) 1049 #if defined(OS_CHROMEOS) || defined(OS_ANDROID)
1009 enable_web_bluetooth = true; 1050 enable_web_bluetooth = true;
1010 #endif 1051 #endif
1011 1052
1012 if (enable_web_bluetooth) { 1053 if (enable_web_bluetooth) {
1013 bluetooth_dispatcher_host_ = new BluetoothDispatcherHost(GetID()); 1054 bluetooth_dispatcher_host_ = new BluetoothDispatcherHost(GetID());
1014 AddFilter(bluetooth_dispatcher_host_.get()); 1055 AddFilter(bluetooth_dispatcher_host_.get());
1015 } 1056 }
1016 } 1057 }
1017 1058
1059 bool RenderProcessHostImpl::SendImpl(std::unique_ptr<IPC::Message> msg,
1060 bool send_now) {
1061 TRACE_EVENT0("renderer_host", "RenderProcessHostImpl::SendImpl");
1062 #if !defined(OS_ANDROID)
1063 DCHECK(!msg->is_sync());
1064 #endif
1065
1066 if (!channel_) {
1067 #if defined(OS_ANDROID)
1068 if (msg->is_sync())
1069 return false;
1070 #endif
1071 if (!is_initialized_) {
1072 queued_messages_.emplace(std::move(msg));
1073 return true;
1074 } else {
1075 return false;
1076 }
1077 }
1078
1079 if (child_process_launcher_.get() && child_process_launcher_->IsStarting()) {
1080 #if defined(OS_ANDROID)
1081 if (msg->is_sync())
1082 return false;
1083 #endif
1084 queued_messages_.emplace(std::move(msg));
1085 return true;
1086 }
1087
1088 if (send_now)
1089 return channel_->SendNow(std::move(msg));
1090
1091 return channel_->SendOnIPCThread(std::move(msg));
1092 }
1093
1018 void RenderProcessHostImpl::RegisterMojoServices() { 1094 void RenderProcessHostImpl::RegisterMojoServices() {
1019 #if !defined(OS_ANDROID) 1095 #if !defined(OS_ANDROID)
1020 mojo_application_host_->service_registry()->AddService( 1096 mojo_application_host_->service_registry()->AddService(
1021 base::Bind(&device::BatteryMonitorImpl::Create)); 1097 base::Bind(&device::BatteryMonitorImpl::Create));
1022 #endif 1098 #endif
1023 1099
1024 mojo_application_host_->service_registry()->AddService( 1100 mojo_application_host_->service_registry()->AddService(
1025 base::Bind(&PermissionServiceContext::CreateService, 1101 base::Bind(&PermissionServiceContext::CreateService,
1026 base::Unretained(permission_service_context_.get()))); 1102 base::Unretained(permission_service_context_.get())));
1027 1103
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
1636 1712
1637 // Set this before ProcessDied() so observers can tell if the render process 1713 // Set this before ProcessDied() so observers can tell if the render process
1638 // died due to fast shutdown versus another cause. 1714 // died due to fast shutdown versus another cause.
1639 fast_shutdown_started_ = true; 1715 fast_shutdown_started_ = true;
1640 1716
1641 ProcessDied(false /* already_dead */, nullptr); 1717 ProcessDied(false /* already_dead */, nullptr);
1642 return true; 1718 return true;
1643 } 1719 }
1644 1720
1645 bool RenderProcessHostImpl::Send(IPC::Message* msg) { 1721 bool RenderProcessHostImpl::Send(IPC::Message* msg) {
1646 TRACE_EVENT0("renderer_host", "RenderProcessHostImpl::Send"); 1722 return SendImpl(base::WrapUnique(msg), false /* send_now */);
1647 #if !defined(OS_ANDROID)
1648 DCHECK(!msg->is_sync());
1649 #endif
1650
1651 if (!channel_) {
1652 #if defined(OS_ANDROID)
1653 if (msg->is_sync()) {
1654 delete msg;
1655 return false;
1656 }
1657 #endif
1658 if (!is_initialized_) {
1659 queued_messages_.push(msg);
1660 return true;
1661 } else {
1662 delete msg;
1663 return false;
1664 }
1665 }
1666
1667 if (child_process_launcher_.get() && child_process_launcher_->IsStarting()) {
1668 #if defined(OS_ANDROID)
1669 if (msg->is_sync()) {
1670 delete msg;
1671 return false;
1672 }
1673 #endif
1674 queued_messages_.push(msg);
1675 return true;
1676 }
1677
1678 return channel_->Send(msg);
1679 } 1723 }
1680 1724
1681 bool RenderProcessHostImpl::OnMessageReceived(const IPC::Message& msg) { 1725 bool RenderProcessHostImpl::OnMessageReceived(const IPC::Message& msg) {
1682 // If we're about to be deleted, or have initiated the fast shutdown sequence, 1726 // If we're about to be deleted, or have initiated the fast shutdown sequence,
1683 // we ignore incoming messages. 1727 // we ignore incoming messages.
1684 1728
1685 if (deleting_soon_ || fast_shutdown_started_) 1729 if (deleting_soon_ || fast_shutdown_started_)
1686 return false; 1730 return false;
1687 1731
1688 mark_child_process_activity_time(); 1732 mark_child_process_activity_time();
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
2024 p2p_socket_dispatcher_host_); 2068 p2p_socket_dispatcher_host_);
2025 } 2069 }
2026 return stop_rtp_dump_callback_; 2070 return stop_rtp_dump_callback_;
2027 } 2071 }
2028 #endif 2072 #endif
2029 2073
2030 IPC::ChannelProxy* RenderProcessHostImpl::GetChannel() { 2074 IPC::ChannelProxy* RenderProcessHostImpl::GetChannel() {
2031 return channel_.get(); 2075 return channel_.get();
2032 } 2076 }
2033 2077
2078 IPC::Sender* RenderProcessHostImpl::GetImmediateSender() {
2079 return safe_sender_->immediate_sender();
2080 }
2081
2082 IPC::Sender* RenderProcessHostImpl::GetIOThreadSender() {
2083 return safe_sender_->io_thread_sender();
2084 }
2085
2034 void RenderProcessHostImpl::AddFilter(BrowserMessageFilter* filter) { 2086 void RenderProcessHostImpl::AddFilter(BrowserMessageFilter* filter) {
2035 channel_->AddFilter(filter->GetFilter()); 2087 channel_->AddFilter(filter->GetFilter());
2036 } 2088 }
2037 2089
2038 bool RenderProcessHostImpl::FastShutdownForPageCount(size_t count) { 2090 bool RenderProcessHostImpl::FastShutdownForPageCount(size_t count) {
2039 if (GetActiveViewCount() == count) 2091 if (GetActiveViewCount() == count)
2040 return FastShutdownIfPossible(); 2092 return FastShutdownIfPossible();
2041 return false; 2093 return false;
2042 } 2094 }
2043 2095
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
2369 } 2421 }
2370 2422
2371 RendererClosedDetails details(status, exit_code); 2423 RendererClosedDetails details(status, exit_code);
2372 2424
2373 child_process_launcher_.reset(); 2425 child_process_launcher_.reset();
2374 #if USE_ATTACHMENT_BROKER 2426 #if USE_ATTACHMENT_BROKER
2375 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( 2427 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel(
2376 channel_.get()); 2428 channel_.get());
2377 #endif 2429 #endif
2378 channel_.reset(); 2430 channel_.reset();
2379 while (!queued_messages_.empty()) { 2431 while (!queued_messages_.empty())
2380 delete queued_messages_.front();
2381 queued_messages_.pop(); 2432 queued_messages_.pop();
2382 }
2383 UpdateProcessPriority(); 2433 UpdateProcessPriority();
2384 DCHECK(!is_process_backgrounded_); 2434 DCHECK(!is_process_backgrounded_);
2385 2435
2386 // RenderProcessExited observers and RenderProcessGone handlers might 2436 // RenderProcessExited observers and RenderProcessGone handlers might
2387 // navigate or perform other actions that require a connection. Ensure that 2437 // navigate or perform other actions that require a connection. Ensure that
2388 // there is one before calling them. 2438 // there is one before calling them.
2389 mojo_application_host_.reset(new MojoApplicationHost); 2439 mojo_application_host_.reset(new MojoApplicationHost);
2390 2440
2391 within_process_died_observer_ = true; 2441 within_process_died_observer_ = true;
2392 NotificationService::current()->Notify( 2442 NotificationService::current()->Notify(
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
2549 // with state that must be there before any JavaScript executes. 2599 // with state that must be there before any JavaScript executes.
2550 // 2600 //
2551 // The queued messages contain such things as "navigate". If this notification 2601 // The queued messages contain such things as "navigate". If this notification
2552 // was after, we can end up executing JavaScript before the initialization 2602 // was after, we can end up executing JavaScript before the initialization
2553 // happens. 2603 // happens.
2554 NotificationService::current()->Notify(NOTIFICATION_RENDERER_PROCESS_CREATED, 2604 NotificationService::current()->Notify(NOTIFICATION_RENDERER_PROCESS_CREATED,
2555 Source<RenderProcessHost>(this), 2605 Source<RenderProcessHost>(this),
2556 NotificationService::NoDetails()); 2606 NotificationService::NoDetails());
2557 2607
2558 while (!queued_messages_.empty()) { 2608 while (!queued_messages_.empty()) {
2559 Send(queued_messages_.front()); 2609 Send(queued_messages_.front().release());
2560 queued_messages_.pop(); 2610 queued_messages_.pop();
2561 } 2611 }
2562 2612
2563 if (IsReady()) { 2613 if (IsReady()) {
2564 DCHECK(!sent_render_process_ready_); 2614 DCHECK(!sent_render_process_ready_);
2565 sent_render_process_ready_ = true; 2615 sent_render_process_ready_ = true;
2566 // Send RenderProcessReady only if the channel is already connected. 2616 // Send RenderProcessReady only if the channel is already connected.
2567 FOR_EACH_OBSERVER(RenderProcessHostObserver, 2617 FOR_EACH_OBSERVER(RenderProcessHostObserver,
2568 observers_, 2618 observers_,
2569 RenderProcessReady(this)); 2619 RenderProcessReady(this));
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
2761 2811
2762 // Skip widgets in other processes. 2812 // Skip widgets in other processes.
2763 if (rvh->GetProcess()->GetID() != GetID()) 2813 if (rvh->GetProcess()->GetID() != GetID())
2764 continue; 2814 continue;
2765 2815
2766 rvh->OnWebkitPreferencesChanged(); 2816 rvh->OnWebkitPreferencesChanged();
2767 } 2817 }
2768 } 2818 }
2769 2819
2770 } // namespace content 2820 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_process_host_impl.h ('k') | content/browser/renderer_host/render_widget_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698