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

Side by Side Diff: public/platform/WebThread.h

Issue 1303153005: Introduce WebTaskRunner Patch 3/5 (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 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 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 10 matching lines...) Expand all
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 #ifndef WebThread_h 25 #ifndef WebThread_h
26 #define WebThread_h 26 #define WebThread_h
27 27
28 #include "WebCommon.h" 28 #include "WebCommon.h"
29 #include <stdint.h> 29 #include <stdint.h>
30 30
31 #ifdef INSIDE_BLINK
32 #include "wtf/Functional.h"
33 #endif
34
35 namespace blink { 31 namespace blink {
36 class WebScheduler; 32 class WebScheduler;
37 class WebTaskRunner; 33 class WebTaskRunner;
38 class WebTraceLocation; 34 class WebTraceLocation;
39 35
40 // Always an integer value. 36 // Always an integer value.
41 typedef uintptr_t PlatformThreadId; 37 typedef uintptr_t PlatformThreadId;
42 38
43 // Provides an interface to an embedder-defined thread implementation. 39 // Provides an interface to an embedder-defined thread implementation.
44 // 40 //
45 // Deleting the thread blocks until all pending, non-delayed tasks have been 41 // Deleting the thread blocks until all pending, non-delayed tasks have been
46 // run. 42 // run.
47 class BLINK_PLATFORM_EXPORT WebThread { 43 class BLINK_PLATFORM_EXPORT WebThread {
48 public: 44 public:
49 // An IdleTask is passed a deadline in CLOCK_MONOTONIC seconds and is 45 // An IdleTask is passed a deadline in CLOCK_MONOTONIC seconds and is
50 // expected to complete before this deadline. 46 // expected to complete before this deadline.
51 class IdleTask { 47 class IdleTask {
52 public: 48 public:
53 virtual ~IdleTask() { } 49 virtual ~IdleTask() { }
54 virtual void run(double deadlineSeconds) = 0; 50 virtual void run(double deadlineSeconds) = 0;
55 }; 51 };
56 52
53 // TODO(alexclarke): Remove this once it's no longer referenced by chromium.
57 class BLINK_PLATFORM_EXPORT Task { 54 class BLINK_PLATFORM_EXPORT Task {
58 public: 55 public:
59 virtual ~Task() { } 56 virtual ~Task() { }
60 virtual void run() = 0; 57 virtual void run() = 0;
61 }; 58 };
62 59
63 class BLINK_PLATFORM_EXPORT TaskObserver { 60 class BLINK_PLATFORM_EXPORT TaskObserver {
64 public: 61 public:
65 virtual ~TaskObserver() { } 62 virtual ~TaskObserver() { }
66 virtual void willProcessTask() = 0; 63 virtual void willProcessTask() = 0;
67 virtual void didProcessTask() = 0; 64 virtual void didProcessTask() = 0;
68 }; 65 };
69 66
70 // postTask() and postDelayedTask() take ownership of the passed Task
71 // object. It is safe to invoke postTask() and postDelayedTask() from any
72 // thread.
73 // TODO(alexclarke): Remove postTask & postDelayedTask.
74 virtual void postTask(const WebTraceLocation&, Task*) = 0;
75 virtual void postDelayedTask(const WebTraceLocation&, Task*, long long delay Ms) = 0;
76
77 // Returns a WebTaskRunner bound to the underlying scheduler's default task queue.
78 virtual WebTaskRunner* defaultTaskRunner() { return nullptr; } 67 virtual WebTaskRunner* defaultTaskRunner() { return nullptr; }
79 68
80 virtual bool isCurrentThread() const = 0; 69 virtual bool isCurrentThread() const = 0;
81 virtual PlatformThreadId threadId() const { return 0; } 70 virtual PlatformThreadId threadId() const { return 0; }
82 71
83 virtual void addTaskObserver(TaskObserver*) { } 72 virtual void addTaskObserver(TaskObserver*) { }
84 virtual void removeTaskObserver(TaskObserver*) { } 73 virtual void removeTaskObserver(TaskObserver*) { }
85 74
86 // Returns the scheduler associated with the thread. 75 // Returns the scheduler associated with the thread.
87 virtual WebScheduler* scheduler() const = 0; 76 virtual WebScheduler* scheduler() const = 0;
88 77
89 virtual ~WebThread() { } 78 virtual ~WebThread() { }
90
91 #ifdef INSIDE_BLINK
92 // Helpers for posting bound functions as tasks.
93 void postTask(const WebTraceLocation&, PassOwnPtr<Function<void()>>);
94 void postDelayedTask(const WebTraceLocation&, PassOwnPtr<Function<void()>>, long long delayMs);
95 #endif
96 }; 79 };
97 80
98 } // namespace blink 81 } // namespace blink
99 82
100 #endif 83 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698