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

Unified Diff: base/mac/scoped_cftyperef.h

Issue 8233027: Support dynamic switching between integrated and discrete GPUs on Mac OS X. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' 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 | chrome/app/app-Info.plist » ('j') | ui/gfx/gl/gl_context_mac.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/mac/scoped_cftyperef.h
===================================================================
--- base/mac/scoped_cftyperef.h (revision 105357)
+++ base/mac/scoped_cftyperef.h (working copy)
@@ -14,6 +14,15 @@
namespace base {
namespace mac {
+// This class wraps the CoreFoundation routine CFRelease() in a class
+// that can be passed as a template argument to ScopedCFTypeRef below.
+class ScopedCFTypeRefRelease {
+ public:
+ inline void operator()(CFTypeRef x) const {
+ CFRelease(x);
+ }
+};
+
// ScopedCFTypeRef<> is patterned after scoped_ptr<>, but maintains ownership
// of a CoreFoundation object: any object that can be represented as a
// CFTypeRef. Style deviations here are solely for compatibility with
@@ -24,7 +33,12 @@
// caller must own the object it gives to ScopedCFTypeRef<>, and relinquishes
// an ownership claim to that object. ScopedCFTypeRef<> does not call
// CFRetain().
-template<typename CFT>
+//
+// The second template argument can be used to specify a functor used
+// to free the object. This allows this class to manage the lifetime
+// of objects similar to Core Foundation types, where the pointer-ness
+// is embedded in the type name) but with specialized releasing routines.
Mark Mentovai 2011/10/13 20:20:48 The ) doesn’t close any (.
+template<typename CFT, class FreeProc = ScopedCFTypeRefRelease>
class ScopedCFTypeRef {
public:
typedef CFT element_type;
@@ -34,13 +48,17 @@
}
~ScopedCFTypeRef() {
- if (object_)
- CFRelease(object_);
+ if (object_) {
+ FreeProc free_proc;
+ free_proc(object_);
+ }
}
void reset(CFT object = NULL) {
- if (object_)
- CFRelease(object_);
+ if (object_) {
+ FreeProc free_proc;
+ free_proc(object_);
+ }
object_ = object;
}
« no previous file with comments | « no previous file | chrome/app/app-Info.plist » ('j') | ui/gfx/gl/gl_context_mac.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698