base_paths.cc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "base/base_paths.h"
  5. #include "base/files/file_path.h"
  6. #include "base/files/file_util.h"
  7. #include "base/path_service.h"
  8. #include "build/build_config.h"
  9. namespace base {
  10. bool PathProvider(int key, FilePath* result) {
  11. // NOTE: DIR_CURRENT is a special case in PathService::Get
  12. switch (key) {
  13. case DIR_EXE:
  14. if (!PathService::Get(FILE_EXE, result))
  15. return false;
  16. *result = result->DirName();
  17. return true;
  18. #if !BUILDFLAG(IS_FUCHSIA)
  19. case DIR_MODULE:
  20. if (!PathService::Get(FILE_MODULE, result))
  21. return false;
  22. *result = result->DirName();
  23. return true;
  24. case DIR_ASSETS:
  25. return PathService::Get(DIR_MODULE, result);
  26. #endif // !BUILDFLAG(IS_FUCHSIA)
  27. case DIR_TEMP:
  28. return GetTempDir(result);
  29. case DIR_HOME:
  30. *result = GetHomeDir();
  31. return true;
  32. case DIR_GEN_TEST_DATA_ROOT:
  33. #if !BUILDFLAG(IS_FUCHSIA)
  34. // On most platforms, all build output is in the same directory, so
  35. // use DIR_MODULE to get the path to the current binary.
  36. return PathService::Get(DIR_MODULE, result);
  37. #endif // !BUILDFLAG(IS_FUCHSIA)
  38. case DIR_TEST_DATA: {
  39. FilePath test_data_path;
  40. if (!PathService::Get(DIR_SRC_TEST_DATA_ROOT, &test_data_path))
  41. return false;
  42. test_data_path = test_data_path.Append(FILE_PATH_LITERAL("base"));
  43. test_data_path = test_data_path.Append(FILE_PATH_LITERAL("test"));
  44. test_data_path = test_data_path.Append(FILE_PATH_LITERAL("data"));
  45. if (!PathExists(test_data_path)) // We don't want to create this.
  46. return false;
  47. *result = test_data_path;
  48. return true;
  49. }
  50. }
  51. return false;
  52. }
  53. } // namespace base