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

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: Cleanup. DefaultMainThreadTaskRunner now dispatches properly. 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
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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 #include "ipc/ipc_channel_handle.h" 100 #include "ipc/ipc_channel_handle.h"
100 #include "ipc/ipc_forwarding_message_filter.h" 101 #include "ipc/ipc_forwarding_message_filter.h"
101 #include "ipc/ipc_platform_file.h" 102 #include "ipc/ipc_platform_file.h"
102 #include "media/base/audio_hardware_config.h" 103 #include "media/base/audio_hardware_config.h"
103 #include "media/base/media.h" 104 #include "media/base/media.h"
104 #include "media/filters/gpu_video_accelerator_factories.h" 105 #include "media/filters/gpu_video_accelerator_factories.h"
105 #include "mojo/common/common_type_converters.h" 106 #include "mojo/common/common_type_converters.h"
106 #include "net/base/net_errors.h" 107 #include "net/base/net_errors.h"
107 #include "net/base/net_util.h" 108 #include "net/base/net_util.h"
108 #include "skia/ext/event_tracer_impl.h" 109 #include "skia/ext/event_tracer_impl.h"
110 #include "third_party/WebKit/public/platform/WebScheduler.h"
109 #include "third_party/WebKit/public/platform/WebString.h" 111 #include "third_party/WebKit/public/platform/WebString.h"
112 #include "third_party/WebKit/public/platform/WebThread.h"
110 #include "third_party/WebKit/public/web/WebColorName.h" 113 #include "third_party/WebKit/public/web/WebColorName.h"
111 #include "third_party/WebKit/public/web/WebDatabase.h" 114 #include "third_party/WebKit/public/web/WebDatabase.h"
112 #include "third_party/WebKit/public/web/WebDocument.h" 115 #include "third_party/WebKit/public/web/WebDocument.h"
113 #include "third_party/WebKit/public/web/WebFrame.h" 116 #include "third_party/WebKit/public/web/WebFrame.h"
114 #include "third_party/WebKit/public/web/WebImageCache.h" 117 #include "third_party/WebKit/public/web/WebImageCache.h"
115 #include "third_party/WebKit/public/web/WebKit.h" 118 #include "third_party/WebKit/public/web/WebKit.h"
116 #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h" 119 #include "third_party/WebKit/public/web/WebNetworkStateNotifier.h"
117 #include "third_party/WebKit/public/web/WebPopupMenu.h" 120 #include "third_party/WebKit/public/web/WebPopupMenu.h"
118 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" 121 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
119 #include "third_party/WebKit/public/web/WebScriptController.h" 122 #include "third_party/WebKit/public/web/WebScriptController.h"
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 frame->BindServiceRegistry(request.PassMessagePipe()); 286 frame->BindServiceRegistry(request.PassMessagePipe());
284 } 287 }
285 288
286 virtual void OnConnectionError() OVERRIDE { delete this; } 289 virtual void OnConnectionError() OVERRIDE { delete this; }
287 }; 290 };
288 291
289 void CreateRenderFrameSetup(mojo::InterfaceRequest<RenderFrameSetup> request) { 292 void CreateRenderFrameSetup(mojo::InterfaceRequest<RenderFrameSetup> request) {
290 mojo::BindToRequest(new RenderFrameSetupImpl(), &request); 293 mojo::BindToRequest(new RenderFrameSetupImpl(), &request);
291 } 294 }
292 295
296 class WebThreadTask: public blink::WebThread::Task {
297 public:
298 explicit WebThreadTask(const base::Closure& function)
299 : m_function(function) {}
300 virtual ~WebThreadTask() {}
301
302 virtual void run() OVERRIDE {
303 m_function.Run();
304 }
305
306 private:
307 base::Closure m_function;
308 };
309
310 class SchedulerCompositorTaskRunner : public cc::MainThreadTaskRunner {
311 public:
312 SchedulerCompositorTaskRunner()
313 : scheduler_(blink::WebScheduler::create()) {}
314
315 virtual void PostBeginMainFrameTask(
316 const tracked_objects::Location& from_here, const base::Closure& task,
317 double frame_time, double deadline, double interval) OVERRIDE {
318 scheduler_.postBeginFrameTask(
319 new WebThreadTask(task), frame_time, deadline, interval);
320 }
321
322 virtual bool PostDelayedTask(
323 const tracked_objects::Location& from_here, const base::Closure& task,
324 base::TimeDelta delay) OVERRIDE {
325 DCHECK(delay == base::TimeDelta());
326 scheduler_.postCompositorTask(new WebThreadTask(task));
327 return true;
328 }
329
330 protected:
331 virtual ~SchedulerCompositorTaskRunner () {}
332
333 private:
334 // TODO: Rename to WebSchedulerProxy.
335 blink::WebScheduler scheduler_;
336 };
337
338 class SchedulerInputTaskRunner : public base::SingleThreadTaskRunner {
339 public:
340 SchedulerInputTaskRunner()
341 : scheduler_(blink::WebScheduler::create()) {}
342
343 virtual bool PostDelayedTask(const tracked_objects::Location& from_here,
344 const base::Closure& task,
345 base::TimeDelta delay) OVERRIDE {
346 DCHECK(delay == base::TimeDelta());
347 scheduler_.postInputTask(new WebThreadTask(task));
348 return true;
349 }
350
351 virtual bool PostNonNestableDelayedTask(
352 const tracked_objects::Location& from_here, const base::Closure& task,
353 base::TimeDelta delay) OVERRIDE {
354 NOTREACHED();
355 return false;
356 }
357
358 virtual bool RunsTasksOnCurrentThread() const OVERRIDE {
359 NOTREACHED();
360 return false;
361 }
362
363 protected:
364 virtual ~SchedulerInputTaskRunner() {}
365
366 private:
367 // TODO: Rename to WebSchedulerProxy.
368 blink::WebScheduler scheduler_;
369 };
370
293 } // namespace 371 } // namespace
294 372
295 RenderThreadImpl::HistogramCustomizer::HistogramCustomizer() { 373 RenderThreadImpl::HistogramCustomizer::HistogramCustomizer() {
296 custom_histograms_.insert("V8.MemoryExternalFragmentationTotal"); 374 custom_histograms_.insert("V8.MemoryExternalFragmentationTotal");
297 custom_histograms_.insert("V8.MemoryHeapSampleTotalCommitted"); 375 custom_histograms_.insert("V8.MemoryHeapSampleTotalCommitted");
298 custom_histograms_.insert("V8.MemoryHeapSampleTotalUsed"); 376 custom_histograms_.insert("V8.MemoryHeapSampleTotalUsed");
299 } 377 }
300 378
301 RenderThreadImpl::HistogramCustomizer::~HistogramCustomizer() {} 379 RenderThreadImpl::HistogramCustomizer::~HistogramCustomizer() {}
302 380
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 ResourceDispatcherDelegate* delegate) { 861 ResourceDispatcherDelegate* delegate) {
784 resource_dispatcher()->set_delegate(delegate); 862 resource_dispatcher()->set_delegate(delegate);
785 } 863 }
786 864
787 void RenderThreadImpl::EnsureWebKitInitialized() { 865 void RenderThreadImpl::EnsureWebKitInitialized() {
788 if (webkit_platform_support_) 866 if (webkit_platform_support_)
789 return; 867 return;
790 868
791 webkit_platform_support_.reset(new RendererWebKitPlatformSupportImpl); 869 webkit_platform_support_.reset(new RendererWebKitPlatformSupportImpl);
792 blink::initialize(webkit_platform_support_.get()); 870 blink::initialize(webkit_platform_support_.get());
871 main_thread_task_runner_ =
872 make_scoped_refptr(new SchedulerCompositorTaskRunner());
873 input_task_runner_ =
874 make_scoped_refptr(new SchedulerInputTaskRunner());
793 875
794 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 876 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
795 877
796 bool enable = command_line.HasSwitch(switches::kEnableThreadedCompositing); 878 bool enable = command_line.HasSwitch(switches::kEnableThreadedCompositing);
797 if (enable) { 879 if (enable) {
798 #if defined(OS_ANDROID) 880 #if defined(OS_ANDROID)
799 if (SynchronousCompositorFactory* factory = 881 if (SynchronousCompositorFactory* factory =
800 SynchronousCompositorFactory::GetInstance()) 882 SynchronousCompositorFactory::GetInstance())
801 compositor_message_loop_proxy_ = 883 compositor_message_loop_proxy_ =
802 factory->GetCompositorMessageLoop(); 884 factory->GetCompositorMessageLoop();
(...skipping 14 matching lines...) Expand all
817 899
818 InputHandlerManagerClient* input_handler_manager_client = NULL; 900 InputHandlerManagerClient* input_handler_manager_client = NULL;
819 #if defined(OS_ANDROID) 901 #if defined(OS_ANDROID)
820 if (SynchronousCompositorFactory* factory = 902 if (SynchronousCompositorFactory* factory =
821 SynchronousCompositorFactory::GetInstance()) { 903 SynchronousCompositorFactory::GetInstance()) {
822 input_handler_manager_client = factory->GetInputHandlerManagerClient(); 904 input_handler_manager_client = factory->GetInputHandlerManagerClient();
823 } 905 }
824 #endif 906 #endif
825 if (!input_handler_manager_client) { 907 if (!input_handler_manager_client) {
826 input_event_filter_ = 908 input_event_filter_ =
827 new InputEventFilter(this, compositor_message_loop_proxy_); 909 new InputEventFilter(this, input_task_runner_,
910 compositor_message_loop_proxy_);
828 AddFilter(input_event_filter_.get()); 911 AddFilter(input_event_filter_.get());
829 input_handler_manager_client = input_event_filter_.get(); 912 input_handler_manager_client = input_event_filter_.get();
830 } 913 }
831 input_handler_manager_.reset( 914 input_handler_manager_.reset(
832 new InputHandlerManager(compositor_message_loop_proxy_, 915 new InputHandlerManager(compositor_message_loop_proxy_,
833 input_handler_manager_client)); 916 input_handler_manager_client));
834 } 917 }
835 918
836 scoped_refptr<base::MessageLoopProxy> output_surface_loop; 919 scoped_refptr<base::MessageLoopProxy> output_surface_loop;
837 if (enable) 920 if (enable)
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after
1565 hidden_widget_count_--; 1648 hidden_widget_count_--;
1566 1649
1567 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) { 1650 if (!GetContentClient()->renderer()->RunIdleHandlerWhenWidgetsHidden()) {
1568 return; 1651 return;
1569 } 1652 }
1570 1653
1571 ScheduleIdleHandler(kLongIdleHandlerDelayMs); 1654 ScheduleIdleHandler(kLongIdleHandlerDelayMs);
1572 } 1655 }
1573 1656
1574 } // namespace content 1657 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698