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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 // single process modes, the global attachment broker is the privileged | 595 // single process modes, the global attachment broker is the privileged |
594 // attachment broker, rather than an unprivileged attachment broker. | 596 // attachment broker, rather than an unprivileged attachment broker. |
595 #if defined(OS_MACOSX) | 597 #if defined(OS_MACOSX) |
596 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded( | 598 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded( |
597 MachBroker::GetInstance()); | 599 MachBroker::GetInstance()); |
598 #else | 600 #else |
599 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded(); | 601 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded(); |
600 #endif // defined(OS_MACOSX) | 602 #endif // defined(OS_MACOSX) |
601 #endif // USE_ATTACHMENT_BROKER | 603 #endif // USE_ATTACHMENT_BROKER |
602 | 604 |
| 605 scoped_refptr<base::SequencedTaskRunner> io_task_runner = |
| 606 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO); |
603 shell::Connector* connector = | 607 shell::Connector* connector = |
604 BrowserContext::GetShellConnectorFor(browser_context_); | 608 BrowserContext::GetShellConnectorFor(browser_context_); |
605 // Some embedders may not initialize Mojo or the shell connector for a browser | 609 // Some embedders may not initialize Mojo or the shell connector for a browser |
606 // context (e.g. Android WebView)... so just fall back to the per-process | 610 // context (e.g. Android WebView)... so just fall back to the per-process |
607 // connector. | 611 // connector. |
608 if (!connector) { | 612 if (!connector) { |
609 // Additionally, some test code may not initialize the process-wide | 613 // Additionally, some test code may not initialize the process-wide |
610 // MojoShellConnection prior to this point. This class of test code doesn't | 614 // MojoShellConnection prior to this point. This class of test code doesn't |
611 // care about render processes so we can initialize a dummy one. | 615 // care about render processes so we can initialize a dummy one. |
612 if (!MojoShellConnection::GetForProcess()) { | 616 if (!MojoShellConnection::GetForProcess()) { |
613 shell::mojom::ServiceRequest request = mojo::GetProxy(&test_service_); | 617 shell::mojom::ServiceRequest request = mojo::GetProxy(&test_service_); |
614 MojoShellConnection::SetForProcess(MojoShellConnection::Create( | 618 MojoShellConnection::SetForProcess(MojoShellConnection::Create( |
615 std::move(request))); | 619 std::move(request), io_task_runner)); |
616 } | 620 } |
617 connector = MojoShellConnection::GetForProcess()->GetConnector(); | 621 connector = MojoShellConnection::GetForProcess()->GetConnector(); |
618 } | 622 } |
619 mojo_child_connection_.reset(new MojoChildConnection( | 623 mojo_child_connection_.reset(new MojoChildConnection( |
620 kRendererMojoApplicationName, | 624 kRendererMojoApplicationName, |
621 base::StringPrintf("%d_%d", id_, instance_id_++), | 625 base::StringPrintf("%d_%d", id_, instance_id_++), child_token_, connector, |
622 child_token_, | 626 io_task_runner)); |
623 connector)); | |
624 } | 627 } |
625 | 628 |
626 // static | 629 // static |
627 void RenderProcessHostImpl::ShutDownInProcessRenderer() { | 630 void RenderProcessHostImpl::ShutDownInProcessRenderer() { |
628 DCHECK(g_run_renderer_in_process_); | 631 DCHECK(g_run_renderer_in_process_); |
629 | 632 |
630 switch (g_all_hosts.Pointer()->size()) { | 633 switch (g_all_hosts.Pointer()->size()) { |
631 case 0: | 634 case 0: |
632 return; | 635 return; |
633 case 1: { | 636 case 1: { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 DCHECK(g_renderer_main_thread_factory); | 756 DCHECK(g_renderer_main_thread_factory); |
754 // Crank up a thread and run the initialization there. With the way that | 757 // Crank up a thread and run the initialization there. With the way that |
755 // messages flow between the browser and renderer, this thread is required | 758 // messages flow between the browser and renderer, this thread is required |
756 // to prevent a deadlock in single-process mode. Since the primordial | 759 // to prevent a deadlock in single-process mode. Since the primordial |
757 // thread in the renderer process runs the WebKit code and can sometimes | 760 // thread in the renderer process runs the WebKit code and can sometimes |
758 // make blocking calls to the UI thread (i.e. this thread), they need to run | 761 // make blocking calls to the UI thread (i.e. this thread), they need to run |
759 // on separate threads. | 762 // on separate threads. |
760 in_process_renderer_.reset( | 763 in_process_renderer_.reset( |
761 g_renderer_main_thread_factory(InProcessChildThreadParams( | 764 g_renderer_main_thread_factory(InProcessChildThreadParams( |
762 channel_id, | 765 channel_id, |
763 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO) | 766 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO), |
764 ->task_runner(), | |
765 mojo_channel_token_, | 767 mojo_channel_token_, |
766 mojo_child_connection_->service_token()))); | 768 mojo_child_connection_->service_token()))); |
767 | 769 |
768 base::Thread::Options options; | 770 base::Thread::Options options; |
769 #if defined(OS_WIN) && !defined(OS_MACOSX) | 771 #if defined(OS_WIN) && !defined(OS_MACOSX) |
770 // In-process plugins require this to be a UI message loop. | 772 // In-process plugins require this to be a UI message loop. |
771 options.message_loop_type = base::MessageLoop::TYPE_UI; | 773 options.message_loop_type = base::MessageLoop::TYPE_UI; |
772 #else | 774 #else |
773 // We can't have multiple UI loops on Linux and Android, so we don't support | 775 // We can't have multiple UI loops on Linux and Android, so we don't support |
774 // in-process plugins. | 776 // in-process plugins. |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1114 void RenderProcessHostImpl::ResumeDeferredNavigation( | 1116 void RenderProcessHostImpl::ResumeDeferredNavigation( |
1115 const GlobalRequestID& request_id) { | 1117 const GlobalRequestID& request_id) { |
1116 widget_helper_->ResumeDeferredNavigation(request_id); | 1118 widget_helper_->ResumeDeferredNavigation(request_id); |
1117 } | 1119 } |
1118 | 1120 |
1119 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { | 1121 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { |
1120 Send(new ViewMsg_TimezoneChange(zone_id)); | 1122 Send(new ViewMsg_TimezoneChange(zone_id)); |
1121 } | 1123 } |
1122 | 1124 |
1123 shell::InterfaceRegistry* RenderProcessHostImpl::GetInterfaceRegistry() { | 1125 shell::InterfaceRegistry* RenderProcessHostImpl::GetInterfaceRegistry() { |
1124 return GetChildConnection()->GetInterfaceRegistry(); | 1126 return mojo_child_connection_->GetInterfaceRegistry(); |
1125 } | 1127 } |
1126 | 1128 |
1127 shell::InterfaceProvider* RenderProcessHostImpl::GetRemoteInterfaces() { | 1129 shell::InterfaceProvider* RenderProcessHostImpl::GetRemoteInterfaces() { |
1128 return GetChildConnection()->GetRemoteInterfaces(); | 1130 return mojo_child_connection_->GetRemoteInterfaces(); |
1129 } | |
1130 | |
1131 shell::Connection* RenderProcessHostImpl::GetChildConnection() { | |
1132 DCHECK(mojo_child_connection_); | |
1133 return mojo_child_connection_->connection(); | |
1134 } | 1131 } |
1135 | 1132 |
1136 std::unique_ptr<base::SharedPersistentMemoryAllocator> | 1133 std::unique_ptr<base::SharedPersistentMemoryAllocator> |
1137 RenderProcessHostImpl::TakeMetricsAllocator() { | 1134 RenderProcessHostImpl::TakeMetricsAllocator() { |
1138 return std::move(metrics_allocator_); | 1135 return std::move(metrics_allocator_); |
1139 } | 1136 } |
1140 | 1137 |
1141 const base::TimeTicks& RenderProcessHostImpl::GetInitTimeForNavigationMetrics() | 1138 const base::TimeTicks& RenderProcessHostImpl::GetInitTimeForNavigationMetrics() |
1142 const { | 1139 const { |
1143 return init_time_; | 1140 return init_time_; |
(...skipping 1283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2427 // RenderProcessExited observers and RenderProcessGone handlers might | 2424 // RenderProcessExited observers and RenderProcessGone handlers might |
2428 // navigate or perform other actions that require a connection. Ensure that | 2425 // navigate or perform other actions that require a connection. Ensure that |
2429 // there is one before calling them. | 2426 // there is one before calling them. |
2430 child_token_ = mojo::edk::GenerateRandomToken(); | 2427 child_token_ = mojo::edk::GenerateRandomToken(); |
2431 shell::Connector* connector = | 2428 shell::Connector* connector = |
2432 BrowserContext::GetShellConnectorFor(browser_context_); | 2429 BrowserContext::GetShellConnectorFor(browser_context_); |
2433 if (!connector) | 2430 if (!connector) |
2434 connector = MojoShellConnection::GetForProcess()->GetConnector(); | 2431 connector = MojoShellConnection::GetForProcess()->GetConnector(); |
2435 mojo_child_connection_.reset(new MojoChildConnection( | 2432 mojo_child_connection_.reset(new MojoChildConnection( |
2436 kRendererMojoApplicationName, | 2433 kRendererMojoApplicationName, |
2437 base::StringPrintf("%d_%d", id_, instance_id_++), | 2434 base::StringPrintf("%d_%d", id_, instance_id_++), child_token_, connector, |
2438 child_token_, | 2435 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO))); |
2439 connector)); | |
2440 | 2436 |
2441 within_process_died_observer_ = true; | 2437 within_process_died_observer_ = true; |
2442 NotificationService::current()->Notify( | 2438 NotificationService::current()->Notify( |
2443 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), | 2439 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), |
2444 Details<RendererClosedDetails>(&details)); | 2440 Details<RendererClosedDetails>(&details)); |
2445 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, | 2441 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, |
2446 RenderProcessExited(this, status, exit_code)); | 2442 RenderProcessExited(this, status, exit_code)); |
2447 within_process_died_observer_ = false; | 2443 within_process_died_observer_ = false; |
2448 | 2444 |
2449 message_port_message_filter_ = NULL; | 2445 message_port_message_filter_ = NULL; |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2764 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; | 2760 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; |
2765 | 2761 |
2766 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias | 2762 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias |
2767 // enough information here so that we can determine what the bad message was. | 2763 // enough information here so that we can determine what the bad message was. |
2768 base::debug::Alias(&error); | 2764 base::debug::Alias(&error); |
2769 bad_message::ReceivedBadMessage(process.get(), | 2765 bad_message::ReceivedBadMessage(process.get(), |
2770 bad_message::RPH_MOJO_PROCESS_ERROR); | 2766 bad_message::RPH_MOJO_PROCESS_ERROR); |
2771 } | 2767 } |
2772 | 2768 |
2773 } // namespace content | 2769 } // namespace content |
OLD | NEW |