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