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

Unified Diff: base/callback_internal.h

Issue 2289703002: Add Callback::IsCancelled (Closed)
Patch Set: revert to PS5 Created 4 years, 3 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
« no previous file with comments | « base/bind_unittest.cc ('k') | base/callback_internal.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/callback_internal.h
diff --git a/base/callback_internal.h b/base/callback_internal.h
index 6aa5fa4e841657bcffd64fa541ecf92c8ce99677..6de18fd39d505b42ef4c07c906ae2c4086bf59e8 100644
--- a/base/callback_internal.h
+++ b/base/callback_internal.h
@@ -36,7 +36,8 @@ class BASE_EXPORT BindStateBase {
protected:
BindStateBase(InvokeFuncStorage polymorphic_invoke,
- void (*destructor)(BindStateBase*));
+ void (*destructor)(BindStateBase*),
+ bool (*is_cancelled)(const BindStateBase*));
~BindStateBase() = default;
private:
@@ -44,6 +45,10 @@ class BASE_EXPORT BindStateBase {
template <CopyMode copy_mode>
friend class CallbackBase;
+ bool IsCancelled() const {
+ return is_cancelled_(this);
+ }
+
void AddRef();
void Release();
@@ -57,6 +62,7 @@ class BASE_EXPORT BindStateBase {
// Pointer to a function that will properly destroy |this|.
void (*destructor_)(BindStateBase*);
+ bool (*is_cancelled_)(const BindStateBase*);
DISALLOW_COPY_AND_ASSIGN(BindStateBase);
};
@@ -75,6 +81,10 @@ class BASE_EXPORT CallbackBase<CopyMode::MoveOnly> {
bool is_null() const { return bind_state_.get() == NULL; }
explicit operator bool() const { return !is_null(); }
+ // Returns true if the callback invocation will be nop due to an cancellation.
+ // It's invalid to call this on uninitialized callback.
+ bool IsCancelled() const;
+
// Returns the Callback into an uninitialized state.
void Reset();
« no previous file with comments | « base/bind_unittest.cc ('k') | base/callback_internal.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698