Index: components/scheduler/promises/promise_executor.h |
diff --git a/components/scheduler/promises/promise_executor.h b/components/scheduler/promises/promise_executor.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7dfce2ddd0a2b5e74bc5219dad7e8df1bc4e372d |
--- /dev/null |
+++ b/components/scheduler/promises/promise_executor.h |
@@ -0,0 +1,57 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef COMPONENTS_SCHEDULER_PROMISES_PROMISE_EXECUTOR_H_ |
+#define COMPONENTS_SCHEDULER_PROMISES_PROMISE_EXECUTOR_H_ |
+ |
+#include <set> |
+ |
+#include "base/macros.h" |
+#include "components/scheduler/promises/promise.h" |
+#include "components/scheduler/scheduler_export.h" |
+ |
+namespace promise { |
+namespace internal { |
+ |
+class SCHEDULER_EXPORT PromiseExecutor { |
+ public: |
+ PromiseExecutor(); |
+ virtual ~PromiseExecutor(); |
+ |
+ template <typename R> |
+ void StartResolve(::promise::Promise<R>& promise) { |
+ StartResolveInternal(promise.promise()); |
+ } |
+ |
+ virtual void StartResolveInternal(internal::PromiseBase* promise); |
+ |
+ // Returns true if some work was done. |
+ bool ResolveOnePromise(); |
+ |
+ // Note this blocks. |
+ void RunUntilIdle(); |
+ |
+ protected: |
+ friend class PromiseBase; |
+ |
+ PromiseBase* GetNextReadyPromise(); |
+ void ResolvePromise(PromiseBase* promise); |
+ |
+ // Returns true if resolving |promise| means we can resolve more work. |
+ virtual bool OnPromiseResolved(PromiseBase* promise); |
+ |
+ // Returns true if rejecting |promise| means we can can run a reject callback. |
+ virtual bool OnPromiseRejected(PromiseBase* promise); |
+ |
+ std::set<PromiseBase*> eager_ready_set_; |
+ std::set<PromiseBase*> lazy_ready_set_; |
+ PromiseBase* cursor_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(PromiseExecutor); |
+}; |
+ |
+} // namespace internal |
+} // namespace promise |
+ |
+#endif // COMPONENTS_SCHEDULER_PROMISES_PROMISE_EXECUTOR_H_ |