| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/base_paths_mac.h" | 5 #include "base/base_paths_mac.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 #include <mach-o/dyld.h> |
| 8 | 9 |
| 9 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/mac_util.h" | 13 #include "base/mac_util.h" |
| 13 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 14 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 15 | 16 |
| 16 namespace base { | 17 namespace base { |
| 17 | 18 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 35 | 36 |
| 36 } // namespace | 37 } // namespace |
| 37 | 38 |
| 38 bool PathProviderMac(int key, FilePath* result) { | 39 bool PathProviderMac(int key, FilePath* result) { |
| 39 std::string cur; | 40 std::string cur; |
| 40 switch (key) { | 41 switch (key) { |
| 41 case base::FILE_EXE: | 42 case base::FILE_EXE: |
| 42 case base::FILE_MODULE: { | 43 case base::FILE_MODULE: { |
| 43 // Executable path can have relative references ("..") depending on | 44 // Executable path can have relative references ("..") depending on |
| 44 // how the app was launched. | 45 // how the app was launched. |
| 45 NSString* path = | 46 uint32_t executable_length = 0; |
| 46 [[[NSBundle mainBundle] executablePath] stringByStandardizingPath]; | 47 _NSGetExecutablePath(NULL, &executable_length); |
| 47 cur = [path fileSystemRepresentation]; | 48 DCHECK_GT(executable_length, 1u); |
| 49 char* executable = WriteInto(&cur, executable_length); |
| 50 int rv = _NSGetExecutablePath(executable, &executable_length); |
| 51 DCHECK_EQ(rv, 0); |
| 52 DCHECK(!cur.empty()); |
| 48 break; | 53 break; |
| 49 } | 54 } |
| 50 case base::DIR_CACHE: | 55 case base::DIR_CACHE: |
| 51 return GetUserDirectory(NSCachesDirectory, result); | 56 return GetUserDirectory(NSCachesDirectory, result); |
| 52 case base::DIR_APP_DATA: | 57 case base::DIR_APP_DATA: |
| 53 return GetUserDirectory(NSApplicationSupportDirectory, result); | 58 return GetUserDirectory(NSApplicationSupportDirectory, result); |
| 54 case base::DIR_SOURCE_ROOT: { | 59 case base::DIR_SOURCE_ROOT: { |
| 55 FilePath path; | 60 PathService::Get(base::DIR_EXE, result); |
| 56 PathService::Get(base::DIR_EXE, &path); | |
| 57 if (mac_util::AmIBundled()) { | 61 if (mac_util::AmIBundled()) { |
| 58 // The bundled app executables (Chromium, TestShell, etc) live five | 62 // The bundled app executables (Chromium, TestShell, etc) live five |
| 59 // levels down, eg: | 63 // levels down, eg: |
| 60 // src/xcodebuild/{Debug|Release}/Chromium.app/Contents/MacOS/Chromium. | 64 // src/xcodebuild/{Debug|Release}/Chromium.app/Contents/MacOS/Chromium. |
| 61 path = path.DirName(); | 65 *result = result->DirName().DirName().DirName().DirName().DirName(); |
| 62 path = path.DirName(); | |
| 63 path = path.DirName(); | |
| 64 path = path.DirName(); | |
| 65 *result = path.DirName(); | |
| 66 } else { | 66 } else { |
| 67 // Unit tests execute two levels deep from the source root, eg: | 67 // Unit tests execute two levels deep from the source root, eg: |
| 68 // src/xcodebuild/{Debug|Release}/base_unittests | 68 // src/xcodebuild/{Debug|Release}/base_unittests |
| 69 path = path.DirName(); | 69 *result = result->DirName().DirName(); |
| 70 *result = path.DirName(); | |
| 71 } | 70 } |
| 72 return true; | 71 return true; |
| 73 } | 72 } |
| 74 default: | 73 default: |
| 75 return false; | 74 return false; |
| 76 } | 75 } |
| 77 | 76 |
| 78 *result = FilePath(cur); | 77 *result = FilePath(cur); |
| 79 return true; | 78 return true; |
| 80 } | 79 } |
| 81 | 80 |
| 82 } // namespace base | 81 } // namespace base |
| OLD | NEW |