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

Unified Diff: base/memory/ref_counted.h

Issue 623633002: scoped_refptr: support opaque pointed-to classes via extern template (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/ref_counted.h
diff --git a/base/memory/ref_counted.h b/base/memory/ref_counted.h
index be4919c1a51908699c260936f4f6b3c62a98d9ab..9ca7451861328cdf48feebefd7041982f4bc0531 100644
--- a/base/memory/ref_counted.h
+++ b/base/memory/ref_counted.h
@@ -276,23 +276,23 @@ class scoped_refptr {
scoped_refptr(T* p) : ptr_(p) {
if (ptr_)
- ptr_->AddRef();
+ AddRef(ptr_);
}
scoped_refptr(const scoped_refptr<T>& r) : ptr_(r.ptr_) {
if (ptr_)
- ptr_->AddRef();
+ AddRef(ptr_);
}
template <typename U>
scoped_refptr(const scoped_refptr<U>& r) : ptr_(r.get()) {
if (ptr_)
- ptr_->AddRef();
+ AddRef(ptr_);
}
~scoped_refptr() {
if (ptr_)
- ptr_->Release();
+ Release(ptr_);
}
T* get() const { return ptr_; }
@@ -316,11 +316,11 @@ class scoped_refptr {
scoped_refptr<T>& operator=(T* p) {
// AddRef first so that self assignment should work
if (p)
- p->AddRef();
+ AddRef(p);
T* old_ptr = ptr_;
ptr_ = p;
if (old_ptr)
- old_ptr->Release();
+ Release(old_ptr);
return *this;
}
@@ -362,8 +362,26 @@ class scoped_refptr {
protected:
T* ptr_;
+
+ private:
+ // Non-inline helpers to allow:
+ // class Opaque;
+ // extern template class scoped_refptr<Opaque>;
+ // Otherwise the compiler will complain that Opaque is an incomplete type.
danakj 2014/10/09 00:06:57 Can you add a test that demonstrates this working?
mdempsky 2014/10/09 00:21:33 Sure. Do you know if there are any existing idiom
danakj 2014/10/09 00:31:47 That sounds like how I'd do it, putting the helper
mdempsky 2014/10/09 00:52:48 SGTM
+ static void AddRef(T* ptr);
+ static void Release(T* ptr);
};
+template <typename T>
+void scoped_refptr<T>::AddRef(T* ptr) {
+ ptr->AddRef();
danakj 2014/10/09 00:06:57 What does the code look like with/out this change
+}
+
+template <typename T>
+void scoped_refptr<T>::Release(T* ptr) {
+ ptr->Release();
+}
+
// Handy utility for creating a scoped_refptr<T> out of a T* explicitly without
// having to retype all the template arguments
template <typename T>
« 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