summaryrefslogtreecommitdiffstats
path: root/base/mac
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-18 02:47:39 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-18 02:47:39 +0000
commitc2818d44191bc4342c2ae322f3e0cb218dd2ec66 (patch)
treede6265a7e8506e6df679a436cb4df1cd7281a614 /base/mac
parente8b53808f5251d1486dd8b992fa94d96bb604e01 (diff)
downloadchromium_src-c2818d44191bc4342c2ae322f3e0cb218dd2ec66.zip
chromium_src-c2818d44191bc4342c2ae322f3e0cb218dd2ec66.tar.gz
chromium_src-c2818d44191bc4342c2ae322f3e0cb218dd2ec66.tar.bz2
Move scoped_nsdisable_screen_update from base to app/mac
Move scoped_aedesc from base to base/mac Use namespace and proper Google-style class naming. TEST=it compiles BUG=none Review URL: http://codereview.chromium.org/3828009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62904 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/mac')
-rw-r--r--base/mac/scoped_aedesc.h53
-rw-r--r--base/mac/scoped_nsautorelease_pool.h55
-rw-r--r--base/mac/scoped_nsautorelease_pool.mm32
3 files changed, 140 insertions, 0 deletions
diff --git a/base/mac/scoped_aedesc.h b/base/mac/scoped_aedesc.h
new file mode 100644
index 0000000..83a38c6
--- /dev/null
+++ b/base/mac/scoped_aedesc.h
@@ -0,0 +1,53 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_MAC_SCOPED_AEDESC_H_
+#define BASE_MAC_SCOPED_AEDESC_H_
+#pragma once
+
+#import <CoreServices/CoreServices.h>
+
+#include "base/basictypes.h"
+
+namespace base {
+namespace mac {
+
+// The ScopedAEDesc is used to scope AppleEvent descriptors. On creation,
+// it will store a NULL descriptor. On destruction, it will dispose of the
+// descriptor.
+//
+// This class is parameterized for additional type safety checks. You can use
+// the generic AEDesc type by not providing a template parameter:
+// ScopedAEDesc<> desc;
+template <typename AEDescType = AEDesc>
+class ScopedAEDesc {
+ public:
+ ScopedAEDesc() {
+ AECreateDesc(typeNull, NULL, 0, &desc_);
+ }
+
+ ~ScopedAEDesc() {
+ AEDisposeDesc(&desc_);
+ }
+
+ // Used for in parameters.
+ operator const AEDescType*() {
+ return &desc_;
+ }
+
+ // Used for out parameters.
+ AEDescType* OutPointer() {
+ return &desc_;
+ }
+
+ private:
+ AEDescType desc_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedAEDesc);
+};
+
+} // namespace mac
+} // namespace base
+
+#endif // BASE_MAC_SCOPED_AEDESC_H_
diff --git a/base/mac/scoped_nsautorelease_pool.h b/base/mac/scoped_nsautorelease_pool.h
new file mode 100644
index 0000000..0a95bd1b
--- /dev/null
+++ b/base/mac/scoped_nsautorelease_pool.h
@@ -0,0 +1,55 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_MAC_SCOPED_NSAUTORELEASE_POOL_H_
+#define BASE_MAC_SCOPED_NSAUTORELEASE_POOL_H_
+#pragma once
+
+#include "base/basictypes.h"
+
+#if defined(OS_MACOSX)
+#if defined(__OBJC__)
+@class NSAutoreleasePool;
+#else // __OBJC__
+class NSAutoreleasePool;
+#endif // __OBJC__
+#endif // OS_MACOSX
+
+namespace base {
+namespace mac {
+
+// On the Mac, ScopedNSAutoreleasePool allocates an NSAutoreleasePool when
+// instantiated and sends it a -drain message when destroyed. This allows an
+// autorelease pool to be maintained in ordinary C++ code without bringing in
+// any direct Objective-C dependency.
+//
+// On other platforms, ScopedNSAutoreleasePool is an empty object with no
+// effects. This allows it to be used directly in cross-platform code without
+// ugly #ifdefs.
+class ScopedNSAutoreleasePool {
+ public:
+#if !defined(OS_MACOSX)
+ ScopedNSAutoreleasePool() {}
+ void Recycle() { }
+#else // OS_MACOSX
+ ScopedNSAutoreleasePool();
+ ~ScopedNSAutoreleasePool();
+
+ // Clear out the pool in case its position on the stack causes it to be
+ // alive for long periods of time (such as the entire length of the app).
+ // Only use then when you're certain the items currently in the pool are
+ // no longer needed.
+ void Recycle();
+ private:
+ NSAutoreleasePool* autorelease_pool_;
+#endif // OS_MACOSX
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ScopedNSAutoreleasePool);
+};
+
+} // namespace mac
+} // namespace base
+
+#endif // BASE_MAC_SCOPED_NSAUTORELEASE_POOL_H_
diff --git a/base/mac/scoped_nsautorelease_pool.mm b/base/mac/scoped_nsautorelease_pool.mm
new file mode 100644
index 0000000..e542ca8
--- /dev/null
+++ b/base/mac/scoped_nsautorelease_pool.mm
@@ -0,0 +1,32 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/mac/scoped_nsautorelease_pool.h"
+
+#import <Foundation/Foundation.h>
+
+#include "base/logging.h"
+
+namespace base {
+namespace mac {
+
+ScopedNSAutoreleasePool::ScopedNSAutoreleasePool()
+ : autorelease_pool_([[NSAutoreleasePool alloc] init]) {
+ DCHECK(autorelease_pool_);
+}
+
+ScopedNSAutoreleasePool::~ScopedNSAutoreleasePool() {
+ [autorelease_pool_ drain];
+}
+
+// Cycle the internal pool, allowing everything there to get cleaned up and
+// start anew.
+void ScopedNSAutoreleasePool::Recycle() {
+ [autorelease_pool_ drain];
+ autorelease_pool_ = [[NSAutoreleasePool alloc] init];
+ DCHECK(autorelease_pool_);
+}
+
+} // namespace mac
+} // namespace base