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


CrOS-Libchrome-Original-Commit: bd5624b004af9e7db9b72f5a8c51bc897962fd43
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 @@
   }
 
   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 @@
   }
 
   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 @@
   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_