Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Side by Side Diff: base/mac/scoped_block.h

Issue 1855483004: [iOS/OS X] Allow base::scoped_nsobject<> to be used when ARC is enabled. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missing copy constructor from scoped_nsobject<subclass> to scoped_nsobject<class> Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/mac/bind_objc_block_unittest_arc.mm ('k') | base/mac/scoped_nsobject.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #if defined(__has_feature) && __has_feature(objc_arc)
13 #define BASE_MAC_BRIDGE_CAST(TYPE, VALUE) (__bridge TYPE)(VALUE)
14 #else
15 #define BASE_MAC_BRIDGE_CAST(TYPE, VALUE) VALUE
16 #endif
17
12 namespace base { 18 namespace base {
13 namespace mac { 19 namespace mac {
14 20
15 namespace internal { 21 namespace internal {
16 22
17 template <typename B> 23 template <typename B>
18 struct ScopedBlockTraits { 24 struct ScopedBlockTraits {
19 static B InvalidValue() { return nullptr; } 25 static B InvalidValue() { return nullptr; }
20 static B Retain(B block) { return Block_copy(block); } 26 static B Retain(B block) {
21 static void Release(B block) { Block_release(block); } 27 return BASE_MAC_BRIDGE_CAST(
28 B, Block_copy(BASE_MAC_BRIDGE_CAST(const void*, block)));
29 }
30 static void Release(B block) {
31 Block_release(BASE_MAC_BRIDGE_CAST(const void*, block));
32 }
22 }; 33 };
23 34
24 } // namespace internal 35 } // namespace internal
25 36
26 // ScopedBlock<> is patterned after ScopedCFTypeRef<>, but uses Block_copy() and 37 // ScopedBlock<> is patterned after ScopedCFTypeRef<>, but uses Block_copy() and
27 // Block_release() instead of CFRetain() and CFRelease(). 38 // Block_release() instead of CFRetain() and CFRelease().
28 39
29 template <typename B> 40 template <typename B>
30 using ScopedBlock = ScopedTypeRef<B, internal::ScopedBlockTraits<B>>; 41 using ScopedBlock = ScopedTypeRef<B, internal::ScopedBlockTraits<B>>;
31 42
32 } // namespace mac 43 } // namespace mac
33 } // namespace base 44 } // namespace base
34 45
46 #undef BASE_MAC_BRIDGE_CAST
47
35 #endif // BASE_MAC_SCOPED_BLOCK_H_ 48 #endif // BASE_MAC_SCOPED_BLOCK_H_
OLDNEW
« no previous file with comments | « base/mac/bind_objc_block_unittest_arc.mm ('k') | base/mac/scoped_nsobject.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698