Add testing/scripts/OWNERS
[chromium-blink-merge.git] / components / nacl / common / nacl_paths.cc
blob442d1493689ce75d0dabda3e23b6ab64e6001cf3
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"
12 namespace {
14 #if defined(OS_LINUX)
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))
26 return false;
27 *output = output->Append(filename);
28 return true;
31 #endif
33 } // namespace
35 namespace nacl {
37 bool PathProvider(int key, base::FilePath* result) {
38 switch (key) {
39 #if defined(OS_LINUX)
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
48 // is supported.
49 return GetNaClHelperPath(kInternalNaClHelperFileName, result);
51 return GetNaClHelperPath(kInternalNaClHelperNonSfiFileName, result);
52 case FILE_NACL_HELPER_BOOTSTRAP:
53 return GetNaClHelperPath(kInternalNaClHelperBootstrapFileName, result);
54 #endif
55 default:
56 return false;
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);
66 } // namespace nacl