chromium/base/path_service.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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 {

// Custom behaviour providers.
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)
// PathProviderPosix is the default path provider on POSIX OSes other than
// Mac and Android.
bool PathProviderPosix(int key, FilePath* result);
#endif

namespace {

PathMap;

// We keep a linked list of providers.  In a debug build we ensure that no two
// providers claim overlapping keys.
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() {}

// Tries to find |key| in the cache.
bool LockedGetFromCache(int key, const PathData* path_data, FilePath* result)
    EXCLUSIVE_LOCKS_REQUIRED(path_data->lock) {}

// Tries to find |key| in the overrides map.
bool LockedGetFromOverrides(int key, PathData* path_data, FilePath* result)
    EXCLUSIVE_LOCKS_REQUIRED(path_data->lock) {}

}  // namespace

// TODO(brettw): this function does not handle long paths (filename > MAX_PATH)
// characters). This isn't supported very well by Windows right now, so it is
// moot, but we should keep this in mind for the future.
// static
bool PathService::Get(int key, FilePath* result) {}

FilePath PathService::CheckedGet(int key) {}

// static
bool PathService::Override(int key, const FilePath& path) {}

// static
bool PathService::OverrideAndCreateIfNeeded(int key,
                                            const FilePath& path,
                                            bool is_absolute,
                                            bool create) {}

// static
bool PathService::RemoveOverrideForTests(int key) {}

// static
bool PathService::IsOverriddenForTesting(int key) {}

// static
void PathService::RegisterProvider(ProviderFunc func, int key_start,
                                   int key_end) {}

// static
void PathService::DisableCache() {}

}  // namespace base