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 <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/allocator/allocator_extension.h" | 12 #include "base/allocator/allocator_extension.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
15 #include "base/location.h" | 15 #include "base/location.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/macros.h" |
17 #include "base/memory/discardable_memory_allocator.h" | 18 #include "base/memory/discardable_memory_allocator.h" |
18 #include "base/memory/shared_memory.h" | 19 #include "base/memory/shared_memory.h" |
19 #include "base/metrics/field_trial.h" | 20 #include "base/metrics/field_trial.h" |
20 #include "base/metrics/histogram.h" | 21 #include "base/metrics/histogram.h" |
21 #include "base/path_service.h" | 22 #include "base/path_service.h" |
22 #include "base/single_thread_task_runner.h" | 23 #include "base/single_thread_task_runner.h" |
23 #include "base/strings/string16.h" | 24 #include "base/strings/string16.h" |
24 #include "base/strings/string_number_conversions.h" | 25 #include "base/strings/string_number_conversions.h" |
25 #include "base/strings/string_split.h" | 26 #include "base/strings/string_split.h" |
26 #include "base/strings/string_tokenizer.h" | 27 #include "base/strings/string_tokenizer.h" |
27 #include "base/strings/sys_string_conversions.h" | 28 #include "base/strings/sys_string_conversions.h" |
28 #include "base/strings/utf_string_conversions.h" | 29 #include "base/strings/utf_string_conversions.h" |
29 #include "base/thread_task_runner_handle.h" | 30 #include "base/thread_task_runner_handle.h" |
30 #include "base/threading/simple_thread.h" | 31 #include "base/threading/simple_thread.h" |
31 #include "base/threading/thread_local.h" | 32 #include "base/threading/thread_local.h" |
32 #include "base/threading/thread_restrictions.h" | 33 #include "base/threading/thread_restrictions.h" |
33 #include "base/trace_event/memory_dump_manager.h" | 34 #include "base/trace_event/memory_dump_manager.h" |
34 #include "base/trace_event/trace_event.h" | 35 #include "base/trace_event/trace_event.h" |
35 #include "base/values.h" | 36 #include "base/values.h" |
| 37 #include "build/build_config.h" |
36 #include "cc/base/histograms.h" | 38 #include "cc/base/histograms.h" |
37 #include "cc/base/switches.h" | 39 #include "cc/base/switches.h" |
38 #include "cc/blink/web_external_bitmap_impl.h" | 40 #include "cc/blink/web_external_bitmap_impl.h" |
39 #include "cc/blink/web_layer_impl.h" | 41 #include "cc/blink/web_layer_impl.h" |
40 #include "cc/layers/layer_settings.h" | 42 #include "cc/layers/layer_settings.h" |
41 #include "cc/raster/task_graph_runner.h" | 43 #include "cc/raster/task_graph_runner.h" |
42 #include "cc/trees/layer_tree_host_common.h" | 44 #include "cc/trees/layer_tree_host_common.h" |
43 #include "cc/trees/layer_tree_settings.h" | 45 #include "cc/trees/layer_tree_settings.h" |
44 #include "components/scheduler/child/webthread_base.h" | 46 #include "components/scheduler/child/webthread_base.h" |
45 #include "components/scheduler/renderer/renderer_scheduler.h" | 47 #include "components/scheduler/renderer/renderer_scheduler.h" |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 using blink::WebRuntimeFeatures; | 217 using blink::WebRuntimeFeatures; |
216 using blink::WebScriptController; | 218 using blink::WebScriptController; |
217 using blink::WebSecurityPolicy; | 219 using blink::WebSecurityPolicy; |
218 using blink::WebString; | 220 using blink::WebString; |
219 using blink::WebView; | 221 using blink::WebView; |
220 | 222 |
221 namespace content { | 223 namespace content { |
222 | 224 |
223 namespace { | 225 namespace { |
224 | 226 |
225 const int64 kInitialIdleHandlerDelayMs = 1000; | 227 const int64_t kInitialIdleHandlerDelayMs = 1000; |
226 const int64 kLongIdleHandlerDelayMs = 30*1000; | 228 const int64_t kLongIdleHandlerDelayMs = 30 * 1000; |
227 | 229 |
228 #if defined(OS_ANDROID) | 230 #if defined(OS_ANDROID) |
229 // On Android, resource messages can each take ~1.5ms to dispatch on the browser | 231 // On Android, resource messages can each take ~1.5ms to dispatch on the browser |
230 // IO thread. Limiting the message rate to 3/frame at 60hz ensures that the | 232 // IO thread. Limiting the message rate to 3/frame at 60hz ensures that the |
231 // induced work takes but a fraction (~1/4) of the overall frame budget. | 233 // induced work takes but a fraction (~1/4) of the overall frame budget. |
232 const int kMaxResourceRequestsPerFlushWhenThrottled = 3; | 234 const int kMaxResourceRequestsPerFlushWhenThrottled = 3; |
233 #else | 235 #else |
234 const int kMaxResourceRequestsPerFlushWhenThrottled = 8; | 236 const int kMaxResourceRequestsPerFlushWhenThrottled = 8; |
235 #endif | 237 #endif |
236 const double kThrottledResourceRequestFlushPeriodS = 1. / 60.; | 238 const double kThrottledResourceRequestFlushPeriodS = 1. / 60.; |
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1027 | 1029 |
1028 IPC::SyncMessageFilter* RenderThreadImpl::GetSyncMessageFilter() { | 1030 IPC::SyncMessageFilter* RenderThreadImpl::GetSyncMessageFilter() { |
1029 return sync_message_filter(); | 1031 return sync_message_filter(); |
1030 } | 1032 } |
1031 | 1033 |
1032 scoped_refptr<base::SingleThreadTaskRunner> | 1034 scoped_refptr<base::SingleThreadTaskRunner> |
1033 RenderThreadImpl::GetIOMessageLoopProxy() { | 1035 RenderThreadImpl::GetIOMessageLoopProxy() { |
1034 return ChildProcess::current()->io_task_runner(); | 1036 return ChildProcess::current()->io_task_runner(); |
1035 } | 1037 } |
1036 | 1038 |
1037 void RenderThreadImpl::AddRoute(int32 routing_id, IPC::Listener* listener) { | 1039 void RenderThreadImpl::AddRoute(int32_t routing_id, IPC::Listener* listener) { |
1038 ChildThreadImpl::GetRouter()->AddRoute(routing_id, listener); | 1040 ChildThreadImpl::GetRouter()->AddRoute(routing_id, listener); |
1039 PendingRenderFrameConnectMap::iterator it = | 1041 PendingRenderFrameConnectMap::iterator it = |
1040 pending_render_frame_connects_.find(routing_id); | 1042 pending_render_frame_connects_.find(routing_id); |
1041 if (it == pending_render_frame_connects_.end()) | 1043 if (it == pending_render_frame_connects_.end()) |
1042 return; | 1044 return; |
1043 | 1045 |
1044 RenderFrameImpl* frame = RenderFrameImpl::FromRoutingID(routing_id); | 1046 RenderFrameImpl* frame = RenderFrameImpl::FromRoutingID(routing_id); |
1045 if (!frame) | 1047 if (!frame) |
1046 return; | 1048 return; |
1047 | 1049 |
1048 scoped_refptr<PendingRenderFrameConnect> connection(it->second); | 1050 scoped_refptr<PendingRenderFrameConnect> connection(it->second); |
1049 mojo::InterfaceRequest<mojo::ServiceProvider> services( | 1051 mojo::InterfaceRequest<mojo::ServiceProvider> services( |
1050 connection->services().Pass()); | 1052 connection->services().Pass()); |
1051 mojo::ServiceProviderPtr exposed_services( | 1053 mojo::ServiceProviderPtr exposed_services( |
1052 connection->exposed_services().Pass()); | 1054 connection->exposed_services().Pass()); |
1053 exposed_services.set_connection_error_handler(mojo::Closure()); | 1055 exposed_services.set_connection_error_handler(mojo::Closure()); |
1054 pending_render_frame_connects_.erase(it); | 1056 pending_render_frame_connects_.erase(it); |
1055 | 1057 |
1056 frame->BindServiceRegistry(services.Pass(), exposed_services.Pass()); | 1058 frame->BindServiceRegistry(services.Pass(), exposed_services.Pass()); |
1057 } | 1059 } |
1058 | 1060 |
1059 void RenderThreadImpl::RemoveRoute(int32 routing_id) { | 1061 void RenderThreadImpl::RemoveRoute(int32_t routing_id) { |
1060 ChildThreadImpl::GetRouter()->RemoveRoute(routing_id); | 1062 ChildThreadImpl::GetRouter()->RemoveRoute(routing_id); |
1061 } | 1063 } |
1062 | 1064 |
1063 void RenderThreadImpl::AddEmbeddedWorkerRoute(int32 routing_id, | 1065 void RenderThreadImpl::AddEmbeddedWorkerRoute(int32_t routing_id, |
1064 IPC::Listener* listener) { | 1066 IPC::Listener* listener) { |
1065 AddRoute(routing_id, listener); | 1067 AddRoute(routing_id, listener); |
1066 if (devtools_agent_message_filter_.get()) { | 1068 if (devtools_agent_message_filter_.get()) { |
1067 devtools_agent_message_filter_->AddEmbeddedWorkerRouteOnMainThread( | 1069 devtools_agent_message_filter_->AddEmbeddedWorkerRouteOnMainThread( |
1068 routing_id); | 1070 routing_id); |
1069 } | 1071 } |
1070 } | 1072 } |
1071 | 1073 |
1072 void RenderThreadImpl::RemoveEmbeddedWorkerRoute(int32 routing_id) { | 1074 void RenderThreadImpl::RemoveEmbeddedWorkerRoute(int32_t routing_id) { |
1073 RemoveRoute(routing_id); | 1075 RemoveRoute(routing_id); |
1074 if (devtools_agent_message_filter_.get()) { | 1076 if (devtools_agent_message_filter_.get()) { |
1075 devtools_agent_message_filter_->RemoveEmbeddedWorkerRouteOnMainThread( | 1077 devtools_agent_message_filter_->RemoveEmbeddedWorkerRouteOnMainThread( |
1076 routing_id); | 1078 routing_id); |
1077 } | 1079 } |
1078 } | 1080 } |
1079 | 1081 |
1080 void RenderThreadImpl::RegisterPendingRenderFrameConnect( | 1082 void RenderThreadImpl::RegisterPendingRenderFrameConnect( |
1081 int routing_id, | 1083 int routing_id, |
1082 mojo::InterfaceRequest<mojo::ServiceProvider> services, | 1084 mojo::InterfaceRequest<mojo::ServiceProvider> services, |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1326 | 1328 |
1327 cc::SharedBitmapManager* RenderThreadImpl::GetSharedBitmapManager() { | 1329 cc::SharedBitmapManager* RenderThreadImpl::GetSharedBitmapManager() { |
1328 return shared_bitmap_manager(); | 1330 return shared_bitmap_manager(); |
1329 } | 1331 } |
1330 | 1332 |
1331 void RenderThreadImpl::RegisterExtension(v8::Extension* extension) { | 1333 void RenderThreadImpl::RegisterExtension(v8::Extension* extension) { |
1332 EnsureWebKitInitialized(); | 1334 EnsureWebKitInitialized(); |
1333 WebScriptController::registerExtension(extension); | 1335 WebScriptController::registerExtension(extension); |
1334 } | 1336 } |
1335 | 1337 |
1336 void RenderThreadImpl::ScheduleIdleHandler(int64 initial_delay_ms) { | 1338 void RenderThreadImpl::ScheduleIdleHandler(int64_t initial_delay_ms) { |
1337 idle_notification_delay_in_ms_ = initial_delay_ms; | 1339 idle_notification_delay_in_ms_ = initial_delay_ms; |
1338 idle_timer_.Stop(); | 1340 idle_timer_.Stop(); |
1339 idle_timer_.Start(FROM_HERE, | 1341 idle_timer_.Start(FROM_HERE, |
1340 base::TimeDelta::FromMilliseconds(initial_delay_ms), | 1342 base::TimeDelta::FromMilliseconds(initial_delay_ms), |
1341 this, &RenderThreadImpl::IdleHandler); | 1343 this, &RenderThreadImpl::IdleHandler); |
1342 } | 1344 } |
1343 | 1345 |
1344 void RenderThreadImpl::IdleHandler() { | 1346 void RenderThreadImpl::IdleHandler() { |
1345 bool run_in_foreground_tab = (widget_count_ > hidden_widget_count_) && | 1347 bool run_in_foreground_tab = (widget_count_ > hidden_widget_count_) && |
1346 GetContentClient()->renderer()-> | 1348 GetContentClient()->renderer()-> |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1380 idle_notification_delay_in_ms_ + | 1382 idle_notification_delay_in_ms_ + |
1381 1000000 / (idle_notification_delay_in_ms_ + 2000))); | 1383 1000000 / (idle_notification_delay_in_ms_ + 2000))); |
1382 | 1384 |
1383 } else { | 1385 } else { |
1384 idle_timer_.Stop(); | 1386 idle_timer_.Stop(); |
1385 } | 1387 } |
1386 | 1388 |
1387 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, IdleNotification()); | 1389 FOR_EACH_OBSERVER(RenderProcessObserver, observers_, IdleNotification()); |
1388 } | 1390 } |
1389 | 1391 |
1390 int64 RenderThreadImpl::GetIdleNotificationDelayInMs() const { | 1392 int64_t RenderThreadImpl::GetIdleNotificationDelayInMs() const { |
1391 return idle_notification_delay_in_ms_; | 1393 return idle_notification_delay_in_ms_; |
1392 } | 1394 } |
1393 | 1395 |
1394 void RenderThreadImpl::SetIdleNotificationDelayInMs( | 1396 void RenderThreadImpl::SetIdleNotificationDelayInMs( |
1395 int64 idle_notification_delay_in_ms) { | 1397 int64_t idle_notification_delay_in_ms) { |
1396 idle_notification_delay_in_ms_ = idle_notification_delay_in_ms; | 1398 idle_notification_delay_in_ms_ = idle_notification_delay_in_ms; |
1397 } | 1399 } |
1398 | 1400 |
1399 void RenderThreadImpl::UpdateHistograms(int sequence_number) { | 1401 void RenderThreadImpl::UpdateHistograms(int sequence_number) { |
1400 child_histogram_message_filter()->SendHistograms(sequence_number); | 1402 child_histogram_message_filter()->SendHistograms(sequence_number); |
1401 } | 1403 } |
1402 | 1404 |
1403 int RenderThreadImpl::PostTaskToAllWebWorkers(const base::Closure& closure) { | 1405 int RenderThreadImpl::PostTaskToAllWebWorkers(const base::Closure& closure) { |
1404 return WorkerThreadRegistry::Instance()->PostTaskToAllThreads(closure); | 1406 return WorkerThreadRegistry::Instance()->PostTaskToAllThreads(closure); |
1405 } | 1407 } |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1653 RenderThreadImpl::GetIOThreadTaskRunner() { | 1655 RenderThreadImpl::GetIOThreadTaskRunner() { |
1654 return io_thread_task_runner_; | 1656 return io_thread_task_runner_; |
1655 } | 1657 } |
1656 | 1658 |
1657 scoped_ptr<base::SharedMemory> RenderThreadImpl::AllocateSharedMemory( | 1659 scoped_ptr<base::SharedMemory> RenderThreadImpl::AllocateSharedMemory( |
1658 size_t size) { | 1660 size_t size) { |
1659 return HostAllocateSharedMemoryBuffer(size); | 1661 return HostAllocateSharedMemoryBuffer(size); |
1660 } | 1662 } |
1661 | 1663 |
1662 CreateCommandBufferResult RenderThreadImpl::CreateViewCommandBuffer( | 1664 CreateCommandBufferResult RenderThreadImpl::CreateViewCommandBuffer( |
1663 int32 surface_id, | 1665 int32_t surface_id, |
1664 const GPUCreateCommandBufferConfig& init_params, | 1666 const GPUCreateCommandBufferConfig& init_params, |
1665 int32 route_id) { | 1667 int32_t route_id) { |
1666 NOTREACHED(); | 1668 NOTREACHED(); |
1667 return CREATE_COMMAND_BUFFER_FAILED; | 1669 return CREATE_COMMAND_BUFFER_FAILED; |
1668 } | 1670 } |
1669 | 1671 |
1670 void RenderThreadImpl::DoNotNotifyWebKitOfModalLoop() { | 1672 void RenderThreadImpl::DoNotNotifyWebKitOfModalLoop() { |
1671 notify_webkit_of_modal_loop_ = false; | 1673 notify_webkit_of_modal_loop_ = false; |
1672 } | 1674 } |
1673 | 1675 |
1674 bool RenderThreadImpl::OnControlMessageReceived(const IPC::Message& msg) { | 1676 bool RenderThreadImpl::OnControlMessageReceived(const IPC::Message& msg) { |
1675 base::ObserverListBase<RenderProcessObserver>::Iterator it(&observers_); | 1677 base::ObserverListBase<RenderProcessObserver>::Iterator it(&observers_); |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2091 } | 2093 } |
2092 | 2094 |
2093 void RenderThreadImpl::PendingRenderFrameConnect::OnConnectionError() { | 2095 void RenderThreadImpl::PendingRenderFrameConnect::OnConnectionError() { |
2094 size_t erased = | 2096 size_t erased = |
2095 RenderThreadImpl::current()->pending_render_frame_connects_.erase( | 2097 RenderThreadImpl::current()->pending_render_frame_connects_.erase( |
2096 routing_id_); | 2098 routing_id_); |
2097 DCHECK_EQ(1u, erased); | 2099 DCHECK_EQ(1u, erased); |
2098 } | 2100 } |
2099 | 2101 |
2100 } // namespace content | 2102 } // namespace content |
OLD | NEW |