diff options
author | kushi.p@gmail.com <kushi.p@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-01 22:12:57 +0000 |
---|---|---|
committer | kushi.p@gmail.com <kushi.p@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-01 22:12:57 +0000 |
commit | f54596d9b7db5831fd0df6f54a492d8cb1c74979 (patch) | |
tree | a0ffd34a4a13215b13df16159e98734e48bbef77 /base | |
parent | 3276041925cec5ad27ab6b57d86715c259f4a5ca (diff) | |
download | chromium_src-f54596d9b7db5831fd0df6f54a492d8cb1c74979.zip chromium_src-f54596d9b7db5831fd0df6f54a492d8cb1c74979.tar.gz chromium_src-f54596d9b7db5831fd0df6f54a492d8cb1c74979.tar.bz2 |
Use the new base::mac::GetValueFromDictionary<>() method.
Remove all cases of the old method signature (and related tests) and
use the new form.
BUG=104200
Review URL: http://codereview.chromium.org/8769016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112553 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/mac/foundation_util.h | 27 | ||||
-rw-r--r-- | base/mac/foundation_util.mm | 47 | ||||
-rw-r--r-- | base/mac/mac_util_unittest.mm | 15 |
3 files changed, 21 insertions, 68 deletions
diff --git a/base/mac/foundation_util.h b/base/mac/foundation_util.h index a36ad75..1a87470 100644 --- a/base/mac/foundation_util.h +++ b/base/mac/foundation_util.h @@ -113,20 +113,6 @@ TYPE_NAME_FOR_CF_TYPE_DECL(CFString); #undef TYPE_NAME_FOR_CF_TYPE_DECL -// Helper function for GetValueFromDictionary to create the error message -// that appears when a type mismatch is encountered. -std::string GetValueFromDictionaryErrorMessage( - CFStringRef key, const std::string& expected_type, CFTypeRef value); - -// Utility function to pull out a value from a dictionary, check its type, and -// return it. Returns NULL if the key is not present or of the wrong type. -// This is now deprecated in favor of the two-argument form below. -// TODO(kushi.p): Remove this function once all cases of it have been -// replaced with the two-argument form below. See: crbug.com/104200. -BASE_EXPORT CFTypeRef GetValueFromDictionary(CFDictionaryRef dict, - CFStringRef key, - CFTypeID expected_type); - // Retain/release calls for memory management in C++. BASE_EXPORT void NSObjectRetain(void* obj); BASE_EXPORT void NSObjectRelease(void* obj); @@ -243,10 +229,8 @@ namespace mac { // CFNumberRef some_number = base::mac::CFCast<CFNumberRef>( // CFArrayGetValueAtIndex(array, index)); // -// CFStringRef some_string = base::mac::CFCastStrict<CFStringRef>( -// base::mac::GetValueFromDictionary(some_dict, -// CFSTR("a_key"), -// CFStringGetTypeID())); +// CFTypeRef hello = CFSTR("hello world"); +// CFStringRef some_string = base::mac::CFCastStrict<CFStringRef>(hello); BASE_EXPORT template<typename T> T CFCast(const CFTypeRef& cf_val); @@ -294,8 +278,13 @@ T* ObjCCastStrict(id objc_val) { #endif // defined(__OBJC__) +// Helper function for GetValueFromDictionary to create the error message +// that appears when a type mismatch is encountered. +std::string GetValueFromDictionaryErrorMessage( + CFStringRef key, const std::string& expected_type, CFTypeRef value); + // Utility function to pull out a value from a dictionary, check its type, and -// return it. Returns NULL if the key is not present or of the wrong type. +// return it. Returns NULL if the key is not present or of the wrong type. BASE_EXPORT template<typename T> T GetValueFromDictionary(CFDictionaryRef dict, CFStringRef key) { CFTypeRef value = CFDictionaryGetValue(dict, key); diff --git a/base/mac/foundation_util.mm b/base/mac/foundation_util.mm index 6778c98..f1d277a 100644 --- a/base/mac/foundation_util.mm +++ b/base/mac/foundation_util.mm @@ -217,40 +217,6 @@ TYPE_NAME_FOR_CF_TYPE_DEFN(CFString); #undef TYPE_NAME_FOR_CF_TYPE_DEFN -std::string GetValueFromDictionaryErrorMessage( - CFStringRef key, const std::string& expected_type, CFTypeRef value) { - ScopedCFTypeRef<CFStringRef> actual_type_ref( - CFCopyTypeIDDescription(CFGetTypeID(value))); - return "Expected value for key " + - base::SysCFStringRefToUTF8(key) + - " to be " + - expected_type + - " but it was " + - base::SysCFStringRefToUTF8(actual_type_ref) + - " instead"; -} - -CFTypeRef GetValueFromDictionary(CFDictionaryRef dict, - CFStringRef key, - CFTypeID expected_type) { - CFTypeRef value = CFDictionaryGetValue(dict, key); - if (!value) - return value; - - if (CFGetTypeID(value) != expected_type) { - ScopedCFTypeRef<CFStringRef> expected_type_name( - CFCopyTypeIDDescription(expected_type)); - std::string expected_type_utf8 = - base::SysCFStringRefToUTF8(expected_type_name); - DLOG(WARNING) << GetValueFromDictionaryErrorMessage(key, - expected_type_utf8, - value); - return NULL; - } - - return value; -} - void NSObjectRetain(void* obj) { id<NSObject> nsobj = static_cast<id<NSObject> >(obj); [nsobj retain]; @@ -379,6 +345,19 @@ CF_CAST_DEFN(CFString); #undef CF_CAST_DEFN +std::string GetValueFromDictionaryErrorMessage( + CFStringRef key, const std::string& expected_type, CFTypeRef value) { + ScopedCFTypeRef<CFStringRef> actual_type_ref( + CFCopyTypeIDDescription(CFGetTypeID(value))); + return "Expected value for key " + + base::SysCFStringRefToUTF8(key) + + " to be " + + expected_type + + " but it was " + + base::SysCFStringRefToUTF8(actual_type_ref) + + " instead"; +} + } // namespace mac } // namespace base diff --git a/base/mac/mac_util_unittest.mm b/base/mac/mac_util_unittest.mm index dd860a6..04f8ddf 100644 --- a/base/mac/mac_util_unittest.mm +++ b/base/mac/mac_util_unittest.mm @@ -121,21 +121,6 @@ TEST_F(MacUtilTest, TestExcludeFileFromBackups) { EXPECT_FALSE(excluded_by_path); } -TEST_F(MacUtilTest, TestGetValueFromDictionary) { - ScopedCFTypeRef<CFMutableDictionaryRef> dict( - CFDictionaryCreateMutable(0, 0, - &kCFTypeDictionaryKeyCallBacks, - &kCFTypeDictionaryValueCallBacks)); - CFDictionarySetValue(dict.get(), CFSTR("key"), CFSTR("value")); - - EXPECT_TRUE(CFEqual(CFSTR("value"), - GetValueFromDictionary( - dict, CFSTR("key"), CFStringGetTypeID()))); - EXPECT_FALSE(GetValueFromDictionary(dict, CFSTR("key"), CFNumberGetTypeID())); - EXPECT_FALSE(GetValueFromDictionary( - dict, CFSTR("no-exist"), CFStringGetTypeID())); -} - TEST_F(MacUtilTest, CopyNSImageToCGImage) { scoped_nsobject<NSImage> nsImage( [[NSImage alloc] initWithSize:NSMakeSize(20, 20)]); |