Chromium Code Reviews| 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 { |
|
Mark Mentovai
2012/05/31 13:15:53
Now we have base::mac::OwnershipPolicy here and sc
sail
2012/06/01 00:05:41
Done.
Moved to base/memory/scoped_policy.h
|
| + 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. |
|
Avi (use Gerrit)
2012/05/31 04:09:40
parameterized
sail
2012/06/01 00:05:41
Done.
|
| +// 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, |
|
Nico
2012/05/30 23:33:39
Wouldn't it be nicer to have a global template fun
sail
2012/05/30 23:37:55
But ScopedCFTypeRef didn't have copy and assign wh
|
| + 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 |