Upload upstream chromium 67.0.3396
[platform/framework/web/chromium-efl.git] / base / base_paths_fuchsia.cc
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
7 #include <stdlib.h>
8
9 #include "base/base_paths_fuchsia.h"
10 #include "base/command_line.h"
11 #include "base/files/file_util.h"
12 #include "base/path_service.h"
13 #include "base/process/process.h"
14
15 namespace base {
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 }
33
34 bool PathProviderFuchsia(int key, FilePath* result) {
35   switch (key) {
36     case FILE_MODULE:
37       NOTIMPLEMENTED();
38       return false;
39     case FILE_EXE: {
40       *result = base::MakeAbsoluteFilePath(base::FilePath(
41           base::CommandLine::ForCurrentProcess()->GetProgram().AsUTF8Unsafe()));
42       return true;
43     }
44     case DIR_SOURCE_ROOT:
45       *result = GetPackageRoot();
46       if (result->empty()) {
47         *result = FilePath("/system");
48       }
49       return true;
50     case DIR_CACHE:
51       *result = FilePath("/data");
52       return true;
53     case DIR_ASSETS:
54       *result = GetPackageRoot();
55       if (result->empty()) {
56         return PathService::Get(DIR_EXE, result);
57       }
58       return true;
59   }
60   return false;
61 }
62
63 }  // namespace base