Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: content/renderer/render_thread_impl.cc

Issue 363383002: Forward input tasks to the Blink scheduler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix tests. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/renderer/render_thread_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 frame->BindServiceRegistry(request.PassMessagePipe()); 288 frame->BindServiceRegistry(request.PassMessagePipe());
285 } 289 }
286 290
287 virtual void OnConnectionError() OVERRIDE { delete this; } 291 virtual void OnConnectionError() OVERRIDE { delete this; }
288 }; 292 };
289 293
290 void CreateRenderFrameSetup(mojo::InterfaceRequest<RenderFrameSetup> request) { 294 void CreateRenderFrameSetup(mojo::InterfaceRequest<RenderFrameSetup> request) {
291 mojo::BindToRequest(new RenderFrameSetupImpl(), &request); 295 mojo::BindToRequest(new RenderFrameSetupImpl(), &request);
292 } 296 }
293 297
298 // Helper for forwarding posted tasks into different WebSchedulerProxy queues.
299 template <void (blink::WebSchedulerProxy::*ProxyFunction)(
300 const blink::WebTraceLocation&,
301 blink::WebThread::Task*)>
302 class SchedulerProxyTaskRunner : public base::SingleThreadTaskRunner {
303 public:
304 SchedulerProxyTaskRunner()
305 : scheduler_proxy_(blink::WebSchedulerProxy::create()),
306 main_thread_id_(base::PlatformThread::CurrentId()) {}
307
308 virtual bool PostDelayedTask(const tracked_objects::Location& from_here,
309 const base::Closure& task,
310 base::TimeDelta delay) OVERRIDE {
311 DCHECK(delay == base::TimeDelta());
312 blink::WebTraceLocation location(from_here.function_name(),
313 from_here.file_name());
314 (scheduler_proxy_.*ProxyFunction)(location, new TaskAdapter(task));
jamesr 2014/07/22 01:07:23 hm, so another malloc/free pair for every task we
Sami 2014/07/22 16:24:33 Yeah :( Both of these are a consequence of the fac
315 return true;
316 }
317
318 virtual bool PostNonNestableDelayedTask(
319 const tracked_objects::Location& from_here,
320 const base::Closure& task,
321 base::TimeDelta delay) OVERRIDE {
322 NOTREACHED();
323 return false;
324 }
325
326 virtual bool RunsTasksOnCurrentThread() const OVERRIDE {
327 return base::PlatformThread::CurrentId() == main_thread_id_;
328 }
329
330 protected:
331 virtual ~SchedulerProxyTaskRunner() {}
332
333 private:
334 class TaskAdapter : public blink::WebThread::Task {
335 public:
336 explicit TaskAdapter(const base::Closure& function) : function_(function) {}
337 virtual ~TaskAdapter() {}
338
339 virtual void run() OVERRIDE { function_.Run(); }
jamesr 2014/07/22 01:07:23 and an extra closure wrapper. hmmm
340
341 private:
342 base::Closure function_;
343 };
344
345 blink::WebSchedulerProxy scheduler_proxy_;
346 const base::PlatformThreadId main_thread_id_;
347
348 DISALLOW_COPY_AND_ASSIGN(SchedulerProxyTaskRunner);
349 };
350
294 } // namespace 351 } // namespace
295 352
296 // For measuring memory usage after each task. Behind a command line flag. 353 // For measuring memory usage after each task. Behind a command line flag.
297 class MemoryObserver : public base::MessageLoop::TaskObserver { 354 class MemoryObserver : public base::MessageLoop::TaskObserver {
298 public: 355 public:
299 MemoryObserver() {} 356 MemoryObserver() {}
300 virtual ~MemoryObserver() {} 357 virtual ~MemoryObserver() {}
301 358
302 virtual void WillProcessTask(const base::PendingTask& pending_task) OVERRIDE { 359 virtual void WillProcessTask(const base::PendingTask& pending_task) OVERRIDE {
303 } 360 }
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 ResourceDispatcherDelegate* delegate) { 859 ResourceDispatcherDelegate* delegate) {
803 resource_dispatcher()->set_delegate(delegate); 860 resource_dispatcher()->set_delegate(delegate);
804 } 861 }
805 862
806 void RenderThreadImpl::EnsureWebKitInitialized() { 863 void RenderThreadImpl::EnsureWebKitInitialized() {
807 if (webkit_platform_support_) 864 if (webkit_platform_support_)
808 return; 865 return;
809 866
810 webkit_platform_support_.reset(new RendererWebKitPlatformSupportImpl); 867 webkit_platform_support_.reset(new RendererWebKitPlatformSupportImpl);
811 blink::initialize(webkit_platform_support_.get()); 868 blink::initialize(webkit_platform_support_.get());
869 main_thread_compositor_task_runner_ =
870 make_scoped_refptr(new SchedulerProxyTaskRunner<
871 &blink::WebSchedulerProxy::postCompositorTask>());
872 main_thread_input_task_runner_ = make_scoped_refptr(
873 new SchedulerProxyTaskRunner<&blink::WebSchedulerProxy::postInputTask>());
812 874
813 v8::Isolate* isolate = blink::mainThreadIsolate(); 875 v8::Isolate* isolate = blink::mainThreadIsolate();
814 876
815 isolate->SetCounterFunction(base::StatsTable::FindLocation); 877 isolate->SetCounterFunction(base::StatsTable::FindLocation);
816 isolate->SetCreateHistogramFunction(CreateHistogram); 878 isolate->SetCreateHistogramFunction(CreateHistogram);
817 isolate->SetAddHistogramSampleFunction(AddHistogramSample); 879 isolate->SetAddHistogramSampleFunction(AddHistogramSample);
818 880
819 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 881 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
820 882
821 bool enable = !command_line.HasSwitch(switches::kDisableThreadedCompositing); 883 bool enable = !command_line.HasSwitch(switches::kDisableThreadedCompositing);
(...skipping 19 matching lines...) Expand all
841 } 903 }
842 904
843 InputHandlerManagerClient* input_handler_manager_client = NULL; 905 InputHandlerManagerClient* input_handler_manager_client = NULL;
844 #if defined(OS_ANDROID) 906 #if defined(OS_ANDROID)
845 if (SynchronousCompositorFactory* factory = 907 if (SynchronousCompositorFactory* factory =
846 SynchronousCompositorFactory::GetInstance()) { 908 SynchronousCompositorFactory::GetInstance()) {
847 input_handler_manager_client = factory->GetInputHandlerManagerClient(); 909 input_handler_manager_client = factory->GetInputHandlerManagerClient();
848 } 910 }
849 #endif 911 #endif
850 if (!input_handler_manager_client) { 912 if (!input_handler_manager_client) {
851 input_event_filter_ = 913 input_event_filter_ = new InputEventFilter(
852 new InputEventFilter(this, compositor_message_loop_proxy_); 914 this, main_thread_input_task_runner_, compositor_message_loop_proxy_);
853 AddFilter(input_event_filter_.get()); 915 AddFilter(input_event_filter_.get());
854 input_handler_manager_client = input_event_filter_.get(); 916 input_handler_manager_client = input_event_filter_.get();
855 } 917 }
856 input_handler_manager_.reset( 918 input_handler_manager_.reset(
857 new InputHandlerManager(compositor_message_loop_proxy_, 919 new InputHandlerManager(compositor_message_loop_proxy_,
858 input_handler_manager_client)); 920 input_handler_manager_client));
859 } 921 }
860 922
861 scoped_refptr<base::MessageLoopProxy> output_surface_loop; 923 scoped_refptr<base::MessageLoopProxy> output_surface_loop;
862 if (enable) 924 if (enable)
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
1607 hidden_widget_count_--; 1669 hidden_widget_count_--;
1608 1670
1609 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) { 1671 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) {
1610 return; 1672 return;
1611 } 1673 }
1612 1674
1613 ScheduleIdleHandler(kLongIdleHandlerDelayMs); 1675 ScheduleIdleHandler(kLongIdleHandlerDelayMs);
1614 } 1676 }
1615 1677
1616 } // namespace content 1678 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_thread_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698