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