| 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 // Defines base::PathProviderMac which replaces base::PathProviderPosix for Mac | 5 // Defines base::PathProviderMac which replaces base::PathProviderPosix for Mac |
| 6 // in base/path_service.cc. | 6 // in base/path_service.cc. |
| 7 | 7 |
| 8 #include <dlfcn.h> | 8 #include <dlfcn.h> |
| 9 #import <Foundation/Foundation.h> | 9 #import <Foundation/Foundation.h> |
| 10 #include <mach-o/dyld.h> | 10 #include <mach-o/dyld.h> |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 void GetNSExecutablePath(base::FilePath* path) { | 24 void GetNSExecutablePath(base::FilePath* path) { |
| 25 DCHECK(path); | 25 DCHECK(path); |
| 26 // Executable path can have relative references ("..") depending on | 26 // Executable path can have relative references ("..") depending on |
| 27 // how the app was launched. | 27 // how the app was launched. |
| 28 uint32_t executable_length = 0; | 28 uint32_t executable_length = 0; |
| 29 _NSGetExecutablePath(NULL, &executable_length); | 29 _NSGetExecutablePath(NULL, &executable_length); |
| 30 DCHECK_GT(executable_length, 1u); | 30 DCHECK_GT(executable_length, 1u); |
| 31 std::string executable_path; | 31 std::string executable_path; |
| 32 int rv = _NSGetExecutablePath(WriteInto(&executable_path, executable_length), | 32 int rv = _NSGetExecutablePath( |
| 33 &executable_length); | 33 base::WriteInto(&executable_path, executable_length), |
| 34 &executable_length); |
| 34 DCHECK_EQ(rv, 0); | 35 DCHECK_EQ(rv, 0); |
| 35 | 36 |
| 36 // _NSGetExecutablePath may return paths containing ./ or ../ which makes | 37 // _NSGetExecutablePath may return paths containing ./ or ../ which makes |
| 37 // FilePath::DirName() work incorrectly, convert it to absolute path so that | 38 // FilePath::DirName() work incorrectly, convert it to absolute path so that |
| 38 // paths such as DIR_SOURCE_ROOT can work, since we expect absolute paths to | 39 // paths such as DIR_SOURCE_ROOT can work, since we expect absolute paths to |
| 39 // be returned here. | 40 // be returned here. |
| 40 *path = base::MakeAbsoluteFilePath(base::FilePath(executable_path)); | 41 *path = base::MakeAbsoluteFilePath(base::FilePath(executable_path)); |
| 41 } | 42 } |
| 42 | 43 |
| 43 // Returns true if the module for |address| is found. |path| will contain | 44 // Returns true if the module for |address| is found. |path| will contain |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 return base::mac::GetUserDirectory(NSDesktopDirectory, result); | 106 return base::mac::GetUserDirectory(NSDesktopDirectory, result); |
| 106 #endif | 107 #endif |
| 107 case base::DIR_CACHE: | 108 case base::DIR_CACHE: |
| 108 return base::mac::GetUserDirectory(NSCachesDirectory, result); | 109 return base::mac::GetUserDirectory(NSCachesDirectory, result); |
| 109 default: | 110 default: |
| 110 return false; | 111 return false; |
| 111 } | 112 } |
| 112 } | 113 } |
| 113 | 114 |
| 114 } // namespace base | 115 } // namespace base |
| OLD | NEW |