summaryrefslogtreecommitdiffstats
path: root/base/scoped_nsobject.h
diff options
context:
space:
mode:
authordmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-19 15:13:52 +0000
committerdmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-19 15:13:52 +0000
commitbd5624b004af9e7db9b72f5a8c51bc897962fd43 (patch)
tree69487da9b14a7ac0d54bf29b0c74dfa3c238828e /base/scoped_nsobject.h
parente72746b145ffb989afedc91e7a16c22a233401b5 (diff)
downloadchromium_src-bd5624b004af9e7db9b72f5a8c51bc897962fd43.zip
chromium_src-bd5624b004af9e7db9b72f5a8c51bc897962fd43.tar.gz
chromium_src-bd5624b004af9e7db9b72f5a8c51bc897962fd43.tar.bz2
Forces user to use ScopedNSAutoreleasePool instead of using
NSAutoreleasePool with scoped_nsobject. BUG=none TEST=none Review URL: http://codereview.chromium.org/292011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29399 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/scoped_nsobject.h')
-rw-r--r--base/scoped_nsobject.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/base/scoped_nsobject.h b/base/scoped_nsobject.h
index 5f6d8bf..cc6f7bf 100644
--- a/base/scoped_nsobject.h
+++ b/base/scoped_nsobject.h
@@ -18,6 +18,12 @@
// caller must own the object it gives to scoped_nsobject<>, and relinquishes
// an ownership claim to that object. scoped_nsobject<> does not call
// -retain.
+//
+// scoped_nsobject<> is not to be used for NSAutoreleasePools. For
+// NSAutoreleasePools use ScopedNSAutoreleasePool from
+// scoped_nsautorelease_pool.h instead.
+// We check for bad uses of scoped_nsobject and NSAutoreleasePool at compile
+// time with a template specialization (see below).
template<typename NST>
class scoped_nsobject {
public:
@@ -32,6 +38,11 @@ class scoped_nsobject {
}
void reset(NST* object = nil) {
+ // We intentionally do not check that object != object_ as the caller must
+ // already have an ownership claim over whatever it gives to scoped_nsobject
+ // and scoped_cftyperef, whether it's in the constructor or in a call to
+ // reset(). In either case, it relinquishes that claim and the scoper
+ // assumes it.
[object_ release];
object_ = object;
}
@@ -88,6 +99,11 @@ class scoped_nsobject<id> {
}
void reset(id object = nil) {
+ // We intentionally do not check that object != object_ as the caller must
+ // already have an ownership claim over whatever it gives to scoped_nsobject
+ // and scoped_cftyperef, whether it's in the constructor or in a call to
+ // reset(). In either case, it relinquishes that claim and the scoper
+ // assumes it.
[object_ release];
object_ = object;
}
@@ -129,4 +145,14 @@ class scoped_nsobject<id> {
DISALLOW_COPY_AND_ASSIGN(scoped_nsobject);
};
+// Do not use scoped_nsobject for NSAutoreleasePools, use
+// ScopedNSAutoreleasePool instead. This is a compile time check. See details
+// at top of header.
+template<>
+class scoped_nsobject<NSAutoreleasePool> {
+ private:
+ explicit scoped_nsobject(NSAutoreleasePool* object = nil);
+ DISALLOW_COPY_AND_ASSIGN(scoped_nsobject);
+};
+
#endif // BASE_SCOPED_NSOBJECT_H_