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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/mac/foundation_util.h" 5 #include "base/mac/foundation_util.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include "base/file_path.h" 10 #include "base/file_path.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/mac/scoped_cftyperef.h"
13 #include "base/sys_string_conversions.h" 12 #include "base/sys_string_conversions.h"
14 13
15 namespace base { 14 namespace base {
16 namespace mac { 15 namespace mac {
17 16
18 static bool g_override_am_i_bundled = false; 17 static bool g_override_am_i_bundled = false;
19 static bool g_override_am_i_bundled_value = false; 18 static bool g_override_am_i_bundled_value = false;
20 19
21 // Adapted from http://developer.apple.com/carbon/tipsandtricks.html#AmIBundled 20 // Adapted from http://developer.apple.com/carbon/tipsandtricks.html#AmIBundled
22 static bool UncachedAmIBundled() { 21 static bool UncachedAmIBundled() {
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 !it->compare(it->length() - kExtLength, kExtLength, kExt, kExtLength)) 192 !it->compare(it->length() - kExtLength, kExtLength, kExt, kExtLength))
194 return FilePath(bundle_name); 193 return FilePath(bundle_name);
195 194
196 // Separate this component from the next one. 195 // Separate this component from the next one.
197 bundle_name += '/'; 196 bundle_name += '/';
198 } 197 }
199 198
200 return FilePath(); 199 return FilePath();
201 } 200 }
202 201
202 #define TYPE_NAME_FOR_CF_TYPE_DEFN(TypeCF) \
203 std::string TypeNameForCFType(TypeCF##Ref cfo) { \
204 std::string type_name = #TypeCF; \
205 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.
206 }
207
208 TYPE_NAME_FOR_CF_TYPE_DEFN(CFArray);
209 TYPE_NAME_FOR_CF_TYPE_DEFN(CFBag);
210 TYPE_NAME_FOR_CF_TYPE_DEFN(CFBoolean);
211 TYPE_NAME_FOR_CF_TYPE_DEFN(CFData);
212 TYPE_NAME_FOR_CF_TYPE_DEFN(CFDate);
213 TYPE_NAME_FOR_CF_TYPE_DEFN(CFDictionary);
214 TYPE_NAME_FOR_CF_TYPE_DEFN(CFNull);
215 TYPE_NAME_FOR_CF_TYPE_DEFN(CFNumber);
216 TYPE_NAME_FOR_CF_TYPE_DEFN(CFSet);
217 TYPE_NAME_FOR_CF_TYPE_DEFN(CFString);
218
219 std::string GetValueFromDictionaryErrorMessage(CFStringRef key,
220 CFStringRef expected_type_ref,
Mark Mentovai 2011/11/14 18:08:55 Do something about this cheesey alignment.
221 CFTypeRef value) {
222 ScopedCFTypeRef<CFStringRef> actual_type_ref(
223 CFCopyTypeIDDescription(CFGetTypeID(value)));
224 return "Expected value for key " +
225 base::SysCFStringRefToUTF8(key) +
226 " to be " +
227 base::SysCFStringRefToUTF8(expected_type_ref) +
228 " but it was " +
229 base::SysCFStringRefToUTF8(actual_type_ref) +
230 " instead";
231 }
232
203 CFTypeRef GetValueFromDictionary(CFDictionaryRef dict, 233 CFTypeRef GetValueFromDictionary(CFDictionaryRef dict,
204 CFStringRef key, 234 CFStringRef key,
205 CFTypeID expected_type) { 235 CFTypeID expected_type) {
206 CFTypeRef value = CFDictionaryGetValue(dict, key); 236 CFTypeRef value = CFDictionaryGetValue(dict, key);
207 if (!value) 237 if (!value)
208 return value; 238 return value;
209 239
210 if (CFGetTypeID(value) != expected_type) { 240 if (CFGetTypeID(value) != expected_type) {
211 ScopedCFTypeRef<CFStringRef> expected_type_ref( 241 ScopedCFTypeRef<CFStringRef> expected_type_ref(
212 CFCopyTypeIDDescription(expected_type)); 242 CFCopyTypeIDDescription(expected_type));
213 ScopedCFTypeRef<CFStringRef> actual_type_ref( 243 DLOG(WARNING) << GetValueFromDictionaryErrorMessage(key,
214 CFCopyTypeIDDescription(CFGetTypeID(value))); 244 expected_type_ref,
215 DLOG(WARNING) << "Expected value for key " 245 value);
216 << base::SysCFStringRefToUTF8(key)
217 << " to be "
218 << base::SysCFStringRefToUTF8(expected_type_ref)
219 << " but it was "
220 << base::SysCFStringRefToUTF8(actual_type_ref)
221 << " instead";
222 return NULL; 246 return NULL;
223 } 247 }
224 248
225 return value; 249 return value;
226 } 250 }
227 251
228 void NSObjectRetain(void* obj) { 252 void NSObjectRetain(void* obj) {
229 id<NSObject> nsobj = static_cast<id<NSObject> >(obj); 253 id<NSObject> nsobj = static_cast<id<NSObject> >(obj);
230 [nsobj retain]; 254 [nsobj retain];
231 } 255 }
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey)); 389 CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey));
366 } 390 }
367 o << "Code: " << CFErrorGetCode(err) 391 o << "Code: " << CFErrorGetCode(err)
368 << " Domain: " << CFErrorGetDomain(err) 392 << " Domain: " << CFErrorGetDomain(err)
369 << " Desc: " << desc.get(); 393 << " Desc: " << desc.get();
370 if(errorDesc) { 394 if(errorDesc) {
371 o << "(" << errorDesc << ")"; 395 o << "(" << errorDesc << ")";
372 } 396 }
373 return o; 397 return o;
374 } 398 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698