• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef BASE_MAC_SCOPED_BLOCK_H_
6 #define BASE_MAC_SCOPED_BLOCK_H_
7 
8 #include <Block.h>
9 
10 #include "base/mac/scoped_typeref.h"
11 
12 namespace base {
13 namespace mac {
14 
15 namespace internal {
16 
17 template <typename B>
18 struct ScopedBlockTraits {
InvalidValueScopedBlockTraits19   static B InvalidValue() { return nullptr; }
RetainScopedBlockTraits20   static B Retain(B block) { return Block_copy(block); }
ReleaseScopedBlockTraits21   static void Release(B block) { Block_release(block); }
22 };
23 
24 }  // namespace internal
25 
26 // ScopedBlock<> is patterned after ScopedCFTypeRef<>, but uses Block_copy() and
27 // Block_release() instead of CFRetain() and CFRelease().
28 
29 template <typename B>
30 using ScopedBlock = ScopedTypeRef<B, internal::ScopedBlockTraits<B>>;
31 
32 }  // namespace mac
33 }  // namespace base
34 
35 #endif  // BASE_MAC_SCOPED_BLOCK_H_
36