#include "base/path_service.h"
#include <unordered_map>
#include <utility>
#include "base/check_op.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/raw_ptr_exclusion.h"
#include "base/synchronization/lock.h"
#include "build/build_config.h"
#if BUILDFLAG(IS_WIN)
#include <windows.h>
#include <shellapi.h>
#include <shlobj.h>
#endif
#define ENABLE_BEHAVIOUR_OVERRIDE_PROVIDER …
namespace base {
bool EnvOverridePathProvider(int key, FilePath* result);
bool PathProvider(int key, FilePath* result);
#if BUILDFLAG(IS_WIN)
bool PathProviderWin(int key, FilePath* result);
#elif BUILDFLAG(IS_MAC)
bool PathProviderMac(int key, FilePath* result);
#elif BUILDFLAG(IS_IOS)
bool PathProviderIOS(int key, FilePath* result);
#elif BUILDFLAG(IS_ANDROID)
bool PathProviderAndroid(int key, FilePath* result);
#elif BUILDFLAG(IS_FUCHSIA)
bool PathProviderFuchsia(int key, FilePath* result);
#elif BUILDFLAG(IS_POSIX)
bool PathProviderPosix(int key, FilePath* result);
#endif
namespace {
PathMap;
struct Provider { … };
Provider base_provider = …;
#if BUILDFLAG(IS_WIN)
Provider win_provider = {PathProviderWin, &base_provider,
#ifndef NDEBUG
PATH_WIN_START, PATH_WIN_END,
#endif
true};
Provider base_provider_win = {EnvOverridePathProvider, &win_provider,
#ifndef NDEBUG
PATH_START, PATH_END,
#endif
true};
#endif
#if BUILDFLAG(IS_MAC)
Provider base_provider_mac = {
PathProviderMac,
&base_provider,
#ifndef NDEBUG
PATH_MAC_START,
PATH_MAC_END,
#endif
true
};
#endif
#if BUILDFLAG(IS_IOS)
Provider base_provider_ios = {
PathProviderIOS,
&base_provider,
#ifndef NDEBUG
PATH_IOS_START,
PATH_IOS_END,
#endif
true
};
#endif
#if BUILDFLAG(IS_ANDROID)
Provider base_provider_android = {
PathProviderAndroid,
&base_provider,
#ifndef NDEBUG
PATH_ANDROID_START,
PATH_ANDROID_END,
#endif
true
};
#endif
#if BUILDFLAG(IS_FUCHSIA)
Provider base_provider_fuchsia = {PathProviderFuchsia, &base_provider,
#ifndef NDEBUG
0, 0,
#endif
true};
#endif
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_APPLE) && !BUILDFLAG(IS_ANDROID)
Provider posix_provider = …;
Provider base_provider_posix = …;
#endif
struct PathData { … };
static PathData* GetPathData() { … }
bool LockedGetFromCache(int key, const PathData* path_data, FilePath* result)
EXCLUSIVE_LOCKS_REQUIRED(path_data->lock) { … }
bool LockedGetFromOverrides(int key, PathData* path_data, FilePath* result)
EXCLUSIVE_LOCKS_REQUIRED(path_data->lock) { … }
}
bool PathService::Get(int key, FilePath* result) { … }
FilePath PathService::CheckedGet(int key) { … }
bool PathService::Override(int key, const FilePath& path) { … }
bool PathService::OverrideAndCreateIfNeeded(int key,
const FilePath& path,
bool is_absolute,
bool create) { … }
bool PathService::RemoveOverrideForTests(int key) { … }
bool PathService::IsOverriddenForTesting(int key) { … }
void PathService::RegisterProvider(ProviderFunc func, int key_start,
int key_end) { … }
void PathService::DisableCache() { … }
}