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

Unified Diff: base/mac/scoped_refptr_cftype.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_refptr_cftype.h
diff --git a/base/mac/scoped_refptr_cftype.h b/base/mac/scoped_refptr_cftype.h
new file mode 100644
index 0000000000000000000000000000000000000000..eac397d1b3f72e61d81a6eb0d5b8b1977de652fc
--- /dev/null
+++ b/base/mac/scoped_refptr_cftype.h
@@ -0,0 +1,98 @@
+// 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.
Avi (use Gerrit) 2012/05/15 18:04:19 scoped_nsobject recently received an extension to
sail 2012/05/15 23:53:31 Done. Added OwnershipPolicy to ScopedCFTypeRef and
+
+#ifndef BASE_MAC_SCOPED_REFPTR_CFTYPE_H_
+#define BASE_MAC_SCOPED_REFPTR_CFTYPE_H_
+#pragma once
+
+#include <CoreFoundation/CoreFoundation.h>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+
+namespace base {
+namespace mac {
+
+// scoped_refptr_cftype<> is patterned after scoped_ref_ptr<> but maintains
+// ownership of a CoreFoundation object: any object that can be represented as a
+// CFTypeRef.
+template <class T>
+class scoped_refptr_cftype {
Robert Sesek 2012/05/15 16:04:49 Needs a test.
Robert Sesek 2012/05/15 16:04:49 I wonder if this should be named ScopedRefptrCFTyp
Ami GONE FROM CHROMIUM 2012/05/15 17:55:22 Could you avoid the need for this class (and tests
sail 2012/05/15 23:53:31 I followed Avi's suggestion and used ScopedCFTypeR
sail 2012/05/15 23:53:31 Removed this class.
+ public:
+ scoped_refptr_cftype() : ptr_(NULL) {
+ }
+
+ scoped_refptr_cftype(T p) : ptr_(p) {
+ if (ptr_)
+ CFRetain(ptr_);
+ }
+
+ scoped_refptr_cftype(const scoped_refptr_cftype<T>& r) : ptr_(r.ptr_) {
+ if (ptr_)
+ CFRetain(ptr_);
+ }
+
+ template <typename U>
+ scoped_refptr_cftype(const scoped_refptr_cftype<U>& r) : ptr_(r.get()) {
+ if (ptr_)
+ CFRetain(ptr_);
+ }
+
+ ~scoped_refptr_cftype() {
+ if (ptr_)
+ CFRelease(ptr_);
+ }
+
+ T get() const { return ptr_; }
+ operator T() const { return ptr_; }
+
+ // Release a pointer.
+ // The return value is the current pointer held by this object.
+ // If this object holds a NULL pointer, the return value is NULL.
+ // After this operation, this object will hold a NULL pointer,
+ // and will not own the object any more.
+ T release() {
+ T retVal = ptr_;
+ ptr_ = NULL;
+ return retVal;
+ }
+
+ scoped_refptr_cftype<T>& operator=(T p) {
+ // Retain first so that self assignment should work
Robert Sesek 2012/05/15 16:04:49 nit: full-stop
+ if (p)
+ CFRetain(p);
+ T old_ptr = ptr_;
+ ptr_ = p;
+ if (old_ptr)
+ CFRelease(old_ptr);
+ return *this;
+ }
+
+ scoped_refptr_cftype<T>& operator=(const scoped_refptr_cftype<T>& r) {
+ return *this = r.ptr_;
+ }
+
+ template <typename U>
+ scoped_refptr_cftype<T>& operator=(const scoped_refptr_cftype<U>& r) {
+ return *this = r.get();
+ }
+
+ void swap(T* pp) {
+ T p = ptr_;
+ ptr_ = *pp;
+ *pp = p;
+ }
+
+ void swap(scoped_refptr_cftype<T>& r) {
+ swap(&r.ptr_);
+ }
+
+ protected:
Robert Sesek 2012/05/15 16:04:49 Why not private?
+ T ptr_;
+};
+
+} // namespace mac
+} // namespace base
+
+#endif // BASE_MAC_SCOPED_REFPTR_CFTYPE_H_

Powered by Google App Engine
This is Rietveld 408576698