OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bundle_locations.h" | 12 #include "base/mac/bundle_locations.h" |
13 #include "base/mac/mac_logging.h" | 13 #include "base/mac/mac_logging.h" |
14 #include "base/sys_string_conversions.h" | 14 #include "base/sys_string_conversions.h" |
15 | 15 |
16 #if !defined(OS_IOS) | |
16 extern "C" { | 17 extern "C" { |
17 CFTypeID SecACLGetTypeID(); | 18 CFTypeID SecACLGetTypeID(); |
18 CFTypeID SecTrustedApplicationGetTypeID(); | 19 CFTypeID SecTrustedApplicationGetTypeID(); |
19 } // extern "C" | 20 } // extern "C" |
21 #endif | |
20 | 22 |
21 namespace base { | 23 namespace base { |
22 namespace mac { | 24 namespace mac { |
23 | 25 |
24 static bool g_override_am_i_bundled = false; | 26 static bool g_override_am_i_bundled = false; |
25 static bool g_override_am_i_bundled_value = false; | 27 static bool g_override_am_i_bundled_value = false; |
26 | 28 |
27 // Adapted from http://developer.apple.com/carbon/tipsandtricks.html#AmIBundled | 29 // Adapted from http://developer.apple.com/carbon/tipsandtricks.html#AmIBundled |
28 static bool UncachedAmIBundled() { | 30 static bool UncachedAmIBundled() { |
29 if (g_override_am_i_bundled) | 31 if (g_override_am_i_bundled) |
30 return g_override_am_i_bundled_value; | 32 return g_override_am_i_bundled_value; |
31 | 33 |
34 #if defined(OS_IOS) | |
Mark Mentovai
2012/07/11 14:04:22
Uh-oh, your changes are colliding…
| |
35 // All apps are bundled on iOS | |
36 return true; | |
37 #else | |
32 ProcessSerialNumber psn = {0, kCurrentProcess}; | 38 ProcessSerialNumber psn = {0, kCurrentProcess}; |
33 | 39 |
34 FSRef fsref; | 40 FSRef fsref; |
35 OSStatus pbErr; | 41 OSStatus pbErr; |
36 if ((pbErr = GetProcessBundleLocation(&psn, &fsref)) != noErr) { | 42 if ((pbErr = GetProcessBundleLocation(&psn, &fsref)) != noErr) { |
37 OSSTATUS_DLOG(ERROR, pbErr) << "GetProcessBundleLocation failed"; | 43 OSSTATUS_DLOG(ERROR, pbErr) << "GetProcessBundleLocation failed"; |
38 return false; | 44 return false; |
39 } | 45 } |
40 | 46 |
41 FSCatalogInfo info; | 47 FSCatalogInfo info; |
42 OSErr fsErr; | 48 OSErr fsErr; |
43 if ((fsErr = FSGetCatalogInfo(&fsref, kFSCatInfoNodeFlags, &info, | 49 if ((fsErr = FSGetCatalogInfo(&fsref, kFSCatInfoNodeFlags, &info, |
44 NULL, NULL, NULL)) != noErr) { | 50 NULL, NULL, NULL)) != noErr) { |
45 OSSTATUS_DLOG(ERROR, fsErr) << "FSGetCatalogInfo failed"; | 51 OSSTATUS_DLOG(ERROR, fsErr) << "FSGetCatalogInfo failed"; |
46 return false; | 52 return false; |
47 } | 53 } |
48 | 54 |
49 return info.nodeFlags & kFSNodeIsDirectoryMask; | 55 return info.nodeFlags & kFSNodeIsDirectoryMask; |
56 #endif | |
50 } | 57 } |
51 | 58 |
52 bool AmIBundled() { | 59 bool AmIBundled() { |
53 // If the return value is not cached, this function will return different | 60 // If the return value is not cached, this function will return different |
54 // values depending on when it's called. This confuses some client code, see | 61 // values depending on when it's called. This confuses some client code, see |
55 // http://crbug.com/63183 . | 62 // http://crbug.com/63183 . |
56 static bool result = UncachedAmIBundled(); | 63 static bool result = UncachedAmIBundled(); |
57 DCHECK_EQ(result, UncachedAmIBundled()) | 64 DCHECK_EQ(result, UncachedAmIBundled()) |
58 << "The return value of AmIBundled() changed. This will confuse tests. " | 65 << "The return value of AmIBundled() changed. This will confuse tests. " |
59 << "Call SetAmIBundled() override manually if your test binary " | 66 << "Call SetAmIBundled() override manually if your test binary " |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
310 CF_CAST_DEFN(CFBag); | 317 CF_CAST_DEFN(CFBag); |
311 CF_CAST_DEFN(CFBoolean); | 318 CF_CAST_DEFN(CFBoolean); |
312 CF_CAST_DEFN(CFData); | 319 CF_CAST_DEFN(CFData); |
313 CF_CAST_DEFN(CFDate); | 320 CF_CAST_DEFN(CFDate); |
314 CF_CAST_DEFN(CFDictionary); | 321 CF_CAST_DEFN(CFDictionary); |
315 CF_CAST_DEFN(CFNull); | 322 CF_CAST_DEFN(CFNull); |
316 CF_CAST_DEFN(CFNumber); | 323 CF_CAST_DEFN(CFNumber); |
317 CF_CAST_DEFN(CFSet); | 324 CF_CAST_DEFN(CFSet); |
318 CF_CAST_DEFN(CFString); | 325 CF_CAST_DEFN(CFString); |
319 | 326 |
327 #if !defined(OS_IOS) | |
320 CF_CAST_DEFN(SecACL); | 328 CF_CAST_DEFN(SecACL); |
321 CF_CAST_DEFN(SecTrustedApplication); | 329 CF_CAST_DEFN(SecTrustedApplication); |
330 #endif | |
322 | 331 |
323 #undef CF_CAST_DEFN | 332 #undef CF_CAST_DEFN |
324 | 333 |
325 std::string GetValueFromDictionaryErrorMessage( | 334 std::string GetValueFromDictionaryErrorMessage( |
326 CFStringRef key, const std::string& expected_type, CFTypeRef value) { | 335 CFStringRef key, const std::string& expected_type, CFTypeRef value) { |
327 ScopedCFTypeRef<CFStringRef> actual_type_ref( | 336 ScopedCFTypeRef<CFStringRef> actual_type_ref( |
328 CFCopyTypeIDDescription(CFGetTypeID(value))); | 337 CFCopyTypeIDDescription(CFGetTypeID(value))); |
329 return "Expected value for key " + | 338 return "Expected value for key " + |
330 base::SysCFStringRefToUTF8(key) + | 339 base::SysCFStringRefToUTF8(key) + |
331 " to be " + | 340 " to be " + |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey)); | 373 CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey)); |
365 } | 374 } |
366 o << "Code: " << CFErrorGetCode(err) | 375 o << "Code: " << CFErrorGetCode(err) |
367 << " Domain: " << CFErrorGetDomain(err) | 376 << " Domain: " << CFErrorGetDomain(err) |
368 << " Desc: " << desc.get(); | 377 << " Desc: " << desc.get(); |
369 if(errorDesc) { | 378 if(errorDesc) { |
370 o << "(" << errorDesc << ")"; | 379 o << "(" << errorDesc << ")"; |
371 } | 380 } |
372 return o; | 381 return o; |
373 } | 382 } |
OLD | NEW |