Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_MAC_SCOPED_BLOCK_H_ | 5 #ifndef BASE_MAC_SCOPED_BLOCK_H_ |
| 6 #define BASE_MAC_SCOPED_BLOCK_H_ | 6 #define BASE_MAC_SCOPED_BLOCK_H_ |
| 7 | 7 |
| 8 #include <Block.h> | 8 #include <Block.h> |
| 9 | 9 |
| 10 #include "base/mac/scoped_typeref.h" | 10 #include "base/mac/scoped_typeref.h" |
| 11 | 11 |
| 12 namespace base { | 12 namespace base { |
| 13 namespace mac { | 13 namespace mac { |
| 14 | 14 |
| 15 namespace internal { | 15 namespace internal { |
| 16 | 16 |
| 17 id ScopedBlockTraitsRetain(id block); | |
|
Mark Mentovai
2016/04/05 00:09:15
Blocks are normally typed as const void*. If you u
| |
| 18 void ScopedBlockTraitsRelease(id block); | |
| 19 | |
| 17 template <typename B> | 20 template <typename B> |
| 18 struct ScopedBlockTraits { | 21 struct ScopedBlockTraits { |
| 19 static B InvalidValue() { return nullptr; } | 22 static B InvalidValue() { return nullptr; } |
| 20 static B Retain(B block) { return Block_copy(block); } | 23 static B Retain(B block) { return ScopedBlockTraitsRetain(block); } |
| 21 static void Release(B block) { Block_release(block); } | 24 static void Release(B block) { ScopedBlockTraitsRelease(block); } |
| 22 }; | 25 }; |
| 23 | 26 |
| 24 } // namespace internal | 27 } // namespace internal |
| 25 | 28 |
| 26 // ScopedBlock<> is patterned after ScopedCFTypeRef<>, but uses Block_copy() and | 29 // ScopedBlock<> is patterned after ScopedCFTypeRef<>, but uses Block_copy() and |
| 27 // Block_release() instead of CFRetain() and CFRelease(). | 30 // Block_release() instead of CFRetain() and CFRelease(). |
| 28 | 31 |
| 29 template <typename B> | 32 template <typename B> |
| 30 using ScopedBlock = ScopedTypeRef<B, internal::ScopedBlockTraits<B>>; | 33 using ScopedBlock = ScopedTypeRef<B, internal::ScopedBlockTraits<B>>; |
| 31 | 34 |
| 32 } // namespace mac | 35 } // namespace mac |
| 33 } // namespace base | 36 } // namespace base |
| 34 | 37 |
| 35 #endif // BASE_MAC_SCOPED_BLOCK_H_ | 38 #endif // BASE_MAC_SCOPED_BLOCK_H_ |
| OLD | NEW |