OLD | NEW |
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" |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 CF_CAST_DEFN(CFBag); | 341 CF_CAST_DEFN(CFBag); |
342 CF_CAST_DEFN(CFBoolean); | 342 CF_CAST_DEFN(CFBoolean); |
343 CF_CAST_DEFN(CFData); | 343 CF_CAST_DEFN(CFData); |
344 CF_CAST_DEFN(CFDate); | 344 CF_CAST_DEFN(CFDate); |
345 CF_CAST_DEFN(CFDictionary); | 345 CF_CAST_DEFN(CFDictionary); |
346 CF_CAST_DEFN(CFNull); | 346 CF_CAST_DEFN(CFNull); |
347 CF_CAST_DEFN(CFNumber); | 347 CF_CAST_DEFN(CFNumber); |
348 CF_CAST_DEFN(CFSet); | 348 CF_CAST_DEFN(CFSet); |
349 CF_CAST_DEFN(CFString); | 349 CF_CAST_DEFN(CFString); |
350 | 350 |
| 351 #define GET_VAL_FROM_DICT_DEFN(TypeCF) \ |
| 352 template<> TypeCF##Ref \ |
| 353 GetValueFromDictionary<TypeCF##Ref>(CFDictionaryRef dict, CFStringRef key) { \ |
| 354 CFTypeRef val = CFDictionaryGetValue(dict, key); \ |
| 355 TypeCF##Ref value = base::mac::CFCast<TypeCF##Ref>(val); \ |
| 356 if (!val) \ |
| 357 return value; \ |
| 358 if (!value) { \ |
| 359 ScopedCFTypeRef<CFStringRef> expected_type_ref( \ |
| 360 CFCopyTypeIDDescription(TypeCF##GetTypeID())); \ |
| 361 ScopedCFTypeRef<CFStringRef> actual_type_ref( \ |
| 362 CFCopyTypeIDDescription(CFGetTypeID(val))); \ |
| 363 DLOG(WARNING) << "Expected value for key " \ |
| 364 << base::SysCFStringRefToUTF8(key) \ |
| 365 << " to be " \ |
| 366 << base::SysCFStringRefToUTF8(expected_type_ref) \ |
| 367 << " but it was " \ |
| 368 << base::SysCFStringRefToUTF8(actual_type_ref) \ |
| 369 << " instead"; \ |
| 370 return NULL; \ |
| 371 } \ |
| 372 return value; \ |
| 373 } |
| 374 |
| 375 GET_VAL_FROM_DICT_DEFN(CFArray); |
| 376 GET_VAL_FROM_DICT_DEFN(CFBag); |
| 377 GET_VAL_FROM_DICT_DEFN(CFBoolean); |
| 378 GET_VAL_FROM_DICT_DEFN(CFData); |
| 379 GET_VAL_FROM_DICT_DEFN(CFDate); |
| 380 GET_VAL_FROM_DICT_DEFN(CFDictionary); |
| 381 GET_VAL_FROM_DICT_DEFN(CFNull); |
| 382 GET_VAL_FROM_DICT_DEFN(CFNumber); |
| 383 GET_VAL_FROM_DICT_DEFN(CFSet); |
| 384 GET_VAL_FROM_DICT_DEFN(CFString); |
| 385 |
351 } // namespace mac | 386 } // namespace mac |
352 } // namespace base | 387 } // namespace base |
353 | 388 |
354 std::ostream& operator<<(std::ostream& o, const CFStringRef string) { | 389 std::ostream& operator<<(std::ostream& o, const CFStringRef string) { |
355 return o << base::SysCFStringRefToUTF8(string); | 390 return o << base::SysCFStringRefToUTF8(string); |
356 } | 391 } |
357 | 392 |
358 std::ostream& operator<<(std::ostream& o, const CFErrorRef err) { | 393 std::ostream& operator<<(std::ostream& o, const CFErrorRef err) { |
359 base::mac::ScopedCFTypeRef<CFStringRef> desc(CFErrorCopyDescription(err)); | 394 base::mac::ScopedCFTypeRef<CFStringRef> desc(CFErrorCopyDescription(err)); |
360 base::mac::ScopedCFTypeRef<CFDictionaryRef> user_info( | 395 base::mac::ScopedCFTypeRef<CFDictionaryRef> user_info( |
361 CFErrorCopyUserInfo(err)); | 396 CFErrorCopyUserInfo(err)); |
362 CFStringRef errorDesc = NULL; | 397 CFStringRef errorDesc = NULL; |
363 if (user_info.get()) { | 398 if (user_info.get()) { |
364 errorDesc = reinterpret_cast<CFStringRef>( | 399 errorDesc = reinterpret_cast<CFStringRef>( |
365 CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey)); | 400 CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey)); |
366 } | 401 } |
367 o << "Code: " << CFErrorGetCode(err) | 402 o << "Code: " << CFErrorGetCode(err) |
368 << " Domain: " << CFErrorGetDomain(err) | 403 << " Domain: " << CFErrorGetDomain(err) |
369 << " Desc: " << desc.get(); | 404 << " Desc: " << desc.get(); |
370 if(errorDesc) { | 405 if(errorDesc) { |
371 o << "(" << errorDesc << ")"; | 406 o << "(" << errorDesc << ")"; |
372 } | 407 } |
373 return o; | 408 return o; |
374 } | 409 } |
OLD | NEW |