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..15563594421e8f809f3e7932140824cc162a4dbb 100644 |
| --- a/base/mac/scoped_cftyperef.h |
| +++ b/base/mac/scoped_cftyperef.h |
| @@ -14,6 +14,11 @@ |
| namespace base { |
| namespace mac { |
| +enum OwnershipPolicy { |
|
Ami GONE FROM CHROMIUM
2012/05/17 21:44:47
Any reason not to live inside ScopedCFTypeRef?
(in
sail
2012/05/23 23:02:29
Moving this would make the calling code look like
|
| + 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 |
| @@ -29,8 +34,17 @@ class ScopedCFTypeRef { |
| public: |
| typedef CFT element_type; |
| - explicit ScopedCFTypeRef(CFT object = NULL) |
| + explicit ScopedCFTypeRef(CFT object = NULL, |
| + OwnershipPolicy policy = ASSUME) |
|
Ami GONE FROM CHROMIUM
2012/05/17 21:44:47
I don't know that this style-guide violation (defa
sail
2012/05/23 23:02:29
This matches the scoped_nsprotocol constructor.
If
Ami GONE FROM CHROMIUM
2012/05/24 21:30:29
Like I said, my opinions about this file are low-p
|
| : object_(object) { |
| + if (object_ && policy == RETAIN) |
| + CFRetain(object_); |
| + } |
| + |
| + ScopedCFTypeRef(const ScopedCFTypeRef<CFT>& that) |
| + : object_(that.object_) { |
| + if (object_) |
| + CFRetain(object_); |
| } |
| ~ScopedCFTypeRef() { |
| @@ -38,7 +52,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 +99,6 @@ class ScopedCFTypeRef { |
| private: |
| CFT object_; |
| - |
| - DISALLOW_COPY_AND_ASSIGN(ScopedCFTypeRef); |
| }; |
| } // namespace mac |