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 | |
| 9 | #include "base/command_line.h" |
John Budorick | 7f8f205 | 2018-01-25 17:48:44 | [diff] [blame] | 10 | #include "base/files/file_path.h" |
scottmg | 1ab7aa8 | 2017-05-25 05:22:49 | [diff] [blame] | 11 | |
| 12 | namespace base { |
| 13 | |
| 14 | bool PathProviderFuchsia(int key, FilePath* result) { |
| 15 | switch (key) { |
Scott Graham | 4bd2b07f | 2017-06-01 04:17:04 | [diff] [blame] | 16 | case FILE_MODULE: |
John Budorick | 7f8f205 | 2018-01-25 17:48:44 | [diff] [blame] | 17 | // Not supported in debug or component builds. Fall back on using the EXE |
| 18 | // path for now. |
| 19 | // TODO(fuchsia): Get this value from an API. See crbug.com/726124 |
Kevin Marshall | fe2f08c | 2017-08-25 21:45:29 | [diff] [blame] | 20 | case FILE_EXE: { |
John Budorick | 7f8f205 | 2018-01-25 17:48:44 | [diff] [blame] | 21 | // Use the binary name as specified on the command line. |
| 22 | // TODO(fuchsia): It would be nice to get the canonical executable path |
| 23 | // from a kernel API. See https://crbug.com/726124 |
| 24 | char bin_dir[PATH_MAX + 1]; |
| 25 | if (realpath(base::CommandLine::ForCurrentProcess() |
| 26 | ->GetProgram() |
| 27 | .AsUTF8Unsafe() |
| 28 | .c_str(), |
| 29 | bin_dir) == NULL) { |
| 30 | return false; |
| 31 | } |
| 32 | *result = FilePath(bin_dir); |
Scott Graham | 4bd2b07f | 2017-06-01 04:17:04 | [diff] [blame] | 33 | return true; |
Kevin Marshall | fe2f08c | 2017-08-25 21:45:29 | [diff] [blame] | 34 | } |
Scott Graham | 4bd2b07f | 2017-06-01 04:17:04 | [diff] [blame] | 35 | case DIR_SOURCE_ROOT: |
John Budorick | 7f8f205 | 2018-01-25 17:48:44 | [diff] [blame] | 36 | // This is only used for tests, so we return the binary location for now. |
| 37 | *result = FilePath("/system"); |
Scott Graham | 4bd2b07f | 2017-06-01 04:17:04 | [diff] [blame] | 38 | return true; |
| 39 | case DIR_CACHE: |
| 40 | *result = FilePath("/data"); |
| 41 | return true; |
scottmg | 1ab7aa8 | 2017-05-25 05:22:49 | [diff] [blame] | 42 | } |
John Budorick | 7f8f205 | 2018-01-25 17:48:44 | [diff] [blame] | 43 | |
scottmg | 1ab7aa8 | 2017-05-25 05:22:49 | [diff] [blame] | 44 | return false; |
| 45 | } |
| 46 | |
| 47 | } // namespace base |