1 // Copyright 2023 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Defines base::PathProviderIOS which replaces base::PathProviderPosix for iOS
6 // in base/path_service.cc.
8 #import <Foundation/Foundation.h>
10 #include "base/apple/bundle_locations.h"
11 #include "base/apple/foundation_util.h"
12 #include "base/base_paths.h"
13 #include "base/base_paths_apple.h"
14 #include "base/files/file_path.h"
15 #include "base/files/file_util.h"
16 #include "base/path_service.h"
20 bool PathProviderIOS(int key, base::FilePath* result) {
23 *result = base::apple::internal::GetExecutablePath();
26 case base::DIR_APP_DATA: {
28 if (!base::apple::GetUserDirectory(NSApplicationSupportDirectory,
33 // On iOS, this directory does not exist unless it is created explicitly.
34 if (!base::PathExists(path) && !base::CreateDirectory(path)) {
42 case base::DIR_SRC_TEST_DATA_ROOT:
43 case base::DIR_OUT_TEST_DATA_ROOT:
44 // On iOS, there is no access to source root, nor build dir,
45 // however, the necessary resources are packaged into the
46 // test app as assets.
49 case base::DIR_ASSETS:
50 // On iOS, the resources are located at the root of the framework bundle.
51 *result = base::apple::FrameworkBundlePath();
52 #if BUILDFLAG(IS_IOS_MACCATALYST)
53 // When running in the catalyst environment (i.e. building an iOS app
54 // to run on macOS), the bundles have the same structure as macOS, so
55 // the resources are in the "Contents/Resources" sub-directory.
56 *result = result->Append(FILE_PATH_LITERAL("Contents"))
57 .Append(FILE_PATH_LITERAL("Resources"));
58 #endif // BUILDFLAG(IS_IOS_MACCATALYST)
62 return base::apple::GetUserDirectory(NSCachesDirectory, result);