| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef Scheduler_h | |
| 6 #define Scheduler_h | |
| 7 | |
| 8 #include "platform/PlatformExport.h" | |
| 9 #include "public/platform/WebThread.h" | |
| 10 #include "wtf/Functional.h" | |
| 11 #include "wtf/Noncopyable.h" | |
| 12 #include "wtf/PassOwnPtr.h" | |
| 13 | |
| 14 namespace blink { | |
| 15 class WebScheduler; | |
| 16 | |
| 17 // The scheduler is an opinionated gateway for arranging work to be run on the | |
| 18 // main thread. It decides which tasks get priority over others based on a | |
| 19 // scheduling policy and the overall system state. | |
| 20 class PLATFORM_EXPORT Scheduler { | |
| 21 WTF_MAKE_NONCOPYABLE(Scheduler); | |
| 22 public: | |
| 23 // An IdleTask is passed a deadline in CLOCK_MONOTONIC seconds and is expect
ed to complete before this deadline. | |
| 24 typedef Function<void(double deadlineSeconds)> IdleTask; | |
| 25 | |
| 26 static Scheduler* shared(); | |
| 27 static void setForTesting(Scheduler*); | |
| 28 static void shutdown(); | |
| 29 | |
| 30 // For non-critical tasks which may be reordered relative to other task type
s and may be starved | |
| 31 // for an arbitrarily long time if no idle time is available. | |
| 32 void postIdleTask(const WebTraceLocation&, PassOwnPtr<IdleTask>); | |
| 33 | |
| 34 // Like postIdleTask but guarantees that the posted task will not run | |
| 35 // nested within an already-running task. Posting an idle task as | |
| 36 // non-nestable may not affect when the task gets run, or it could | |
| 37 // make it run later than it normally would, but it won't make it | |
| 38 // run earlier than it normally would. | |
| 39 void postNonNestableIdleTask(const WebTraceLocation&, PassOwnPtr<IdleTask>); | |
| 40 | |
| 41 // Like postIdleTask but does not run the idle task until after some other | |
| 42 // task has run. This enables posting of a task which won't stop the Blink | |
| 43 // main thread from sleeping, but will start running after it wakes up. | |
| 44 void postIdleTaskAfterWakeup(const WebTraceLocation&, PassOwnPtr<IdleTask>); | |
| 45 | |
| 46 // For tasks related to loading, e.g. HTML parsing. Loading tasks usually h
ave default priority | |
| 47 // but they may be deprioritized when the user is interacting with the devic
e. | |
| 48 // Takes ownership of |WebThread::Task|. | |
| 49 void postLoadingTask(const WebTraceLocation&, WebThread::Task*); | |
| 50 | |
| 51 // Returns true if there is high priority work pending on the main thread | |
| 52 // and the caller should yield to let the scheduler service that work. | |
| 53 // Must be called on the main thread. | |
| 54 bool shouldYieldForHighPriorityWork() const; | |
| 55 | |
| 56 // Returns true if a currently running idle task could exceed its deadline | |
| 57 // without impacting user experience too much. This should only be used if | |
| 58 // there is a task which cannot be pre-empted and is likely to take longer | |
| 59 // than the largest expected idle task deadline. It should NOT be polled to | |
| 60 // check whether more work can be performed on the current idle task after | |
| 61 // its deadline has expired - post a new idle task for the continuation of | |
| 62 // the work in this case. | |
| 63 // Must be called from the main thread. | |
| 64 bool canExceedIdleDeadlineIfRequired() const; | |
| 65 | |
| 66 protected: | |
| 67 Scheduler(WebScheduler*); | |
| 68 virtual ~Scheduler(); | |
| 69 | |
| 70 static Scheduler* s_sharedScheduler; | |
| 71 WebScheduler* m_webScheduler; | |
| 72 }; | |
| 73 | |
| 74 } // namespace blink | |
| 75 | |
| 76 #endif // Scheduler_h | |
| OLD | NEW |