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

Unified Diff: base/bind_helpers.h

Issue 8171013: Support scoped_refptr<> as the object for a method call in base::Bind(). Reduce useless copies. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix comment Created 9 years, 2 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 | base/bind_unittest.cc » ('j') | 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 7eb5716caef4f7b566f0026ad57f91d7a373ace7..07f11f98d2cde4e730b0c811e6b176dac1fa9ca7 100644
--- a/base/bind_helpers.h
+++ b/base/bind_helpers.h
@@ -227,6 +227,11 @@ const T& Unwrap(ConstRefWrapper<T> const_ref) {
return const_ref.get();
}
+template <typename T>
+T* Unwrap(const scoped_refptr<T>& o) { return o.get(); }
+
+template <typename T>
+const WeakPtr<T>& Unwrap(const WeakPtr<T>& o) { return o; }
// Utility for handling different refcounting semantics in the Bind()
// function.
@@ -257,6 +262,14 @@ struct MaybeRefcount<base::true_type, T*> {
static void Release(T* o) { o->Release(); }
};
+// No need to additionally AddRef() and Release() since we are storing a
+// scoped_refptr<> inside the storage object already.
+template <typename T>
+struct MaybeRefcount<base::true_type, scoped_refptr<T> > {
+ static void AddRef(const scoped_refptr<T>& o) {}
+ static void Release(const scoped_refptr<T>& o) {}
+};
+
template <typename T>
struct MaybeRefcount<base::true_type, const T*> {
static void AddRef(const T* o) { o->AddRef(); }
« no previous file with comments | « no previous file | base/bind_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698