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.
5 #include "components/nacl/common/nacl_paths.h"
7 #include "base/command_line.h"
8 #include "base/files/file_util.h"
9 #include "base/path_service.h"
10 #include "components/nacl/common/nacl_switches.h"
15 // File name of the nacl_helper and nacl_helper_bootstrap, Linux only.
16 const base::FilePath::CharType kInternalNaClHelperFileName
[] =
17 FILE_PATH_LITERAL("nacl_helper");
18 const base::FilePath::CharType kInternalNaClHelperNonSfiFileName
[] =
19 FILE_PATH_LITERAL("nacl_helper_nonsfi");
20 const base::FilePath::CharType kInternalNaClHelperBootstrapFileName
[] =
21 FILE_PATH_LITERAL("nacl_helper_bootstrap");
23 bool GetNaClHelperPath(const base::FilePath::CharType
* filename
,
24 base::FilePath
* output
) {
25 if (!PathService::Get(base::DIR_MODULE
, output
))
27 *output
= output
->Append(filename
);
37 bool PathProvider(int key
, base::FilePath
* result
) {
40 case FILE_NACL_HELPER
:
41 return GetNaClHelperPath(kInternalNaClHelperFileName
, result
);
42 case FILE_NACL_HELPER_NONSFI
:
43 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
44 switches::kUseNaClHelperNonSfi
)) {
45 // Currently nacl_helper_nonsfi is disabled, so use nacl_helper
46 // in Non-SFI mode instead.
47 // TODO(hidehiko): Remove this code path after nacl_helper_nonsfi
49 return GetNaClHelperPath(kInternalNaClHelperFileName
, result
);
51 return GetNaClHelperPath(kInternalNaClHelperNonSfiFileName
, result
);
52 case FILE_NACL_HELPER_BOOTSTRAP
:
53 return GetNaClHelperPath(kInternalNaClHelperBootstrapFileName
, result
);
60 // This cannot be done as a static initializer sadly since Visual Studio will
61 // eliminate this object file if there is no direct entry point into it.
62 void RegisterPathProvider() {
63 PathService::RegisterProvider(PathProvider
, PATH_START
, PATH_END
);