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 10 matching lines...) Expand all Loading... |
21 // Adapted from http://developer.apple.com/carbon/tipsandtricks.html#AmIBundled | 21 // Adapted from http://developer.apple.com/carbon/tipsandtricks.html#AmIBundled |
22 static bool UncachedAmIBundled() { | 22 static bool UncachedAmIBundled() { |
23 if (g_override_am_i_bundled) | 23 if (g_override_am_i_bundled) |
24 return g_override_am_i_bundled_value; | 24 return g_override_am_i_bundled_value; |
25 | 25 |
26 ProcessSerialNumber psn = {0, kCurrentProcess}; | 26 ProcessSerialNumber psn = {0, kCurrentProcess}; |
27 | 27 |
28 FSRef fsref; | 28 FSRef fsref; |
29 OSStatus pbErr; | 29 OSStatus pbErr; |
30 if ((pbErr = GetProcessBundleLocation(&psn, &fsref)) != noErr) { | 30 if ((pbErr = GetProcessBundleLocation(&psn, &fsref)) != noErr) { |
31 LOG(ERROR) << "GetProcessBundleLocation failed: error " << pbErr; | 31 DLOG(ERROR) << "GetProcessBundleLocation failed: error " << pbErr; |
32 return false; | 32 return false; |
33 } | 33 } |
34 | 34 |
35 FSCatalogInfo info; | 35 FSCatalogInfo info; |
36 OSErr fsErr; | 36 OSErr fsErr; |
37 if ((fsErr = FSGetCatalogInfo(&fsref, kFSCatInfoNodeFlags, &info, | 37 if ((fsErr = FSGetCatalogInfo(&fsref, kFSCatInfoNodeFlags, &info, |
38 NULL, NULL, NULL)) != noErr) { | 38 NULL, NULL, NULL)) != noErr) { |
39 LOG(ERROR) << "FSGetCatalogInfo failed: error " << fsErr; | 39 DLOG(ERROR) << "FSGetCatalogInfo failed: error " << fsErr; |
40 return false; | 40 return false; |
41 } | 41 } |
42 | 42 |
43 return info.nodeFlags & kFSNodeIsDirectoryMask; | 43 return info.nodeFlags & kFSNodeIsDirectoryMask; |
44 } | 44 } |
45 | 45 |
46 bool AmIBundled() { | 46 bool AmIBundled() { |
47 // If the return value is not cached, this function will return different | 47 // If the return value is not cached, this function will return different |
48 // values depending on when it's called. This confuses some client code, see | 48 // values depending on when it's called. This confuses some client code, see |
49 // http://crbug.com/63183 . | 49 // http://crbug.com/63183 . |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 void SetOverrideAppBundle(NSBundle* bundle) { | 95 void SetOverrideAppBundle(NSBundle* bundle) { |
96 if (bundle != g_override_app_bundle) { | 96 if (bundle != g_override_app_bundle) { |
97 [g_override_app_bundle release]; | 97 [g_override_app_bundle release]; |
98 g_override_app_bundle = [bundle retain]; | 98 g_override_app_bundle = [bundle retain]; |
99 } | 99 } |
100 } | 100 } |
101 | 101 |
102 void SetOverrideAppBundlePath(const FilePath& file_path) { | 102 void SetOverrideAppBundlePath(const FilePath& file_path) { |
103 NSString* path = base::SysUTF8ToNSString(file_path.value()); | 103 NSString* path = base::SysUTF8ToNSString(file_path.value()); |
104 NSBundle* bundle = [NSBundle bundleWithPath:path]; | 104 NSBundle* bundle = [NSBundle bundleWithPath:path]; |
105 CHECK(bundle) << "Failed to load the bundle at " << file_path.value(); | 105 DCHECK(bundle) << "Failed to load the bundle at " << file_path.value(); |
106 | 106 |
107 SetOverrideAppBundle(bundle); | 107 SetOverrideAppBundle(bundle); |
108 } | 108 } |
109 | 109 |
110 OSType CreatorCodeForCFBundleRef(CFBundleRef bundle) { | 110 OSType CreatorCodeForCFBundleRef(CFBundleRef bundle) { |
111 OSType creator = kUnknownType; | 111 OSType creator = kUnknownType; |
112 CFBundleGetPackageInfo(bundle, NULL, &creator); | 112 CFBundleGetPackageInfo(bundle, NULL, &creator); |
113 return creator; | 113 return creator; |
114 } | 114 } |
115 | 115 |
(...skipping 23 matching lines...) Expand all Loading... |
139 return GetSearchPathDirectory(directory, NSLocalDomainMask, result); | 139 return GetSearchPathDirectory(directory, NSLocalDomainMask, result); |
140 } | 140 } |
141 | 141 |
142 bool GetUserDirectory(NSSearchPathDirectory directory, FilePath* result) { | 142 bool GetUserDirectory(NSSearchPathDirectory directory, FilePath* result) { |
143 return GetSearchPathDirectory(directory, NSUserDomainMask, result); | 143 return GetSearchPathDirectory(directory, NSUserDomainMask, result); |
144 } | 144 } |
145 | 145 |
146 FilePath GetUserLibraryPath() { | 146 FilePath GetUserLibraryPath() { |
147 FilePath user_library_path; | 147 FilePath user_library_path; |
148 if (!GetUserDirectory(NSLibraryDirectory, &user_library_path)) { | 148 if (!GetUserDirectory(NSLibraryDirectory, &user_library_path)) { |
149 LOG(WARNING) << "Could not get user library path"; | 149 DLOG(WARNING) << "Could not get user library path"; |
150 } | 150 } |
151 return user_library_path; | 151 return user_library_path; |
152 } | 152 } |
153 | 153 |
154 // Takes a path to an (executable) binary and tries to provide the path to an | 154 // Takes a path to an (executable) binary and tries to provide the path to an |
155 // application bundle containing it. It takes the outermost bundle that it can | 155 // application bundle containing it. It takes the outermost bundle that it can |
156 // find (so for "/Foo/Bar.app/.../Baz.app/..." it produces "/Foo/Bar.app"). | 156 // find (so for "/Foo/Bar.app/.../Baz.app/..." it produces "/Foo/Bar.app"). |
157 // |exec_name| - path to the binary | 157 // |exec_name| - path to the binary |
158 // returns - path to the application bundle, or empty on error | 158 // returns - path to the application bundle, or empty on error |
159 FilePath GetAppBundlePath(const FilePath& exec_name) { | 159 FilePath GetAppBundlePath(const FilePath& exec_name) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 CFTypeID expected_type) { | 205 CFTypeID expected_type) { |
206 CFTypeRef value = CFDictionaryGetValue(dict, key); | 206 CFTypeRef value = CFDictionaryGetValue(dict, key); |
207 if (!value) | 207 if (!value) |
208 return value; | 208 return value; |
209 | 209 |
210 if (CFGetTypeID(value) != expected_type) { | 210 if (CFGetTypeID(value) != expected_type) { |
211 ScopedCFTypeRef<CFStringRef> expected_type_ref( | 211 ScopedCFTypeRef<CFStringRef> expected_type_ref( |
212 CFCopyTypeIDDescription(expected_type)); | 212 CFCopyTypeIDDescription(expected_type)); |
213 ScopedCFTypeRef<CFStringRef> actual_type_ref( | 213 ScopedCFTypeRef<CFStringRef> actual_type_ref( |
214 CFCopyTypeIDDescription(CFGetTypeID(value))); | 214 CFCopyTypeIDDescription(CFGetTypeID(value))); |
215 LOG(WARNING) << "Expected value for key " | 215 DLOG(WARNING) << "Expected value for key " |
216 << base::SysCFStringRefToUTF8(key) | 216 << base::SysCFStringRefToUTF8(key) |
217 << " to be " | 217 << " to be " |
218 << base::SysCFStringRefToUTF8(expected_type_ref) | 218 << base::SysCFStringRefToUTF8(expected_type_ref) |
219 << " but it was " | 219 << " but it was " |
220 << base::SysCFStringRefToUTF8(actual_type_ref) | 220 << base::SysCFStringRefToUTF8(actual_type_ref) |
221 << " instead"; | 221 << " instead"; |
222 return NULL; | 222 return NULL; |
223 } | 223 } |
224 | 224 |
225 return value; | 225 return value; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey)); | 365 CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey)); |
366 } | 366 } |
367 o << "Code: " << CFErrorGetCode(err) | 367 o << "Code: " << CFErrorGetCode(err) |
368 << " Domain: " << CFErrorGetDomain(err) | 368 << " Domain: " << CFErrorGetDomain(err) |
369 << " Desc: " << desc.get(); | 369 << " Desc: " << desc.get(); |
370 if(errorDesc) { | 370 if(errorDesc) { |
371 o << "(" << errorDesc << ")"; | 371 o << "(" << errorDesc << ")"; |
372 } | 372 } |
373 return o; | 373 return o; |
374 } | 374 } |
OLD | NEW |