diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-17 04:09:06 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-17 04:09:06 +0000 |
commit | df0ca6c858762b101bf424ff6c0522409fa195fc (patch) | |
tree | efa188eee6972e2c0de358f2d19a2348ce6dcb06 /base | |
parent | 73de26a684944782a92f8e6840e1b290c9a424cd (diff) | |
download | chromium_src-df0ca6c858762b101bf424ff6c0522409fa195fc.zip chromium_src-df0ca6c858762b101bf424ff6c0522409fa195fc.tar.gz chromium_src-df0ca6c858762b101bf424ff6c0522409fa195fc.tar.bz2 |
Move scoped_cftyperef from base to base/mac, use the new namespace, and name it
properly (scoped_cftyperef -> ScopedCFTypeRef).
TEST=it compiles
BUG=none
Review URL: http://codereview.chromium.org/3855001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62887 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/file_path.cc | 8 | ||||
-rw-r--r-- | base/mac/scoped_cftyperef.h (renamed from base/scoped_cftyperef.h) | 39 | ||||
-rw-r--r-- | base/mac_util.mm | 32 | ||||
-rw-r--r-- | base/mac_util_unittest.mm | 6 | ||||
-rw-r--r-- | base/native_library_mac.mm | 15 | ||||
-rw-r--r-- | base/scoped_nsobject.h | 16 | ||||
-rw-r--r-- | base/sys_string_conversions_mac.mm | 4 | ||||
-rw-r--r-- | base/time_mac.cc | 6 |
8 files changed, 68 insertions, 58 deletions
diff --git a/base/file_path.cc b/base/file_path.cc index e330e3c..5165828 100644 --- a/base/file_path.cc +++ b/base/file_path.cc @@ -21,7 +21,7 @@ #include "base/utf_string_conversions.h" #if defined(OS_MACOSX) -#include "base/scoped_cftyperef.h" +#include "base/mac/scoped_cftyperef.h" #include "base/third_party/icu/icu_utf.h" #endif @@ -991,7 +991,7 @@ int FilePath::HFSFastUnicodeCompare(const StringType& string1, } StringType FilePath::GetHFSDecomposedForm(const StringType& string) { - scoped_cftyperef<CFStringRef> cfstring( + base::mac::ScopedCFTypeRef<CFStringRef> cfstring( CFStringCreateWithBytesNoCopy( NULL, reinterpret_cast<const UInt8*>(string.c_str()), @@ -1038,7 +1038,7 @@ int FilePath::CompareIgnoreCase(const StringType& string1, // GetHFSDecomposedForm() returns an empty string in an error case. if (hfs1.empty() || hfs2.empty()) { NOTREACHED(); - scoped_cftyperef<CFStringRef> cfstring1( + base::mac::ScopedCFTypeRef<CFStringRef> cfstring1( CFStringCreateWithBytesNoCopy( NULL, reinterpret_cast<const UInt8*>(string1.c_str()), @@ -1046,7 +1046,7 @@ int FilePath::CompareIgnoreCase(const StringType& string1, kCFStringEncodingUTF8, false, kCFAllocatorNull)); - scoped_cftyperef<CFStringRef> cfstring2( + base::mac::ScopedCFTypeRef<CFStringRef> cfstring2( CFStringCreateWithBytesNoCopy( NULL, reinterpret_cast<const UInt8*>(string2.c_str()), diff --git a/base/scoped_cftyperef.h b/base/mac/scoped_cftyperef.h index 4e41816..9add988 100644 --- a/base/scoped_cftyperef.h +++ b/base/mac/scoped_cftyperef.h @@ -1,35 +1,39 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// 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_SCOPED_CFTYPEREF_H_ -#define BASE_SCOPED_CFTYPEREF_H_ +#ifndef BASE_MAC_SCOPED_CFTYPEREF_H_ +#define BASE_MAC_SCOPED_CFTYPEREF_H_ #pragma once #include <CoreFoundation/CoreFoundation.h> + #include "base/basictypes.h" #include "base/compiler_specific.h" -// scoped_cftyperef<> is patterned after scoped_ptr<>, but maintains ownership +namespace base { +namespace mac { + +// ScopedCFTypeRef<> is patterned after scoped_ptr<>, but maintains ownership // of a CoreFoundation object: any object that can be represented as a // CFTypeRef. Style deviations here are solely for compatibility with // scoped_ptr<>'s interface, with which everyone is already familiar. // -// When scoped_cftyperef<> takes ownership of an object (in the constructor or +// When ScopedCFTypeRef<> takes ownership of an object (in the constructor or // in reset()), it takes over the caller's existing ownership claim. The -// caller must own the object it gives to scoped_cftyperef<>, and relinquishes -// an ownership claim to that object. scoped_cftyperef<> does not call +// caller must own the object it gives to ScopedCFTypeRef<>, and relinquishes +// an ownership claim to that object. ScopedCFTypeRef<> does not call // CFRetain(). template<typename CFT> -class scoped_cftyperef { +class ScopedCFTypeRef { public: typedef CFT element_type; - explicit scoped_cftyperef(CFT object = NULL) + explicit ScopedCFTypeRef(CFT object = NULL) : object_(object) { } - ~scoped_cftyperef() { + ~ScopedCFTypeRef() { if (object_) CFRelease(object_); } @@ -56,15 +60,15 @@ class scoped_cftyperef { return object_; } - void swap(scoped_cftyperef& that) { + void swap(ScopedCFTypeRef& that) { CFT temp = that.object_; that.object_ = object_; object_ = temp; } - // scoped_cftyperef<>::release() is like scoped_ptr<>::release. It is NOT - // a wrapper for CFRelease(). To force a scoped_cftyperef<> object to call - // CFRelease(), use scoped_cftyperef<>::reset(). + // ScopedCFTypeRef<>::release() is like scoped_ptr<>::release. It is NOT + // a wrapper for CFRelease(). To force a ScopedCFTypeRef<> object to call + // CFRelease(), use ScopedCFTypeRef<>::reset(). CFT release() WARN_UNUSED_RESULT { CFT temp = object_; object_ = NULL; @@ -74,7 +78,10 @@ class scoped_cftyperef { private: CFT object_; - DISALLOW_COPY_AND_ASSIGN(scoped_cftyperef); + DISALLOW_COPY_AND_ASSIGN(ScopedCFTypeRef); }; -#endif // BASE_SCOPED_CFTYPEREF_H_ +} // namespace mac +} // namespace base + +#endif // BASE_MAC_SCOPED_CFTYPEREF_H_ diff --git a/base/mac_util.mm b/base/mac_util.mm index b3a594a..f4e988a 100644 --- a/base/mac_util.mm +++ b/base/mac_util.mm @@ -8,11 +8,13 @@ #include "base/file_path.h" #include "base/logging.h" +#include "base/mac/scoped_cftyperef.h" #include "base/message_loop.h" -#include "base/scoped_cftyperef.h" #include "base/scoped_nsobject.h" #include "base/sys_string_conversions.h" +using base::mac::ScopedCFTypeRef; + namespace { // a count of currently outstanding requests for full screen mode from browser @@ -78,7 +80,7 @@ bool WasLaunchedAsLoginItem() { // representing the current application. If such an item is found, returns // retained reference to it. Caller is responsible for releasing the reference. LSSharedFileListItemRef GetLoginItemForApp() { - scoped_cftyperef<LSSharedFileListRef> login_items(LSSharedFileListCreate( + ScopedCFTypeRef<LSSharedFileListRef> login_items(LSSharedFileListCreate( NULL, kLSSharedFileListSessionLoginItems, NULL)); if (!login_items.get()) { @@ -98,7 +100,7 @@ LSSharedFileListItemRef GetLoginItemForApp() { CFURLRef item_url_ref = NULL; if (LSSharedFileListItemResolve(item, 0, &item_url_ref, NULL) == noErr) { - scoped_cftyperef<CFURLRef> item_url(item_url_ref); + ScopedCFTypeRef<CFURLRef> item_url(item_url_ref); if (CFEqual(item_url, url)) { CFRetain(item); return item; @@ -119,7 +121,7 @@ static NSString* kLSSharedFileListLoginItemHidden = #endif bool IsHiddenLoginItem(LSSharedFileListItemRef item) { - scoped_cftyperef<CFBooleanRef> hidden(reinterpret_cast<CFBooleanRef>( + ScopedCFTypeRef<CFBooleanRef> hidden(reinterpret_cast<CFBooleanRef>( LSSharedFileListItemCopyProperty(item, reinterpret_cast<CFStringRef>(kLSSharedFileListLoginItemHidden)))); @@ -131,7 +133,7 @@ bool IsHiddenLoginItem(LSSharedFileListItemRef item) { namespace mac_util { std::string PathFromFSRef(const FSRef& ref) { - scoped_cftyperef<CFURLRef> url( + ScopedCFTypeRef<CFURLRef> url( CFURLCreateFromFSRef(kCFAllocatorDefault, &ref)); NSString *path_string = [(NSURL *)url.get() path]; return [path_string fileSystemRepresentation]; @@ -455,9 +457,9 @@ CFTypeRef GetValueFromDictionary(CFDictionaryRef dict, return value; if (CFGetTypeID(value) != expected_type) { - scoped_cftyperef<CFStringRef> expected_type_ref( + ScopedCFTypeRef<CFStringRef> expected_type_ref( CFCopyTypeIDDescription(expected_type)); - scoped_cftyperef<CFStringRef> actual_type_ref( + ScopedCFTypeRef<CFStringRef> actual_type_ref( CFCopyTypeIDDescription(CFGetTypeID(value))); LOG(WARNING) << "Expected value for key " << base::SysCFStringRefToUTF8(key) @@ -569,7 +571,7 @@ void SetProcessName(CFStringRef process_name) { CGImageRef CopyNSImageToCGImage(NSImage* image) { // This is based loosely on http://www.cocoadev.com/index.pl?CGImageRef . NSSize size = [image size]; - scoped_cftyperef<CGContextRef> context( + ScopedCFTypeRef<CGContextRef> context( CGBitmapContextCreate(NULL, // Allow CG to allocate memory. size.width, size.height, @@ -595,7 +597,7 @@ CGImageRef CopyNSImageToCGImage(NSImage* image) { } bool CheckLoginItemStatus(bool* is_hidden) { - scoped_cftyperef<LSSharedFileListItemRef> item(GetLoginItemForApp()); + ScopedCFTypeRef<LSSharedFileListItemRef> item(GetLoginItemForApp()); if (!item.get()) return false; @@ -606,12 +608,12 @@ bool CheckLoginItemStatus(bool* is_hidden) { } void AddToLoginItems(bool hide_on_startup) { - scoped_cftyperef<LSSharedFileListItemRef> item(GetLoginItemForApp()); + ScopedCFTypeRef<LSSharedFileListItemRef> item(GetLoginItemForApp()); if (item.get() && (IsHiddenLoginItem(item) == hide_on_startup)) { return; // Already is a login item with required hide flag. } - scoped_cftyperef<LSSharedFileListRef> login_items(LSSharedFileListCreate( + ScopedCFTypeRef<LSSharedFileListRef> login_items(LSSharedFileListCreate( NULL, kLSSharedFileListSessionLoginItems, NULL)); if (!login_items.get()) { @@ -632,7 +634,7 @@ void AddToLoginItems(bool hide_on_startup) { dictionaryWithObject:[NSNumber numberWithBool:hide] forKey:(NSString*)kLSSharedFileListLoginItemHidden]; - scoped_cftyperef<LSSharedFileListItemRef> new_item; + ScopedCFTypeRef<LSSharedFileListItemRef> new_item; new_item.reset(LSSharedFileListInsertItemURL( login_items, kLSSharedFileListItemLast, NULL, NULL, reinterpret_cast<CFURLRef>(url), @@ -644,11 +646,11 @@ void AddToLoginItems(bool hide_on_startup) { } void RemoveFromLoginItems() { - scoped_cftyperef<LSSharedFileListItemRef> item(GetLoginItemForApp()); + ScopedCFTypeRef<LSSharedFileListItemRef> item(GetLoginItemForApp()); if (!item.get()) return; - scoped_cftyperef<LSSharedFileListRef> login_items(LSSharedFileListCreate( + ScopedCFTypeRef<LSSharedFileListRef> login_items(LSSharedFileListCreate( NULL, kLSSharedFileListSessionLoginItems, NULL)); if (!login_items.get()) { @@ -663,7 +665,7 @@ bool WasLaunchedAsHiddenLoginItem() { if (!WasLaunchedAsLoginItem()) return false; - scoped_cftyperef<LSSharedFileListItemRef> item(GetLoginItemForApp()); + ScopedCFTypeRef<LSSharedFileListItemRef> item(GetLoginItemForApp()); if (!item.get()) { LOG(ERROR) << "Process launched at Login but can't access Login Item List."; return false; diff --git a/base/mac_util_unittest.mm b/base/mac_util_unittest.mm index 45b3c0e..7999878 100644 --- a/base/mac_util_unittest.mm +++ b/base/mac_util_unittest.mm @@ -10,7 +10,7 @@ #import "base/chrome_application_mac.h" #include "base/file_path.h" #include "base/file_util.h" -#include "base/scoped_cftyperef.h" +#include "base/mac/scoped_cftyperef.h" #include "base/scoped_nsobject.h" #include "base/scoped_ptr.h" #include "testing/gtest/include/gtest/gtest.h" @@ -151,7 +151,7 @@ TEST_F(MacUtilTest, TestExcludeFileFromBackups) { } TEST_F(MacUtilTest, TestGetValueFromDictionary) { - scoped_cftyperef<CFMutableDictionaryRef> dict( + base::mac::ScopedCFTypeRef<CFMutableDictionaryRef> dict( CFDictionaryCreateMutable(0, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); @@ -175,7 +175,7 @@ TEST_F(MacUtilTest, CopyNSImageToCGImage) { NSRectFill(rect); [nsImage unlockFocus]; - scoped_cftyperef<CGImageRef> cgImage( + base::mac::ScopedCFTypeRef<CGImageRef> cgImage( mac_util::CopyNSImageToCGImage(nsImage.get())); EXPECT_TRUE(cgImage.get()); } diff --git a/base/native_library_mac.mm b/base/native_library_mac.mm index d13a4b6..95cac15 100644 --- a/base/native_library_mac.mm +++ b/base/native_library_mac.mm @@ -9,7 +9,7 @@ #include "base/file_path.h" #include "base/file_util.h" -#include "base/scoped_cftyperef.h" +#include "base/mac/scoped_cftyperef.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" @@ -27,11 +27,12 @@ NativeLibrary LoadNativeLibrary(const FilePath& library_path) { native_lib->dylib = dylib; return native_lib; } - scoped_cftyperef<CFURLRef> url(CFURLCreateFromFileSystemRepresentation( - kCFAllocatorDefault, - (const UInt8*)library_path.value().c_str(), - library_path.value().length(), - true)); + base::mac::ScopedCFTypeRef<CFURLRef> url( + CFURLCreateFromFileSystemRepresentation( + kCFAllocatorDefault, + (const UInt8*)library_path.value().c_str(), + library_path.value().length(), + true)); if (!url) return NULL; CFBundleRef bundle = CFBundleCreate(kCFAllocatorDefault, url.get()); @@ -61,7 +62,7 @@ void UnloadNativeLibrary(NativeLibrary library) { void* GetFunctionPointerFromNativeLibrary(NativeLibrary library, const char* name) { if (library->type == BUNDLE) { - scoped_cftyperef<CFStringRef> symbol_name( + base::mac::ScopedCFTypeRef<CFStringRef> symbol_name( CFStringCreateWithCString(kCFAllocatorDefault, name, kCFStringEncodingUTF8)); return CFBundleGetFunctionPointerForName(library->bundle, symbol_name); diff --git a/base/scoped_nsobject.h b/base/scoped_nsobject.h index 1b40ade..a9783e0 100644 --- a/base/scoped_nsobject.h +++ b/base/scoped_nsobject.h @@ -41,10 +41,10 @@ class scoped_nsobject { void reset(NST* object = nil) { // We intentionally do not check that object != object_ as the caller must - // already have an ownership claim over whatever it gives to scoped_nsobject - // and scoped_cftyperef, whether it's in the constructor or in a call to - // reset(). In either case, it relinquishes that claim and the scoper - // assumes it. + // already have an ownership claim over whatever it gives to + // scoped_nsobject and ScopedCFTypeRef, whether it's in the constructor or + // in a call to reset(). In either case, it relinquishes that claim and + // the scoper assumes it. [object_ release]; object_ = object; } @@ -114,10 +114,10 @@ class scoped_nsobject<id> { void reset(id object = nil) { // We intentionally do not check that object != object_ as the caller must - // already have an ownership claim over whatever it gives to scoped_nsobject - // and scoped_cftyperef, whether it's in the constructor or in a call to - // reset(). In either case, it relinquishes that claim and the scoper - // assumes it. + // already have an ownership claim over whatever it gives to + // scoped_nsobject and ScopedCFTypeRef, whether it's in the constructor or + // in a call to reset(). In either case, it relinquishes that claim and + // the scoper assumes it. [object_ release]; object_ = object; } diff --git a/base/sys_string_conversions_mac.mm b/base/sys_string_conversions_mac.mm index 9b9a07e..4b5648c 100644 --- a/base/sys_string_conversions_mac.mm +++ b/base/sys_string_conversions_mac.mm @@ -9,7 +9,7 @@ #include <vector> #include "base/foundation_utils_mac.h" -#include "base/scoped_cftyperef.h" +#include "base/mac/scoped_cftyperef.h" #include "base/string_piece.h" namespace base { @@ -78,7 +78,7 @@ static OutStringType STLStringToSTLStringWithEncodingsT( if (in_length == 0) return OutStringType(); - scoped_cftyperef<CFStringRef> cfstring( + base::mac::ScopedCFTypeRef<CFStringRef> cfstring( CFStringCreateWithBytesNoCopy(NULL, reinterpret_cast<const UInt8*>(in.data()), in_length * diff --git a/base/time_mac.cc b/base/time_mac.cc index 6b46b95..6dfaa20 100644 --- a/base/time_mac.cc +++ b/base/time_mac.cc @@ -12,7 +12,7 @@ #include "base/basictypes.h" #include "base/logging.h" -#include "base/scoped_cftyperef.h" +#include "base/mac/scoped_cftyperef.h" namespace base { @@ -70,7 +70,7 @@ Time Time::FromExploded(bool is_local, const Exploded& exploded) { date.month = exploded.month; date.year = exploded.year; - scoped_cftyperef<CFTimeZoneRef> + base::mac::ScopedCFTypeRef<CFTimeZoneRef> time_zone(is_local ? CFTimeZoneCopySystem() : NULL); CFAbsoluteTime seconds = CFGregorianDateGetAbsoluteTime(date, time_zone) + kCFAbsoluteTimeIntervalSince1970; @@ -83,7 +83,7 @@ void Time::Explode(bool is_local, Exploded* exploded) const { (static_cast<double>((us_ - kWindowsEpochDeltaMicroseconds) / kMicrosecondsPerSecond) - kCFAbsoluteTimeIntervalSince1970); - scoped_cftyperef<CFTimeZoneRef> + base::mac::ScopedCFTypeRef<CFTimeZoneRef> time_zone(is_local ? CFTimeZoneCopySystem() : NULL); CFGregorianDate date = CFAbsoluteTimeGetGregorianDate(seconds, time_zone); |