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

Unified Diff: base/bind_helpers.h

Issue 1815493002: base: Add RetainedRef for unwrapping scoped_refptrs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/bind_helpers.h
diff --git a/base/bind_helpers.h b/base/bind_helpers.h
index 117fc68e177d59afe3c7dba93b2cd77ebb006a03..735c1aa726f1ae749760d8f039b785d5b2ddc7e9 100644
--- a/base/bind_helpers.h
+++ b/base/bind_helpers.h
@@ -312,6 +312,16 @@ class ConstRefWrapper {
};
template <typename T>
+class RetainedRefWrapper {
+ public:
+ explicit RetainedRefWrapper(T* o) : ptr_(o) {}
+ explicit RetainedRefWrapper(scoped_refptr<T> o) : ptr_(std::move(o)) {}
+ T* get() const { return ptr_.get(); }
+ private:
+ scoped_refptr<T> ptr_;
+};
+
+template <typename T>
struct IgnoreResultHelper {
explicit IgnoreResultHelper(T functor) : functor_(functor) {}
@@ -410,6 +420,11 @@ T* Unwrap(const scoped_refptr<T>& o) {
}
template <typename T>
+T* Unwrap(const RetainedRefWrapper<T>& o) {
+ return o.get();
+}
+
+template <typename T>
const WeakPtr<T>& Unwrap(const WeakPtr<T>& o) {
return o;
}
@@ -545,6 +560,16 @@ static inline internal::UnretainedWrapper<T> Unretained(T* o) {
}
template <typename T>
+static inline internal::RetainedRefWrapper<T> RetainedRef(T* o) {
+ return internal::RetainedRefWrapper<T>(o);
+}
+
+template <typename T>
+static inline internal::RetainedRefWrapper<T> RetainedRef(scoped_refptr<T> o) {
+ return internal::RetainedRefWrapper<T>(std::move(o));
+}
+
+template <typename T>
static inline internal::ConstRefWrapper<T> ConstRef(const T& o) {
return internal::ConstRefWrapper<T>(o);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698