paths.cc 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2017 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 "components/viz/test/paths.h"
  5. #include "base/files/file_path.h"
  6. #include "base/files/file_util.h"
  7. #include "base/path_service.h"
  8. namespace viz {
  9. bool PathProvider(int key, base::FilePath* result) {
  10. base::FilePath cur;
  11. switch (key) {
  12. // The following are only valid in the development environment, and
  13. // will fail if executed from an installed executable (because the
  14. // generated path won't exist).
  15. case Paths::DIR_TEST_DATA:
  16. if (!base::PathService::Get(base::DIR_SOURCE_ROOT, &cur))
  17. return false;
  18. cur = cur.Append(FILE_PATH_LITERAL("components"));
  19. cur = cur.Append(FILE_PATH_LITERAL("viz"));
  20. cur = cur.Append(FILE_PATH_LITERAL("test"));
  21. cur = cur.Append(FILE_PATH_LITERAL("data"));
  22. if (!base::PathExists(cur)) // we don't want to create this
  23. return false;
  24. break;
  25. default:
  26. return false;
  27. }
  28. *result = cur;
  29. return true;
  30. }
  31. // This cannot be done as a static initializer sadly since Visual Studio will
  32. // eliminate this object file if there is no direct entry point into it.
  33. void Paths::RegisterPathProvider() {
  34. base::PathService::RegisterProvider(PathProvider, PATH_START, PATH_END);
  35. }
  36. } // namespace viz