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

Unified Diff: third_party/WebKit/Source/wtf/MakeCancellable.cpp

Issue 2177283005: Add WTF::makeCancellable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: +comment Created 4 years, 5 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: third_party/WebKit/Source/wtf/MakeCancellable.cpp
diff --git a/third_party/WebKit/Source/wtf/MakeCancellable.cpp b/third_party/WebKit/Source/wtf/MakeCancellable.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..7b0f585d9d2e4b32dc4c81f84755c9411a17d27e
--- /dev/null
+++ b/third_party/WebKit/Source/wtf/MakeCancellable.cpp
@@ -0,0 +1,53 @@
+// 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.
+
+#include "wtf/MakeCancellable.h"
+
+namespace WTF {
+
+namespace internal {
+
+FunctionCanceller::FunctionCanceller() = default;
+FunctionCanceller::~FunctionCanceller() = default;
+
+} // namespace internal
+
+ScopedFunctionCanceller::ScopedFunctionCanceller() = default;
+ScopedFunctionCanceller::ScopedFunctionCanceller(PassRefPtr<internal::FunctionCanceller> canceller)
+ : m_canceller(std::move(canceller)) { }
+
+ScopedFunctionCanceller::ScopedFunctionCanceller(ScopedFunctionCanceller&&) = default;
+ScopedFunctionCanceller& ScopedFunctionCanceller::operator=(ScopedFunctionCanceller&& other)
+{
+ RefPtr<internal::FunctionCanceller> canceller = std::move(other.m_canceller);
+ cancel();
+ m_canceller = std::move(canceller);
+ return *this;
+}
+
+ScopedFunctionCanceller::~ScopedFunctionCanceller()
+{
+ cancel();
+}
+
+void ScopedFunctionCanceller::detach()
+{
+ m_canceller = nullptr;
+}
+
+void ScopedFunctionCanceller::cancel()
+{
+ if (!m_canceller)
+ return;
+
+ m_canceller->cancel();
+ m_canceller = nullptr;
+}
+
+bool ScopedFunctionCanceller::isActive() const
+{
+ return m_canceller && m_canceller->isActive();
+}
+
+} // namespace WTF
« no previous file with comments | « third_party/WebKit/Source/wtf/MakeCancellable.h ('k') | third_party/WebKit/Source/wtf/MakeCancellableTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698