OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/nacl/common/nacl_paths.h" | 5 #include "components/nacl/common/nacl_paths.h" |
6 | 6 |
7 #include "base/command_line.h" | |
7 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
8 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "components/nacl/common/nacl_switches.h" | |
9 | 11 |
10 namespace { | 12 namespace { |
11 | 13 |
12 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 14 #if defined(OS_LINUX) |
13 // File name of the nacl_helper and nacl_helper_bootstrap, Linux only. | 15 // File name of the nacl_helper and nacl_helper_bootstrap, Linux only. |
14 const base::FilePath::CharType kInternalNaClHelperFileName[] = | 16 const base::FilePath::CharType kInternalNaClHelperFileName[] = |
15 FILE_PATH_LITERAL("nacl_helper"); | 17 FILE_PATH_LITERAL("nacl_helper"); |
18 const base::FilePath::CharType kInternalNaClHelperNonSfiFileName[] = | |
19 FILE_PATH_LITERAL("nacl_helper_nonsfi"); | |
16 const base::FilePath::CharType kInternalNaClHelperBootstrapFileName[] = | 20 const base::FilePath::CharType kInternalNaClHelperBootstrapFileName[] = |
17 FILE_PATH_LITERAL("nacl_helper_bootstrap"); | 21 FILE_PATH_LITERAL("nacl_helper_bootstrap"); |
22 | |
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); | |
Junichi Uekawa
2014/10/30 11:04:19
This blew my mind, I see operator= is overloaded s
hidehiko
2014/10/30 11:08:40
FilePath::Append() is const method, i.e. does not
| |
28 return true; | |
29 } | |
30 | |
18 #endif | 31 #endif |
19 | 32 |
20 } // namespace | 33 } // namespace |
21 | 34 |
22 namespace nacl { | 35 namespace nacl { |
23 | 36 |
24 bool PathProvider(int key, base::FilePath* result) { | 37 bool PathProvider(int key, base::FilePath* result) { |
25 base::FilePath cur; | |
26 switch (key) { | 38 switch (key) { |
27 #if defined(OS_LINUX) | 39 #if defined(OS_LINUX) |
28 case FILE_NACL_HELPER: | 40 case FILE_NACL_HELPER: |
29 if (!PathService::Get(base::DIR_MODULE, &cur)) | 41 return GetNaClHelperPath(kInternalNaClHelperFileName, result); |
30 return false; | 42 case FILE_NACL_HELPER_NONSFI: |
31 cur = cur.Append(kInternalNaClHelperFileName); | 43 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
32 break; | 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); | |
50 } | |
51 return GetNaClHelperPath(kInternalNaClHelperNonSfiFileName, result); | |
33 case FILE_NACL_HELPER_BOOTSTRAP: | 52 case FILE_NACL_HELPER_BOOTSTRAP: |
34 if (!PathService::Get(base::DIR_MODULE, &cur)) | 53 return GetNaClHelperPath(kInternalNaClHelperBootstrapFileName, result); |
35 return false; | |
36 cur = cur.Append(kInternalNaClHelperBootstrapFileName); | |
37 break; | |
38 #endif | 54 #endif |
39 default: | 55 default: |
40 return false; | 56 return false; |
41 } | 57 } |
42 | |
43 *result = cur; | |
44 return true; | |
45 } | 58 } |
46 | 59 |
47 // This cannot be done as a static initializer sadly since Visual Studio will | 60 // This cannot be done as a static initializer sadly since Visual Studio will |
48 // eliminate this object file if there is no direct entry point into it. | 61 // eliminate this object file if there is no direct entry point into it. |
49 void RegisterPathProvider() { | 62 void RegisterPathProvider() { |
50 PathService::RegisterProvider(PathProvider, PATH_START, PATH_END); | 63 PathService::RegisterProvider(PathProvider, PATH_START, PATH_END); |
51 } | 64 } |
52 | 65 |
53 } // namespace nacl | 66 } // namespace nacl |
OLD | NEW |