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> |
11 #include <stdint.h> | 11 #include <stdint.h> |
12 | 12 |
13 #include "base/base_paths.h" | 13 #include "base/base_paths.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
16 #include "base/files/file_util.h" | 16 #include "base/files/file_util.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/mac/foundation_util.h" | 18 #include "base/mac/foundation_util.h" |
19 #include "base/path_service.h" | 19 #include "base/path_service.h" |
20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 21 #include "base/threading/thread_restrictions.h" |
21 #include "build/build_config.h" | 22 #include "build/build_config.h" |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 void GetNSExecutablePath(base::FilePath* path) { | 26 void GetNSExecutablePath(base::FilePath* path) { |
26 DCHECK(path); | 27 DCHECK(path); |
27 // Executable path can have relative references ("..") depending on | 28 // Executable path can have relative references ("..") depending on |
28 // how the app was launched. | 29 // how the app was launched. |
29 uint32_t executable_length = 0; | 30 uint32_t executable_length = 0; |
30 _NSGetExecutablePath(NULL, &executable_length); | 31 _NSGetExecutablePath(NULL, &executable_length); |
31 DCHECK_GT(executable_length, 1u); | 32 DCHECK_GT(executable_length, 1u); |
32 std::string executable_path; | 33 std::string executable_path; |
33 int rv = _NSGetExecutablePath( | 34 int rv = _NSGetExecutablePath( |
34 base::WriteInto(&executable_path, executable_length), | 35 base::WriteInto(&executable_path, executable_length), |
35 &executable_length); | 36 &executable_length); |
36 DCHECK_EQ(rv, 0); | 37 DCHECK_EQ(rv, 0); |
37 | 38 |
38 // _NSGetExecutablePath may return paths containing ./ or ../ which makes | 39 // _NSGetExecutablePath may return paths containing ./ or ../ which makes |
39 // FilePath::DirName() work incorrectly, convert it to absolute path so that | 40 // FilePath::DirName() work incorrectly, convert it to absolute path so that |
40 // paths such as DIR_SOURCE_ROOT can work, since we expect absolute paths to | 41 // paths such as DIR_SOURCE_ROOT can work, since we expect absolute paths to |
41 // be returned here. | 42 // be returned here. |
| 43 // TODO(bauerb): http://crbug.com/259796, http://crbug.com/373477 |
| 44 base::ThreadRestrictions::ScopedAllowIO allow_io; |
42 *path = base::MakeAbsoluteFilePath(base::FilePath(executable_path)); | 45 *path = base::MakeAbsoluteFilePath(base::FilePath(executable_path)); |
43 } | 46 } |
44 | 47 |
45 // Returns true if the module for |address| is found. |path| will contain | 48 // Returns true if the module for |address| is found. |path| will contain |
46 // the path to the module. Note that |path| may not be absolute. | 49 // the path to the module. Note that |path| may not be absolute. |
47 bool GetModulePathForAddress(base::FilePath* path, | 50 bool GetModulePathForAddress(base::FilePath* path, |
48 const void* address) WARN_UNUSED_RESULT; | 51 const void* address) WARN_UNUSED_RESULT; |
49 | 52 |
50 bool GetModulePathForAddress(base::FilePath* path, const void* address) { | 53 bool GetModulePathForAddress(base::FilePath* path, const void* address) { |
51 Dl_info info; | 54 Dl_info info; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 return base::mac::GetUserDirectory(NSDesktopDirectory, result); | 110 return base::mac::GetUserDirectory(NSDesktopDirectory, result); |
108 #endif | 111 #endif |
109 case base::DIR_CACHE: | 112 case base::DIR_CACHE: |
110 return base::mac::GetUserDirectory(NSCachesDirectory, result); | 113 return base::mac::GetUserDirectory(NSCachesDirectory, result); |
111 default: | 114 default: |
112 return false; | 115 return false; |
113 } | 116 } |
114 } | 117 } |
115 | 118 |
116 } // namespace base | 119 } // namespace base |
OLD | NEW |