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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 #include "ipc/ipc_channel_handle.h" | 103 #include "ipc/ipc_channel_handle.h" |
| 103 #include "ipc/ipc_forwarding_message_filter.h" | 104 #include "ipc/ipc_forwarding_message_filter.h" |
| 104 #include "ipc/ipc_platform_file.h" | 105 #include "ipc/ipc_platform_file.h" |
| 105 #include "media/base/audio_hardware_config.h" | 106 #include "media/base/audio_hardware_config.h" |
| 106 #include "media/base/media.h" | 107 #include "media/base/media.h" |
| 107 #include "media/filters/gpu_video_accelerator_factories.h" | 108 #include "media/filters/gpu_video_accelerator_factories.h" |
| 108 #include "mojo/common/common_type_converters.h" | 109 #include "mojo/common/common_type_converters.h" |
| 109 #include "net/base/net_errors.h" | 110 #include "net/base/net_errors.h" |
| 110 #include "net/base/net_util.h" | 111 #include "net/base/net_util.h" |
| 111 #include "skia/ext/event_tracer_impl.h" | 112 #include "skia/ext/event_tracer_impl.h" |
| 113 #include "third_party/WebKit/public/platform/WebSchedulerProxy.h" | |
| 112 #include "third_party/WebKit/public/platform/WebString.h" | 114 #include "third_party/WebKit/public/platform/WebString.h" |
| 115 #include "third_party/WebKit/public/platform/WebThread.h" | |
| 116 #include "third_party/WebKit/public/platform/WebTraceLocation.h" | |
| 113 #include "third_party/WebKit/public/web/WebColorName.h" | 117 #include "third_party/WebKit/public/web/WebColorName.h" |
| 114 #include "third_party/WebKit/public/web/WebDatabase.h" | 118 #include "third_party/WebKit/public/web/WebDatabase.h" |
| 115 #include "third_party/WebKit/public/web/WebDocument.h" | 119 #include "third_party/WebKit/public/web/WebDocument.h" |
| 116 #include "third_party/WebKit/public/web/WebFrame.h" | 120 #include "third_party/WebKit/public/web/WebFrame.h" |
| 117 #include "third_party/WebKit/public/web/WebImageCache.h" | 121 #include "third_party/WebKit/public/web/WebImageCache.h" |
| 118 #include "third_party/WebKit/public/web/WebKit.h" | 122 #include "third_party/WebKit/public/web/WebKit.h" |
| 119 #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h" | 123 #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h" |
| 120 #include "third_party/WebKit/public/web/WebPopupMenu.h" | 124 #include "third_party/WebKit/public/web/WebPopupMenu.h" |
| 121 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 125 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
| 122 #include "third_party/WebKit/public/web/WebScriptController.h" | 126 #include "third_party/WebKit/public/web/WebScriptController.h" |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 | 299 |
| 296 void CreateRenderFrameSetup(mojo::InterfaceRequest<RenderFrameSetup> request) { | 300 void CreateRenderFrameSetup(mojo::InterfaceRequest<RenderFrameSetup> request) { |
| 297 mojo::BindToRequest(new RenderFrameSetupImpl(), &request); | 301 mojo::BindToRequest(new RenderFrameSetupImpl(), &request); |
| 298 } | 302 } |
| 299 | 303 |
| 300 bool ShouldUseMojoChannel() { | 304 bool ShouldUseMojoChannel() { |
| 301 return CommandLine::ForCurrentProcess()->HasSwitch( | 305 return CommandLine::ForCurrentProcess()->HasSwitch( |
| 302 switches::kEnableRendererMojoChannel); | 306 switches::kEnableRendererMojoChannel); |
| 303 } | 307 } |
| 304 | 308 |
| 309 // Helper for forwarding posted tasks into different WebSchedulerProxy queues. | |
|
jamesr
2014/08/08 17:06:49
this belongs in its own .h/.cc and should have som
Sami
2014/08/08 18:40:27
Done.
| |
| 310 template <void (blink::WebSchedulerProxy::*ProxyFunction)( | |
| 311 const blink::WebTraceLocation&, | |
| 312 blink::WebThread::Task*)> | |
| 313 class SchedulerProxyTaskRunner : public base::SingleThreadTaskRunner { | |
| 314 public: | |
| 315 SchedulerProxyTaskRunner() | |
| 316 : main_thread_id_(base::PlatformThread::CurrentId()), | |
| 317 scheduler_proxy_(blink::WebSchedulerProxy::create()) {} | |
| 318 | |
| 319 // base::SingleThreadTaskRunner implementation: | |
| 320 virtual bool RunsTasksOnCurrentThread() const OVERRIDE { | |
| 321 return base::PlatformThread::CurrentId() == main_thread_id_; | |
| 322 } | |
| 323 | |
| 324 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, | |
| 325 const base::Closure& task, | |
| 326 base::TimeDelta delay) OVERRIDE { | |
| 327 DCHECK(RenderThreadImpl::current()); | |
| 328 DCHECK(delay == base::TimeDelta()); | |
| 329 blink::WebTraceLocation location(from_here.function_name(), | |
| 330 from_here.file_name()); | |
|
jamesr
2014/08/08 17:09:01
this isn't a full fidelity copy of a tracked_objec
| |
| 331 (scheduler_proxy_.*ProxyFunction)(location, new TaskAdapter(task)); | |
|
jamesr
2014/08/08 17:52:49
what if you put the original tracked_objects::Loca
| |
| 332 return true; | |
| 333 } | |
| 334 | |
| 335 virtual bool PostNonNestableDelayedTask( | |
| 336 const tracked_objects::Location& from_here, | |
| 337 const base::Closure& task, | |
| 338 base::TimeDelta delay) OVERRIDE { | |
| 339 NOTREACHED(); | |
| 340 return false; | |
| 341 } | |
| 342 | |
| 343 protected: | |
| 344 virtual ~SchedulerProxyTaskRunner() {} | |
| 345 | |
| 346 private: | |
| 347 class TaskAdapter : public blink::WebThread::Task { | |
| 348 public: | |
| 349 explicit TaskAdapter(const base::Closure& function) : function_(function) {} | |
| 350 virtual ~TaskAdapter() {} | |
| 351 | |
| 352 virtual void run() OVERRIDE { function_.Run(); } | |
|
jamesr
2014/08/08 17:06:49
NAK, you should never use OVERRIDE for cross-repos
Sami
2014/08/08 18:40:27
Oops, good catch!
| |
| 353 | |
| 354 private: | |
| 355 base::Closure function_; | |
| 356 }; | |
| 357 | |
| 358 const base::PlatformThreadId main_thread_id_; | |
| 359 blink::WebSchedulerProxy scheduler_proxy_; | |
| 360 | |
| 361 DISALLOW_COPY_AND_ASSIGN(SchedulerProxyTaskRunner); | |
| 362 }; | |
| 363 | |
| 305 } // namespace | 364 } // namespace |
| 306 | 365 |
| 307 // For measuring memory usage after each task. Behind a command line flag. | 366 // For measuring memory usage after each task. Behind a command line flag. |
| 308 class MemoryObserver : public base::MessageLoop::TaskObserver { | 367 class MemoryObserver : public base::MessageLoop::TaskObserver { |
| 309 public: | 368 public: |
| 310 MemoryObserver() {} | 369 MemoryObserver() {} |
| 311 virtual ~MemoryObserver() {} | 370 virtual ~MemoryObserver() {} |
| 312 | 371 |
| 313 virtual void WillProcessTask(const base::PendingTask& pending_task) OVERRIDE { | 372 virtual void WillProcessTask(const base::PendingTask& pending_task) OVERRIDE { |
| 314 } | 373 } |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 637 | 696 |
| 638 // RemoveEmbeddedWorkerRoute may be called while deleting | 697 // RemoveEmbeddedWorkerRoute may be called while deleting |
| 639 // EmbeddedWorkerDispatcher. So it must be deleted before deleting | 698 // EmbeddedWorkerDispatcher. So it must be deleted before deleting |
| 640 // RenderThreadImpl. | 699 // RenderThreadImpl. |
| 641 embedded_worker_dispatcher_.reset(); | 700 embedded_worker_dispatcher_.reset(); |
| 642 | 701 |
| 643 // Ramp down IDB before we ramp down WebKit (and V8), since IDB classes might | 702 // Ramp down IDB before we ramp down WebKit (and V8), since IDB classes might |
| 644 // hold pointers to V8 objects (e.g., via pending requests). | 703 // hold pointers to V8 objects (e.g., via pending requests). |
| 645 main_thread_indexed_db_dispatcher_.reset(); | 704 main_thread_indexed_db_dispatcher_.reset(); |
| 646 | 705 |
| 706 main_thread_compositor_task_runner_ = NULL; | |
| 707 main_thread_input_task_runner_ = NULL; | |
| 708 | |
| 647 if (webkit_platform_support_) | 709 if (webkit_platform_support_) |
| 648 blink::shutdown(); | 710 blink::shutdown(); |
| 649 | 711 |
| 650 lazy_tls.Pointer()->Set(NULL); | 712 lazy_tls.Pointer()->Set(NULL); |
| 651 | 713 |
| 652 // TODO(port) | 714 // TODO(port) |
| 653 #if defined(OS_WIN) | 715 #if defined(OS_WIN) |
| 654 // Clean up plugin channels before this thread goes away. | 716 // Clean up plugin channels before this thread goes away. |
| 655 NPChannelBase::CleanupChannels(); | 717 NPChannelBase::CleanupChannels(); |
| 656 #endif | 718 #endif |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 819 ResourceDispatcherDelegate* delegate) { | 881 ResourceDispatcherDelegate* delegate) { |
| 820 resource_dispatcher()->set_delegate(delegate); | 882 resource_dispatcher()->set_delegate(delegate); |
| 821 } | 883 } |
| 822 | 884 |
| 823 void RenderThreadImpl::EnsureWebKitInitialized() { | 885 void RenderThreadImpl::EnsureWebKitInitialized() { |
| 824 if (webkit_platform_support_) | 886 if (webkit_platform_support_) |
| 825 return; | 887 return; |
| 826 | 888 |
| 827 webkit_platform_support_.reset(new RendererWebKitPlatformSupportImpl); | 889 webkit_platform_support_.reset(new RendererWebKitPlatformSupportImpl); |
| 828 blink::initialize(webkit_platform_support_.get()); | 890 blink::initialize(webkit_platform_support_.get()); |
| 891 main_thread_compositor_task_runner_ = | |
| 892 make_scoped_refptr(new SchedulerProxyTaskRunner< | |
| 893 &blink::WebSchedulerProxy::postCompositorTask>()); | |
| 894 main_thread_input_task_runner_ = make_scoped_refptr( | |
| 895 new SchedulerProxyTaskRunner<&blink::WebSchedulerProxy::postInputTask>()); | |
| 829 | 896 |
| 830 v8::Isolate* isolate = blink::mainThreadIsolate(); | 897 v8::Isolate* isolate = blink::mainThreadIsolate(); |
| 831 | 898 |
| 832 isolate->SetCounterFunction(base::StatsTable::FindLocation); | 899 isolate->SetCounterFunction(base::StatsTable::FindLocation); |
| 833 isolate->SetCreateHistogramFunction(CreateHistogram); | 900 isolate->SetCreateHistogramFunction(CreateHistogram); |
| 834 isolate->SetAddHistogramSampleFunction(AddHistogramSample); | 901 isolate->SetAddHistogramSampleFunction(AddHistogramSample); |
| 835 | 902 |
| 836 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 903 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 837 | 904 |
| 838 bool enable = !command_line.HasSwitch(switches::kDisableThreadedCompositing); | 905 bool enable = !command_line.HasSwitch(switches::kDisableThreadedCompositing); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 858 } | 925 } |
| 859 | 926 |
| 860 InputHandlerManagerClient* input_handler_manager_client = NULL; | 927 InputHandlerManagerClient* input_handler_manager_client = NULL; |
| 861 #if defined(OS_ANDROID) | 928 #if defined(OS_ANDROID) |
| 862 if (SynchronousCompositorFactory* factory = | 929 if (SynchronousCompositorFactory* factory = |
| 863 SynchronousCompositorFactory::GetInstance()) { | 930 SynchronousCompositorFactory::GetInstance()) { |
| 864 input_handler_manager_client = factory->GetInputHandlerManagerClient(); | 931 input_handler_manager_client = factory->GetInputHandlerManagerClient(); |
| 865 } | 932 } |
| 866 #endif | 933 #endif |
| 867 if (!input_handler_manager_client) { | 934 if (!input_handler_manager_client) { |
| 868 input_event_filter_ = | 935 input_event_filter_ = new InputEventFilter( |
| 869 new InputEventFilter(this, compositor_message_loop_proxy_); | 936 this, main_thread_input_task_runner_, compositor_message_loop_proxy_); |
| 870 AddFilter(input_event_filter_.get()); | 937 AddFilter(input_event_filter_.get()); |
| 871 input_handler_manager_client = input_event_filter_.get(); | 938 input_handler_manager_client = input_event_filter_.get(); |
| 872 } | 939 } |
| 873 input_handler_manager_.reset( | 940 input_handler_manager_.reset( |
| 874 new InputHandlerManager(compositor_message_loop_proxy_, | 941 new InputHandlerManager(compositor_message_loop_proxy_, |
| 875 input_handler_manager_client)); | 942 input_handler_manager_client)); |
| 876 } | 943 } |
| 877 | 944 |
| 878 scoped_refptr<base::MessageLoopProxy> output_surface_loop; | 945 scoped_refptr<base::MessageLoopProxy> output_surface_loop; |
| 879 if (enable) | 946 if (enable) |
| (...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1633 hidden_widget_count_--; | 1700 hidden_widget_count_--; |
| 1634 | 1701 |
| 1635 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) { | 1702 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) { |
| 1636 return; | 1703 return; |
| 1637 } | 1704 } |
| 1638 | 1705 |
| 1639 ScheduleIdleHandler(kLongIdleHandlerDelayMs); | 1706 ScheduleIdleHandler(kLongIdleHandlerDelayMs); |
| 1640 } | 1707 } |
| 1641 | 1708 |
| 1642 } // namespace content | 1709 } // namespace content |
| OLD | NEW |