Index: base/mac/scoped_block.h |
diff --git a/base/mac/scoped_block.h b/base/mac/scoped_block.h |
index cff910f865dbb2fd09ef782379fcf22a13a75859..bc2688f13ac064d9c1acfd37fedc37d72c52b458 100644 |
--- a/base/mac/scoped_block.h |
+++ b/base/mac/scoped_block.h |
@@ -7,83 +7,27 @@ |
#include <Block.h> |
-#include "base/compiler_specific.h" |
-#include "base/memory/scoped_policy.h" |
+#include "base/mac/scoped_typeref.h" |
namespace base { |
namespace mac { |
-// ScopedBlock<> is patterned after ScopedCFTypeRef<>, but uses Block_copy() and |
-// Block_release() instead of CFRetain() and CFRelease(). |
- |
-template<typename B> |
-class ScopedBlock { |
- public: |
- explicit ScopedBlock( |
- B block = nullptr, |
- base::scoped_policy::OwnershipPolicy policy = base::scoped_policy::ASSUME) |
- : block_(block) { |
- if (block_ && policy == base::scoped_policy::RETAIN) |
- block_ = Block_copy(block); |
- } |
- |
- ScopedBlock(const ScopedBlock<B>& that) |
- : block_(that.block_) { |
- if (block_) |
- block_ = Block_copy(block_); |
- } |
- |
- ~ScopedBlock() { |
- if (block_) |
- Block_release(block_); |
- } |
- |
- ScopedBlock& operator=(const ScopedBlock<B>& that) { |
- reset(that.get(), base::scoped_policy::RETAIN); |
- return *this; |
- } |
- |
- void reset(B block = nullptr, |
- base::scoped_policy::OwnershipPolicy policy = |
- base::scoped_policy::ASSUME) { |
- if (block && policy == base::scoped_policy::RETAIN) |
- block = Block_copy(block); |
- if (block_) |
- Block_release(block_); |
- block_ = block; |
- } |
+namespace internal { |
- bool operator==(B that) const { |
- return block_ == that; |
- } |
- |
- bool operator!=(B that) const { |
- return block_ != that; |
- } |
- |
- operator B() const { |
- return block_; |
- } |
- |
- B get() const { |
- return block_; |
- } |
+template <typename B> |
+struct ScopedBlockTraits { |
+ static B InvalidValue() { return nullptr; } |
+ static B Retain(B block) { return Block_copy(block); } |
+ static void Release(B block) { Block_release(block); } |
+}; |
- void swap(ScopedBlock& that) { |
- B temp = that.block_; |
- that.block_ = block_; |
- block_ = temp; |
- } |
+} // namespace internal |
- B release() WARN_UNUSED_RESULT { |
- B temp = block_; |
- block_ = nullptr; |
- return temp; |
- } |
+// ScopedBlock<> is patterned after ScopedCFTypeRef<>, but uses Block_copy() and |
+// Block_release() instead of CFRetain() and CFRelease(). |
- private: |
- B block_; |
-}; |
+template <typename B> |
+using ScopedBlock = ScopedTypeRef<B, internal::ScopedBlockTraits<B>>; |
} // namespace mac |
} // namespace base |