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

Unified Diff: base/bind_internal.h

Issue 1699123002: Unify BindState refcount management into the bound arguments. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: +comment Created 4 years, 10 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_helpers.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/bind_internal.h
diff --git a/base/bind_internal.h b/base/bind_internal.h
index 186222ac8c0c6cd3d7b78d3ef6bcbb7d76490ae0..f296bbcc353f10e48a18f1113857aff8b0221a1d 100644
--- a/base/bind_internal.h
+++ b/base/bind_internal.h
@@ -355,6 +355,24 @@ struct Invoker<IndexSequence<bound_indices...>, StorageType,
}
};
+// Used to implement MakeArgsStorage.
+template <bool is_method, typename... BoundArgs>
+struct MakeArgsStorageImpl {
+ using Type = std::tuple<BoundArgs...>;
+};
+
+template <typename Obj, typename... BoundArgs>
+struct MakeArgsStorageImpl<true, Obj*, BoundArgs...> {
+ using Type = std::tuple<scoped_refptr<Obj>, BoundArgs...>;
+};
+
+// Constructs a tuple type to store BoundArgs into BindState.
+// This wraps the first argument into a scoped_refptr if |is_method| is true and
+// the first argument is a raw pointer.
+// Other arguments are adjusted for store and packed into a tuple.
+template <bool is_method, typename... BoundArgs>
+using MakeArgsStorage = typename MakeArgsStorageImpl<
+ is_method, typename std::decay<BoundArgs>::type...>::Type;
// BindState<>
//
@@ -380,10 +398,12 @@ struct BindState<Runnable, R(Args...), BoundArgs...> final
using StorageType = BindState<Runnable, R(Args...), BoundArgs...>;
using RunnableType = Runnable;
+ enum { is_method = HasIsMethodTag<Runnable>::value };
+
// true_type if Runnable is a method invocation and the first bound argument
// is a WeakPtr.
using IsWeakCall =
- IsWeakMethod<HasIsMethodTag<Runnable>::value, BoundArgs...>;
+ IsWeakMethod<is_method, typename std::decay<BoundArgs>::type...>;
using BoundIndices = MakeIndexSequence<sizeof...(BoundArgs)>;
using UnboundForwardArgs = DropTypeListItem<
@@ -403,12 +423,10 @@ struct BindState<Runnable, R(Args...), BoundArgs...> final
BindState(const Runnable& runnable, ForwardArgs&&... bound_args)
: BindStateBase(&Destroy),
runnable_(runnable),
- ref_(bound_args...),
bound_args_(std::forward<ForwardArgs>(bound_args)...) {}
RunnableType runnable_;
- MaybeScopedRefPtr<HasIsMethodTag<Runnable>::value, BoundArgs...> ref_;
- Tuple<BoundArgs...> bound_args_;
+ MakeArgsStorage<is_method, BoundArgs...> bound_args_;
private:
~BindState() {}
« no previous file with comments | « base/bind_helpers.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698