OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #include "content/renderer/render_thread_impl.h" | 5 #include "content/renderer/render_thread_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <map> | 9 #include <map> |
10 #include <utility> | 10 #include <utility> |
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 const InProcessChildThreadParams& params, | 581 const InProcessChildThreadParams& params, |
582 std::unique_ptr<blink::scheduler::RendererScheduler> scheduler, | 582 std::unique_ptr<blink::scheduler::RendererScheduler> scheduler, |
583 scoped_refptr<base::SingleThreadTaskRunner>& resource_task_queue) | 583 scoped_refptr<base::SingleThreadTaskRunner>& resource_task_queue) |
584 : ChildThreadImpl(Options::Builder() | 584 : ChildThreadImpl(Options::Builder() |
585 .InBrowserProcess(params) | 585 .InBrowserProcess(params) |
586 .UseMojoChannel(true) | 586 .UseMojoChannel(true) |
587 .AutoStartMojoShellConnection(false) | 587 .AutoStartMojoShellConnection(false) |
588 .ConnectToBrowser(true) | 588 .ConnectToBrowser(true) |
589 .Build()), | 589 .Build()), |
590 renderer_scheduler_(std::move(scheduler)), | 590 renderer_scheduler_(std::move(scheduler)), |
591 categorized_worker_pool_(new CategorizedWorkerPool()) { | 591 categorized_worker_pool_(new CategorizedWorkerPool()), |
| 592 route_provider_binding_(this) { |
592 Init(resource_task_queue); | 593 Init(resource_task_queue); |
593 } | 594 } |
594 | 595 |
595 // When we run plugins in process, we actually run them on the render thread, | 596 // When we run plugins in process, we actually run them on the render thread, |
596 // which means that we need to make the render thread pump UI events. | 597 // which means that we need to make the render thread pump UI events. |
597 RenderThreadImpl::RenderThreadImpl( | 598 RenderThreadImpl::RenderThreadImpl( |
598 std::unique_ptr<base::MessageLoop> main_message_loop, | 599 std::unique_ptr<base::MessageLoop> main_message_loop, |
599 std::unique_ptr<blink::scheduler::RendererScheduler> scheduler) | 600 std::unique_ptr<blink::scheduler::RendererScheduler> scheduler) |
600 : ChildThreadImpl(Options::Builder() | 601 : ChildThreadImpl(Options::Builder() |
601 .UseMojoChannel(true) | 602 .UseMojoChannel(true) |
602 .AutoStartMojoShellConnection(false) | 603 .AutoStartMojoShellConnection(false) |
603 .ConnectToBrowser(true) | 604 .ConnectToBrowser(true) |
604 .Build()), | 605 .Build()), |
605 renderer_scheduler_(std::move(scheduler)), | 606 renderer_scheduler_(std::move(scheduler)), |
606 main_message_loop_(std::move(main_message_loop)), | 607 main_message_loop_(std::move(main_message_loop)), |
607 categorized_worker_pool_(new CategorizedWorkerPool()) { | 608 categorized_worker_pool_(new CategorizedWorkerPool()), |
| 609 route_provider_binding_(this) { |
608 scoped_refptr<base::SingleThreadTaskRunner> test_task_counter; | 610 scoped_refptr<base::SingleThreadTaskRunner> test_task_counter; |
609 Init(test_task_counter); | 611 Init(test_task_counter); |
610 } | 612 } |
611 | 613 |
612 void RenderThreadImpl::Init( | 614 void RenderThreadImpl::Init( |
613 scoped_refptr<base::SingleThreadTaskRunner>& resource_task_queue) { | 615 scoped_refptr<base::SingleThreadTaskRunner>& resource_task_queue) { |
614 TRACE_EVENT0("startup", "RenderThreadImpl::Init"); | 616 TRACE_EVENT0("startup", "RenderThreadImpl::Init"); |
615 | 617 |
616 base::trace_event::TraceLog::GetInstance()->SetThreadSortIndex( | 618 base::trace_event::TraceLog::GetInstance()->SetThreadSortIndex( |
617 base::PlatformThread::CurrentId(), | 619 base::PlatformThread::CurrentId(), |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 | 708 |
707 AddFilter((new ServiceWorkerContextMessageFilter())->GetFilter()); | 709 AddFilter((new ServiceWorkerContextMessageFilter())->GetFilter()); |
708 | 710 |
709 #if defined(USE_AURA) | 711 #if defined(USE_AURA) |
710 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 712 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
711 switches::kUseMusInRenderer)) { | 713 switches::kUseMusInRenderer)) { |
712 CreateRenderWidgetWindowTreeClientFactory(GetMojoShellConnection()); | 714 CreateRenderWidgetWindowTreeClientFactory(GetMojoShellConnection()); |
713 } | 715 } |
714 #endif | 716 #endif |
715 | 717 |
| 718 GetChannel()->AddAssociatedInterface(base::Bind( |
| 719 &RenderThreadImpl::OnRouteProviderRequest, base::Unretained(this))); |
| 720 |
716 // Must be called before RenderThreadStarted() below. | 721 // Must be called before RenderThreadStarted() below. |
717 StartMojoShellConnection(); | 722 StartMojoShellConnection(); |
718 | 723 |
719 GetContentClient()->renderer()->RenderThreadStarted(); | 724 GetContentClient()->renderer()->RenderThreadStarted(); |
720 | 725 |
721 InitSkiaEventTracer(); | 726 InitSkiaEventTracer(); |
722 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | 727 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
723 skia::SkiaMemoryDumpProvider::GetInstance(), "Skia", nullptr); | 728 skia::SkiaMemoryDumpProvider::GetInstance(), "Skia", nullptr); |
724 | 729 |
725 const base::CommandLine& command_line = | 730 const base::CommandLine& command_line = |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1033 if (!frame) | 1038 if (!frame) |
1034 return; | 1039 return; |
1035 | 1040 |
1036 scoped_refptr<PendingFrameCreate> create(it->second); | 1041 scoped_refptr<PendingFrameCreate> create(it->second); |
1037 frame->Bind(it->second->TakeFrameRequest(), it->second->TakeFrameHost()); | 1042 frame->Bind(it->second->TakeFrameRequest(), it->second->TakeFrameHost()); |
1038 pending_frame_creates_.erase(it); | 1043 pending_frame_creates_.erase(it); |
1039 } | 1044 } |
1040 | 1045 |
1041 void RenderThreadImpl::RemoveRoute(int32_t routing_id) { | 1046 void RenderThreadImpl::RemoveRoute(int32_t routing_id) { |
1042 ChildThreadImpl::GetRouter()->RemoveRoute(routing_id); | 1047 ChildThreadImpl::GetRouter()->RemoveRoute(routing_id); |
| 1048 routed_interface_providers_.erase(routing_id); |
1043 } | 1049 } |
1044 | 1050 |
1045 void RenderThreadImpl::AddEmbeddedWorkerRoute(int32_t routing_id, | 1051 void RenderThreadImpl::AddEmbeddedWorkerRoute(int32_t routing_id, |
1046 IPC::Listener* listener) { | 1052 IPC::Listener* listener) { |
1047 AddRoute(routing_id, listener); | 1053 AddRoute(routing_id, listener); |
1048 if (devtools_agent_message_filter_.get()) { | 1054 if (devtools_agent_message_filter_.get()) { |
1049 devtools_agent_message_filter_->AddEmbeddedWorkerRouteOnMainThread( | 1055 devtools_agent_message_filter_->AddEmbeddedWorkerRouteOnMainThread( |
1050 routing_id); | 1056 routing_id); |
1051 } | 1057 } |
1052 } | 1058 } |
(...skipping 21 matching lines...) Expand all Loading... |
1074 mojom::StoragePartitionService* RenderThreadImpl::GetStoragePartitionService() { | 1080 mojom::StoragePartitionService* RenderThreadImpl::GetStoragePartitionService() { |
1075 return storage_partition_service_.get(); | 1081 return storage_partition_service_.get(); |
1076 } | 1082 } |
1077 | 1083 |
1078 int RenderThreadImpl::GenerateRoutingID() { | 1084 int RenderThreadImpl::GenerateRoutingID() { |
1079 int routing_id = MSG_ROUTING_NONE; | 1085 int routing_id = MSG_ROUTING_NONE; |
1080 Send(new ViewHostMsg_GenerateRoutingID(&routing_id)); | 1086 Send(new ViewHostMsg_GenerateRoutingID(&routing_id)); |
1081 return routing_id; | 1087 return routing_id; |
1082 } | 1088 } |
1083 | 1089 |
| 1090 void RenderThreadImpl::AddRoutedInterfaces( |
| 1091 int32_t routing_id, |
| 1092 mojom::RoutedInterfaceProvider* provider) { |
| 1093 auto result = |
| 1094 routed_interface_providers_.insert(std::make_pair(routing_id, provider)); |
| 1095 DCHECK(result.second); |
| 1096 } |
| 1097 |
| 1098 mojom::RouteProvider* RenderThreadImpl::GetRemoteRouteProvider() { |
| 1099 if (!remote_route_provider_) |
| 1100 channel()->GetRemoteAssociatedInterface(&remote_route_provider_); |
| 1101 return remote_route_provider_.get(); |
| 1102 } |
| 1103 |
1084 void RenderThreadImpl::AddFilter(IPC::MessageFilter* filter) { | 1104 void RenderThreadImpl::AddFilter(IPC::MessageFilter* filter) { |
1085 channel()->AddFilter(filter); | 1105 channel()->AddFilter(filter); |
1086 } | 1106 } |
1087 | 1107 |
1088 void RenderThreadImpl::RemoveFilter(IPC::MessageFilter* filter) { | 1108 void RenderThreadImpl::RemoveFilter(IPC::MessageFilter* filter) { |
1089 channel()->RemoveFilter(filter); | 1109 channel()->RemoveFilter(filter); |
1090 } | 1110 } |
1091 | 1111 |
1092 void RenderThreadImpl::AddObserver(RenderThreadObserver* observer) { | 1112 void RenderThreadImpl::AddObserver(RenderThreadObserver* observer) { |
1093 observers_.AddObserver(observer); | 1113 observers_.AddObserver(observer); |
(...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2225 // OnSyncMemoryPressure() is never called in that case. | 2245 // OnSyncMemoryPressure() is never called in that case. |
2226 void RenderThreadImpl::OnTrimMemoryImmediately() { | 2246 void RenderThreadImpl::OnTrimMemoryImmediately() { |
2227 if (blink::mainThreadIsolate()) { | 2247 if (blink::mainThreadIsolate()) { |
2228 blink::mainThreadIsolate()->MemoryPressureNotification( | 2248 blink::mainThreadIsolate()->MemoryPressureNotification( |
2229 v8::MemoryPressureLevel::kCritical); | 2249 v8::MemoryPressureLevel::kCritical); |
2230 blink::MemoryPressureNotificationToWorkerThreadIsolates( | 2250 blink::MemoryPressureNotificationToWorkerThreadIsolates( |
2231 v8::MemoryPressureLevel::kCritical); | 2251 v8::MemoryPressureLevel::kCritical); |
2232 } | 2252 } |
2233 } | 2253 } |
2234 | 2254 |
| 2255 void RenderThreadImpl::OnRouteProviderRequest( |
| 2256 mojom::RouteProviderAssociatedRequest request) { |
| 2257 DCHECK(!route_provider_binding_.is_bound()); |
| 2258 route_provider_binding_.Bind(std::move(request)); |
| 2259 } |
| 2260 |
| 2261 void RenderThreadImpl::GetRoutedInterfaces( |
| 2262 int32_t routing_id, |
| 2263 mojom::RoutedInterfaceProviderAssociatedRequest request) { |
| 2264 auto it = routed_interface_providers_.find(routing_id); |
| 2265 if (it == routed_interface_providers_.end()) |
| 2266 return; |
| 2267 routed_interface_provider_bindings_.AddBinding(it->second, |
| 2268 std::move(request)); |
| 2269 } |
2235 | 2270 |
2236 } // namespace content | 2271 } // namespace content |
OLD | NEW |