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

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

Issue 2111353002: Move content's shell connections to the IO thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 5 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 #include "ipc/attachment_broker.h" 162 #include "ipc/attachment_broker.h"
163 #include "ipc/attachment_broker_privileged.h" 163 #include "ipc/attachment_broker_privileged.h"
164 #include "ipc/ipc_channel.h" 164 #include "ipc/ipc_channel.h"
165 #include "ipc/ipc_channel_mojo.h" 165 #include "ipc/ipc_channel_mojo.h"
166 #include "ipc/ipc_logging.h" 166 #include "ipc/ipc_logging.h"
167 #include "ipc/ipc_switches.h" 167 #include "ipc/ipc_switches.h"
168 #include "media/base/media_switches.h" 168 #include "media/base/media_switches.h"
169 #include "mojo/edk/embedder/embedder.h" 169 #include "mojo/edk/embedder/embedder.h"
170 #include "net/url_request/url_request_context_getter.h" 170 #include "net/url_request/url_request_context_getter.h"
171 #include "ppapi/shared_impl/ppapi_switches.h" 171 #include "ppapi/shared_impl/ppapi_switches.h"
172 #include "services/shell/public/cpp/interface_provider.h"
173 #include "services/shell/public/cpp/interface_registry.h"
172 #include "services/shell/runner/common/switches.h" 174 #include "services/shell/runner/common/switches.h"
173 #include "storage/browser/fileapi/sandbox_file_system_backend.h" 175 #include "storage/browser/fileapi/sandbox_file_system_backend.h"
174 #include "third_party/skia/include/core/SkBitmap.h" 176 #include "third_party/skia/include/core/SkBitmap.h"
175 #include "ui/base/ui_base_switches.h" 177 #include "ui/base/ui_base_switches.h"
176 #include "ui/display/display_switches.h" 178 #include "ui/display/display_switches.h"
177 #include "ui/events/event_switches.h" 179 #include "ui/events/event_switches.h"
178 #include "ui/gfx/switches.h" 180 #include "ui/gfx/switches.h"
179 #include "ui/gl/gl_switches.h" 181 #include "ui/gl/gl_switches.h"
180 #include "ui/gl/gpu_switching_manager.h" 182 #include "ui/gl/gpu_switching_manager.h"
181 #include "ui/native_theme/native_theme_switches.h" 183 #include "ui/native_theme/native_theme_switches.h"
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 // single process modes, the global attachment broker is the privileged 598 // single process modes, the global attachment broker is the privileged
597 // attachment broker, rather than an unprivileged attachment broker. 599 // attachment broker, rather than an unprivileged attachment broker.
598 #if defined(OS_MACOSX) 600 #if defined(OS_MACOSX)
599 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded( 601 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded(
600 MachBroker::GetInstance()); 602 MachBroker::GetInstance());
601 #else 603 #else
602 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded(); 604 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded();
603 #endif // defined(OS_MACOSX) 605 #endif // defined(OS_MACOSX)
604 #endif // USE_ATTACHMENT_BROKER 606 #endif // USE_ATTACHMENT_BROKER
605 607
608 scoped_refptr<base::SequencedTaskRunner> io_task_runner =
609 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO);
606 shell::Connector* connector = 610 shell::Connector* connector =
607 BrowserContext::GetShellConnectorFor(browser_context_); 611 BrowserContext::GetShellConnectorFor(browser_context_);
608 // Some embedders may not initialize Mojo or the shell connector for a browser 612 // Some embedders may not initialize Mojo or the shell connector for a browser
609 // context (e.g. Android WebView)... so just fall back to the per-process 613 // context (e.g. Android WebView)... so just fall back to the per-process
610 // connector. 614 // connector.
611 if (!connector) { 615 if (!connector) {
612 // Additionally, some test code may not initialize the process-wide 616 // Additionally, some test code may not initialize the process-wide
613 // MojoShellConnection prior to this point. This class of test code doesn't 617 // MojoShellConnection prior to this point. This class of test code doesn't
614 // care about render processes so we can initialize a dummy one. 618 // care about render processes so we can initialize a dummy one.
615 if (!MojoShellConnection::GetForProcess()) { 619 if (!MojoShellConnection::GetForProcess()) {
616 shell::mojom::ServiceRequest request = mojo::GetProxy(&test_service_); 620 shell::mojom::ServiceRequest request = mojo::GetProxy(&test_service_);
617 MojoShellConnection::SetForProcess(MojoShellConnection::Create( 621 MojoShellConnection::SetForProcess(MojoShellConnection::Create(
618 std::move(request))); 622 std::move(request), io_task_runner));
619 } 623 }
620 connector = MojoShellConnection::GetForProcess()->GetConnector(); 624 connector = MojoShellConnection::GetForProcess()->GetConnector();
621 } 625 }
622 mojo_child_connection_.reset(new MojoChildConnection( 626 mojo_child_connection_.reset(new MojoChildConnection(
623 kRendererMojoApplicationName, 627 kRendererMojoApplicationName,
624 base::StringPrintf("%d_%d", id_, instance_id_++), 628 base::StringPrintf("%d_%d", id_, instance_id_++), child_token_, connector,
625 child_token_, 629 io_task_runner));
626 connector));
627 } 630 }
628 631
629 // static 632 // static
630 void RenderProcessHostImpl::ShutDownInProcessRenderer() { 633 void RenderProcessHostImpl::ShutDownInProcessRenderer() {
631 DCHECK(g_run_renderer_in_process_); 634 DCHECK(g_run_renderer_in_process_);
632 635
633 switch (g_all_hosts.Pointer()->size()) { 636 switch (g_all_hosts.Pointer()->size()) {
634 case 0: 637 case 0:
635 return; 638 return;
636 case 1: { 639 case 1: {
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 DCHECK(g_renderer_main_thread_factory); 759 DCHECK(g_renderer_main_thread_factory);
757 // Crank up a thread and run the initialization there. With the way that 760 // Crank up a thread and run the initialization there. With the way that
758 // messages flow between the browser and renderer, this thread is required 761 // messages flow between the browser and renderer, this thread is required
759 // to prevent a deadlock in single-process mode. Since the primordial 762 // to prevent a deadlock in single-process mode. Since the primordial
760 // thread in the renderer process runs the WebKit code and can sometimes 763 // thread in the renderer process runs the WebKit code and can sometimes
761 // make blocking calls to the UI thread (i.e. this thread), they need to run 764 // make blocking calls to the UI thread (i.e. this thread), they need to run
762 // on separate threads. 765 // on separate threads.
763 in_process_renderer_.reset( 766 in_process_renderer_.reset(
764 g_renderer_main_thread_factory(InProcessChildThreadParams( 767 g_renderer_main_thread_factory(InProcessChildThreadParams(
765 channel_id, 768 channel_id,
766 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO) 769 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO),
767 ->task_runner(),
768 mojo_channel_token_, 770 mojo_channel_token_,
769 mojo_child_connection_->service_token()))); 771 mojo_child_connection_->service_token())));
770 772
771 base::Thread::Options options; 773 base::Thread::Options options;
772 #if defined(OS_WIN) && !defined(OS_MACOSX) 774 #if defined(OS_WIN) && !defined(OS_MACOSX)
773 // In-process plugins require this to be a UI message loop. 775 // In-process plugins require this to be a UI message loop.
774 options.message_loop_type = base::MessageLoop::TYPE_UI; 776 options.message_loop_type = base::MessageLoop::TYPE_UI;
775 #else 777 #else
776 // We can't have multiple UI loops on Linux and Android, so we don't support 778 // We can't have multiple UI loops on Linux and Android, so we don't support
777 // in-process plugins. 779 // in-process plugins.
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 void RenderProcessHostImpl::ResumeDeferredNavigation( 1125 void RenderProcessHostImpl::ResumeDeferredNavigation(
1124 const GlobalRequestID& request_id) { 1126 const GlobalRequestID& request_id) {
1125 widget_helper_->ResumeDeferredNavigation(request_id); 1127 widget_helper_->ResumeDeferredNavigation(request_id);
1126 } 1128 }
1127 1129
1128 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { 1130 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) {
1129 Send(new ViewMsg_TimezoneChange(zone_id)); 1131 Send(new ViewMsg_TimezoneChange(zone_id));
1130 } 1132 }
1131 1133
1132 shell::InterfaceRegistry* RenderProcessHostImpl::GetInterfaceRegistry() { 1134 shell::InterfaceRegistry* RenderProcessHostImpl::GetInterfaceRegistry() {
1133 return GetChildConnection()->GetInterfaceRegistry(); 1135 return mojo_child_connection_->GetInterfaceRegistry();
1134 } 1136 }
1135 1137
1136 shell::InterfaceProvider* RenderProcessHostImpl::GetRemoteInterfaces() { 1138 shell::InterfaceProvider* RenderProcessHostImpl::GetRemoteInterfaces() {
1137 return GetChildConnection()->GetRemoteInterfaces(); 1139 return mojo_child_connection_->GetRemoteInterfaces();
1138 }
1139
1140 shell::Connection* RenderProcessHostImpl::GetChildConnection() {
1141 DCHECK(mojo_child_connection_);
1142 return mojo_child_connection_->connection();
1143 } 1140 }
1144 1141
1145 std::unique_ptr<base::SharedPersistentMemoryAllocator> 1142 std::unique_ptr<base::SharedPersistentMemoryAllocator>
1146 RenderProcessHostImpl::TakeMetricsAllocator() { 1143 RenderProcessHostImpl::TakeMetricsAllocator() {
1147 return std::move(metrics_allocator_); 1144 return std::move(metrics_allocator_);
1148 } 1145 }
1149 1146
1150 const base::TimeTicks& RenderProcessHostImpl::GetInitTimeForNavigationMetrics() 1147 const base::TimeTicks& RenderProcessHostImpl::GetInitTimeForNavigationMetrics()
1151 const { 1148 const {
1152 return init_time_; 1149 return init_time_;
(...skipping 1296 matching lines...) Expand 10 before | Expand all | Expand 10 after
2449 // RenderProcessExited observers and RenderProcessGone handlers might 2446 // RenderProcessExited observers and RenderProcessGone handlers might
2450 // navigate or perform other actions that require a connection. Ensure that 2447 // navigate or perform other actions that require a connection. Ensure that
2451 // there is one before calling them. 2448 // there is one before calling them.
2452 child_token_ = mojo::edk::GenerateRandomToken(); 2449 child_token_ = mojo::edk::GenerateRandomToken();
2453 shell::Connector* connector = 2450 shell::Connector* connector =
2454 BrowserContext::GetShellConnectorFor(browser_context_); 2451 BrowserContext::GetShellConnectorFor(browser_context_);
2455 if (!connector) 2452 if (!connector)
2456 connector = MojoShellConnection::GetForProcess()->GetConnector(); 2453 connector = MojoShellConnection::GetForProcess()->GetConnector();
2457 mojo_child_connection_.reset(new MojoChildConnection( 2454 mojo_child_connection_.reset(new MojoChildConnection(
2458 kRendererMojoApplicationName, 2455 kRendererMojoApplicationName,
2459 base::StringPrintf("%d_%d", id_, instance_id_++), 2456 base::StringPrintf("%d_%d", id_, instance_id_++), child_token_, connector,
2460 child_token_, 2457 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)));
2461 connector));
2462 2458
2463 within_process_died_observer_ = true; 2459 within_process_died_observer_ = true;
2464 NotificationService::current()->Notify( 2460 NotificationService::current()->Notify(
2465 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), 2461 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this),
2466 Details<RendererClosedDetails>(&details)); 2462 Details<RendererClosedDetails>(&details));
2467 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, 2463 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_,
2468 RenderProcessExited(this, status, exit_code)); 2464 RenderProcessExited(this, status, exit_code));
2469 within_process_died_observer_ = false; 2465 within_process_died_observer_ = false;
2470 2466
2471 message_port_message_filter_ = NULL; 2467 message_port_message_filter_ = NULL;
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
2786 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; 2782 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error;
2787 2783
2788 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias 2784 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias
2789 // enough information here so that we can determine what the bad message was. 2785 // enough information here so that we can determine what the bad message was.
2790 base::debug::Alias(&error); 2786 base::debug::Alias(&error);
2791 bad_message::ReceivedBadMessage(process.get(), 2787 bad_message::ReceivedBadMessage(process.get(),
2792 bad_message::RPH_MOJO_PROCESS_ERROR); 2788 bad_message::RPH_MOJO_PROCESS_ERROR);
2793 } 2789 }
2794 2790
2795 } // namespace content 2791 } // 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_view_mus.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698