diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-29 15:06:32 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-29 15:06:32 +0000 |
commit | 1671162ffe4a1dd3b54de53732c6ae865b2f8ea3 (patch) | |
tree | aa53729a9a9adc4348e546dcfc873370ecbae820 | |
parent | f19a218851c01749340806ed9be59135cfced928 (diff) | |
download | chromium_src-1671162ffe4a1dd3b54de53732c6ae865b2f8ea3.zip chromium_src-1671162ffe4a1dd3b54de53732c6ae865b2f8ea3.tar.gz chromium_src-1671162ffe4a1dd3b54de53732c6ae865b2f8ea3.tar.bz2 |
Mac base cleanup.
Move the sole inhabitant of base/foundation_utils_mac.h into base/mac/foundation_util.h|mm.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6904128
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@83514 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/base.gypi | 1 | ||||
-rw-r--r-- | base/foundation_utils_mac.h | 38 | ||||
-rw-r--r-- | base/mac/foundation_util.h | 19 | ||||
-rw-r--r-- | base/mac/foundation_util.mm | 11 | ||||
-rw-r--r-- | base/sys_string_conversions_mac.mm | 13 |
5 files changed, 38 insertions, 44 deletions
diff --git a/base/base.gypi b/base/base.gypi index 58089e9..e8aeb50 100644 --- a/base/base.gypi +++ b/base/base.gypi @@ -94,7 +94,6 @@ 'files/file_path_watcher_win.cc', 'fix_wp64.h', 'float_util.h', - 'foundation_utils_mac.h', 'global_descriptors_posix.cc', 'global_descriptors_posix.h', 'gtest_prod_util.h', diff --git a/base/foundation_utils_mac.h b/base/foundation_utils_mac.h deleted file mode 100644 index 740a383..0000000 --- a/base/foundation_utils_mac.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2008 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_FOUNDATION_UTILS_MAC_H_ -#define BASE_FOUNDATION_UTILS_MAC_H_ -#pragma once - -#include <CoreFoundation/CoreFoundation.h> -#import <Foundation/Foundation.h> - -// CFTypeRefToNSObjectAutorelease transfers ownership of a Core Foundation -// object (one derived from CFTypeRef) to the Foundation memory management -// system. In a traditional managed-memory environment, cf_object is -// autoreleased and returned as an NSObject. In a garbage-collected -// environment, cf_object is marked as eligible for garbage collection. -// -// This function should only be used to convert a concrete CFTypeRef type to -// its equivalent "toll-free bridged" NSObject subclass, for example, -// converting a CFStringRef to NSString. -// -// By calling this function, callers relinquish any ownership claim to -// cf_object. In a managed-memory environment, the object's ownership will be -// managed by the innermost NSAutoreleasePool, so after this function returns, -// callers should not assume that cf_object is valid any longer than the -// returned NSObject. -static inline id CFTypeRefToNSObjectAutorelease(CFTypeRef cf_object) { - // When GC is on, NSMakeCollectable marks cf_object for GC and autorelease - // is a no-op. - // - // In the traditional GC-less environment, NSMakeCollectable is a no-op, - // and cf_object is autoreleased, balancing out the caller's ownership claim. - // - // NSMakeCollectable returns nil when used on a NULL object. - return [NSMakeCollectable(cf_object) autorelease]; -} - -#endif // BASE_FOUNDATION_UTILS_MAC_H_ diff --git a/base/mac/foundation_util.h b/base/mac/foundation_util.h index 7f14d93..24a301e 100644 --- a/base/mac/foundation_util.h +++ b/base/mac/foundation_util.h @@ -103,6 +103,25 @@ CFTypeRef GetValueFromDictionary(CFDictionaryRef dict, void NSObjectRetain(void* obj); void NSObjectRelease(void* obj); +// CFTypeRefToNSObjectAutorelease transfers ownership of a Core Foundation +// object (one derived from CFTypeRef) to the Foundation memory management +// system. In a traditional managed-memory environment, cf_object is +// autoreleased and returned as an NSObject. In a garbage-collected +// environment, cf_object is marked as eligible for garbage collection. +// +// This function should only be used to convert a concrete CFTypeRef type to +// its equivalent "toll-free bridged" NSObject subclass, for example, +// converting a CFStringRef to NSString. +// +// By calling this function, callers relinquish any ownership claim to +// cf_object. In a managed-memory environment, the object's ownership will be +// managed by the innermost NSAutoreleasePool, so after this function returns, +// callers should not assume that cf_object is valid any longer than the +// returned NSObject. +// +// Returns an id, typed here for C++'s sake as a void*. +void* CFTypeRefToNSObjectAutorelease(CFTypeRef cf_object); + // Returns the base bundle ID, which can be set by SetBaseBundleID but // defaults to a reasonable string. This never returns NULL. BaseBundleID // returns a pointer to static storage that must not be freed. diff --git a/base/mac/foundation_util.mm b/base/mac/foundation_util.mm index e8c3efc..6ad3b01 100644 --- a/base/mac/foundation_util.mm +++ b/base/mac/foundation_util.mm @@ -235,6 +235,17 @@ void NSObjectRelease(void* obj) { [nsobj release]; } +void* CFTypeRefToNSObjectAutorelease(CFTypeRef cf_object) { + // When GC is on, NSMakeCollectable marks cf_object for GC and autorelease + // is a no-op. + // + // In the traditional GC-less environment, NSMakeCollectable is a no-op, + // and cf_object is autoreleased, balancing out the caller's ownership claim. + // + // NSMakeCollectable returns nil when used on a NULL object. + return [NSMakeCollectable(cf_object) autorelease]; +} + static const char* base_bundle_id; const char* BaseBundleID() { diff --git a/base/sys_string_conversions_mac.mm b/base/sys_string_conversions_mac.mm index 4b5648c..5f507ce 100644 --- a/base/sys_string_conversions_mac.mm +++ b/base/sys_string_conversions_mac.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// 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. @@ -8,7 +8,7 @@ #include <vector> -#include "base/foundation_utils_mac.h" +#include "base/mac/foundation_util.h" #include "base/mac/scoped_cftyperef.h" #include "base/string_piece.h" @@ -157,15 +157,18 @@ CFStringRef SysWideToCFStringRef(const std::wstring& wide) { } NSString* SysUTF8ToNSString(const std::string& utf8) { - return CFTypeRefToNSObjectAutorelease(SysUTF8ToCFStringRef(utf8)); + return (NSString*)base::mac::CFTypeRefToNSObjectAutorelease( + SysUTF8ToCFStringRef(utf8)); } NSString* SysUTF16ToNSString(const string16& utf16) { - return CFTypeRefToNSObjectAutorelease(SysUTF16ToCFStringRef(utf16)); + return (NSString*)base::mac::CFTypeRefToNSObjectAutorelease( + SysUTF16ToCFStringRef(utf16)); } NSString* SysWideToNSString(const std::wstring& wide) { - return CFTypeRefToNSObjectAutorelease(SysWideToCFStringRef(wide)); + return (NSString*)base::mac::CFTypeRefToNSObjectAutorelease( + SysWideToCFStringRef(wide)); } std::string SysCFStringRefToUTF8(CFStringRef ref) { |