mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-18 04:19:55 +01:00
Add ScopedNSAutoreleasePool from Chromium.
This commit is contained in:
parent
1434cf0115
commit
3e65d3d5f0
1
debian/copyright
vendored
1
debian/copyright
vendored
@ -47,6 +47,7 @@ License: GPL-2+
|
||||
|
||||
Files: src/core/scoped_nsobject.h
|
||||
src/core/scoped_cftyperef.h
|
||||
src/core/scoped_nsautorelease_pool.*
|
||||
Copyright: 2011, The Chromium Authors
|
||||
License: BSD-Google
|
||||
|
||||
|
@ -728,6 +728,7 @@ optional_source(APPLE
|
||||
core/macfslistener.mm
|
||||
core/macglobalshortcutbackend.mm
|
||||
core/mac_startup.mm
|
||||
core/scoped_nsautorelease_pool.mm
|
||||
devices/macdevicelister.mm
|
||||
ui/globalshortcutgrabber.mm
|
||||
ui/macscreensaver.cpp
|
||||
|
@ -21,7 +21,6 @@
|
||||
#import <AppKit/NSNibDeclarations.h>
|
||||
#import <AppKit/NSViewController.h>
|
||||
|
||||
#import <Foundation/NSAutoreleasePool.h>
|
||||
#import <Foundation/NSBundle.h>
|
||||
#import <Foundation/NSError.h>
|
||||
#import <Foundation/NSFileManager.h>
|
||||
@ -47,6 +46,7 @@
|
||||
#include "utilities.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/scoped_cftyperef.h"
|
||||
#include "core/scoped_nsautorelease_pool.h"
|
||||
|
||||
#ifdef HAVE_SPARKLE
|
||||
#import <Sparkle/SUUpdater.h>
|
||||
@ -85,7 +85,7 @@ static bool BreakpadCallback(int, int, mach_port_t, void*) {
|
||||
}
|
||||
|
||||
static BreakpadRef InitBreakpad() {
|
||||
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
||||
ScopedNSAutoreleasePool pool;
|
||||
BreakpadRef breakpad = nil;
|
||||
NSDictionary* plist = [[NSBundle mainBundle] infoDictionary];
|
||||
if (plist) {
|
||||
@ -236,7 +236,7 @@ static BreakpadRef InitBreakpad() {
|
||||
namespace mac {
|
||||
|
||||
void MacMain() {
|
||||
[[NSAutoreleasePool alloc] init];
|
||||
ScopedNSAutoreleasePool pool;
|
||||
// Creates and sets the magic global variable so QApplication will find it.
|
||||
[MacApplication sharedApplication];
|
||||
#ifdef HAVE_SPARKLE
|
||||
@ -273,8 +273,7 @@ QString GetResourcesPath() {
|
||||
}
|
||||
|
||||
QString GetApplicationSupportPath() {
|
||||
NSAutoreleasePool* pool = [NSAutoreleasePool alloc];
|
||||
[pool init];
|
||||
ScopedNSAutoreleasePool pool;
|
||||
NSArray* paths = NSSearchPathForDirectoriesInDomains(
|
||||
NSApplicationSupportDirectory,
|
||||
NSUserDomainMask,
|
||||
@ -286,13 +285,11 @@ QString GetApplicationSupportPath() {
|
||||
} else {
|
||||
ret = "~/Library/Application Support";
|
||||
}
|
||||
[pool drain];
|
||||
return ret;
|
||||
}
|
||||
|
||||
QString GetMusicDirectory() {
|
||||
NSAutoreleasePool* pool = [NSAutoreleasePool alloc];
|
||||
[pool init];
|
||||
ScopedNSAutoreleasePool pool;
|
||||
NSArray* paths = NSSearchPathForDirectoriesInDomains(
|
||||
NSMusicDirectory,
|
||||
NSUserDomainMask,
|
||||
@ -304,7 +301,6 @@ QString GetMusicDirectory() {
|
||||
} else {
|
||||
ret = "~/Music";
|
||||
}
|
||||
[pool drain];
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
38
src/core/scoped_nsautorelease_pool.h
Normal file
38
src/core/scoped_nsautorelease_pool.h
Normal file
@ -0,0 +1,38 @@
|
||||
// Copyright (c) 2011 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_
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#if defined(__OBJC__)
|
||||
@class NSAutoreleasePool;
|
||||
#else // __OBJC__
|
||||
class NSAutoreleasePool;
|
||||
#endif // __OBJC__
|
||||
|
||||
// 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.
|
||||
|
||||
class ScopedNSAutoreleasePool {
|
||||
public:
|
||||
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_;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(ScopedNSAutoreleasePool);
|
||||
};
|
||||
|
||||
#endif // BASE_MAC_SCOPED_NSAUTORELEASE_POOL_H_
|
24
src/core/scoped_nsautorelease_pool.mm
Normal file
24
src/core/scoped_nsautorelease_pool.mm
Normal file
@ -0,0 +1,24 @@
|
||||
// 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 "scoped_nsautorelease_pool.h"
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
ScopedNSAutoreleasePool::ScopedNSAutoreleasePool()
|
||||
: autorelease_pool_([[NSAutoreleasePool alloc] init]) {
|
||||
Q_ASSERT(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];
|
||||
Q_ASSERT(autorelease_pool_);
|
||||
}
|
@ -20,6 +20,7 @@
|
||||
#include "mtpconnection.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/scoped_cftyperef.h"
|
||||
#include "core/scoped_nsautorelease_pool.h"
|
||||
#include "core/scoped_nsobject.h"
|
||||
|
||||
#include <CoreFoundation/CFRunLoop.h>
|
||||
@ -31,7 +32,6 @@
|
||||
#include <IOKit/storage/IOCDMedia.h>
|
||||
|
||||
#import <AppKit/NSWorkspace.h>
|
||||
#import <Foundation/NSAutoreleasePool.h>
|
||||
#import <Foundation/NSDictionary.h>
|
||||
#import <Foundation/NSNotification.h>
|
||||
#import <Foundation/NSPathUtilities.h>
|
||||
@ -113,7 +113,7 @@ MacDeviceLister::~MacDeviceLister() {
|
||||
}
|
||||
|
||||
void MacDeviceLister::Init() {
|
||||
[[NSAutoreleasePool alloc] init];
|
||||
ScopedNSAutoreleasePool pool;
|
||||
|
||||
// Populate MTP Device list.
|
||||
if (sMTPDeviceList.empty()) {
|
||||
|
@ -24,6 +24,8 @@
|
||||
|
||||
#import <GrowlApplicationBridge.h>
|
||||
|
||||
#include "core/scoped_nsautorelease_pool.h"
|
||||
|
||||
@interface GrowlInterface :NSObject <GrowlApplicationBridgeDelegate> {
|
||||
}
|
||||
-(void) SendGrowlAlert:(NSString*)message title:(NSString*)title image:(NSData*)image;
|
||||
@ -120,6 +122,7 @@ class OSD::GrowlNotificationWrapper {
|
||||
|
||||
private:
|
||||
GrowlInterface* growl_interface_;
|
||||
ScopedNSAutoreleasePool pool_;
|
||||
};
|
||||
|
||||
void OSD::Init() {
|
||||
|
Loading…
Reference in New Issue
Block a user