| 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 #include "base/mac/mac_util.h" |
| 6 | 7 |
| 7 #include <stdlib.h> | 8 #include <stdlib.h> |
| 8 #include <string.h> | 9 #include <string.h> |
| 9 | 10 |
| 10 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/mac/bundle_locations.h" | 13 #include "base/mac/bundle_locations.h" |
| 13 #include "base/mac/mac_logging.h" | 14 #include "base/mac/mac_logging.h" |
| 14 #include "base/sys_string_conversions.h" | 15 #include "base/sys_string_conversions.h" |
| 15 | 16 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 } | 122 } |
| 122 | 123 |
| 123 bool GetLocalDirectory(NSSearchPathDirectory directory, FilePath* result) { | 124 bool GetLocalDirectory(NSSearchPathDirectory directory, FilePath* result) { |
| 124 return GetSearchPathDirectory(directory, NSLocalDomainMask, result); | 125 return GetSearchPathDirectory(directory, NSLocalDomainMask, result); |
| 125 } | 126 } |
| 126 | 127 |
| 127 bool GetUserDirectory(NSSearchPathDirectory directory, FilePath* result) { | 128 bool GetUserDirectory(NSSearchPathDirectory directory, FilePath* result) { |
| 128 return GetSearchPathDirectory(directory, NSUserDomainMask, result); | 129 return GetSearchPathDirectory(directory, NSUserDomainMask, result); |
| 129 } | 130 } |
| 130 | 131 |
| 132 void GetDisplayNameForPath(const FilePath& path, std::string* result) { |
| 133 FSRef ref; |
| 134 if (!FSRefFromPath(path.value(), &ref)) { |
| 135 *result = path.BaseName().value(); |
| 136 return; |
| 137 } |
| 138 |
| 139 CFStringRef str; |
| 140 if (LSCopyDisplayNameForRef(&ref, &str)) { |
| 141 *result = path.BaseName().value(); |
| 142 return; |
| 143 } |
| 144 |
| 145 *result = base::SysCFStringRefToUTF8(str); |
| 146 NSObjectRelease((void *) str); |
| 147 } |
| 148 |
| 131 FilePath GetUserLibraryPath() { | 149 FilePath GetUserLibraryPath() { |
| 132 FilePath user_library_path; | 150 FilePath user_library_path; |
| 133 if (!GetUserDirectory(NSLibraryDirectory, &user_library_path)) { | 151 if (!GetUserDirectory(NSLibraryDirectory, &user_library_path)) { |
| 134 DLOG(WARNING) << "Could not get user library path"; | 152 DLOG(WARNING) << "Could not get user library path"; |
| 135 } | 153 } |
| 136 return user_library_path; | 154 return user_library_path; |
| 137 } | 155 } |
| 138 | 156 |
| 139 // Takes a path to an (executable) binary and tries to provide the path to an | 157 // Takes a path to an (executable) binary and tries to provide the path to an |
| 140 // application bundle containing it. It takes the outermost bundle that it can | 158 // application bundle containing it. It takes the outermost bundle that it can |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey)); | 406 CFDictionaryGetValue(user_info.get(), kCFErrorDescriptionKey)); |
| 389 } | 407 } |
| 390 o << "Code: " << CFErrorGetCode(err) | 408 o << "Code: " << CFErrorGetCode(err) |
| 391 << " Domain: " << CFErrorGetDomain(err) | 409 << " Domain: " << CFErrorGetDomain(err) |
| 392 << " Desc: " << desc.get(); | 410 << " Desc: " << desc.get(); |
| 393 if(errorDesc) { | 411 if(errorDesc) { |
| 394 o << "(" << errorDesc << ")"; | 412 o << "(" << errorDesc << ")"; |
| 395 } | 413 } |
| 396 return o; | 414 return o; |
| 397 } | 415 } |
| OLD | NEW |