| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef COMPONENTS_SCHEDULER_CHILD_WEB_TASK_RUNNER_H_ | 5 #ifndef COMPONENTS_SCHEDULER_CHILD_WEB_TASK_RUNNER_H_ |
| 6 #define COMPONENTS_SCHEDULER_CHILD_WEB_TASK_RUNNER_H_ | 6 #define COMPONENTS_SCHEDULER_CHILD_WEB_TASK_RUNNER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "components/scheduler/scheduler_export.h" | 13 #include "components/scheduler/scheduler_export.h" |
| 14 #include "third_party/WebKit/public/platform/WebTaskRunner.h" | 14 #include "third_party/WebKit/public/platform/WebTaskRunner.h" |
| 15 | 15 |
| 16 namespace base { |
| 17 class SingleThreadTaskRunner; |
| 18 }; |
| 19 |
| 16 namespace scheduler { | 20 namespace scheduler { |
| 17 class TaskQueue; | 21 class TaskQueue; |
| 18 | 22 |
| 19 class SCHEDULER_EXPORT WebTaskRunnerImpl : public blink::WebTaskRunner { | 23 class SCHEDULER_EXPORT WebTaskRunnerImpl : public blink::WebTaskRunner { |
| 20 public: | 24 public: |
| 21 explicit WebTaskRunnerImpl(scoped_refptr<TaskQueue> task_queue); | 25 explicit WebTaskRunnerImpl(scoped_refptr<TaskQueue> task_queue); |
| 22 | 26 |
| 23 ~WebTaskRunnerImpl() override; | 27 ~WebTaskRunnerImpl() override; |
| 24 | 28 |
| 25 // blink::WebTaskRunner implementation: | 29 // blink::WebTaskRunner implementation: |
| 26 void postTask(const blink::WebTraceLocation& web_location, | 30 void postTask(const blink::WebTraceLocation& web_location, |
| 27 blink::WebTaskRunner::Task* task) override; | 31 blink::WebTaskRunner::Task* task) override; |
| 28 void postDelayedTask(const blink::WebTraceLocation& web_location, | 32 void postDelayedTask(const blink::WebTraceLocation& web_location, |
| 29 blink::WebTaskRunner::Task* task, | 33 blink::WebTaskRunner::Task* task, |
| 30 double delayMs) override; | 34 double delayMs) override; |
| 31 bool runsTasksOnCurrentThread() override; | 35 bool runsTasksOnCurrentThread() override; |
| 32 double virtualTimeSeconds() const override; | 36 double virtualTimeSeconds() const override; |
| 33 double monotonicallyIncreasingVirtualTimeSeconds() const override; | 37 double monotonicallyIncreasingVirtualTimeSeconds() const override; |
| 34 std::unique_ptr<blink::WebTaskRunner> clone() override; | 38 std::unique_ptr<blink::WebTaskRunner> clone() override; |
| 35 | 39 |
| 36 // blink::WebTaskRunner::Task should be wrapped by base::Passed() when | 40 // blink::WebTaskRunner::Task should be wrapped by base::Passed() when |
| 37 // used with base::Bind(). See https://crbug.com/551356. | 41 // used with base::Bind(). See https://crbug.com/551356. |
| 38 // runTask() is a helper to call blink::WebTaskRunner::Task::run from | 42 // runTask() is a helper to call blink::WebTaskRunner::Task::run from |
| 39 // std::unique_ptr<blink::WebTaskRunner::Task>. | 43 // std::unique_ptr<blink::WebTaskRunner::Task>. |
| 40 // runTask() is placed here because std::unique_ptr<> cannot be used from | 44 // runTask() is placed here because std::unique_ptr<> cannot be used from |
| 41 // Blink. | 45 // Blink. |
| 42 static void runTask(std::unique_ptr<blink::WebTaskRunner::Task>); | 46 static void runTask(std::unique_ptr<blink::WebTaskRunner::Task>); |
| 43 | 47 |
| 48 static scoped_refptr<base::SingleThreadTaskRunner> GetBaseTaskRunner( |
| 49 const blink::WebTaskRunner&); |
| 50 |
| 44 private: | 51 private: |
| 45 base::TimeTicks Now() const; | 52 base::TimeTicks Now() const; |
| 46 | 53 |
| 47 scoped_refptr<TaskQueue> task_queue_; | 54 scoped_refptr<TaskQueue> task_queue_; |
| 48 | 55 |
| 49 DISALLOW_COPY_AND_ASSIGN(WebTaskRunnerImpl); | 56 DISALLOW_COPY_AND_ASSIGN(WebTaskRunnerImpl); |
| 50 }; | 57 }; |
| 51 | 58 |
| 52 } // namespace scheduler | 59 } // namespace scheduler |
| 53 | 60 |
| 54 #endif // COMPONENTS_SCHEDULER_CHILD_WEB_TASK_RUNNER_H_ | 61 #endif // COMPONENTS_SCHEDULER_CHILD_WEB_TASK_RUNNER_H_ |
| OLD | NEW |