Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
[email protected] | 49df602 | 2008-08-27 19:03:43 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
[email protected] | 5af2edb9 | 2008-08-08 20:16:08 | [diff] [blame] | 4 | |
[email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 5 | // Defines base::PathProviderMac which replaces base::PathProviderPosix for Mac |
| 6 | // in base/path_service.cc. |
[email protected] | 5af2edb9 | 2008-08-08 20:16:08 | [diff] [blame] | 7 | |
Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 8 | #include "base/base_paths.h" |
| 9 | |
[email protected] | 880a6d5e | 2010-11-16 22:25:47 | [diff] [blame] | 10 | #import <Foundation/Foundation.h> |
[email protected] | 5af2edb9 | 2008-08-08 20:16:08 | [diff] [blame] | 11 | |
Avi Drissman | d4f0708 | 2023-05-12 18:05:44 | [diff] [blame] | 12 | #include "base/apple/bundle_locations.h" |
Avi Drissman | eac566b0 | 2023-08-18 02:56:21 | [diff] [blame] | 13 | #include "base/apple/foundation_util.h" |
Sylvain Defresne | a9ffa99 | 2023-06-19 09:29:06 | [diff] [blame] | 14 | #include "base/base_paths_apple.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 15 | #include "base/files/file_path.h" |
[email protected] | e3177dd5 | 2014-08-13 20:22:14 | [diff] [blame] | 16 | #include "base/files/file_util.h" |
Hans Wennborg | a47ddf8 | 2020-05-05 18:08:07 | [diff] [blame] | 17 | #include "base/notreached.h" |
[email protected] | 37088fef | 2008-08-15 17:32:10 | [diff] [blame] | 18 | #include "base/path_service.h" |
Etienne Pierre-doray | 8927291 | 2022-11-07 22:35:38 | [diff] [blame] | 19 | |
| 20 | namespace base { |
| 21 | |
[email protected] | aaa6df4 | 2013-02-17 19:36:03 | [diff] [blame] | 22 | bool PathProviderMac(int key, base::FilePath* result) { |
[email protected] | 5af2edb9 | 2008-08-08 20:16:08 | [diff] [blame] | 23 | switch (key) { |
| 24 | case base::FILE_EXE: |
Sylvain Defresne | a9ffa99 | 2023-06-19 09:29:06 | [diff] [blame] | 25 | *result = base::apple::internal::GetExecutablePath(); |
[email protected] | fdce478 | 2011-11-29 20:06:18 | [diff] [blame] | 26 | return true; |
[email protected] | 699c26c | 2011-05-26 16:19:01 | [diff] [blame] | 27 | case base::FILE_MODULE: |
Sylvain Defresne | a9ffa99 | 2023-06-19 09:29:06 | [diff] [blame] | 28 | return base::apple::internal::GetModulePathForAddress( |
| 29 | result, reinterpret_cast<const void*>(&base::PathProviderMac)); |
[email protected] | 8495af3 | 2012-08-01 00:29:15 | [diff] [blame] | 30 | case base::DIR_APP_DATA: { |
Sylvain Defresne | a9ffa99 | 2023-06-19 09:29:06 | [diff] [blame] | 31 | bool success = |
Avi Drissman | eac566b0 | 2023-08-18 02:56:21 | [diff] [blame] | 32 | base::apple::GetUserDirectory(NSApplicationSupportDirectory, result); |
[email protected] | 8495af3 | 2012-08-01 00:29:15 | [diff] [blame] | 33 | return success; |
| 34 | } |
David Dorwin | c694f72 | 2021-10-29 22:46:59 | [diff] [blame] | 35 | case base::DIR_SRC_TEST_DATA_ROOT: |
[email protected] | 7fac888 | 2010-11-15 19:52:52 | [diff] [blame] | 36 | // Go through PathService to catch overrides. |
Sylvain Defresne | a9ffa99 | 2023-06-19 09:29:06 | [diff] [blame] | 37 | if (!PathService::Get(base::FILE_EXE, result)) { |
[email protected] | b266ffea | 2011-04-12 06:07:25 | [diff] [blame] | 38 | return false; |
Sylvain Defresne | a9ffa99 | 2023-06-19 09:29:06 | [diff] [blame] | 39 | } |
[email protected] | b266ffea | 2011-04-12 06:07:25 | [diff] [blame] | 40 | |
| 41 | // Start with the executable's directory. |
| 42 | *result = result->DirName(); |
[email protected] | da19703b | 2012-07-17 14:15:34 | [diff] [blame] | 43 | |
Avi Drissman | eac566b0 | 2023-08-18 02:56:21 | [diff] [blame] | 44 | if (base::apple::AmIBundled()) { |
[email protected] | b266ffea | 2011-04-12 06:07:25 | [diff] [blame] | 45 | // The bundled app executables (Chromium, TestShell, etc) live five |
| 46 | // levels down, eg: |
| 47 | // src/xcodebuild/{Debug|Release}/Chromium.app/Contents/MacOS/Chromium |
| 48 | *result = result->DirName().DirName().DirName().DirName().DirName(); |
| 49 | } else { |
| 50 | // Unit tests execute two levels deep from the source root, eg: |
| 51 | // src/xcodebuild/{Debug|Release}/base_unittests |
| 52 | *result = result->DirName().DirName(); |
[email protected] | d480bc8 | 2009-04-22 18:35:10 | [diff] [blame] | 53 | } |
[email protected] | e2ac7000 | 2008-12-09 14:58:13 | [diff] [blame] | 54 | return true; |
[email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 55 | case base::DIR_USER_DESKTOP: |
Avi Drissman | eac566b0 | 2023-08-18 02:56:21 | [diff] [blame] | 56 | return base::apple::GetUserDirectory(NSDesktopDirectory, result); |
Sergey Ulanov | d5ae68e | 2018-02-07 20:14:21 | [diff] [blame] | 57 | case base::DIR_ASSETS: |
Avi Drissman | eac566b0 | 2023-08-18 02:56:21 | [diff] [blame] | 58 | if (!base::apple::AmIBundled()) { |
Sergey Ulanov | d5ae68e | 2018-02-07 20:14:21 | [diff] [blame] | 59 | return PathService::Get(base::DIR_MODULE, result); |
| 60 | } |
Avi Drissman | d4f0708 | 2023-05-12 18:05:44 | [diff] [blame] | 61 | *result = base::apple::FrameworkBundlePath().Append( |
Sergey Ulanov | d5ae68e | 2018-02-07 20:14:21 | [diff] [blame] | 62 | FILE_PATH_LITERAL("Resources")); |
| 63 | return true; |
[email protected] | dea1d7d | 2012-09-20 16:24:52 | [diff] [blame] | 64 | case base::DIR_CACHE: |
Avi Drissman | eac566b0 | 2023-08-18 02:56:21 | [diff] [blame] | 65 | return base::apple::GetUserDirectory(NSCachesDirectory, result); |
[email protected] | 5af2edb9 | 2008-08-08 20:16:08 | [diff] [blame] | 66 | default: |
| 67 | return false; |
| 68 | } |
[email protected] | 5af2edb9 | 2008-08-08 20:16:08 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | } // namespace base |