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

Unified Diff: skia/ext/refptr.h

Issue 19267024: cc: Don't leak a ref to SkColorFilter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: filterleak: caps Created 7 years, 5 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 | « cc/output/gl_renderer.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: skia/ext/refptr.h
diff --git a/skia/ext/refptr.h b/skia/ext/refptr.h
index a3900f61ba4502c0d59c3b8664cf6bb4dd3c4aa1..5d3165988ae6ace57c4fb393ad8cc84f6da933ee 100644
--- a/skia/ext/refptr.h
+++ b/skia/ext/refptr.h
@@ -5,6 +5,8 @@
#ifndef SKIA_EXT_REFPTR_H_
#define SKIA_EXT_REFPTR_H_
+#include "base/basictypes.h"
+#include "base/logging.h"
#include "third_party/skia/include/core/SkRefCnt.h"
namespace skia {
@@ -87,6 +89,41 @@ class RefPtr {
return ptr_ ? &RefPtr::ptr_ : NULL;
}
+ class Receiver {
+ public:
+ ~Receiver() {
+ DCHECK(!*refptr_) << "RefPtr must be empty.";
+ refptr_->ptr_ = ptr_;
+ }
+
+ operator T**() { return &ptr_; }
+
+ private:
+ friend class RefPtr;
+
+ explicit Receiver(RefPtr* refptr) : refptr_(refptr), ptr_(NULL) {
+ DCHECK(!*refptr_) << "RefPtr must be empty.";
+ }
+
+ RefPtr* refptr_;
+ T* ptr_;
+
+ DISALLOW_COPY_AND_ASSIGN(Receiver);
+ };
+
+ // Call this and pass it to a function that takes a T** argument and
+ // sets it to an object with an unowned reference.
awong 2013/07/17 23:51:02 suggestion: Call this and pass the returned tempor
+ // NOTE: Do not use this function as part of a subexpression, and try to use
awong 2013/07/17 23:51:02 suggestion: Do not use this function as part of a
danakj 2013/07/17 23:58:29 Thanks, will do. I think that I can also DCHECK t
+ // the RefPtr in the same subexpression, as this operation will not be
+ // complete and the RefPtr will be empty still.
+ //
+ // Bad (refptr will be NULL when it is dereffed):
+ // Foo(refptr.ReceiveAndAdoptRef()) && refptr->Bar();
+ // Good:
+ // bool ok = Foo(refptr.ReceiveAndAdoptRef());
+ // ok && refptr->Bar();
+ Receiver ReceiveAndAdoptRef() { return Receiver(this); }
+
private:
T* ptr_;
« no previous file with comments | « cc/output/gl_renderer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698