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 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 // single process modes, the global attachment broker is the privileged | 593 // single process modes, the global attachment broker is the privileged |
592 // attachment broker, rather than an unprivileged attachment broker. | 594 // attachment broker, rather than an unprivileged attachment broker. |
593 #if defined(OS_MACOSX) | 595 #if defined(OS_MACOSX) |
594 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded( | 596 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded( |
595 MachBroker::GetInstance()); | 597 MachBroker::GetInstance()); |
596 #else | 598 #else |
597 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded(); | 599 IPC::AttachmentBrokerPrivileged::CreateBrokerIfNeeded(); |
598 #endif // defined(OS_MACOSX) | 600 #endif // defined(OS_MACOSX) |
599 #endif // USE_ATTACHMENT_BROKER | 601 #endif // USE_ATTACHMENT_BROKER |
600 | 602 |
| 603 scoped_refptr<base::SequencedTaskRunner> io_task_runner = |
| 604 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
601 shell::Connector* connector = | 605 shell::Connector* connector = |
602 BrowserContext::GetShellConnectorFor(browser_context_); | 606 BrowserContext::GetShellConnectorFor(browser_context_); |
603 // Some embedders may not initialize Mojo or the shell connector for a browser | 607 // Some embedders may not initialize Mojo or the shell connector for a browser |
604 // context (e.g. Android WebView)... so just fall back to the per-process | 608 // context (e.g. Android WebView)... so just fall back to the per-process |
605 // connector. | 609 // connector. |
606 if (!connector) { | 610 if (!connector) { |
607 // Additionally, some test code may not initialize the process-wide | 611 // Additionally, some test code may not initialize the process-wide |
608 // MojoShellConnection prior to this point. This class of test code doesn't | 612 // MojoShellConnection prior to this point. This class of test code doesn't |
609 // care about render processes so we can initialize a dummy one. | 613 // care about render processes so we can initialize a dummy one. |
610 if (!MojoShellConnection::GetForProcess()) { | 614 if (!MojoShellConnection::GetForProcess()) { |
611 shell::mojom::ServiceRequest request = mojo::GetProxy(&test_service_); | 615 shell::mojom::ServiceRequest request = mojo::GetProxy(&test_service_); |
612 MojoShellConnection::SetForProcess(MojoShellConnection::Create( | 616 MojoShellConnection::SetForProcess(MojoShellConnection::Create( |
613 std::move(request))); | 617 std::move(request), io_task_runner)); |
614 } | 618 } |
615 connector = MojoShellConnection::GetForProcess()->GetConnector(); | 619 connector = MojoShellConnection::GetForProcess()->GetConnector(); |
616 } | 620 } |
617 mojo_child_connection_.reset(new MojoChildConnection( | 621 mojo_child_connection_.reset(new MojoChildConnection( |
618 kRendererMojoApplicationName, | 622 kRendererMojoApplicationName, |
619 base::StringPrintf("%d_%d", id_, instance_id_++), | 623 base::StringPrintf("%d_%d", id_, instance_id_++), child_token_, connector, |
620 child_token_, | 624 io_task_runner)); |
621 connector)); | |
622 } | 625 } |
623 | 626 |
624 // static | 627 // static |
625 void RenderProcessHostImpl::ShutDownInProcessRenderer() { | 628 void RenderProcessHostImpl::ShutDownInProcessRenderer() { |
626 DCHECK(g_run_renderer_in_process_); | 629 DCHECK(g_run_renderer_in_process_); |
627 | 630 |
628 switch (g_all_hosts.Pointer()->size()) { | 631 switch (g_all_hosts.Pointer()->size()) { |
629 case 0: | 632 case 0: |
630 return; | 633 return; |
631 case 1: { | 634 case 1: { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 DCHECK(g_renderer_main_thread_factory); | 739 DCHECK(g_renderer_main_thread_factory); |
737 // Crank up a thread and run the initialization there. With the way that | 740 // Crank up a thread and run the initialization there. With the way that |
738 // messages flow between the browser and renderer, this thread is required | 741 // messages flow between the browser and renderer, this thread is required |
739 // to prevent a deadlock in single-process mode. Since the primordial | 742 // to prevent a deadlock in single-process mode. Since the primordial |
740 // thread in the renderer process runs the WebKit code and can sometimes | 743 // thread in the renderer process runs the WebKit code and can sometimes |
741 // make blocking calls to the UI thread (i.e. this thread), they need to run | 744 // make blocking calls to the UI thread (i.e. this thread), they need to run |
742 // on separate threads. | 745 // on separate threads. |
743 in_process_renderer_.reset( | 746 in_process_renderer_.reset( |
744 g_renderer_main_thread_factory(InProcessChildThreadParams( | 747 g_renderer_main_thread_factory(InProcessChildThreadParams( |
745 channel_id, | 748 channel_id, |
746 BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO) | 749 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), |
747 ->task_runner(), | |
748 mojo_channel_token_, | 750 mojo_channel_token_, |
749 mojo_child_connection_->service_token()))); | 751 mojo_child_connection_->service_token()))); |
750 | 752 |
751 base::Thread::Options options; | 753 base::Thread::Options options; |
752 #if defined(OS_WIN) && !defined(OS_MACOSX) | 754 #if defined(OS_WIN) && !defined(OS_MACOSX) |
753 // In-process plugins require this to be a UI message loop. | 755 // In-process plugins require this to be a UI message loop. |
754 options.message_loop_type = base::MessageLoop::TYPE_UI; | 756 options.message_loop_type = base::MessageLoop::TYPE_UI; |
755 #else | 757 #else |
756 // We can't have multiple UI loops on Linux and Android, so we don't support | 758 // We can't have multiple UI loops on Linux and Android, so we don't support |
757 // in-process plugins. | 759 // in-process plugins. |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1096 void RenderProcessHostImpl::ResumeDeferredNavigation( | 1098 void RenderProcessHostImpl::ResumeDeferredNavigation( |
1097 const GlobalRequestID& request_id) { | 1099 const GlobalRequestID& request_id) { |
1098 widget_helper_->ResumeDeferredNavigation(request_id); | 1100 widget_helper_->ResumeDeferredNavigation(request_id); |
1099 } | 1101 } |
1100 | 1102 |
1101 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { | 1103 void RenderProcessHostImpl::NotifyTimezoneChange(const std::string& zone_id) { |
1102 Send(new ViewMsg_TimezoneChange(zone_id)); | 1104 Send(new ViewMsg_TimezoneChange(zone_id)); |
1103 } | 1105 } |
1104 | 1106 |
1105 shell::InterfaceRegistry* RenderProcessHostImpl::GetInterfaceRegistry() { | 1107 shell::InterfaceRegistry* RenderProcessHostImpl::GetInterfaceRegistry() { |
1106 return GetChildConnection()->GetInterfaceRegistry(); | 1108 return mojo_child_connection_->GetInterfaceRegistry(); |
1107 } | 1109 } |
1108 | 1110 |
1109 shell::InterfaceProvider* RenderProcessHostImpl::GetRemoteInterfaces() { | 1111 shell::InterfaceProvider* RenderProcessHostImpl::GetRemoteInterfaces() { |
1110 return GetChildConnection()->GetRemoteInterfaces(); | 1112 return mojo_child_connection_->GetRemoteInterfaces(); |
1111 } | |
1112 | |
1113 shell::Connection* RenderProcessHostImpl::GetChildConnection() { | |
1114 DCHECK(mojo_child_connection_); | |
1115 return mojo_child_connection_->connection(); | |
1116 } | 1113 } |
1117 | 1114 |
1118 std::unique_ptr<base::SharedPersistentMemoryAllocator> | 1115 std::unique_ptr<base::SharedPersistentMemoryAllocator> |
1119 RenderProcessHostImpl::TakeMetricsAllocator() { | 1116 RenderProcessHostImpl::TakeMetricsAllocator() { |
1120 return std::move(metrics_allocator_); | 1117 return std::move(metrics_allocator_); |
1121 } | 1118 } |
1122 | 1119 |
1123 const base::TimeTicks& RenderProcessHostImpl::GetInitTimeForNavigationMetrics() | 1120 const base::TimeTicks& RenderProcessHostImpl::GetInitTimeForNavigationMetrics() |
1124 const { | 1121 const { |
1125 return init_time_; | 1122 return init_time_; |
(...skipping 1298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2424 // RenderProcessExited observers and RenderProcessGone handlers might | 2421 // RenderProcessExited observers and RenderProcessGone handlers might |
2425 // navigate or perform other actions that require a connection. Ensure that | 2422 // navigate or perform other actions that require a connection. Ensure that |
2426 // there is one before calling them. | 2423 // there is one before calling them. |
2427 child_token_ = mojo::edk::GenerateRandomToken(); | 2424 child_token_ = mojo::edk::GenerateRandomToken(); |
2428 shell::Connector* connector = | 2425 shell::Connector* connector = |
2429 BrowserContext::GetShellConnectorFor(browser_context_); | 2426 BrowserContext::GetShellConnectorFor(browser_context_); |
2430 if (!connector) | 2427 if (!connector) |
2431 connector = MojoShellConnection::GetForProcess()->GetConnector(); | 2428 connector = MojoShellConnection::GetForProcess()->GetConnector(); |
2432 mojo_child_connection_.reset(new MojoChildConnection( | 2429 mojo_child_connection_.reset(new MojoChildConnection( |
2433 kRendererMojoApplicationName, | 2430 kRendererMojoApplicationName, |
2434 base::StringPrintf("%d_%d", id_, instance_id_++), | 2431 base::StringPrintf("%d_%d", id_, instance_id_++), child_token_, connector, |
2435 child_token_, | 2432 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); |
2436 connector)); | |
2437 | 2433 |
2438 within_process_died_observer_ = true; | 2434 within_process_died_observer_ = true; |
2439 NotificationService::current()->Notify( | 2435 NotificationService::current()->Notify( |
2440 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), | 2436 NOTIFICATION_RENDERER_PROCESS_CLOSED, Source<RenderProcessHost>(this), |
2441 Details<RendererClosedDetails>(&details)); | 2437 Details<RendererClosedDetails>(&details)); |
2442 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, | 2438 FOR_EACH_OBSERVER(RenderProcessHostObserver, observers_, |
2443 RenderProcessExited(this, status, exit_code)); | 2439 RenderProcessExited(this, status, exit_code)); |
2444 within_process_died_observer_ = false; | 2440 within_process_died_observer_ = false; |
2445 | 2441 |
2446 message_port_message_filter_ = NULL; | 2442 message_port_message_filter_ = NULL; |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2830 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; | 2826 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; |
2831 | 2827 |
2832 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias | 2828 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. Alias |
2833 // enough information here so that we can determine what the bad message was. | 2829 // enough information here so that we can determine what the bad message was. |
2834 base::debug::Alias(&error); | 2830 base::debug::Alias(&error); |
2835 bad_message::ReceivedBadMessage(process.get(), | 2831 bad_message::ReceivedBadMessage(process.get(), |
2836 bad_message::RPH_MOJO_PROCESS_ERROR); | 2832 bad_message::RPH_MOJO_PROCESS_ERROR); |
2837 } | 2833 } |
2838 | 2834 |
2839 } // namespace content | 2835 } // namespace content |
OLD | NEW |