Chromium Code Reviews| 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/debug/trace_event.h" | 14 #include "base/debug/trace_event.h" |
| 15 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/memory/discardable_memory.h" | 17 #include "base/memory/discardable_memory.h" |
| 18 #include "base/memory/shared_memory.h" | 18 #include "base/memory/shared_memory.h" |
| 19 #include "base/metrics/field_trial.h" | 19 #include "base/metrics/field_trial.h" |
| 20 #include "base/metrics/histogram.h" | 20 #include "base/metrics/histogram.h" |
| 21 #include "base/metrics/stats_table.h" | 21 #include "base/metrics/stats_table.h" |
| 22 #include "base/path_service.h" | 22 #include "base/path_service.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_tokenizer.h" | 26 #include "base/strings/string_tokenizer.h" |
| 26 #include "base/strings/utf_string_conversions.h" | 27 #include "base/strings/utf_string_conversions.h" |
| 27 #include "base/threading/thread_local.h" | 28 #include "base/threading/thread_local.h" |
| 28 #include "base/threading/thread_restrictions.h" | 29 #include "base/threading/thread_restrictions.h" |
| 29 #include "base/values.h" | 30 #include "base/values.h" |
| 30 #include "cc/base/switches.h" | 31 #include "cc/base/switches.h" |
| 31 #include "cc/resources/raster_worker_pool.h" | 32 #include "cc/resources/raster_worker_pool.h" |
| 32 #include "content/child/appcache/appcache_dispatcher.h" | 33 #include "content/child/appcache/appcache_dispatcher.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 #include "ipc/ipc_channel_handle.h" | 101 #include "ipc/ipc_channel_handle.h" |
| 101 #include "ipc/ipc_forwarding_message_filter.h" | 102 #include "ipc/ipc_forwarding_message_filter.h" |
| 102 #include "ipc/ipc_platform_file.h" | 103 #include "ipc/ipc_platform_file.h" |
| 103 #include "media/base/audio_hardware_config.h" | 104 #include "media/base/audio_hardware_config.h" |
| 104 #include "media/base/media.h" | 105 #include "media/base/media.h" |
| 105 #include "media/filters/gpu_video_accelerator_factories.h" | 106 #include "media/filters/gpu_video_accelerator_factories.h" |
| 106 #include "mojo/common/common_type_converters.h" | 107 #include "mojo/common/common_type_converters.h" |
| 107 #include "net/base/net_errors.h" | 108 #include "net/base/net_errors.h" |
| 108 #include "net/base/net_util.h" | 109 #include "net/base/net_util.h" |
| 109 #include "skia/ext/event_tracer_impl.h" | 110 #include "skia/ext/event_tracer_impl.h" |
| 111 #include "third_party/WebKit/public/platform/WebSchedulerProxy.h" | |
| 110 #include "third_party/WebKit/public/platform/WebString.h" | 112 #include "third_party/WebKit/public/platform/WebString.h" |
| 113 #include "third_party/WebKit/public/platform/WebThread.h" | |
| 114 #include "third_party/WebKit/public/platform/WebTraceLocation.h" | |
| 111 #include "third_party/WebKit/public/web/WebColorName.h" | 115 #include "third_party/WebKit/public/web/WebColorName.h" |
| 112 #include "third_party/WebKit/public/web/WebDatabase.h" | 116 #include "third_party/WebKit/public/web/WebDatabase.h" |
| 113 #include "third_party/WebKit/public/web/WebDocument.h" | 117 #include "third_party/WebKit/public/web/WebDocument.h" |
| 114 #include "third_party/WebKit/public/web/WebFrame.h" | 118 #include "third_party/WebKit/public/web/WebFrame.h" |
| 115 #include "third_party/WebKit/public/web/WebImageCache.h" | 119 #include "third_party/WebKit/public/web/WebImageCache.h" |
| 116 #include "third_party/WebKit/public/web/WebKit.h" | 120 #include "third_party/WebKit/public/web/WebKit.h" |
| 117 #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h" | 121 #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h" |
| 118 #include "third_party/WebKit/public/web/WebPopupMenu.h" | 122 #include "third_party/WebKit/public/web/WebPopupMenu.h" |
| 119 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 123 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
| 120 #include "third_party/WebKit/public/web/WebScriptController.h" | 124 #include "third_party/WebKit/public/web/WebScriptController.h" |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 frame->BindServiceRegistry(request.PassMessagePipe()); | 294 frame->BindServiceRegistry(request.PassMessagePipe()); |
| 291 } | 295 } |
| 292 }; | 296 }; |
| 293 | 297 |
| 294 void CreateRenderFrameSetup(mojo::InterfaceRequest<RenderFrameSetup> request) { | 298 void CreateRenderFrameSetup(mojo::InterfaceRequest<RenderFrameSetup> request) { |
| 295 mojo::BindToRequest(new RenderFrameSetupImpl(), &request); | 299 mojo::BindToRequest(new RenderFrameSetupImpl(), &request); |
| 296 } | 300 } |
| 297 | 301 |
| 298 } // namespace | 302 } // namespace |
| 299 | 303 |
| 304 class SchedulerProxyTaskRunnerBase : public base::SingleThreadTaskRunner { | |
| 305 public: | |
| 306 SchedulerProxyTaskRunnerBase() | |
| 307 : main_thread_id_(base::PlatformThread::CurrentId()), | |
| 308 scheduler_proxy_(blink::WebSchedulerProxy::create()), | |
| 309 fallback_task_runner_(base::MessageLoopProxy::current()), | |
| 310 is_active_(true) {} | |
| 311 | |
| 312 // base::SingleThreadTaskRunner implementation: | |
| 313 virtual bool RunsTasksOnCurrentThread() const OVERRIDE { | |
| 314 return base::PlatformThread::CurrentId() == main_thread_id_; | |
| 315 } | |
| 316 | |
| 317 void Shutdown() { | |
| 318 base::AutoLock lock(scheduler_lock_); | |
| 319 is_active_ = false; | |
| 320 } | |
| 321 | |
| 322 protected: | |
| 323 virtual ~SchedulerProxyTaskRunnerBase() {} | |
| 324 | |
| 325 const base::PlatformThreadId main_thread_id_; | |
| 326 blink::WebSchedulerProxy scheduler_proxy_; | |
| 327 scoped_refptr<base::SingleThreadTaskRunner> fallback_task_runner_; | |
| 328 | |
| 329 bool is_active_; | |
| 330 base::Lock scheduler_lock_; | |
| 331 | |
| 332 DISALLOW_COPY_AND_ASSIGN(SchedulerProxyTaskRunnerBase); | |
| 333 }; | |
| 334 | |
| 335 // Helper for forwarding posted tasks into different WebSchedulerProxy queues. | |
| 336 template <void (blink::WebSchedulerProxy::*ProxyFunction)( | |
| 337 const blink::WebTraceLocation&, | |
| 338 blink::WebThread::Task*)> | |
| 339 class SchedulerProxyTaskRunner : public SchedulerProxyTaskRunnerBase { | |
| 340 public: | |
| 341 SchedulerProxyTaskRunner() {} | |
| 342 | |
| 343 // base::SingleThreadTaskRunner implementation: | |
| 344 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, | |
| 345 const base::Closure& task, | |
| 346 base::TimeDelta delay) OVERRIDE { | |
| 347 DCHECK(delay == base::TimeDelta()); | |
| 348 base::AutoLock lock(scheduler_lock_); | |
| 349 if (!is_active_) | |
| 350 return fallback_task_runner_->PostDelayedTask(from_here, task, delay); | |
|
jamesr
2014/08/07 17:59:24
why do you have a fallback? when is it used? are t
Sami
2014/08/08 11:39:16
I added it as a safe guard based on your comment #
| |
| 351 blink::WebTraceLocation location(from_here.function_name(), | |
| 352 from_here.file_name()); | |
| 353 (scheduler_proxy_.*ProxyFunction)(location, new TaskAdapter(task)); | |
| 354 return true; | |
| 355 } | |
| 356 | |
| 357 virtual bool PostNonNestableDelayedTask( | |
| 358 const tracked_objects::Location& from_here, | |
| 359 const base::Closure& task, | |
| 360 base::TimeDelta delay) OVERRIDE { | |
| 361 NOTREACHED(); | |
| 362 return false; | |
| 363 } | |
| 364 | |
| 365 protected: | |
| 366 virtual ~SchedulerProxyTaskRunner() {} | |
| 367 | |
| 368 private: | |
| 369 class TaskAdapter : public blink::WebThread::Task { | |
| 370 public: | |
| 371 explicit TaskAdapter(const base::Closure& function) : function_(function) {} | |
| 372 virtual ~TaskAdapter() {} | |
| 373 | |
| 374 virtual void run() OVERRIDE { function_.Run(); } | |
| 375 | |
| 376 private: | |
| 377 base::Closure function_; | |
| 378 }; | |
| 379 | |
| 380 DISALLOW_COPY_AND_ASSIGN(SchedulerProxyTaskRunner); | |
| 381 }; | |
| 382 | |
| 300 // For measuring memory usage after each task. Behind a command line flag. | 383 // For measuring memory usage after each task. Behind a command line flag. |
| 301 class MemoryObserver : public base::MessageLoop::TaskObserver { | 384 class MemoryObserver : public base::MessageLoop::TaskObserver { |
| 302 public: | 385 public: |
| 303 MemoryObserver() {} | 386 MemoryObserver() {} |
| 304 virtual ~MemoryObserver() {} | 387 virtual ~MemoryObserver() {} |
| 305 | 388 |
| 306 virtual void WillProcessTask(const base::PendingTask& pending_task) OVERRIDE { | 389 virtual void WillProcessTask(const base::PendingTask& pending_task) OVERRIDE { |
| 307 } | 390 } |
| 308 | 391 |
| 309 virtual void DidProcessTask(const base::PendingTask& pending_task) OVERRIDE { | 392 virtual void DidProcessTask(const base::PendingTask& pending_task) OVERRIDE { |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 629 | 712 |
| 630 // RemoveEmbeddedWorkerRoute may be called while deleting | 713 // RemoveEmbeddedWorkerRoute may be called while deleting |
| 631 // EmbeddedWorkerDispatcher. So it must be deleted before deleting | 714 // EmbeddedWorkerDispatcher. So it must be deleted before deleting |
| 632 // RenderThreadImpl. | 715 // RenderThreadImpl. |
| 633 embedded_worker_dispatcher_.reset(); | 716 embedded_worker_dispatcher_.reset(); |
| 634 | 717 |
| 635 // Ramp down IDB before we ramp down WebKit (and V8), since IDB classes might | 718 // Ramp down IDB before we ramp down WebKit (and V8), since IDB classes might |
| 636 // hold pointers to V8 objects (e.g., via pending requests). | 719 // hold pointers to V8 objects (e.g., via pending requests). |
| 637 main_thread_indexed_db_dispatcher_.reset(); | 720 main_thread_indexed_db_dispatcher_.reset(); |
| 638 | 721 |
| 722 // Stop forwarding tasks to the Blink scheduler. | |
| 723 main_thread_compositor_task_runner_->Shutdown(); | |
| 724 main_thread_input_task_runner_->Shutdown(); | |
| 725 | |
| 639 if (webkit_platform_support_) | 726 if (webkit_platform_support_) |
| 640 blink::shutdown(); | 727 blink::shutdown(); |
| 641 | 728 |
| 642 lazy_tls.Pointer()->Set(NULL); | 729 lazy_tls.Pointer()->Set(NULL); |
| 643 | 730 |
| 644 // TODO(port) | 731 // TODO(port) |
| 645 #if defined(OS_WIN) | 732 #if defined(OS_WIN) |
| 646 // Clean up plugin channels before this thread goes away. | 733 // Clean up plugin channels before this thread goes away. |
| 647 NPChannelBase::CleanupChannels(); | 734 NPChannelBase::CleanupChannels(); |
| 648 #endif | 735 #endif |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 811 ResourceDispatcherDelegate* delegate) { | 898 ResourceDispatcherDelegate* delegate) { |
| 812 resource_dispatcher()->set_delegate(delegate); | 899 resource_dispatcher()->set_delegate(delegate); |
| 813 } | 900 } |
| 814 | 901 |
| 815 void RenderThreadImpl::EnsureWebKitInitialized() { | 902 void RenderThreadImpl::EnsureWebKitInitialized() { |
| 816 if (webkit_platform_support_) | 903 if (webkit_platform_support_) |
| 817 return; | 904 return; |
| 818 | 905 |
| 819 webkit_platform_support_.reset(new RendererWebKitPlatformSupportImpl); | 906 webkit_platform_support_.reset(new RendererWebKitPlatformSupportImpl); |
| 820 blink::initialize(webkit_platform_support_.get()); | 907 blink::initialize(webkit_platform_support_.get()); |
| 908 main_thread_compositor_task_runner_ = | |
| 909 make_scoped_refptr(new SchedulerProxyTaskRunner< | |
| 910 &blink::WebSchedulerProxy::postCompositorTask>()); | |
| 911 main_thread_input_task_runner_ = make_scoped_refptr( | |
| 912 new SchedulerProxyTaskRunner<&blink::WebSchedulerProxy::postInputTask>()); | |
| 821 | 913 |
| 822 v8::Isolate* isolate = blink::mainThreadIsolate(); | 914 v8::Isolate* isolate = blink::mainThreadIsolate(); |
| 823 | 915 |
| 824 isolate->SetCounterFunction(base::StatsTable::FindLocation); | 916 isolate->SetCounterFunction(base::StatsTable::FindLocation); |
| 825 isolate->SetCreateHistogramFunction(CreateHistogram); | 917 isolate->SetCreateHistogramFunction(CreateHistogram); |
| 826 isolate->SetAddHistogramSampleFunction(AddHistogramSample); | 918 isolate->SetAddHistogramSampleFunction(AddHistogramSample); |
| 827 | 919 |
| 828 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 920 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 829 | 921 |
| 830 bool enable = !command_line.HasSwitch(switches::kDisableThreadedCompositing); | 922 bool enable = !command_line.HasSwitch(switches::kDisableThreadedCompositing); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 850 } | 942 } |
| 851 | 943 |
| 852 InputHandlerManagerClient* input_handler_manager_client = NULL; | 944 InputHandlerManagerClient* input_handler_manager_client = NULL; |
| 853 #if defined(OS_ANDROID) | 945 #if defined(OS_ANDROID) |
| 854 if (SynchronousCompositorFactory* factory = | 946 if (SynchronousCompositorFactory* factory = |
| 855 SynchronousCompositorFactory::GetInstance()) { | 947 SynchronousCompositorFactory::GetInstance()) { |
| 856 input_handler_manager_client = factory->GetInputHandlerManagerClient(); | 948 input_handler_manager_client = factory->GetInputHandlerManagerClient(); |
| 857 } | 949 } |
| 858 #endif | 950 #endif |
| 859 if (!input_handler_manager_client) { | 951 if (!input_handler_manager_client) { |
| 860 input_event_filter_ = | 952 input_event_filter_ = new InputEventFilter( |
| 861 new InputEventFilter(this, compositor_message_loop_proxy_); | 953 this, main_thread_input_task_runner_, compositor_message_loop_proxy_); |
| 862 AddFilter(input_event_filter_.get()); | 954 AddFilter(input_event_filter_.get()); |
| 863 input_handler_manager_client = input_event_filter_.get(); | 955 input_handler_manager_client = input_event_filter_.get(); |
| 864 } | 956 } |
| 865 input_handler_manager_.reset( | 957 input_handler_manager_.reset( |
| 866 new InputHandlerManager(compositor_message_loop_proxy_, | 958 new InputHandlerManager(compositor_message_loop_proxy_, |
| 867 input_handler_manager_client)); | 959 input_handler_manager_client)); |
| 868 } | 960 } |
| 869 | 961 |
| 870 scoped_refptr<base::MessageLoopProxy> output_surface_loop; | 962 scoped_refptr<base::MessageLoopProxy> output_surface_loop; |
| 871 if (enable) | 963 if (enable) |
| (...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1567 media_thread_->Start(); | 1659 media_thread_->Start(); |
| 1568 | 1660 |
| 1569 #if defined(OS_ANDROID) | 1661 #if defined(OS_ANDROID) |
| 1570 renderer_demuxer_ = new RendererDemuxerAndroid(); | 1662 renderer_demuxer_ = new RendererDemuxerAndroid(); |
| 1571 AddFilter(renderer_demuxer_.get()); | 1663 AddFilter(renderer_demuxer_.get()); |
| 1572 #endif | 1664 #endif |
| 1573 } | 1665 } |
| 1574 return media_thread_->message_loop_proxy(); | 1666 return media_thread_->message_loop_proxy(); |
| 1575 } | 1667 } |
| 1576 | 1668 |
| 1669 scoped_refptr<base::SingleThreadTaskRunner> | |
| 1670 RenderThreadImpl::MainThreadCompositorTaskRunner() const { | |
| 1671 return main_thread_compositor_task_runner_; | |
| 1672 } | |
| 1673 | |
| 1577 void RenderThreadImpl::SetFlingCurveParameters( | 1674 void RenderThreadImpl::SetFlingCurveParameters( |
| 1578 const std::vector<float>& new_touchpad, | 1675 const std::vector<float>& new_touchpad, |
| 1579 const std::vector<float>& new_touchscreen) { | 1676 const std::vector<float>& new_touchscreen) { |
| 1580 webkit_platform_support_->SetFlingCurveParameters(new_touchpad, | 1677 webkit_platform_support_->SetFlingCurveParameters(new_touchpad, |
| 1581 new_touchscreen); | 1678 new_touchscreen); |
| 1582 | 1679 |
| 1583 } | 1680 } |
| 1584 | 1681 |
| 1585 void RenderThreadImpl::SampleGamepads(blink::WebGamepads* data) { | 1682 void RenderThreadImpl::SampleGamepads(blink::WebGamepads* data) { |
| 1586 gamepad_shared_memory_reader_->SampleGamepads(*data); | 1683 gamepad_shared_memory_reader_->SampleGamepads(*data); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 1613 hidden_widget_count_--; | 1710 hidden_widget_count_--; |
| 1614 | 1711 |
| 1615 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) { | 1712 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) { |
| 1616 return; | 1713 return; |
| 1617 } | 1714 } |
| 1618 | 1715 |
| 1619 ScheduleIdleHandler(kLongIdleHandlerDelayMs); | 1716 ScheduleIdleHandler(kLongIdleHandlerDelayMs); |
| 1620 } | 1717 } |
| 1621 | 1718 |
| 1622 } // namespace content | 1719 } // namespace content |
| OLD | NEW |