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