blob: e5c12b944ec3f96867fe8d63db725e71fd8e7f31 [file] [log] [blame]
[email protected]e1ae9fa2013-04-23 18:08:331// Copyright (c) 2013 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 "chromeos/chromeos_paths.h"
6
7#include "base/files/file_path.h"
thestigb44bd352014-09-10 01:47:068#include "base/files/file_util.h"
[email protected]e1ae9fa2013-04-23 18:08:339#include "base/path_service.h"
[email protected]ff9ed9f2014-05-02 17:59:4210#include "base/sys_info.h"
[email protected]e1ae9fa2013-04-23 18:08:3311
12namespace chromeos {
13
14namespace {
15
16const base::FilePath::CharType kDefaultAppOrderFileName[] =
17#if defined(GOOGLE_CHROME_BUILD)
18 FILE_PATH_LITERAL("/usr/share/google-chrome/default_app_order.json");
19#else
20 FILE_PATH_LITERAL("/usr/share/chromium/default_app_order.json");
21#endif // defined(GOOGLE_CHROME_BUILD)
22
23const base::FilePath::CharType kDefaultUserPolicyKeysDir[] =
hashimoto72ed43f2015-04-17 06:25:1024 FILE_PATH_LITERAL("/run/user_policy");
[email protected]e1ae9fa2013-04-23 18:08:3325
26const base::FilePath::CharType kOwnerKeyFileName[] =
27 FILE_PATH_LITERAL("/var/lib/whitelist/owner.key");
28
29const base::FilePath::CharType kInstallAttributesFileName[] =
hashimoto72ed43f2015-04-17 06:25:1030 FILE_PATH_LITERAL("/run/lockbox/install_attributes.pb");
[email protected]e1ae9fa2013-04-23 18:08:3331
tnagel53a233802014-12-17 20:28:5032const base::FilePath::CharType kMachineHardwareInfoFileName[] =
33 FILE_PATH_LITERAL("/tmp/machine-info");
34
tnagele62605f2017-04-27 12:19:5535const base::FilePath::CharType kVpdFileName[] = FILE_PATH_LITERAL(
36 "/mnt/stateful_partition/unencrypted/cache/vpd/filtered.txt");
tnagel9157ba42017-04-11 16:56:1537
[email protected]e1ae9fa2013-04-23 18:08:3338const base::FilePath::CharType kUptimeFileName[] =
39 FILE_PATH_LITERAL("/proc/uptime");
40
41const base::FilePath::CharType kUpdateRebootNeededUptimeFile[] =
hashimoto72ed43f2015-04-17 06:25:1042 FILE_PATH_LITERAL("/run/chrome/update_reboot_needed_uptime");
[email protected]e1ae9fa2013-04-23 18:08:3343
[email protected]888a25f2013-11-05 19:30:5144const base::FilePath::CharType kDeviceLocalAccountExtensionDir[] =
[email protected]af984882013-10-21 21:08:5145 FILE_PATH_LITERAL("/var/cache/device_local_account_extensions");
46
[email protected]888a25f2013-11-05 19:30:5147const base::FilePath::CharType kDeviceLocalAccountExternalDataDir[] =
48 FILE_PATH_LITERAL("/var/cache/device_local_account_external_policy_data");
49
[email protected]68a31b12014-06-20 17:12:2150const base::FilePath::CharType kDeviceLocalAccountComponentPolicy[] =
51 FILE_PATH_LITERAL("/var/cache/device_local_account_component_policy");
52
glevin5dd01a72016-03-23 23:08:1253const base::FilePath::CharType kDeviceDisplayProfileDirectory[] =
54 FILE_PATH_LITERAL("/var/cache/display_profiles");
jennyz26b7f432015-09-03 20:59:2755
glevin5dd01a72016-03-23 23:08:1256const base::FilePath::CharType kDeviceExtensionLocalCache[] =
57 FILE_PATH_LITERAL("/var/cache/external_cache");
58
emaxxebe5cbc2016-11-10 03:39:3059const base::FilePath::CharType kSigninProfileComponentPolicy[] =
60 FILE_PATH_LITERAL("/var/cache/signin_profile_component_policy");
61
[email protected]e1ae9fa2013-04-23 18:08:3362bool PathProvider(int key, base::FilePath* result) {
63 switch (key) {
64 case FILE_DEFAULT_APP_ORDER:
65 *result = base::FilePath(kDefaultAppOrderFileName);
66 break;
67 case DIR_USER_POLICY_KEYS:
68 *result = base::FilePath(kDefaultUserPolicyKeysDir);
69 break;
70 case FILE_OWNER_KEY:
71 *result = base::FilePath(kOwnerKeyFileName);
72 break;
73 case FILE_INSTALL_ATTRIBUTES:
74 *result = base::FilePath(kInstallAttributesFileName);
75 break;
tnagel53a233802014-12-17 20:28:5076 case FILE_MACHINE_INFO:
77 *result = base::FilePath(kMachineHardwareInfoFileName);
78 break;
tnagel9157ba42017-04-11 16:56:1579 case FILE_VPD:
80 *result = base::FilePath(kVpdFileName);
81 break;
[email protected]e1ae9fa2013-04-23 18:08:3382 case FILE_UPTIME:
83 *result = base::FilePath(kUptimeFileName);
84 break;
85 case FILE_UPDATE_REBOOT_NEEDED_UPTIME:
86 *result = base::FilePath(kUpdateRebootNeededUptimeFile);
87 break;
[email protected]888a25f2013-11-05 19:30:5188 case DIR_DEVICE_LOCAL_ACCOUNT_EXTENSIONS:
89 *result = base::FilePath(kDeviceLocalAccountExtensionDir);
90 break;
91 case DIR_DEVICE_LOCAL_ACCOUNT_EXTERNAL_DATA:
92 *result = base::FilePath(kDeviceLocalAccountExternalDataDir);
[email protected]af984882013-10-21 21:08:5193 break;
[email protected]68a31b12014-06-20 17:12:2194 case DIR_DEVICE_LOCAL_ACCOUNT_COMPONENT_POLICY:
95 *result = base::FilePath(kDeviceLocalAccountComponentPolicy);
96 break;
glevin5dd01a72016-03-23 23:08:1297 case DIR_DEVICE_DISPLAY_PROFILES:
98 *result = base::FilePath(kDeviceDisplayProfileDirectory);
99 break;
jennyz26b7f432015-09-03 20:59:27100 case DIR_DEVICE_EXTENSION_LOCAL_CACHE:
101 *result = base::FilePath(kDeviceExtensionLocalCache);
102 break;
emaxxebe5cbc2016-11-10 03:39:30103 case DIR_SIGNIN_PROFILE_COMPONENT_POLICY:
104 *result = base::FilePath(kSigninProfileComponentPolicy);
105 break;
[email protected]e1ae9fa2013-04-23 18:08:33106 default:
107 return false;
108 }
109 return true;
110}
111
112} // namespace
113
114void RegisterPathProvider() {
115 PathService::RegisterProvider(PathProvider, PATH_START, PATH_END);
116}
117
[email protected]ff9ed9f2014-05-02 17:59:42118void RegisterStubPathOverrides(const base::FilePath& stubs_dir) {
119 CHECK(!base::SysInfo::IsRunningOnChromeOS());
tnagel9157ba42017-04-11 16:56:15120 // Override these paths on the desktop, so that enrollment and cloud policy
121 // work and can be tested.
[email protected]ff9ed9f2014-05-02 17:59:42122 base::FilePath parent = base::MakeAbsoluteFilePath(stubs_dir);
123 PathService::Override(
124 DIR_USER_POLICY_KEYS,
125 parent.AppendASCII("stub_user_policy"));
126 const bool is_absolute = true;
127 const bool create = false;
128 PathService::OverrideAndCreateIfNeeded(
129 FILE_OWNER_KEY,
130 parent.AppendASCII("stub_owner.key"),
131 is_absolute,
132 create);
133 PathService::OverrideAndCreateIfNeeded(
134 FILE_INSTALL_ATTRIBUTES,
135 parent.AppendASCII("stub_install_attributes.pb"),
136 is_absolute,
137 create);
tnagel53a233802014-12-17 20:28:50138 PathService::OverrideAndCreateIfNeeded(
139 FILE_MACHINE_INFO,
140 parent.AppendASCII("stub_machine-info"),
141 is_absolute,
142 create);
tnagel9157ba42017-04-11 16:56:15143 PathService::OverrideAndCreateIfNeeded(
144 FILE_VPD,
145 parent.AppendASCII("stub_vpd"),
146 is_absolute,
147 create);
[email protected]68a31b12014-06-20 17:12:21148 PathService::Override(
149 DIR_DEVICE_LOCAL_ACCOUNT_EXTENSIONS,
150 parent.AppendASCII("stub_device_local_account_extensions"));
151 PathService::Override(
152 DIR_DEVICE_LOCAL_ACCOUNT_EXTERNAL_DATA,
153 parent.AppendASCII("stub_device_local_account_external_data"));
154 PathService::Override(
155 DIR_DEVICE_LOCAL_ACCOUNT_COMPONENT_POLICY,
156 parent.AppendASCII("stub_device_local_account_component_policy"));
jennyz26b7f432015-09-03 20:59:27157 PathService::Override(
158 DIR_DEVICE_EXTENSION_LOCAL_CACHE,
159 parent.AppendASCII("stub_device_local_extension_cache"));
emaxxebe5cbc2016-11-10 03:39:30160 PathService::Override(
161 DIR_SIGNIN_PROFILE_COMPONENT_POLICY,
162 parent.AppendASCII("stub_signin_profile_component_policy"));
[email protected]ff9ed9f2014-05-02 17:59:42163}
164
[email protected]e1ae9fa2013-04-23 18:08:33165} // namespace chromeos