1 // Copyright 2012 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::PathProviderMac which replaces base::PathProviderPosix for Mac
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/notreached.h"
17 #include "base/path_service.h"
21 bool PathProviderMac(int key, base::FilePath* result) {
24 *result = base::apple::internal::GetExecutablePath();
26 case base::FILE_MODULE:
27 return base::apple::internal::GetModulePathForAddress(
28 result, reinterpret_cast<const void*>(&base::PathProviderMac));
29 case base::DIR_APP_DATA: {
31 base::apple::GetUserDirectory(NSApplicationSupportDirectory, result);
34 case base::DIR_SRC_TEST_DATA_ROOT:
35 // Go through PathService to catch overrides.
36 if (!PathService::Get(base::FILE_EXE, result)) {
40 // Start with the executable's directory.
41 *result = result->DirName();
43 if (base::apple::AmIBundled()) {
44 // The bundled app executables (Chromium, TestShell, etc) live five
46 // src/xcodebuild/{Debug|Release}/Chromium.app/Contents/MacOS/Chromium
47 *result = result->DirName().DirName().DirName().DirName().DirName();
49 // Unit tests execute two levels deep from the source root, eg:
50 // src/xcodebuild/{Debug|Release}/base_unittests
51 *result = result->DirName().DirName();
54 case base::DIR_USER_DESKTOP:
55 return base::apple::GetUserDirectory(NSDesktopDirectory, result);
56 case base::DIR_ASSETS:
57 if (!base::apple::AmIBundled()) {
58 return PathService::Get(base::DIR_MODULE, result);
60 *result = base::apple::FrameworkBundlePath().Append(
61 FILE_PATH_LITERAL("Resources"));
64 return base::apple::GetUserDirectory(NSCachesDirectory, result);