| 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 #include "public/platform/WebTaskRunner.h" | 5 #include "public/platform/WebTaskRunner.h" |
| 6 | 6 |
| 7 #include "platform/Task.h" | 7 namespace blink { |
| 8 | 8 |
| 9 namespace blink { | 9 class SameThreadTask : public WebTaskRunner::Task { |
| 10 USING_FAST_MALLOC(SameThreadTask); |
| 11 WTF_MAKE_NONCOPYABLE(SameThreadTask); |
| 12 public: |
| 13 explicit SameThreadTask(std::unique_ptr<SameThreadClosure> closure) |
| 14 : m_closure(std::move(closure)) |
| 15 { |
| 16 } |
| 17 |
| 18 void run() override |
| 19 { |
| 20 (*m_closure)(); |
| 21 } |
| 22 |
| 23 private: |
| 24 std::unique_ptr<SameThreadClosure> m_closure; |
| 25 }; |
| 26 |
| 27 class CrossThreadTask : public WebTaskRunner::Task { |
| 28 USING_FAST_MALLOC(CrossThreadTask); |
| 29 WTF_MAKE_NONCOPYABLE(CrossThreadTask); |
| 30 public: |
| 31 explicit CrossThreadTask(std::unique_ptr<CrossThreadClosure> closure) |
| 32 : m_closure(std::move(closure)) |
| 33 { |
| 34 } |
| 35 |
| 36 void run() override |
| 37 { |
| 38 (*m_closure)(); |
| 39 } |
| 40 |
| 41 private: |
| 42 std::unique_ptr<CrossThreadClosure> m_closure; |
| 43 }; |
| 10 | 44 |
| 11 void WebTaskRunner::postTask(const WebTraceLocation& location, std::unique_ptr<C
rossThreadClosure> task) | 45 void WebTaskRunner::postTask(const WebTraceLocation& location, std::unique_ptr<C
rossThreadClosure> task) |
| 12 { | 46 { |
| 13 postTask(location, new CrossThreadTask(std::move(task))); | 47 postTask(location, new CrossThreadTask(std::move(task))); |
| 14 } | 48 } |
| 15 | 49 |
| 16 void WebTaskRunner::postDelayedTask(const WebTraceLocation& location, std::uniqu
e_ptr<CrossThreadClosure> task, long long delayMs) | 50 void WebTaskRunner::postDelayedTask(const WebTraceLocation& location, std::uniqu
e_ptr<CrossThreadClosure> task, long long delayMs) |
| 17 { | 51 { |
| 18 postDelayedTask(location, new CrossThreadTask(std::move(task)), delayMs); | 52 postDelayedTask(location, new CrossThreadTask(std::move(task)), delayMs); |
| 19 } | 53 } |
| 20 | 54 |
| 21 void WebTaskRunner::postTask(const WebTraceLocation& location, std::unique_ptr<S
ameThreadClosure> task) | 55 void WebTaskRunner::postTask(const WebTraceLocation& location, std::unique_ptr<S
ameThreadClosure> task) |
| 22 { | 56 { |
| 23 postTask(location, new SameThreadTask(std::move(task))); | 57 postTask(location, new SameThreadTask(std::move(task))); |
| 24 } | 58 } |
| 25 | 59 |
| 26 void WebTaskRunner::postDelayedTask(const WebTraceLocation& location, std::uniqu
e_ptr<SameThreadClosure> task, long long delayMs) | 60 void WebTaskRunner::postDelayedTask(const WebTraceLocation& location, std::uniqu
e_ptr<SameThreadClosure> task, long long delayMs) |
| 27 { | 61 { |
| 28 postDelayedTask(location, new SameThreadTask(std::move(task)), delayMs); | 62 postDelayedTask(location, new SameThreadTask(std::move(task)), delayMs); |
| 29 } | 63 } |
| 30 | 64 |
| 31 } // namespace blink | 65 } // namespace blink |
| OLD | NEW |