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

Unified Diff: Source/platform/scheduler/CancellableTaskFactory.h

Issue 876623002: Adds a CancellableTaskFactory and exposes postLoadingTasks to Blink (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: Source/platform/scheduler/CancellableTaskFactory.h
diff --git a/Source/platform/scheduler/CancellableTaskFactory.h b/Source/platform/scheduler/CancellableTaskFactory.h
new file mode 100644
index 0000000000000000000000000000000000000000..eaf27f557ec14ecb09d05de87fd8e9e4588dd48c
--- /dev/null
+++ b/Source/platform/scheduler/CancellableTaskFactory.h
@@ -0,0 +1,58 @@
+// Copyright 2015 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 CancellableTaskFactory_h
+#define CancellableTaskFactory_h
+
+#include "platform/PlatformExport.h"
+#include "public/platform/WebScheduler.h"
+#include "wtf/Functional.h"
+#include "wtf/Noncopyable.h"
+#include "wtf/OwnPtr.h"
+#include "wtf/PassOwnPtr.h"
+#include "wtf/RefCounted.h"
+#include "wtf/WeakPtr.h"
+
+namespace blink {
+class TraceLocation;
+
+class PLATFORM_EXPORT CancellableTaskFactory {
+ WTF_MAKE_NONCOPYABLE(CancellableTaskFactory);
+public:
+ explicit CancellableTaskFactory(PassOwnPtr<Closure> closure) : m_closure(closure), m_weakPtrFactory(this) { }
+
+ bool isPending() const
+ {
+ return m_weakPtrFactory.hasWeakPtrs();
+ }
+
+ void cancel();
+
+ // Returns a task that can be disabled by calling cancel(). The user takes
+ // ownership of the task. Creating a new task cancels any previous ones.
+ WebThread::Task* task();
+
+private:
+ class CancellableTask : public WebThread::Task {
+ public:
jochen (gone - plz use gerrit) 2015/01/26 15:53:31 nit. also make this non copyable
alex clarke (OOO till 29th) 2015/01/26 17:00:45 Done.
+ explicit CancellableTask(WeakPtr<CancellableTaskFactory> weakPtr) : m_weakPtr(weakPtr) { }
Sami 2015/01/26 16:08:14 nit: Something like |factory| would be a little mo
+ virtual ~CancellableTask() { }
+
+ void run() override;
+
+ private:
+ WeakPtr<CancellableTaskFactory> m_weakPtr;
+ };
+
+ void runInternal();
+
+ OwnPtr<Closure> m_closure;
+ WeakPtrFactory<CancellableTaskFactory> m_weakPtrFactory;
+
+ friend class CancellableTask;
+};
+
+} // namespace blink
+
+#endif // CancellableTaskFactory_h

Powered by Google App Engine
This is Rietveld 408576698