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

Side by Side Diff: third_party/WebKit/Source/platform/WebTaskRunner.cpp

Issue 2266443002: Optimize posting of WTF::Closure and improve scheduler test mocks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cut back to just the WTF::Closure fix plus the scheduler test mock refactor. Created 4 years, 3 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
OLDNEW
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 namespace blink { 7 namespace blink {
8 8
9 class SameThreadTask : public WebTaskRunner::Task {
10 USING_FAST_MALLOC(SameThreadTask);
11 WTF_MAKE_NONCOPYABLE(SameThreadTask);
12 public:
13 explicit SameThreadTask(std::unique_ptr<WTF::Closure> 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<WTF::Closure> 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 };
44
45 void WebTaskRunner::postTask(const WebTraceLocation& location, std::unique_ptr<C rossThreadClosure> task) 9 void WebTaskRunner::postTask(const WebTraceLocation& location, std::unique_ptr<C rossThreadClosure> task)
46 { 10 {
47 postTask(location, new CrossThreadTask(std::move(task))); 11 toSingleThreadTaskRunner()->PostTask(location, convertToBaseCallback(std::mo ve(task)));
48 } 12 }
49 13
50 void WebTaskRunner::postDelayedTask(const WebTraceLocation& location, std::uniqu e_ptr<CrossThreadClosure> task, long long delayMs) 14 void WebTaskRunner::postDelayedTask(const WebTraceLocation& location, std::uniqu e_ptr<CrossThreadClosure> task, long long delayMs)
51 { 15 {
52 postDelayedTask(location, new CrossThreadTask(std::move(task)), delayMs); 16 toSingleThreadTaskRunner()->PostDelayedTask(location, convertToBaseCallback( std::move(task)), base::TimeDelta::FromMilliseconds(delayMs));
53 } 17 }
54 18
55 void WebTaskRunner::postTask(const WebTraceLocation& location, std::unique_ptr<W TF::Closure> task) 19 void WebTaskRunner::postTask(const WebTraceLocation& location, std::unique_ptr<W TF::Closure> task)
56 { 20 {
57 postTask(location, new SameThreadTask(std::move(task))); 21 toSingleThreadTaskRunner()->PostTask(location, convertToBaseCallback(std::mo ve(task)));
58 } 22 }
59 23
60 void WebTaskRunner::postDelayedTask(const WebTraceLocation& location, std::uniqu e_ptr<WTF::Closure> task, long long delayMs) 24 void WebTaskRunner::postDelayedTask(const WebTraceLocation& location, std::uniqu e_ptr<WTF::Closure> task, long long delayMs)
61 { 25 {
62 postDelayedTask(location, new SameThreadTask(std::move(task)), delayMs); 26 toSingleThreadTaskRunner()->PostDelayedTask(location, convertToBaseCallback( std::move(task)), base::TimeDelta::FromMilliseconds(delayMs));
63 } 27 }
64 28
65 } // namespace blink 29 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/TimerTest.cpp ('k') | third_party/WebKit/Source/platform/blink_platform.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698