blob: ebc9b1f9013b092eab3c815488d8135bc86f866e [file] [log] [blame]
scottmg1ab7aa82017-05-25 05:22:491// 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 Marshallfe2f08c2017-08-25 21:45:297#include <stdlib.h>
8
Kevin Marshallf35fa5f2018-01-29 19:24:429#include "base/base_paths_fuchsia.h"
Kevin Marshallfe2f08c2017-08-25 21:45:2910#include "base/command_line.h"
Kevin Marshallf35fa5f2018-01-29 19:24:4211#include "base/files/file_util.h"
12#include "base/path_service.h"
13#include "base/process/process.h"
scottmg1ab7aa82017-05-25 05:22:4914
15namespace base {
Kevin Marshallf35fa5f2018-01-29 19:24:4216namespace {
17
18constexpr char kPackageRoot[] = "/pkg";
19
20} // namespace
21
22base::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}
scottmg1ab7aa82017-05-25 05:22:4933
34bool PathProviderFuchsia(int key, FilePath* result) {
35 switch (key) {
Scott Graham4bd2b07f2017-06-01 04:17:0436 case FILE_MODULE:
Kevin Marshallf35fa5f2018-01-29 19:24:4237 NOTIMPLEMENTED();
38 return false;
Kevin Marshallfe2f08c2017-08-25 21:45:2939 case FILE_EXE: {
Kevin Marshallf35fa5f2018-01-29 19:24:4240 *result = base::MakeAbsoluteFilePath(base::FilePath(
41 base::CommandLine::ForCurrentProcess()->GetProgram().AsUTF8Unsafe()));
Scott Graham4bd2b07f2017-06-01 04:17:0442 return true;
Kevin Marshallfe2f08c2017-08-25 21:45:2943 }
Scott Graham4bd2b07f2017-06-01 04:17:0444 case DIR_SOURCE_ROOT:
Kevin Marshallf35fa5f2018-01-29 19:24:4245 *result = GetPackageRoot();
46 if (result->empty()) {
47 *result = FilePath("/system");
48 }
Scott Graham4bd2b07f2017-06-01 04:17:0449 return true;
50 case DIR_CACHE:
51 *result = FilePath("/data");
52 return true;
Kevin Marshallf35fa5f2018-01-29 19:24:4253 case DIR_FUCHSIA_RESOURCES:
54 *result = GetPackageRoot();
55 if (result->empty()) {
56 PathService::Get(DIR_EXE, result);
57 }
58 return true;
scottmg1ab7aa82017-05-25 05:22:4959 }
scottmg1ab7aa82017-05-25 05:22:4960 return false;
61}
62
63} // namespace base