Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2595)

Unified Diff: base/mac/foundation_util.mm

Issue 8540021: Create a nicer interface for base::mac::GetValueFromDictionary (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Add a TypeNameForCFType function Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/mac/foundation_util.mm
diff --git a/base/mac/foundation_util.mm b/base/mac/foundation_util.mm
index 8a4ce471765e1157886e293ae4c7b9007ccc24f7..9467314cfa2e8eae4ec1675cee74b50c76ec77f6 100644
--- a/base/mac/foundation_util.mm
+++ b/base/mac/foundation_util.mm
@@ -9,7 +9,6 @@
#include "base/file_path.h"
#include "base/logging.h"
-#include "base/mac/scoped_cftyperef.h"
#include "base/sys_string_conversions.h"
namespace base {
@@ -200,6 +199,37 @@ FilePath GetAppBundlePath(const FilePath& exec_name) {
return FilePath();
}
+#define TYPE_NAME_FOR_CF_TYPE_DEFN(TypeCF) \
+std::string TypeNameForCFType(TypeCF##Ref cfo) { \
+ std::string type_name = #TypeCF; \
+ return type_name + "Ref"; \
Mark Mentovai 2011/11/14 18:08:55 The values returned by CFCopyTypeIDDescription don
KushalP 2011/11/14 18:47:02 No. They do not. Fixed.
+}
+
+TYPE_NAME_FOR_CF_TYPE_DEFN(CFArray);
+TYPE_NAME_FOR_CF_TYPE_DEFN(CFBag);
+TYPE_NAME_FOR_CF_TYPE_DEFN(CFBoolean);
+TYPE_NAME_FOR_CF_TYPE_DEFN(CFData);
+TYPE_NAME_FOR_CF_TYPE_DEFN(CFDate);
+TYPE_NAME_FOR_CF_TYPE_DEFN(CFDictionary);
+TYPE_NAME_FOR_CF_TYPE_DEFN(CFNull);
+TYPE_NAME_FOR_CF_TYPE_DEFN(CFNumber);
+TYPE_NAME_FOR_CF_TYPE_DEFN(CFSet);
+TYPE_NAME_FOR_CF_TYPE_DEFN(CFString);
+
+std::string GetValueFromDictionaryErrorMessage(CFStringRef key,
+ CFStringRef expected_type_ref,
Mark Mentovai 2011/11/14 18:08:55 Do something about this cheesey alignment.
+ CFTypeRef value) {
+ ScopedCFTypeRef<CFStringRef> actual_type_ref(
+ CFCopyTypeIDDescription(CFGetTypeID(value)));
+ return "Expected value for key " +
+ base::SysCFStringRefToUTF8(key) +
+ " to be " +
+ base::SysCFStringRefToUTF8(expected_type_ref) +
+ " but it was " +
+ base::SysCFStringRefToUTF8(actual_type_ref) +
+ " instead";
+}
+
CFTypeRef GetValueFromDictionary(CFDictionaryRef dict,
CFStringRef key,
CFTypeID expected_type) {
@@ -210,15 +240,9 @@ CFTypeRef GetValueFromDictionary(CFDictionaryRef dict,
if (CFGetTypeID(value) != expected_type) {
ScopedCFTypeRef<CFStringRef> expected_type_ref(
CFCopyTypeIDDescription(expected_type));
- ScopedCFTypeRef<CFStringRef> actual_type_ref(
- CFCopyTypeIDDescription(CFGetTypeID(value)));
- DLOG(WARNING) << "Expected value for key "
- << base::SysCFStringRefToUTF8(key)
- << " to be "
- << base::SysCFStringRefToUTF8(expected_type_ref)
- << " but it was "
- << base::SysCFStringRefToUTF8(actual_type_ref)
- << " instead";
+ DLOG(WARNING) << GetValueFromDictionaryErrorMessage(key,
+ expected_type_ref,
+ value);
return NULL;
}

Powered by Google App Engine
This is Rietveld 408576698