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

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: . 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 #include "ipc/attachment_broker.h" 165 #include "ipc/attachment_broker.h"
166 #include "ipc/attachment_broker_privileged.h" 166 #include "ipc/attachment_broker_privileged.h"
167 #include "ipc/ipc_channel.h" 167 #include "ipc/ipc_channel.h"
168 #include "ipc/ipc_channel_mojo.h" 168 #include "ipc/ipc_channel_mojo.h"
169 #include "ipc/ipc_logging.h" 169 #include "ipc/ipc_logging.h"
170 #include "ipc/ipc_switches.h" 170 #include "ipc/ipc_switches.h"
171 #include "media/base/media_switches.h" 171 #include "media/base/media_switches.h"
172 #include "mojo/edk/embedder/embedder.h" 172 #include "mojo/edk/embedder/embedder.h"
173 #include "net/url_request/url_request_context_getter.h" 173 #include "net/url_request/url_request_context_getter.h"
174 #include "ppapi/shared_impl/ppapi_switches.h" 174 #include "ppapi/shared_impl/ppapi_switches.h"
175 #include "services/shell/public/cpp/interface_provider.h"
176 #include "services/shell/public/cpp/interface_registry.h"
175 #include "services/shell/runner/common/switches.h" 177 #include "services/shell/runner/common/switches.h"
176 #include "storage/browser/fileapi/sandbox_file_system_backend.h" 178 #include "storage/browser/fileapi/sandbox_file_system_backend.h"
177 #include "third_party/skia/include/core/SkBitmap.h" 179 #include "third_party/skia/include/core/SkBitmap.h"
178 #include "ui/base/ui_base_switches.h" 180 #include "ui/base/ui_base_switches.h"
179 #include "ui/display/display_switches.h" 181 #include "ui/display/display_switches.h"
180 #include "ui/events/event_switches.h" 182 #include "ui/events/event_switches.h"
181 #include "ui/gfx/switches.h" 183 #include "ui/gfx/switches.h"
182 #include "ui/gl/gl_switches.h" 184 #include "ui/gl/gl_switches.h"
183 #include "ui/gl/gpu_switching_manager.h" 185 #include "ui/gl/gpu_switching_manager.h"
184 #include "ui/native_theme/native_theme_switches.h" 186 #include "ui/native_theme/native_theme_switches.h"
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 // single process modes, the global attachment broker is the privileged 597 // single process modes, the global attachment broker is the privileged
596 // attachment broker, rather than an unprivileged attachment broker. 598 // attachment broker, rather than an unprivileged attachment broker.
597 #if defined(OS_MACOSX) 599 #if defined(OS_MACOSX)
598 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded( 600 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded(
599 MachBroker::GetInstance()); 601 MachBroker::GetInstance());
600 #else 602 #else
601 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded(); 603 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded();
602 #endif // defined(OS_MACOSX) 604 #endif // defined(OS_MACOSX)
603 #endif // USE_ATTACHMENT_BROKER 605 #endif // USE_ATTACHMENT_BROKER
604 606
607 scoped_refptr<base::SequencedTaskRunner> io_task_runner =
608 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
605 shell::Connector* connector = 609 shell::Connector* connector =
606 BrowserContext::GetShellConnectorFor(browser_context_); 610 BrowserContext::GetShellConnectorFor(browser_context_);
607 // Some embedders may not initialize Mojo or the shell connector for a browser 611 // Some embedders may not initialize Mojo or the shell connector for a browser
608 // context (e.g. Android WebView)... so just fall back to the per-process 612 // context (e.g. Android WebView)... so just fall back to the per-process
609 // connector. 613 // connector.
610 if (!connector) { 614 if (!connector) {
611 // Additionally, some test code may not initialize the process-wide 615 // Additionally, some test code may not initialize the process-wide
612 // MojoShellConnection prior to this point. This class of test code doesn't 616 // MojoShellConnection prior to this point. This class of test code doesn't
613 // care about render processes so we can initialize a dummy one. 617 // care about render processes so we can initialize a dummy one.
614 if (!MojoShellConnection::GetForProcess()) { 618 if (!MojoShellConnection::GetForProcess()) {
615 shell::mojom::ShellClientRequest request = 619 shell::mojom::ShellClientRequest request =
616 mojo::GetProxy(&test_shell_client_); 620 mojo::GetProxy(&test_shell_client_);
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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 DCHECK(g_renderer_main_thread_factory); 744 DCHECK(g_renderer_main_thread_factory);
742 // Crank up a thread and run the initialization there. With the way that 745 // Crank up a thread and run the initialization there. With the way that
743 // messages flow between the browser and renderer, this thread is required 746 // messages flow between the browser and renderer, this thread is required
744 // to prevent a deadlock in single-process mode. Since the primordial 747 // to prevent a deadlock in single-process mode. Since the primordial
745 // thread in the renderer process runs the WebKit code and can sometimes 748 // thread in the renderer process runs the WebKit code and can sometimes
746 // make blocking calls to the UI thread (i.e. this thread), they need to run 749 // make blocking calls to the UI thread (i.e. this thread), they need to run
747 // on separate threads. 750 // on separate threads.
748 in_process_renderer_.reset( 751 in_process_renderer_.reset(
749 g_renderer_main_thread_factory(InProcessChildThreadParams( 752 g_renderer_main_thread_factory(InProcessChildThreadParams(
750 channel_id, 753 channel_id,
751 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO) 754 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
752 ->task_runner(),
753 mojo_channel_token_, 755 mojo_channel_token_,
754 mojo_child_connection_->shell_client_token()))); 756 mojo_child_connection_->shell_client_token())));
755 757
756 base::Thread::Options options; 758 base::Thread::Options options;
757 #if defined(OS_WIN) && !defined(OS_MACOSX) 759 #if defined(OS_WIN) && !defined(OS_MACOSX)
758 // In-process plugins require this to be a UI message loop. 760 // In-process plugins require this to be a UI message loop.
759 options.message_loop_type = base::MessageLoop::TYPE_UI; 761 options.message_loop_type = base::MessageLoop::TYPE_UI;
760 #else 762 #else
761 // We can't have multiple UI loops on Linux and Android, so we don't support 763 // We can't have multiple UI loops on Linux and Android, so we don't support
762 // in-process plugins. 764 // in-process plugins.
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 void RenderProcessHostImpl::ResumeDeferredNavigation( 1099 void RenderProcessHostImpl::ResumeDeferredNavigation(
1098 const GlobalRequestID& request_id) { 1100 const GlobalRequestID& request_id) {
1099 widget_helper_->ResumeDeferredNavigation(request_id); 1101 widget_helper_->ResumeDeferredNavigation(request_id);
1100 } 1102 }
1101 1103
1102 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { 1104 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) {
1103 Send(new ViewMsg_TimezoneChange(zone_id)); 1105 Send(new ViewMsg_TimezoneChange(zone_id));
1104 } 1106 }
1105 1107
1106 shell::InterfaceRegistry* RenderProcessHostImpl::GetInterfaceRegistry() { 1108 shell::InterfaceRegistry* RenderProcessHostImpl::GetInterfaceRegistry() {
1107 return GetChildConnection()->GetInterfaceRegistry(); 1109 return mojo_child_connection_->GetInterfaceRegistry();
1108 } 1110 }
1109 1111
1110 shell::InterfaceProvider* RenderProcessHostImpl::GetRemoteInterfaces() { 1112 shell::InterfaceProvider* RenderProcessHostImpl::GetRemoteInterfaces() {
1111 return GetChildConnection()->GetRemoteInterfaces(); 1113 return mojo_child_connection_->GetRemoteInterfaces();
1112 }
1113
1114 shell::Connection* RenderProcessHostImpl::GetChildConnection() {
1115 DCHECK(mojo_child_connection_);
1116 return mojo_child_connection_->connection();
1117 } 1114 }
1118 1115
1119 std::unique_ptr<base::SharedPersistentMemoryAllocator> 1116 std::unique_ptr<base::SharedPersistentMemoryAllocator>
1120 RenderProcessHostImpl::TakeMetricsAllocator() { 1117 RenderProcessHostImpl::TakeMetricsAllocator() {
1121 return std::move(metrics_allocator_); 1118 return std::move(metrics_allocator_);
1122 } 1119 }
1123 1120
1124 const base::TimeTicks& RenderProcessHostImpl::GetInitTimeForNavigationMetrics() 1121 const base::TimeTicks& RenderProcessHostImpl::GetInitTimeForNavigationMetrics()
1125 const { 1122 const {
1126 return init_time_; 1123 return init_time_;
(...skipping 1298 matching lines...) Expand 10 before | Expand all | Expand 10 after
2425 // RenderProcessExited observers and RenderProcessGone handlers might 2422 // RenderProcessExited observers and RenderProcessGone handlers might
2426 // navigate or perform other actions that require a connection. Ensure that 2423 // navigate or perform other actions that require a connection. Ensure that
2427 // there is one before calling them. 2424 // there is one before calling them.
2428 child_token_ = mojo::edk::GenerateRandomToken(); 2425 child_token_ = mojo::edk::GenerateRandomToken();
2429 shell::Connector* connector = 2426 shell::Connector* connector =
2430 BrowserContext::GetShellConnectorFor(browser_context_); 2427 BrowserContext::GetShellConnectorFor(browser_context_);
2431 if (!connector) 2428 if (!connector)
2432 connector = MojoShellConnection::GetForProcess()->GetConnector(); 2429 connector = MojoShellConnection::GetForProcess()->GetConnector();
2433 mojo_child_connection_.reset(new MojoChildConnection( 2430 mojo_child_connection_.reset(new MojoChildConnection(
2434 kRendererMojoApplicationName, 2431 kRendererMojoApplicationName,
2435 base::StringPrintf("%d_%d", id_, instance_id_++), 2432 base::StringPrintf("%d_%d", id_, instance_id_++), child_token_, connector,
2436 child_token_, 2433 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)));
2437 connector));
2438 2434
2439 within_process_died_observer_ = true; 2435 within_process_died_observer_ = true;
2440 NotificationService::current()->Notify( 2436 NotificationService::current()->Notify(
2441 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), 2437 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this),
2442 Details<RendererClosedDetails>(&details)); 2438 Details<RendererClosedDetails>(&details));
2443 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, 2439 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_,
2444 RenderProcessExited(this, status, exit_code)); 2440 RenderProcessExited(this, status, exit_code));
2445 within_process_died_observer_ = false; 2441 within_process_died_observer_ = false;
2446 2442
2447 message_port_message_filter_ = NULL; 2443 message_port_message_filter_ = NULL;
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
2831 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; 2827 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error;
2832 2828
2833 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias 2829 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias
2834 // enough information here so that we can determine what the bad message was. 2830 // enough information here so that we can determine what the bad message was.
2835 base::debug::Alias(&error); 2831 base::debug::Alias(&error);
2836 bad_message::ReceivedBadMessage(process.get(), 2832 bad_message::ReceivedBadMessage(process.get(),
2837 bad_message::RPH_MOJO_PROCESS_ERROR); 2833 bad_message::RPH_MOJO_PROCESS_ERROR);
2838 } 2834 }
2839 2835
2840 } // namespace content 2836 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698