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

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

Issue 1087203002: Patch 2/3 to get WebScheduler via WebThread (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Style nits Created 5 years, 8 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
« no previous file with comments | « public/platform/Platform.h ('k') | public/platform/WebThread.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 WebScheduler_h 5 #ifndef WebScheduler_h
6 #define WebScheduler_h 6 #define WebScheduler_h
7 7
8 #include "WebCommon.h" 8 #include "WebCommon.h"
9 #include "public/platform/WebThread.h" 9 #include "public/platform/WebThread.h"
10 10
11 namespace blink { 11 namespace blink {
12 12
13 class WebTraceLocation; 13 class WebTraceLocation;
14 14
15 // This class is used to submit tasks and pass other information from Blink to 15 // This class is used to submit tasks and pass other information from Blink to
16 // the platform's scheduler. 16 // the platform's scheduler.
17 class BLINK_PLATFORM_EXPORT WebScheduler { 17 class BLINK_PLATFORM_EXPORT WebScheduler {
18 public: 18 public:
19 virtual ~WebScheduler() { } 19 virtual ~WebScheduler() { }
20 20
21 // Returns true if there is high priority work pending on the main thread 21 // Returns true if there is high priority work pending on the associated Web Thread
22 // and the caller should yield to let the scheduler service that work. 22 // and the caller should yield to let the scheduler service that work.
23 // Must be called on the main thread. 23 // Must be called on the associated WebThread.
24 virtual bool shouldYieldForHighPriorityWork() { return false; } 24 virtual bool shouldYieldForHighPriorityWork() { return false; }
25 25
26 // Returns true if a currently running idle task could exceed its deadline 26 // Returns true if a currently running idle task could exceed its deadline
27 // without impacting user experience too much. This should only be used if 27 // without impacting user experience too much. This should only be used if
28 // there is a task which cannot be pre-empted and is likely to take longer 28 // there is a task which cannot be pre-empted and is likely to take longer
29 // than the largest expected idle task deadline. It should NOT be polled to 29 // than the largest expected idle task deadline. It should NOT be polled to
30 // check whether more work can be performed on the current idle task after 30 // check whether more work can be performed on the current idle task after
31 // its deadline has expired - post a new idle task for the continuation of 31 // its deadline has expired - post a new idle task for the continuation of
32 // the work in this case. 32 // the work in this case.
33 // Must be called from the main thread. 33 // Must be called from the associated WebThread.
34 virtual bool canExceedIdleDeadlineIfRequired() { return false; } 34 virtual bool canExceedIdleDeadlineIfRequired() { return false; }
35 35
36 // Schedule an idle task to run the Blink main thread. For non-critical 36 // Schedule an idle task to run the associated WebThread. For non-critical
37 // tasks which may be reordered relative to other task types and may be 37 // tasks which may be reordered relative to other task types and may be
38 // starved for an arbitrarily long time if no idle time is available. 38 // starved for an arbitrarily long time if no idle time is available.
39 // Takes ownership of |IdleTask|. Can be called from any thread. 39 // Takes ownership of |IdleTask|. Can be called from any thread.
40 virtual void postIdleTask(const WebTraceLocation&, WebThread::IdleTask*) { } 40 virtual void postIdleTask(const WebTraceLocation&, WebThread::IdleTask*) { }
41 41
42 // Like postIdleTask but guarantees that the posted task will not run 42 // Like postIdleTask but guarantees that the posted task will not run
43 // nested within an already-running task. Posting an idle task as 43 // nested within an already-running task. Posting an idle task as
44 // non-nestable may not affect when the task gets run, or it could 44 // non-nestable may not affect when the task gets run, or it could
45 // make it run later than it normally would, but it won't make it 45 // make it run later than it normally would, but it won't make it
46 // run earlier than it normally would. 46 // run earlier than it normally would.
47 virtual void postNonNestableIdleTask(const WebTraceLocation&, WebThread::Idl eTask*) { } 47 virtual void postNonNestableIdleTask(const WebTraceLocation&, WebThread::Idl eTask*) { }
48 48
49 // Like postIdleTask but does not run the idle task until after some other 49 // Like postIdleTask but does not run the idle task until after some other
50 // task has run. This enables posting of a task which won't stop the Blink 50 // task has run. This enables posting of a task which won't stop the Blink
51 // main thread from sleeping, but will start running after it wakes up. 51 // main thread from sleeping, but will start running after it wakes up.
52 // Takes ownership of |IdleTask|. Can be called from any thread. 52 // Takes ownership of |IdleTask|. Can be called from any thread.
53 virtual void postIdleTaskAfterWakeup(const WebTraceLocation&, WebThread::Idl eTask*) { } 53 virtual void postIdleTaskAfterWakeup(const WebTraceLocation&, WebThread::Idl eTask*) { }
54 54
55 // Schedule a loading task to be run on the Blink main thread. Loading 55 // Schedule a loading task to be run on the the associated WebThread. Loadin g
56 // tasks usually have the default priority, but may be deprioritised 56 // tasks usually have the default priority, but may be deprioritised
57 // when the user is interacting with the device. 57 // when the user is interacting with the device.
58 // Takes ownership of |WebThread::Task|. Can be called from any thread. 58 // Takes ownership of |WebThread::Task|. Can be called from any thread.
59 virtual void postLoadingTask(const WebTraceLocation&, WebThread::Task*) { } 59 virtual void postLoadingTask(const WebTraceLocation&, WebThread::Task*) { }
60
61 // Schedule a timer task to be run on the the associated WebThread. Timer Ta sks
62 // tasks usually have the default priority, but may be delayed
63 // when the user is interacting with the device.
64 // Takes ownership of |WebThread::Task|. Can be called from any thread.
65 virtual void postTimerTask(const WebTraceLocation&, WebThread::Task*, long l ong delayMs) { }
66
67 #ifdef INSIDE_BLINK
68 // Helpers for posting bound functions as tasks.
69 typedef Function<void(double deadlineSeconds)> IdleTask;
70 typedef Function<void()> Task;
71
72 void postIdleTask(const WebTraceLocation&, PassOwnPtr<IdleTask>);
73 void postNonNestableIdleTask(const WebTraceLocation&, PassOwnPtr<IdleTask>);
74 void postIdleTaskAfterWakeup(const WebTraceLocation&, PassOwnPtr<IdleTask>);
75 void postLoadingTask(const WebTraceLocation&, PassOwnPtr<Task>);
76 #endif
60 }; 77 };
61 78
62 } // namespace blink 79 } // namespace blink
63 80
64 #endif // WebScheduler_h 81 #endif // WebScheduler_h
OLDNEW
« no previous file with comments | « public/platform/Platform.h ('k') | public/platform/WebThread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698