Chromium Code Reviews| Index: content/renderer/render_thread_impl.cc |
| diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc |
| index 5f4d4fb280e11282c5d955b23ccaf4a645d84e0d..224b5944f8a3dee96480aa9ba23121cecc904321 100644 |
| --- a/content/renderer/render_thread_impl.cc |
| +++ b/content/renderer/render_thread_impl.cc |
| @@ -20,6 +20,7 @@ |
| #include "base/metrics/histogram.h" |
| #include "base/metrics/stats_table.h" |
| #include "base/path_service.h" |
| +#include "base/single_thread_task_runner.h" |
| #include "base/strings/string16.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "base/strings/string_tokenizer.h" |
| @@ -107,7 +108,10 @@ |
| #include "net/base/net_errors.h" |
| #include "net/base/net_util.h" |
| #include "skia/ext/event_tracer_impl.h" |
| +#include "third_party/WebKit/public/platform/WebSchedulerProxy.h" |
| #include "third_party/WebKit/public/platform/WebString.h" |
| +#include "third_party/WebKit/public/platform/WebThread.h" |
| +#include "third_party/WebKit/public/platform/WebTraceLocation.h" |
| #include "third_party/WebKit/public/web/WebColorName.h" |
| #include "third_party/WebKit/public/web/WebDatabase.h" |
| #include "third_party/WebKit/public/web/WebDocument.h" |
| @@ -297,6 +301,85 @@ void CreateRenderFrameSetup(mojo::InterfaceRequest<RenderFrameSetup> request) { |
| } // namespace |
| +class SchedulerProxyTaskRunnerBase : public base::SingleThreadTaskRunner { |
| + public: |
| + SchedulerProxyTaskRunnerBase() |
| + : main_thread_id_(base::PlatformThread::CurrentId()), |
| + scheduler_proxy_(blink::WebSchedulerProxy::create()), |
| + fallback_task_runner_(base::MessageLoopProxy::current()), |
| + is_active_(true) {} |
| + |
| + // base::SingleThreadTaskRunner implementation: |
| + virtual bool RunsTasksOnCurrentThread() const OVERRIDE { |
| + return base::PlatformThread::CurrentId() == main_thread_id_; |
| + } |
| + |
| + void Shutdown() { |
| + base::AutoLock lock(scheduler_lock_); |
| + is_active_ = false; |
| + } |
| + |
| + protected: |
| + virtual ~SchedulerProxyTaskRunnerBase() {} |
| + |
| + const base::PlatformThreadId main_thread_id_; |
| + blink::WebSchedulerProxy scheduler_proxy_; |
| + scoped_refptr<base::SingleThreadTaskRunner> fallback_task_runner_; |
| + |
| + bool is_active_; |
| + base::Lock scheduler_lock_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SchedulerProxyTaskRunnerBase); |
| +}; |
| + |
| +// Helper for forwarding posted tasks into different WebSchedulerProxy queues. |
| +template <void (blink::WebSchedulerProxy::*ProxyFunction)( |
| + const blink::WebTraceLocation&, |
| + blink::WebThread::Task*)> |
| +class SchedulerProxyTaskRunner : public SchedulerProxyTaskRunnerBase { |
| + public: |
| + SchedulerProxyTaskRunner() {} |
| + |
| + // base::SingleThreadTaskRunner implementation: |
| + virtual bool PostDelayedTask(const tracked_objects::Location& from_here, |
| + const base::Closure& task, |
| + base::TimeDelta delay) OVERRIDE { |
| + DCHECK(delay == base::TimeDelta()); |
| + base::AutoLock lock(scheduler_lock_); |
| + if (!is_active_) |
| + 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 #
|
| + blink::WebTraceLocation location(from_here.function_name(), |
| + from_here.file_name()); |
| + (scheduler_proxy_.*ProxyFunction)(location, new TaskAdapter(task)); |
| + return true; |
| + } |
| + |
| + virtual bool PostNonNestableDelayedTask( |
| + const tracked_objects::Location& from_here, |
| + const base::Closure& task, |
| + base::TimeDelta delay) OVERRIDE { |
| + NOTREACHED(); |
| + return false; |
| + } |
| + |
| + protected: |
| + virtual ~SchedulerProxyTaskRunner() {} |
| + |
| + private: |
| + class TaskAdapter : public blink::WebThread::Task { |
| + public: |
| + explicit TaskAdapter(const base::Closure& function) : function_(function) {} |
| + virtual ~TaskAdapter() {} |
| + |
| + virtual void run() OVERRIDE { function_.Run(); } |
| + |
| + private: |
| + base::Closure function_; |
| + }; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SchedulerProxyTaskRunner); |
| +}; |
| + |
| // For measuring memory usage after each task. Behind a command line flag. |
| class MemoryObserver : public base::MessageLoop::TaskObserver { |
| public: |
| @@ -636,6 +719,10 @@ void RenderThreadImpl::Shutdown() { |
| // hold pointers to V8 objects (e.g., via pending requests). |
| main_thread_indexed_db_dispatcher_.reset(); |
| + // Stop forwarding tasks to the Blink scheduler. |
| + main_thread_compositor_task_runner_->Shutdown(); |
| + main_thread_input_task_runner_->Shutdown(); |
| + |
| if (webkit_platform_support_) |
| blink::shutdown(); |
| @@ -818,6 +905,11 @@ void RenderThreadImpl::EnsureWebKitInitialized() { |
| webkit_platform_support_.reset(new RendererWebKitPlatformSupportImpl); |
| blink::initialize(webkit_platform_support_.get()); |
| + main_thread_compositor_task_runner_ = |
| + make_scoped_refptr(new SchedulerProxyTaskRunner< |
| + &blink::WebSchedulerProxy::postCompositorTask>()); |
| + main_thread_input_task_runner_ = make_scoped_refptr( |
| + new SchedulerProxyTaskRunner<&blink::WebSchedulerProxy::postInputTask>()); |
| v8::Isolate* isolate = blink::mainThreadIsolate(); |
| @@ -857,8 +949,8 @@ void RenderThreadImpl::EnsureWebKitInitialized() { |
| } |
| #endif |
| if (!input_handler_manager_client) { |
| - input_event_filter_ = |
| - new InputEventFilter(this, compositor_message_loop_proxy_); |
| + input_event_filter_ = new InputEventFilter( |
| + this, main_thread_input_task_runner_, compositor_message_loop_proxy_); |
| AddFilter(input_event_filter_.get()); |
| input_handler_manager_client = input_event_filter_.get(); |
| } |
| @@ -1574,6 +1666,11 @@ RenderThreadImpl::GetMediaThreadMessageLoopProxy() { |
| return media_thread_->message_loop_proxy(); |
| } |
| +scoped_refptr<base::SingleThreadTaskRunner> |
| +RenderThreadImpl::MainThreadCompositorTaskRunner() const { |
| + return main_thread_compositor_task_runner_; |
| +} |
| + |
| void RenderThreadImpl::SetFlingCurveParameters( |
| const std::vector<float>& new_touchpad, |
| const std::vector<float>& new_touchscreen) { |