nacl_paths.cc 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2013 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/nacl/common/nacl_paths.h"
  5. #include "base/command_line.h"
  6. #include "base/files/file_util.h"
  7. #include "base/path_service.h"
  8. #include "build/build_config.h"
  9. #include "components/nacl/common/nacl_switches.h"
  10. namespace {
  11. #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
  12. // File name of the nacl_helper and nacl_helper_bootstrap, Linux only.
  13. const base::FilePath::CharType kInternalNaClHelperFileName[] =
  14. FILE_PATH_LITERAL("nacl_helper");
  15. const base::FilePath::CharType kInternalNaClHelperBootstrapFileName[] =
  16. FILE_PATH_LITERAL("nacl_helper_bootstrap");
  17. bool GetNaClHelperPath(const base::FilePath::CharType* filename,
  18. base::FilePath* output) {
  19. if (!base::PathService::Get(base::DIR_MODULE, output))
  20. return false;
  21. *output = output->Append(filename);
  22. return true;
  23. }
  24. #endif
  25. } // namespace
  26. namespace nacl {
  27. bool PathProvider(int key, base::FilePath* result) {
  28. switch (key) {
  29. #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
  30. case FILE_NACL_HELPER:
  31. return GetNaClHelperPath(kInternalNaClHelperFileName, result);
  32. case FILE_NACL_HELPER_BOOTSTRAP:
  33. return GetNaClHelperPath(kInternalNaClHelperBootstrapFileName, result);
  34. #endif
  35. default:
  36. return false;
  37. }
  38. }
  39. // This cannot be done as a static initializer sadly since Visual Studio will
  40. // eliminate this object file if there is no direct entry point into it.
  41. void RegisterPathProvider() {
  42. base::PathService::RegisterProvider(PathProvider, PATH_START, PATH_END);
  43. }
  44. } // namespace nacl