| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_NSAUTORELEASE_POOL_H_ | 5 #ifndef BASE_MAC_SCOPED_NSAUTORELEASE_POOL_H_ |
| 6 #define BASE_MAC_SCOPED_NSAUTORELEASE_POOL_H_ | 6 #define BASE_MAC_SCOPED_NSAUTORELEASE_POOL_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/base_export.h" | 9 #include "base/base_export.h" |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 | 11 |
| 12 #if defined(OS_MACOSX) | |
| 13 #if defined(__OBJC__) | 12 #if defined(__OBJC__) |
| 14 @class NSAutoreleasePool; | 13 @class NSAutoreleasePool; |
| 15 #else // __OBJC__ | 14 #else // __OBJC__ |
| 16 class NSAutoreleasePool; | 15 class NSAutoreleasePool; |
| 17 #endif // __OBJC__ | 16 #endif // __OBJC__ |
| 18 #endif // OS_MACOSX | |
| 19 | 17 |
| 20 namespace base { | 18 namespace base { |
| 21 namespace mac { | 19 namespace mac { |
| 22 | 20 |
| 23 // On the Mac, ScopedNSAutoreleasePool allocates an NSAutoreleasePool when | 21 // ScopedNSAutoreleasePool allocates an NSAutoreleasePool when instantiated and |
| 24 // instantiated and sends it a -drain message when destroyed. This allows an | 22 // sends it a -drain message when destroyed. This allows an autorelease pool to |
| 25 // autorelease pool to be maintained in ordinary C++ code without bringing in | 23 // be maintained in ordinary C++ code without bringing in any direct Objective-C |
| 26 // any direct Objective-C dependency. | 24 // dependency. |
| 27 // | 25 |
| 28 // On other platforms, ScopedNSAutoreleasePool is an empty object with no | |
| 29 // effects. This allows it to be used directly in cross-platform code without | |
| 30 // ugly #ifdefs. | |
| 31 class BASE_EXPORT ScopedNSAutoreleasePool { | 26 class BASE_EXPORT ScopedNSAutoreleasePool { |
| 32 public: | 27 public: |
| 33 #if !defined(OS_MACOSX) | |
| 34 ScopedNSAutoreleasePool() {} | |
| 35 void Recycle() { } | |
| 36 #else // OS_MACOSX | |
| 37 ScopedNSAutoreleasePool(); | 28 ScopedNSAutoreleasePool(); |
| 38 ~ScopedNSAutoreleasePool(); | 29 ~ScopedNSAutoreleasePool(); |
| 39 | 30 |
| 40 // Clear out the pool in case its position on the stack causes it to be | 31 // Clear out the pool in case its position on the stack causes it to be |
| 41 // alive for long periods of time (such as the entire length of the app). | 32 // alive for long periods of time (such as the entire length of the app). |
| 42 // Only use then when you're certain the items currently in the pool are | 33 // Only use then when you're certain the items currently in the pool are |
| 43 // no longer needed. | 34 // no longer needed. |
| 44 void Recycle(); | 35 void Recycle(); |
| 45 private: | 36 private: |
| 46 NSAutoreleasePool* autorelease_pool_; | 37 NSAutoreleasePool* autorelease_pool_; |
| 47 #endif // OS_MACOSX | |
| 48 | 38 |
| 49 private: | 39 private: |
| 50 DISALLOW_COPY_AND_ASSIGN(ScopedNSAutoreleasePool); | 40 DISALLOW_COPY_AND_ASSIGN(ScopedNSAutoreleasePool); |
| 51 }; | 41 }; |
| 52 | 42 |
| 53 } // namespace mac | 43 } // namespace mac |
| 54 } // namespace base | 44 } // namespace base |
| 55 | 45 |
| 56 #endif // BASE_MAC_SCOPED_NSAUTORELEASE_POOL_H_ | 46 #endif // BASE_MAC_SCOPED_NSAUTORELEASE_POOL_H_ |
| OLD | NEW |