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), &executable_length); |
34 DCHECK_EQ(rv, 0); | 34 DCHECK_EQ(rv, 0); |
35 | 35 |
36 // _NSGetExecutablePath may return paths containing ./ or ../ which makes | 36 // _NSGetExecutablePath may return paths containing ./ or ../ which makes |
37 // FilePath::DirName() work incorrectly, convert it to absolute path so that | 37 // 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 | 38 // paths such as DIR_SOURCE_ROOT can work, since we expect absolute paths to |
39 // be returned here. | 39 // be returned here. |
40 *path = base::MakeAbsoluteFilePath(base::FilePath(executable_path)); | 40 *path = base::MakeAbsoluteFilePath(base::FilePath(executable_path)); |
41 } | 41 } |
42 | 42 |
43 // Returns true if the module for |address| is found. |path| will contain | 43 // 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); | 105 return base::mac::GetUserDirectory(NSDesktopDirectory, result); |
106 #endif | 106 #endif |
107 case base::DIR_CACHE: | 107 case base::DIR_CACHE: |
108 return base::mac::GetUserDirectory(NSCachesDirectory, result); | 108 return base::mac::GetUserDirectory(NSCachesDirectory, result); |
109 default: | 109 default: |
110 return false; | 110 return false; |
111 } | 111 } |
112 } | 112 } |
113 | 113 |
114 } // namespace base | 114 } // namespace base |
OLD | NEW |