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" |
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 Loading... |
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 return #TypeCF; \ |
| 205 } |
| 206 |
| 207 TYPE_NAME_FOR_CF_TYPE_DEFN(CFArray); |
| 208 TYPE_NAME_FOR_CF_TYPE_DEFN(CFBag); |
| 209 TYPE_NAME_FOR_CF_TYPE_DEFN(CFBoolean); |
| 210 TYPE_NAME_FOR_CF_TYPE_DEFN(CFData); |
| 211 TYPE_NAME_FOR_CF_TYPE_DEFN(CFDate); |
| 212 TYPE_NAME_FOR_CF_TYPE_DEFN(CFDictionary); |
| 213 TYPE_NAME_FOR_CF_TYPE_DEFN(CFNull); |
| 214 TYPE_NAME_FOR_CF_TYPE_DEFN(CFNumber); |
| 215 TYPE_NAME_FOR_CF_TYPE_DEFN(CFSet); |
| 216 TYPE_NAME_FOR_CF_TYPE_DEFN(CFString); |
| 217 |
| 218 std::string GetValueFromDictionaryErrorMessage(CFStringRef key, |
| 219 std::string expected_type_ref, |
| 220 CFTypeRef value) { |
| 221 ScopedCFTypeRef<CFStringRef> actual_type_ref( |
| 222 CFCopyTypeIDDescription(CFGetTypeID(value))); |
| 223 return "Expected value for key " + |
| 224 base::SysCFStringRefToUTF8(key) + |
| 225 " to be " + |
| 226 expected_type_ref + |
| 227 " but it was " + |
| 228 base::SysCFStringRefToUTF8(actual_type_ref) + |
| 229 " instead"; |
| 230 } |
| 231 |
203 CFTypeRef GetValueFromDictionary(CFDictionaryRef dict, | 232 CFTypeRef GetValueFromDictionary(CFDictionaryRef dict, |
204 CFStringRef key, | 233 CFStringRef key, |
205 CFTypeID expected_type) { | 234 CFTypeID expected_type) { |
206 CFTypeRef value = CFDictionaryGetValue(dict, key); | 235 CFTypeRef value = CFDictionaryGetValue(dict, key); |
207 if (!value) | 236 if (!value) |
208 return value; | 237 return value; |
209 | 238 |
210 if (CFGetTypeID(value) != expected_type) { | 239 if (CFGetTypeID(value) != expected_type) { |
211 ScopedCFTypeRef<CFStringRef> expected_type_ref( | 240 std::string expected_type_ref = base::SysCFStringRefToUTF8( |
212 CFCopyTypeIDDescription(expected_type)); | 241 CFCopyTypeIDDescription(expected_type)); |
213 ScopedCFTypeRef<CFStringRef> actual_type_ref( | 242 DLOG(WARNING) << GetValueFromDictionaryErrorMessage(key, |
214 CFCopyTypeIDDescription(CFGetTypeID(value))); | 243 expected_type_ref, |
215 DLOG(WARNING) << "Expected value for key " | 244 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; | 245 return NULL; |
223 } | 246 } |
224 | 247 |
225 return value; | 248 return value; |
226 } | 249 } |
227 | 250 |
228 void NSObjectRetain(void* obj) { | 251 void NSObjectRetain(void* obj) { |
229 id<NSObject> nsobj = static_cast<id<NSObject> >(obj); | 252 id<NSObject> nsobj = static_cast<id<NSObject> >(obj); |
230 [nsobj retain]; | 253 [nsobj retain]; |
231 } | 254 } |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey)); | 388 CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey)); |
366 } | 389 } |
367 o << "Code: " << CFErrorGetCode(err) | 390 o << "Code: " << CFErrorGetCode(err) |
368 << " Domain: " << CFErrorGetDomain(err) | 391 << " Domain: " << CFErrorGetDomain(err) |
369 << " Desc: " << desc.get(); | 392 << " Desc: " << desc.get(); |
370 if(errorDesc) { | 393 if(errorDesc) { |
371 o << "(" << errorDesc << ")"; | 394 o << "(" << errorDesc << ")"; |
372 } | 395 } |
373 return o; | 396 return o; |
374 } | 397 } |
OLD | NEW |