1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/ipc/chromium/src/base/scoped_nsautorelease_pool.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,52 @@ 1.4 +// Copyright (c) 2008 The Chromium Authors. All rights reserved. 1.5 +// Use of this source code is governed by a BSD-style license that can be 1.6 +// found in the LICENSE file. 1.7 + 1.8 +#ifndef BASE_SCOPED_NSAUTORELEASE_POOL_H_ 1.9 +#define BASE_SCOPED_NSAUTORELEASE_POOL_H_ 1.10 + 1.11 +#include "base/basictypes.h" 1.12 + 1.13 +#if defined(OS_MACOSX) 1.14 +#if defined(__OBJC__) 1.15 +@class NSAutoreleasePool; 1.16 +#else // __OBJC__ 1.17 +class NSAutoreleasePool; 1.18 +#endif // __OBJC__ 1.19 +#endif // OS_MACOSX 1.20 + 1.21 +namespace base { 1.22 + 1.23 +// On the Mac, ScopedNSAutoreleasePool allocates an NSAutoreleasePool when 1.24 +// instantiated and sends it a -drain message when destroyed. This allows an 1.25 +// autorelease pool to be maintained in ordinary C++ code without bringing in 1.26 +// any direct Objective-C dependency. 1.27 +// 1.28 +// On other platforms, ScopedNSAutoreleasePool is an empty object with no 1.29 +// effects. This allows it to be used directly in cross-platform code without 1.30 +// ugly #ifdefs. 1.31 +class ScopedNSAutoreleasePool { 1.32 + public: 1.33 +#if !defined(OS_MACOSX) 1.34 + ScopedNSAutoreleasePool() {} 1.35 + void Recycle() { } 1.36 +#else // OS_MACOSX 1.37 + ScopedNSAutoreleasePool(); 1.38 + ~ScopedNSAutoreleasePool(); 1.39 + 1.40 + // Clear out the pool in case its position on the stack causes it to be 1.41 + // alive for long periods of time (such as the entire length of the app). 1.42 + // Only use then when you're certain the items currently in the pool are 1.43 + // no longer needed. 1.44 + void Recycle(); 1.45 + private: 1.46 + NSAutoreleasePool* autorelease_pool_; 1.47 +#endif // OS_MACOSX 1.48 + 1.49 + private: 1.50 + DISALLOW_COPY_AND_ASSIGN(ScopedNSAutoreleasePool); 1.51 +}; 1.52 + 1.53 +} // namespace base 1.54 + 1.55 +#endif // BASE_SCOPED_NSAUTORELEASE_POOL_H_