lacros_paths.cc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2022 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 "chromeos/lacros/lacros_paths.h"
  5. #include "base/files/file_path.h"
  6. #include "base/files/file_util.h"
  7. #include "base/no_destructor.h"
  8. #include "base/path_service.h"
  9. #include "base/system/sys_info.h"
  10. #include "chromeos/crosapi/cpp/crosapi_constants.h"
  11. namespace {
  12. struct LacrosPaths {
  13. base::FilePath ash_resource_dir;
  14. };
  15. LacrosPaths& GetLacrosPaths() {
  16. static base::NoDestructor<LacrosPaths> lacros_paths;
  17. return *lacros_paths;
  18. }
  19. bool PathProvider(int key, base::FilePath* result) {
  20. switch (key) {
  21. case chromeos::lacros_paths::ASH_RESOURCES_DIR:
  22. *result = GetLacrosPaths().ash_resource_dir;
  23. return !result->empty();
  24. case chromeos::lacros_paths::USER_DATA_DIR:
  25. // The value for USER_DATA_DIR should be consistent with ash-side
  26. // UserDataDir defined in browser_util::GetUserDataDir().
  27. if (base::SysInfo::IsRunningOnChromeOS()) {
  28. *result = base::FilePath(crosapi::kLacrosUserDataPath);
  29. } else {
  30. *result = base::GetHomeDir().Append(".config").Append("lacros");
  31. }
  32. return true;
  33. default:
  34. return false;
  35. }
  36. }
  37. } // namespace
  38. namespace chromeos {
  39. namespace lacros_paths {
  40. void RegisterPathProvider() {
  41. base::PathService::RegisterProvider(PathProvider, PATH_START, PATH_END);
  42. }
  43. void SetAshResourcesPath(const base::FilePath& path) {
  44. GetLacrosPaths().ash_resource_dir = path;
  45. }
  46. } // namespace lacros_paths
  47. } // namespace chromeos