blob: bdb3fa9c1f5997be3f72c058967e0c9e28b46379 [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
[email protected]e1ae9fa2013-04-23 18:08:3335const base::FilePath::CharType kUptimeFileName[] =
36 FILE_PATH_LITERAL("/proc/uptime");
37
38const base::FilePath::CharType kUpdateRebootNeededUptimeFile[] =
hashimoto72ed43f2015-04-17 06:25:1039 FILE_PATH_LITERAL("/run/chrome/update_reboot_needed_uptime");
[email protected]e1ae9fa2013-04-23 18:08:3340
[email protected]888a25f2013-11-05 19:30:5141const base::FilePath::CharType kDeviceLocalAccountExtensionDir[] =
[email protected]af984882013-10-21 21:08:5142 FILE_PATH_LITERAL("/var/cache/device_local_account_extensions");
43
[email protected]888a25f2013-11-05 19:30:5144const base::FilePath::CharType kDeviceLocalAccountExternalDataDir[] =
45 FILE_PATH_LITERAL("/var/cache/device_local_account_external_policy_data");
46
[email protected]68a31b12014-06-20 17:12:2147const base::FilePath::CharType kDeviceLocalAccountComponentPolicy[] =
48 FILE_PATH_LITERAL("/var/cache/device_local_account_component_policy");
49
glevin5dd01a72016-03-23 23:08:1250const base::FilePath::CharType kDeviceDisplayProfileDirectory[] =
51 FILE_PATH_LITERAL("/var/cache/display_profiles");
jennyz26b7f432015-09-03 20:59:2752
glevin5dd01a72016-03-23 23:08:1253const base::FilePath::CharType kDeviceExtensionLocalCache[] =
54 FILE_PATH_LITERAL("/var/cache/external_cache");
55
emaxxebe5cbc2016-11-10 03:39:3056const base::FilePath::CharType kSigninProfileComponentPolicy[] =
57 FILE_PATH_LITERAL("/var/cache/signin_profile_component_policy");
58
[email protected]e1ae9fa2013-04-23 18:08:3359bool PathProvider(int key, base::FilePath* result) {
60 switch (key) {
61 case FILE_DEFAULT_APP_ORDER:
62 *result = base::FilePath(kDefaultAppOrderFileName);
63 break;
64 case DIR_USER_POLICY_KEYS:
65 *result = base::FilePath(kDefaultUserPolicyKeysDir);
66 break;
67 case FILE_OWNER_KEY:
68 *result = base::FilePath(kOwnerKeyFileName);
69 break;
70 case FILE_INSTALL_ATTRIBUTES:
71 *result = base::FilePath(kInstallAttributesFileName);
72 break;
tnagel53a233802014-12-17 20:28:5073 case FILE_MACHINE_INFO:
74 *result = base::FilePath(kMachineHardwareInfoFileName);
75 break;
[email protected]e1ae9fa2013-04-23 18:08:3376 case FILE_UPTIME:
77 *result = base::FilePath(kUptimeFileName);
78 break;
79 case FILE_UPDATE_REBOOT_NEEDED_UPTIME:
80 *result = base::FilePath(kUpdateRebootNeededUptimeFile);
81 break;
[email protected]888a25f2013-11-05 19:30:5182 case DIR_DEVICE_LOCAL_ACCOUNT_EXTENSIONS:
83 *result = base::FilePath(kDeviceLocalAccountExtensionDir);
84 break;
85 case DIR_DEVICE_LOCAL_ACCOUNT_EXTERNAL_DATA:
86 *result = base::FilePath(kDeviceLocalAccountExternalDataDir);
[email protected]af984882013-10-21 21:08:5187 break;
[email protected]68a31b12014-06-20 17:12:2188 case DIR_DEVICE_LOCAL_ACCOUNT_COMPONENT_POLICY:
89 *result = base::FilePath(kDeviceLocalAccountComponentPolicy);
90 break;
glevin5dd01a72016-03-23 23:08:1291 case DIR_DEVICE_DISPLAY_PROFILES:
92 *result = base::FilePath(kDeviceDisplayProfileDirectory);
93 break;
jennyz26b7f432015-09-03 20:59:2794 case DIR_DEVICE_EXTENSION_LOCAL_CACHE:
95 *result = base::FilePath(kDeviceExtensionLocalCache);
96 break;
emaxxebe5cbc2016-11-10 03:39:3097 case DIR_SIGNIN_PROFILE_COMPONENT_POLICY:
98 *result = base::FilePath(kSigninProfileComponentPolicy);
99 break;
[email protected]e1ae9fa2013-04-23 18:08:33100 default:
101 return false;
102 }
103 return true;
104}
105
106} // namespace
107
108void RegisterPathProvider() {
109 PathService::RegisterProvider(PathProvider, PATH_START, PATH_END);
110}
111
[email protected]ff9ed9f2014-05-02 17:59:42112void RegisterStubPathOverrides(const base::FilePath& stubs_dir) {
113 CHECK(!base::SysInfo::IsRunningOnChromeOS());
114 // Override these paths on the desktop, so that enrollment and cloud
115 // policy work and can be tested.
116 base::FilePath parent = base::MakeAbsoluteFilePath(stubs_dir);
117 PathService::Override(
118 DIR_USER_POLICY_KEYS,
119 parent.AppendASCII("stub_user_policy"));
120 const bool is_absolute = true;
121 const bool create = false;
122 PathService::OverrideAndCreateIfNeeded(
123 FILE_OWNER_KEY,
124 parent.AppendASCII("stub_owner.key"),
125 is_absolute,
126 create);
127 PathService::OverrideAndCreateIfNeeded(
128 FILE_INSTALL_ATTRIBUTES,
129 parent.AppendASCII("stub_install_attributes.pb"),
130 is_absolute,
131 create);
tnagel53a233802014-12-17 20:28:50132 PathService::OverrideAndCreateIfNeeded(
133 FILE_MACHINE_INFO,
134 parent.AppendASCII("stub_machine-info"),
135 is_absolute,
136 create);
[email protected]68a31b12014-06-20 17:12:21137 PathService::Override(
138 DIR_DEVICE_LOCAL_ACCOUNT_EXTENSIONS,
139 parent.AppendASCII("stub_device_local_account_extensions"));
140 PathService::Override(
141 DIR_DEVICE_LOCAL_ACCOUNT_EXTERNAL_DATA,
142 parent.AppendASCII("stub_device_local_account_external_data"));
143 PathService::Override(
144 DIR_DEVICE_LOCAL_ACCOUNT_COMPONENT_POLICY,
145 parent.AppendASCII("stub_device_local_account_component_policy"));
jennyz26b7f432015-09-03 20:59:27146 PathService::Override(
147 DIR_DEVICE_EXTENSION_LOCAL_CACHE,
148 parent.AppendASCII("stub_device_local_extension_cache"));
emaxxebe5cbc2016-11-10 03:39:30149 PathService::Override(
150 DIR_SIGNIN_PROFILE_COMPONENT_POLICY,
151 parent.AppendASCII("stub_signin_profile_component_policy"));
[email protected]ff9ed9f2014-05-02 17:59:42152}
153
[email protected]e1ae9fa2013-04-23 18:08:33154} // namespace chromeos