| Index: base/mac/scoped_cftyperef.h
|
| diff --git a/base/mac/scoped_cftyperef.h b/base/mac/scoped_cftyperef.h
|
| index 9add9883f6eb221effb7be8432d38ee585f1d92c..ae008fba83709be9044bd4af39271746e1b2415e 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.
|
|
|
| @@ -10,6 +10,7 @@
|
|
|
| #include "base/basictypes.h"
|
| #include "base/compiler_specific.h"
|
| +#include "base/memory/scoped_policy.h"
|
|
|
| namespace base {
|
| namespace mac {
|
| @@ -19,18 +20,32 @@ namespace mac {
|
| // 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 parameterized 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,
|
| + base::scoped_policy::OwnershipPolicy policy = base::scoped_policy::ASSUME)
|
| : object_(object) {
|
| + if (object_ && policy == base::scoped_policy::RETAIN)
|
| + CFRetain(object_);
|
| + }
|
| +
|
| + ScopedCFTypeRef(const ScopedCFTypeRef<CFT>& that)
|
| + : object_(that.object_) {
|
| + if (object_)
|
| + CFRetain(object_);
|
| }
|
|
|
| ~ScopedCFTypeRef() {
|
| @@ -38,7 +53,16 @@ class ScopedCFTypeRef {
|
| CFRelease(object_);
|
| }
|
|
|
| - void reset(CFT object = NULL) {
|
| + ScopedCFTypeRef& operator=(const ScopedCFTypeRef<CFT>& that) {
|
| + reset(that.get(), base::scoped_policy::RETAIN);
|
| + return *this;
|
| + }
|
| +
|
| + void reset(CFT object = NULL,
|
| + base::scoped_policy::OwnershipPolicy policy =
|
| + base::scoped_policy::ASSUME) {
|
| + if (object && policy == base::scoped_policy::RETAIN)
|
| + CFRetain(object);
|
| if (object_)
|
| CFRelease(object_);
|
| object_ = object;
|
| @@ -77,8 +101,6 @@ class ScopedCFTypeRef {
|
|
|
| private:
|
| CFT object_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(ScopedCFTypeRef);
|
| };
|
|
|
| } // namespace mac
|
|
|