Index: cc/raster/task.h |
diff --git a/cc/raster/task.h b/cc/raster/task.h |
index 96959c1ba00b0e4bf8a0e3044e698ee84bfafd8e..54bcf8b6b1a508b9d31e50fa39e0a327f144513c 100644 |
--- a/cc/raster/task.h |
+++ b/cc/raster/task.h |
@@ -13,6 +13,41 @@ |
#include "cc/base/cc_export.h" |
namespace cc { |
+class Task; |
+ |
+// States to manage life cycle of a task. Task gets created with NEW state and |
+// concludes either in FINISHED or CANCELLED state. So possible life cycle |
+// paths for task are - |
+// NEW -> SCHEDULED -> RUNNING -> FINISHED |
+// NEW -> SCHEDULED -> CANCELED |
+class CC_EXPORT TaskState { |
+ public: |
+ bool IsScheduled() const; |
+ bool IsRunning() const; |
+ bool IsFinished() const; |
+ bool IsCanceled() const; |
+ |
+ // Functions to change the state of task. These functions should be called |
+ // only from TaskGraphWorkQueue where the life cycle of a task is decided or |
+ // from tests. These functions are not thread-safe. Caller is responsible for |
+ // thread safety. |
+ void Reset(); // Sets state to NEW. |
+ void DidSchedule(); |
+ void DidStart(); |
+ void DidFinish(); |
+ void DidCancel(); |
+ |
+ private: |
+ friend class Task; |
+ |
+ // Let only Task class create the TaskState. |
+ TaskState(); |
+ ~TaskState(); |
+ |
+ enum class Value : uint16_t { NEW, SCHEDULED, RUNNING, FINISHED, CANCELED }; |
+ |
+ Value value_; |
+}; |
// A task which can be run by a TaskGraphRunner. To run a Task, it should be |
// inserted into a TaskGraph, which can then be scheduled on the |
@@ -21,23 +56,21 @@ class CC_EXPORT Task : public base::RefCountedThreadSafe<Task> { |
public: |
typedef std::vector<scoped_refptr<Task>> Vector; |
+ TaskState& state() { return state_; } |
+ |
// Subclasses should implement this method. RunOnWorkerThread may be called |
// on any thread, and subclasses are responsible for locking and thread |
// safety. |
virtual void RunOnWorkerThread() = 0; |
- void WillRun(); |
- void DidRun(); |
- bool HasFinishedRunning() const; |
- |
protected: |
friend class base::RefCountedThreadSafe<Task>; |
Task(); |
virtual ~Task(); |
- bool will_run_; |
- bool did_run_; |
+ private: |
+ TaskState state_; |
}; |
// A task dependency graph describes the order in which to execute a set |