scottmg | 1ab7aa8 | 2017-05-25 05:22:49 | [diff] [blame] | 1 | // Copyright 2017 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 | |
| 5 | #include "base/base_paths.h" |
| 6 | |
Kevin Marshall | fe2f08c | 2017-08-25 21:45:29 | [diff] [blame] | 7 | #include <stdlib.h> |
| 8 | |
Kevin Marshall | f35fa5f | 2018-01-29 19:24:42 | [diff] [blame^] | 9 | #include "base/base_paths_fuchsia.h" |
Kevin Marshall | fe2f08c | 2017-08-25 21:45:29 | [diff] [blame] | 10 | #include "base/command_line.h" |
Kevin Marshall | f35fa5f | 2018-01-29 19:24:42 | [diff] [blame^] | 11 | #include "base/files/file_util.h" |
| 12 | #include "base/path_service.h" |
| 13 | #include "base/process/process.h" |
scottmg | 1ab7aa8 | 2017-05-25 05:22:49 | [diff] [blame] | 14 | |
| 15 | namespace base { |
Kevin Marshall | f35fa5f | 2018-01-29 19:24:42 | [diff] [blame^] | 16 | namespace { |
| 17 | |
| 18 | constexpr char kPackageRoot[] = "/pkg"; |
| 19 | |
| 20 | } // namespace |
| 21 | |
| 22 | base::FilePath GetPackageRoot() { |
| 23 | base::FilePath path_obj(kPackageRoot); |
| 24 | |
| 25 | // Fuchsia's appmgr will set argv[0] to a fully qualified executable path |
| 26 | // under /pkg for packaged binaries. |
| 27 | if (path_obj.IsParent(base::CommandLine::ForCurrentProcess()->GetProgram())) { |
| 28 | return path_obj; |
| 29 | } else { |
| 30 | return base::FilePath(); |
| 31 | } |
| 32 | } |
scottmg | 1ab7aa8 | 2017-05-25 05:22:49 | [diff] [blame] | 33 | |
| 34 | bool PathProviderFuchsia(int key, FilePath* result) { |
| 35 | switch (key) { |
Scott Graham | 4bd2b07f | 2017-06-01 04:17:04 | [diff] [blame] | 36 | case FILE_MODULE: |
Kevin Marshall | f35fa5f | 2018-01-29 19:24:42 | [diff] [blame^] | 37 | NOTIMPLEMENTED(); |
| 38 | return false; |
Kevin Marshall | fe2f08c | 2017-08-25 21:45:29 | [diff] [blame] | 39 | case FILE_EXE: { |
Kevin Marshall | f35fa5f | 2018-01-29 19:24:42 | [diff] [blame^] | 40 | *result = base::MakeAbsoluteFilePath(base::FilePath( |
| 41 | base::CommandLine::ForCurrentProcess()->GetProgram().AsUTF8Unsafe())); |
Scott Graham | 4bd2b07f | 2017-06-01 04:17:04 | [diff] [blame] | 42 | return true; |
Kevin Marshall | fe2f08c | 2017-08-25 21:45:29 | [diff] [blame] | 43 | } |
Scott Graham | 4bd2b07f | 2017-06-01 04:17:04 | [diff] [blame] | 44 | case DIR_SOURCE_ROOT: |
Kevin Marshall | f35fa5f | 2018-01-29 19:24:42 | [diff] [blame^] | 45 | *result = GetPackageRoot(); |
| 46 | if (result->empty()) { |
| 47 | *result = FilePath("/system"); |
| 48 | } |
Scott Graham | 4bd2b07f | 2017-06-01 04:17:04 | [diff] [blame] | 49 | return true; |
| 50 | case DIR_CACHE: |
| 51 | *result = FilePath("/data"); |
| 52 | return true; |
Kevin Marshall | f35fa5f | 2018-01-29 19:24:42 | [diff] [blame^] | 53 | case DIR_FUCHSIA_RESOURCES: |
| 54 | *result = GetPackageRoot(); |
| 55 | if (result->empty()) { |
| 56 | PathService::Get(DIR_EXE, result); |
| 57 | } |
| 58 | return true; |
scottmg | 1ab7aa8 | 2017-05-25 05:22:49 | [diff] [blame] | 59 | } |
scottmg | 1ab7aa8 | 2017-05-25 05:22:49 | [diff] [blame] | 60 | return false; |
| 61 | } |
| 62 | |
| 63 | } // namespace base |