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

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

Issue 2068343003: Revert "Send input event IPCs directly from the UI thread" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 #include "content/public/common/url_constants.h" 158 #include "content/public/common/url_constants.h"
159 #include "device/battery/battery_monitor_impl.h" 159 #include "device/battery/battery_monitor_impl.h"
160 #include "gpu/GLES2/gl2extchromium.h" 160 #include "gpu/GLES2/gl2extchromium.h"
161 #include "gpu/command_buffer/client/gpu_switches.h" 161 #include "gpu/command_buffer/client/gpu_switches.h"
162 #include "gpu/command_buffer/common/gles2_cmd_utils.h" 162 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
163 #include "gpu/command_buffer/service/gpu_switches.h" 163 #include "gpu/command_buffer/service/gpu_switches.h"
164 #include "ipc/attachment_broker.h" 164 #include "ipc/attachment_broker.h"
165 #include "ipc/attachment_broker_privileged.h" 165 #include "ipc/attachment_broker_privileged.h"
166 #include "ipc/ipc_channel.h" 166 #include "ipc/ipc_channel.h"
167 #include "ipc/ipc_logging.h" 167 #include "ipc/ipc_logging.h"
168 #include "ipc/ipc_sender.h"
169 #include "ipc/ipc_switches.h" 168 #include "ipc/ipc_switches.h"
170 #include "ipc/mojo/ipc_channel_mojo.h" 169 #include "ipc/mojo/ipc_channel_mojo.h"
171 #include "media/base/media_switches.h" 170 #include "media/base/media_switches.h"
172 #include "mojo/edk/embedder/embedder.h" 171 #include "mojo/edk/embedder/embedder.h"
173 #include "net/url_request/url_request_context_getter.h" 172 #include "net/url_request/url_request_context_getter.h"
174 #include "ppapi/shared_impl/ppapi_switches.h" 173 #include "ppapi/shared_impl/ppapi_switches.h"
175 #include "services/shell/runner/common/switches.h" 174 #include "services/shell/runner/common/switches.h"
176 #include "storage/browser/fileapi/sandbox_file_system_backend.h" 175 #include "storage/browser/fileapi/sandbox_file_system_backend.h"
177 #include "third_party/skia/include/core/SkBitmap.h" 176 #include "third_party/skia/include/core/SkBitmap.h"
178 #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
442 for (auto it : vector) { 441 for (auto it : vector) {
443 if (!str.empty()) 442 if (!str.empty())
444 str += ","; 443 str += ",";
445 str += base::UintToString(it); 444 str += base::UintToString(it);
446 } 445 }
447 return str; 446 return str;
448 } 447 }
449 448
450 } // namespace 449 } // namespace
451 450
452 class RenderProcessHostImpl::SafeSenderProxy : public IPC::Sender {
453 public:
454 // |process| must outlive this object.
455 explicit SafeSenderProxy(RenderProcessHostImpl* process, bool send_now)
456 : process_(process), send_now_(send_now) {}
457 ~SafeSenderProxy() override {}
458
459 // IPC::Sender:
460 bool Send(IPC::Message* message) override {
461 return process_->SendImpl(base::WrapUnique(message), send_now_);
462 }
463
464 private:
465 RenderProcessHostImpl* const process_;
466 const bool send_now_;
467
468 DISALLOW_COPY_AND_ASSIGN(SafeSenderProxy);
469 };
470
471 RendererMainThreadFactoryFunction g_renderer_main_thread_factory = NULL; 451 RendererMainThreadFactoryFunction g_renderer_main_thread_factory = NULL;
472 452
473 base::MessageLoop* g_in_process_thread; 453 base::MessageLoop* g_in_process_thread;
474 454
475 base::MessageLoop* 455 base::MessageLoop*
476 RenderProcessHostImpl::GetInProcessRendererThreadForTesting() { 456 RenderProcessHostImpl::GetInProcessRendererThreadForTesting() {
477 return g_in_process_thread; 457 return g_in_process_thread;
478 } 458 }
479 459
480 // Stores the maximum number of renderer processes the content module can 460 // Stores the maximum number of renderer processes the content module can
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 RenderProcessHostImpl::RenderProcessHostImpl( 530 RenderProcessHostImpl::RenderProcessHostImpl(
551 BrowserContext* browser_context, 531 BrowserContext* browser_context,
552 StoragePartitionImpl* storage_partition_impl, 532 StoragePartitionImpl* storage_partition_impl,
553 bool is_for_guests_only) 533 bool is_for_guests_only)
554 : fast_shutdown_started_(false), 534 : fast_shutdown_started_(false),
555 deleting_soon_(false), 535 deleting_soon_(false),
556 #ifndef NDEBUG 536 #ifndef NDEBUG
557 is_self_deleted_(false), 537 is_self_deleted_(false),
558 #endif 538 #endif
559 pending_views_(0), 539 pending_views_(0),
560 immediate_sender_(new SafeSenderProxy(this, true)),
561 io_thread_sender_(new SafeSenderProxy(this, false)),
562 child_token_(mojo::edk::GenerateRandomToken()), 540 child_token_(mojo::edk::GenerateRandomToken()),
563 mojo_application_host_(new MojoApplicationHost(child_token_)), 541 mojo_application_host_(new MojoApplicationHost(child_token_)),
564 visible_widgets_(0), 542 visible_widgets_(0),
565 is_process_backgrounded_(false), 543 is_process_backgrounded_(false),
566 is_initialized_(false), 544 is_initialized_(false),
567 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), 545 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()),
568 browser_context_(browser_context), 546 browser_context_(browser_context),
569 storage_partition_impl_(storage_partition_impl), 547 storage_partition_impl_(storage_partition_impl),
570 sudden_termination_allowed_(true), 548 sudden_termination_allowed_(true),
571 ignore_input_events_(false), 549 ignore_input_events_(false),
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 ui::GpuSwitchingManager::GetInstance()->RemoveObserver(this); 644 ui::GpuSwitchingManager::GetInstance()->RemoveObserver(this);
667 gpu_observer_registered_ = false; 645 gpu_observer_registered_ = false;
668 } 646 }
669 647
670 #if USE_ATTACHMENT_BROKER 648 #if USE_ATTACHMENT_BROKER
671 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( 649 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel(
672 channel_.get()); 650 channel_.get());
673 #endif 651 #endif
674 // We may have some unsent messages at this point, but that's OK. 652 // We may have some unsent messages at this point, but that's OK.
675 channel_.reset(); 653 channel_.reset();
676 while (!queued_messages_.empty()) 654 while (!queued_messages_.empty()) {
655 delete queued_messages_.front();
677 queued_messages_.pop(); 656 queued_messages_.pop();
657 }
678 658
679 UnregisterHost(GetID()); 659 UnregisterHost(GetID());
680 660
681 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 661 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
682 switches::kDisableGpuShaderDiskCache)) { 662 switches::kDisableGpuShaderDiskCache)) {
683 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 663 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
684 base::Bind(&RemoveShaderInfo, GetID())); 664 base::Bind(&RemoveShaderInfo, GetID()));
685 } 665 }
686 } 666 }
687 667
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 AddFilter(new ProfilerMessageFilter(PROCESS_TYPE_RENDERER)); 1003 AddFilter(new ProfilerMessageFilter(PROCESS_TYPE_RENDERER));
1024 AddFilter(new HistogramMessageFilter()); 1004 AddFilter(new HistogramMessageFilter());
1025 AddFilter(new MemoryMessageFilter(this)); 1005 AddFilter(new MemoryMessageFilter(this));
1026 AddFilter(new PushMessagingMessageFilter( 1006 AddFilter(new PushMessagingMessageFilter(
1027 GetID(), storage_partition_impl_->GetServiceWorkerContext())); 1007 GetID(), storage_partition_impl_->GetServiceWorkerContext()));
1028 #if defined(OS_ANDROID) 1008 #if defined(OS_ANDROID)
1029 AddFilter(new ScreenOrientationMessageFilterAndroid()); 1009 AddFilter(new ScreenOrientationMessageFilterAndroid());
1030 #endif 1010 #endif
1031 } 1011 }
1032 1012
1033 bool RenderProcessHostImpl::SendImpl(std::unique_ptr<IPC::Message> msg,
1034 bool send_now) {
1035 TRACE_EVENT0("renderer_host", "RenderProcessHostImpl::SendImpl");
1036 #if !defined(OS_ANDROID)
1037 DCHECK(!msg->is_sync());
1038 #endif
1039
1040 if (!channel_) {
1041 #if defined(OS_ANDROID)
1042 if (msg->is_sync())
1043 return false;
1044 #endif
1045 if (!is_initialized_) {
1046 queued_messages_.emplace(std::move(msg));
1047 return true;
1048 } else {
1049 return false;
1050 }
1051 }
1052
1053 if (child_process_launcher_.get() && child_process_launcher_->IsStarting()) {
1054 #if defined(OS_ANDROID)
1055 if (msg->is_sync())
1056 return false;
1057 #endif
1058 queued_messages_.emplace(std::move(msg));
1059 return true;
1060 }
1061
1062 if (send_now)
1063 return channel_->SendNow(std::move(msg));
1064
1065 return channel_->SendOnIPCThread(std::move(msg));
1066 }
1067
1068 void RenderProcessHostImpl::RegisterMojoServices() { 1013 void RenderProcessHostImpl::RegisterMojoServices() {
1069 #if !defined(OS_ANDROID) 1014 #if !defined(OS_ANDROID)
1070 mojo_application_host_->service_registry()->AddService( 1015 mojo_application_host_->service_registry()->AddService(
1071 base::Bind(&device::BatteryMonitorImpl::Create)); 1016 base::Bind(&device::BatteryMonitorImpl::Create));
1072 #endif 1017 #endif
1073 1018
1074 mojo_application_host_->service_registry()->AddService( 1019 mojo_application_host_->service_registry()->AddService(
1075 base::Bind(&PermissionServiceContext::CreateService, 1020 base::Bind(&PermissionServiceContext::CreateService,
1076 base::Unretained(permission_service_context_.get()))); 1021 base::Unretained(permission_service_context_.get())));
1077 1022
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
1698 1643
1699 // Set this before ProcessDied() so observers can tell if the render process 1644 // Set this before ProcessDied() so observers can tell if the render process
1700 // died due to fast shutdown versus another cause. 1645 // died due to fast shutdown versus another cause.
1701 fast_shutdown_started_ = true; 1646 fast_shutdown_started_ = true;
1702 1647
1703 ProcessDied(false /* already_dead */, nullptr); 1648 ProcessDied(false /* already_dead */, nullptr);
1704 return true; 1649 return true;
1705 } 1650 }
1706 1651
1707 bool RenderProcessHostImpl::Send(IPC::Message* msg) { 1652 bool RenderProcessHostImpl::Send(IPC::Message* msg) {
1708 return SendImpl(base::WrapUnique(msg), false /* send_now */); 1653 TRACE_EVENT0("renderer_host", "RenderProcessHostImpl::Send");
1654 #if !defined(OS_ANDROID)
1655 DCHECK(!msg->is_sync());
1656 #endif
1657
1658 if (!channel_) {
1659 #if defined(OS_ANDROID)
1660 if (msg->is_sync()) {
1661 delete msg;
1662 return false;
1663 }
1664 #endif
1665 if (!is_initialized_) {
1666 queued_messages_.push(msg);
1667 return true;
1668 } else {
1669 delete msg;
1670 return false;
1671 }
1672 }
1673
1674 if (child_process_launcher_.get() && child_process_launcher_->IsStarting()) {
1675 #if defined(OS_ANDROID)
1676 if (msg->is_sync()) {
1677 delete msg;
1678 return false;
1679 }
1680 #endif
1681 queued_messages_.push(msg);
1682 return true;
1683 }
1684
1685 return channel_->Send(msg);
1709 } 1686 }
1710 1687
1711 bool RenderProcessHostImpl::OnMessageReceived(const IPC::Message& msg) { 1688 bool RenderProcessHostImpl::OnMessageReceived(const IPC::Message& msg) {
1712 // If we're about to be deleted, or have initiated the fast shutdown sequence, 1689 // If we're about to be deleted, or have initiated the fast shutdown sequence,
1713 // we ignore incoming messages. 1690 // we ignore incoming messages.
1714 1691
1715 if (deleting_soon_ || fast_shutdown_started_) 1692 if (deleting_soon_ || fast_shutdown_started_)
1716 return false; 1693 return false;
1717 1694
1718 mark_child_process_activity_time(); 1695 mark_child_process_activity_time();
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
2058 p2p_socket_dispatcher_host_); 2035 p2p_socket_dispatcher_host_);
2059 } 2036 }
2060 return stop_rtp_dump_callback_; 2037 return stop_rtp_dump_callback_;
2061 } 2038 }
2062 #endif 2039 #endif
2063 2040
2064 IPC::ChannelProxy* RenderProcessHostImpl::GetChannel() { 2041 IPC::ChannelProxy* RenderProcessHostImpl::GetChannel() {
2065 return channel_.get(); 2042 return channel_.get();
2066 } 2043 }
2067 2044
2068 IPC::Sender* RenderProcessHostImpl::GetImmediateSender() {
2069 return immediate_sender_.get();
2070 }
2071
2072 IPC::Sender* RenderProcessHostImpl::GetIOThreadSender() {
2073 return io_thread_sender_.get();
2074 }
2075
2076 void RenderProcessHostImpl::AddFilter(BrowserMessageFilter* filter) { 2045 void RenderProcessHostImpl::AddFilter(BrowserMessageFilter* filter) {
2077 channel_->AddFilter(filter->GetFilter()); 2046 channel_->AddFilter(filter->GetFilter());
2078 } 2047 }
2079 2048
2080 bool RenderProcessHostImpl::FastShutdownForPageCount(size_t count) { 2049 bool RenderProcessHostImpl::FastShutdownForPageCount(size_t count) {
2081 if (GetActiveViewCount() == count) 2050 if (GetActiveViewCount() == count)
2082 return FastShutdownIfPossible(); 2051 return FastShutdownIfPossible();
2083 return false; 2052 return false;
2084 } 2053 }
2085 2054
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
2411 } 2380 }
2412 2381
2413 RendererClosedDetails details(status, exit_code); 2382 RendererClosedDetails details(status, exit_code);
2414 2383
2415 child_process_launcher_.reset(); 2384 child_process_launcher_.reset();
2416 #if USE_ATTACHMENT_BROKER 2385 #if USE_ATTACHMENT_BROKER
2417 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel( 2386 IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel(
2418 channel_.get()); 2387 channel_.get());
2419 #endif 2388 #endif
2420 channel_.reset(); 2389 channel_.reset();
2421 while (!queued_messages_.empty()) 2390 while (!queued_messages_.empty()) {
2391 delete queued_messages_.front();
2422 queued_messages_.pop(); 2392 queued_messages_.pop();
2393 }
2423 UpdateProcessPriority(); 2394 UpdateProcessPriority();
2424 DCHECK(!is_process_backgrounded_); 2395 DCHECK(!is_process_backgrounded_);
2425 2396
2426 // RenderProcessExited observers and RenderProcessGone handlers might 2397 // RenderProcessExited observers and RenderProcessGone handlers might
2427 // navigate or perform other actions that require a connection. Ensure that 2398 // navigate or perform other actions that require a connection. Ensure that
2428 // there is one before calling them. 2399 // there is one before calling them.
2429 child_token_ = mojo::edk::GenerateRandomToken(); 2400 child_token_ = mojo::edk::GenerateRandomToken();
2430 mojo_application_host_.reset(new MojoApplicationHost(child_token_)); 2401 mojo_application_host_.reset(new MojoApplicationHost(child_token_));
2431 2402
2432 within_process_died_observer_ = true; 2403 within_process_died_observer_ = true;
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
2590 // with state that must be there before any JavaScript executes. 2561 // with state that must be there before any JavaScript executes.
2591 // 2562 //
2592 // The queued messages contain such things as "navigate". If this notification 2563 // The queued messages contain such things as "navigate". If this notification
2593 // was after, we can end up executing JavaScript before the initialization 2564 // was after, we can end up executing JavaScript before the initialization
2594 // happens. 2565 // happens.
2595 NotificationService::current()->Notify(NOTIFICATION_RENDERER_PROCESS_CREATED, 2566 NotificationService::current()->Notify(NOTIFICATION_RENDERER_PROCESS_CREATED,
2596 Source<RenderProcessHost>(this), 2567 Source<RenderProcessHost>(this),
2597 NotificationService::NoDetails()); 2568 NotificationService::NoDetails());
2598 2569
2599 while (!queued_messages_.empty()) { 2570 while (!queued_messages_.empty()) {
2600 Send(queued_messages_.front().release()); 2571 Send(queued_messages_.front());
2601 queued_messages_.pop(); 2572 queued_messages_.pop();
2602 } 2573 }
2603 2574
2604 if (IsReady()) { 2575 if (IsReady()) {
2605 DCHECK(!sent_render_process_ready_); 2576 DCHECK(!sent_render_process_ready_);
2606 sent_render_process_ready_ = true; 2577 sent_render_process_ready_ = true;
2607 // Send RenderProcessReady only if the channel is already connected. 2578 // Send RenderProcessReady only if the channel is already connected.
2608 FOR_EACH_OBSERVER(RenderProcessHostObserver, 2579 FOR_EACH_OBSERVER(RenderProcessHostObserver,
2609 observers_, 2580 observers_,
2610 RenderProcessReady(this)); 2581 RenderProcessReady(this));
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
2824 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; 2795 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error;
2825 2796
2826 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias 2797 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias
2827 // enough information here so that we can determine what the bad message was. 2798 // enough information here so that we can determine what the bad message was.
2828 base::debug::Alias(&error); 2799 base::debug::Alias(&error);
2829 bad_message::ReceivedBadMessage(process.get(), 2800 bad_message::ReceivedBadMessage(process.get(),
2830 bad_message::RPH_MOJO_PROCESS_ERROR); 2801 bad_message::RPH_MOJO_PROCESS_ERROR);
2831 } 2802 }
2832 2803
2833 } // namespace content 2804 } // 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