blob: 1dde038cb4a70ebd7f67e9432ad0eb6ddbc0ec9a [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2012 The Chromium Authors
[email protected]49df6022008-08-27 19:03:432// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
[email protected]5af2edb92008-08-08 20:16:084
[email protected]dea1d7d2012-09-20 16:24:525// Defines base::PathProviderMac which replaces base::PathProviderPosix for Mac
6// in base/path_service.cc.
[email protected]5af2edb92008-08-08 20:16:087
Peter Kasting134ef9af2024-12-28 02:30:098#include "base/base_paths.h"
9
[email protected]880a6d5e2010-11-16 22:25:4710#import <Foundation/Foundation.h>
[email protected]5af2edb92008-08-08 20:16:0811
Avi Drissmand4f07082023-05-12 18:05:4412#include "base/apple/bundle_locations.h"
Avi Drissmaneac566b02023-08-18 02:56:2113#include "base/apple/foundation_util.h"
Sylvain Defresnea9ffa992023-06-19 09:29:0614#include "base/base_paths_apple.h"
[email protected]57999812013-02-24 05:40:5215#include "base/files/file_path.h"
[email protected]e3177dd52014-08-13 20:22:1416#include "base/files/file_util.h"
Hans Wennborga47ddf82020-05-05 18:08:0717#include "base/notreached.h"
[email protected]37088fef2008-08-15 17:32:1018#include "base/path_service.h"
Etienne Pierre-doray89272912022-11-07 22:35:3819
20namespace base {
21
[email protected]aaa6df42013-02-17 19:36:0322bool PathProviderMac(int key, base::FilePath* result) {
[email protected]5af2edb92008-08-08 20:16:0823 switch (key) {
24 case base::FILE_EXE:
Sylvain Defresnea9ffa992023-06-19 09:29:0625 *result = base::apple::internal::GetExecutablePath();
[email protected]fdce4782011-11-29 20:06:1826 return true;
[email protected]699c26c2011-05-26 16:19:0127 case base::FILE_MODULE:
Sylvain Defresnea9ffa992023-06-19 09:29:0628 return base::apple::internal::GetModulePathForAddress(
29 result, reinterpret_cast<const void*>(&base::PathProviderMac));
[email protected]8495af32012-08-01 00:29:1530 case base::DIR_APP_DATA: {
Sylvain Defresnea9ffa992023-06-19 09:29:0631 bool success =
Avi Drissmaneac566b02023-08-18 02:56:2132 base::apple::GetUserDirectory(NSApplicationSupportDirectory, result);
[email protected]8495af32012-08-01 00:29:1533 return success;
34 }
David Dorwinc694f722021-10-29 22:46:5935 case base::DIR_SRC_TEST_DATA_ROOT:
[email protected]7fac8882010-11-15 19:52:5236 // Go through PathService to catch overrides.
Sylvain Defresnea9ffa992023-06-19 09:29:0637 if (!PathService::Get(base::FILE_EXE, result)) {
[email protected]b266ffea2011-04-12 06:07:2538 return false;
Sylvain Defresnea9ffa992023-06-19 09:29:0639 }
[email protected]b266ffea2011-04-12 06:07:2540
41 // Start with the executable's directory.
42 *result = result->DirName();
[email protected]da19703b2012-07-17 14:15:3443
Avi Drissmaneac566b02023-08-18 02:56:2144 if (base::apple::AmIBundled()) {
[email protected]b266ffea2011-04-12 06:07:2545 // 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]d480bc82009-04-22 18:35:1053 }
[email protected]e2ac70002008-12-09 14:58:1354 return true;
[email protected]dea1d7d2012-09-20 16:24:5255 case base::DIR_USER_DESKTOP:
Avi Drissmaneac566b02023-08-18 02:56:2156 return base::apple::GetUserDirectory(NSDesktopDirectory, result);
Sergey Ulanovd5ae68e2018-02-07 20:14:2157 case base::DIR_ASSETS:
Avi Drissmaneac566b02023-08-18 02:56:2158 if (!base::apple::AmIBundled()) {
Sergey Ulanovd5ae68e2018-02-07 20:14:2159 return PathService::Get(base::DIR_MODULE, result);
60 }
Avi Drissmand4f07082023-05-12 18:05:4461 *result = base::apple::FrameworkBundlePath().Append(
Sergey Ulanovd5ae68e2018-02-07 20:14:2162 FILE_PATH_LITERAL("Resources"));
63 return true;
[email protected]dea1d7d2012-09-20 16:24:5264 case base::DIR_CACHE:
Avi Drissmaneac566b02023-08-18 02:56:2165 return base::apple::GetUserDirectory(NSCachesDirectory, result);
[email protected]5af2edb92008-08-08 20:16:0866 default:
67 return false;
68 }
[email protected]5af2edb92008-08-08 20:16:0869}
70
71} // namespace base