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

Unified Diff: base/mac/scoped_cftyperef.h

Issue 10388108: Implement media::VideoDecodeAccelerator on Mac (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: a Created 8 years, 7 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
Index: base/mac/scoped_cftyperef.h
diff --git a/base/mac/scoped_cftyperef.h b/base/mac/scoped_cftyperef.h
index 9add9883f6eb221effb7be8432d38ee585f1d92c..75815c9b1e5bb02c796249a9fd25dd4f7d09803c 100644
--- a/base/mac/scoped_cftyperef.h
+++ b/base/mac/scoped_cftyperef.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -14,23 +14,41 @@
namespace base {
namespace mac {
+enum OwnershipPolicy {
+ ASSUME,
+ RETAIN
+};
+
// 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
// scoped_ptr<>'s interface, with which everyone is already familiar.
//
-// When ScopedCFTypeRef<> takes ownership of an object (in the constructor or
-// in reset()), it takes over the caller's existing ownership claim. The
-// caller must own the object it gives to ScopedCFTypeRef<>, and relinquishes
-// an ownership claim to that object. ScopedCFTypeRef<> does not call
-// CFRetain().
+// By default, ScopedCFTypeRef<> takes ownership of an object (in the
+// constructor or in reset()) by taking over the caller's existing ownership
+// claim. The caller must own the object it gives to ScopedCFTypeRef<>, and
+// relinquishes an ownership claim to that object. ScopedCFTypeRef<> does not
+// call CFRetain(). This behavior is parametrized by the |OwnershipPolicy| enum.
+// If the value |RETAIN| is passed (in the constructor or in reset()), then
+// ScopedCFTypeRef<> will call CFRetain() on the object, and the initial
+// ownership is not changed.
+
template<typename CFT>
class ScopedCFTypeRef {
public:
typedef CFT element_type;
- explicit ScopedCFTypeRef(CFT object = NULL)
+ explicit ScopedCFTypeRef(CFT object = NULL,
+ OwnershipPolicy policy = ASSUME)
: object_(object) {
+ if (object_ && policy == RETAIN)
+ CFRetain(object_);
+ }
+
+ ScopedCFTypeRef(const ScopedCFTypeRef<CFT>& that)
+ : object_(that.object_) {
+ if (object_)
+ CFRetain(object_);
}
~ScopedCFTypeRef() {
@@ -38,7 +56,15 @@ class ScopedCFTypeRef {
CFRelease(object_);
}
- void reset(CFT object = NULL) {
+ ScopedCFTypeRef& operator=(const ScopedCFTypeRef<CFT>& that) {
+ reset(that.get(), RETAIN);
+ return *this;
+ }
+
+ void reset(CFT object = NULL,
+ OwnershipPolicy policy = ASSUME) {
+ if (object && policy == RETAIN)
+ CFRetain(object);
if (object_)
CFRelease(object_);
object_ = object;
@@ -77,8 +103,6 @@ class ScopedCFTypeRef {
private:
CFT object_;
-
- DISALLOW_COPY_AND_ASSIGN(ScopedCFTypeRef);
};
} // namespace mac

Powered by Google App Engine
This is Rietveld 408576698