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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 TYPE_NAME_FOR_CF_TYPE_DEFN(CFData); | 210 TYPE_NAME_FOR_CF_TYPE_DEFN(CFData); |
211 TYPE_NAME_FOR_CF_TYPE_DEFN(CFDate); | 211 TYPE_NAME_FOR_CF_TYPE_DEFN(CFDate); |
212 TYPE_NAME_FOR_CF_TYPE_DEFN(CFDictionary); | 212 TYPE_NAME_FOR_CF_TYPE_DEFN(CFDictionary); |
213 TYPE_NAME_FOR_CF_TYPE_DEFN(CFNull); | 213 TYPE_NAME_FOR_CF_TYPE_DEFN(CFNull); |
214 TYPE_NAME_FOR_CF_TYPE_DEFN(CFNumber); | 214 TYPE_NAME_FOR_CF_TYPE_DEFN(CFNumber); |
215 TYPE_NAME_FOR_CF_TYPE_DEFN(CFSet); | 215 TYPE_NAME_FOR_CF_TYPE_DEFN(CFSet); |
216 TYPE_NAME_FOR_CF_TYPE_DEFN(CFString); | 216 TYPE_NAME_FOR_CF_TYPE_DEFN(CFString); |
217 | 217 |
218 #undef TYPE_NAME_FOR_CF_TYPE_DEFN | 218 #undef TYPE_NAME_FOR_CF_TYPE_DEFN |
219 | 219 |
220 std::string GetValueFromDictionaryErrorMessage( | |
221 CFStringRef key, const std::string& expected_type, 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 expected_type + | |
228 " but it was " + | |
229 base::SysCFStringRefToUTF8(actual_type_ref) + | |
230 " instead"; | |
231 } | |
232 | |
233 CFTypeRef GetValueFromDictionary(CFDictionaryRef dict, | |
234 CFStringRef key, | |
235 CFTypeID expected_type) { | |
236 CFTypeRef value = CFDictionaryGetValue(dict, key); | |
237 if (!value) | |
238 return value; | |
239 | |
240 if (CFGetTypeID(value) != expected_type) { | |
241 ScopedCFTypeRef<CFStringRef> expected_type_name( | |
242 CFCopyTypeIDDescription(expected_type)); | |
243 std::string expected_type_utf8 = | |
244 base::SysCFStringRefToUTF8(expected_type_name); | |
245 DLOG(WARNING) << GetValueFromDictionaryErrorMessage(key, | |
246 expected_type_utf8, | |
247 value); | |
248 return NULL; | |
249 } | |
250 | |
251 return value; | |
252 } | |
253 | |
254 void NSObjectRetain(void* obj) { | 220 void NSObjectRetain(void* obj) { |
255 id<NSObject> nsobj = static_cast<id<NSObject> >(obj); | 221 id<NSObject> nsobj = static_cast<id<NSObject> >(obj); |
256 [nsobj retain]; | 222 [nsobj retain]; |
257 } | 223 } |
258 | 224 |
259 void NSObjectRelease(void* obj) { | 225 void NSObjectRelease(void* obj) { |
260 id<NSObject> nsobj = static_cast<id<NSObject> >(obj); | 226 id<NSObject> nsobj = static_cast<id<NSObject> >(obj); |
261 [nsobj release]; | 227 [nsobj release]; |
262 } | 228 } |
263 | 229 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 CF_CAST_DEFN(CFData); | 338 CF_CAST_DEFN(CFData); |
373 CF_CAST_DEFN(CFDate); | 339 CF_CAST_DEFN(CFDate); |
374 CF_CAST_DEFN(CFDictionary); | 340 CF_CAST_DEFN(CFDictionary); |
375 CF_CAST_DEFN(CFNull); | 341 CF_CAST_DEFN(CFNull); |
376 CF_CAST_DEFN(CFNumber); | 342 CF_CAST_DEFN(CFNumber); |
377 CF_CAST_DEFN(CFSet); | 343 CF_CAST_DEFN(CFSet); |
378 CF_CAST_DEFN(CFString); | 344 CF_CAST_DEFN(CFString); |
379 | 345 |
380 #undef CF_CAST_DEFN | 346 #undef CF_CAST_DEFN |
381 | 347 |
| 348 std::string GetValueFromDictionaryErrorMessage( |
| 349 CFStringRef key, const std::string& expected_type, CFTypeRef value) { |
| 350 ScopedCFTypeRef<CFStringRef> actual_type_ref( |
| 351 CFCopyTypeIDDescription(CFGetTypeID(value))); |
| 352 return "Expected value for key " + |
| 353 base::SysCFStringRefToUTF8(key) + |
| 354 " to be " + |
| 355 expected_type + |
| 356 " but it was " + |
| 357 base::SysCFStringRefToUTF8(actual_type_ref) + |
| 358 " instead"; |
| 359 } |
| 360 |
382 } // namespace mac | 361 } // namespace mac |
383 } // namespace base | 362 } // namespace base |
384 | 363 |
385 std::ostream& operator<<(std::ostream& o, const CFStringRef string) { | 364 std::ostream& operator<<(std::ostream& o, const CFStringRef string) { |
386 return o << base::SysCFStringRefToUTF8(string); | 365 return o << base::SysCFStringRefToUTF8(string); |
387 } | 366 } |
388 | 367 |
389 std::ostream& operator<<(std::ostream& o, const CFErrorRef err) { | 368 std::ostream& operator<<(std::ostream& o, const CFErrorRef err) { |
390 base::mac::ScopedCFTypeRef<CFStringRef> desc(CFErrorCopyDescription(err)); | 369 base::mac::ScopedCFTypeRef<CFStringRef> desc(CFErrorCopyDescription(err)); |
391 base::mac::ScopedCFTypeRef<CFDictionaryRef> user_info( | 370 base::mac::ScopedCFTypeRef<CFDictionaryRef> user_info( |
392 CFErrorCopyUserInfo(err)); | 371 CFErrorCopyUserInfo(err)); |
393 CFStringRef errorDesc = NULL; | 372 CFStringRef errorDesc = NULL; |
394 if (user_info.get()) { | 373 if (user_info.get()) { |
395 errorDesc = reinterpret_cast<CFStringRef>( | 374 errorDesc = reinterpret_cast<CFStringRef>( |
396 CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey)); | 375 CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey)); |
397 } | 376 } |
398 o << "Code: " << CFErrorGetCode(err) | 377 o << "Code: " << CFErrorGetCode(err) |
399 << " Domain: " << CFErrorGetDomain(err) | 378 << " Domain: " << CFErrorGetDomain(err) |
400 << " Desc: " << desc.get(); | 379 << " Desc: " << desc.get(); |
401 if(errorDesc) { | 380 if(errorDesc) { |
402 o << "(" << errorDesc << ")"; | 381 o << "(" << errorDesc << ")"; |
403 } | 382 } |
404 return o; | 383 return o; |
405 } | 384 } |
OLD | NEW |