ipc/chromium/src/base/scoped_nsautorelease_pool.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial