[email protected] | e1ae9fa | 2013-04-23 18:08:33 | [diff] [blame] | 1 | // 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" |
thestig | b44bd35 | 2014-09-10 01:47:06 | [diff] [blame] | 8 | #include "base/files/file_util.h" |
[email protected] | e1ae9fa | 2013-04-23 18:08:33 | [diff] [blame] | 9 | #include "base/path_service.h" |
[email protected] | ff9ed9f | 2014-05-02 17:59:42 | [diff] [blame] | 10 | #include "base/sys_info.h" |
[email protected] | e1ae9fa | 2013-04-23 18:08:33 | [diff] [blame] | 11 | |
| 12 | namespace chromeos { |
| 13 | |
| 14 | namespace { |
| 15 | |
| 16 | const 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 | |
| 23 | const base::FilePath::CharType kDefaultUserPolicyKeysDir[] = |
hashimoto | 72ed43f | 2015-04-17 06:25:10 | [diff] [blame] | 24 | FILE_PATH_LITERAL("/run/user_policy"); |
[email protected] | e1ae9fa | 2013-04-23 18:08:33 | [diff] [blame] | 25 | |
| 26 | const base::FilePath::CharType kOwnerKeyFileName[] = |
| 27 | FILE_PATH_LITERAL("/var/lib/whitelist/owner.key"); |
| 28 | |
| 29 | const base::FilePath::CharType kInstallAttributesFileName[] = |
hashimoto | 72ed43f | 2015-04-17 06:25:10 | [diff] [blame] | 30 | FILE_PATH_LITERAL("/run/lockbox/install_attributes.pb"); |
[email protected] | e1ae9fa | 2013-04-23 18:08:33 | [diff] [blame] | 31 | |
tnagel | 53a23380 | 2014-12-17 20:28:50 | [diff] [blame] | 32 | const base::FilePath::CharType kMachineHardwareInfoFileName[] = |
| 33 | FILE_PATH_LITERAL("/tmp/machine-info"); |
| 34 | |
[email protected] | e1ae9fa | 2013-04-23 18:08:33 | [diff] [blame] | 35 | const base::FilePath::CharType kUptimeFileName[] = |
| 36 | FILE_PATH_LITERAL("/proc/uptime"); |
| 37 | |
| 38 | const base::FilePath::CharType kUpdateRebootNeededUptimeFile[] = |
hashimoto | 72ed43f | 2015-04-17 06:25:10 | [diff] [blame] | 39 | FILE_PATH_LITERAL("/run/chrome/update_reboot_needed_uptime"); |
[email protected] | e1ae9fa | 2013-04-23 18:08:33 | [diff] [blame] | 40 | |
[email protected] | 888a25f | 2013-11-05 19:30:51 | [diff] [blame] | 41 | const base::FilePath::CharType kDeviceLocalAccountExtensionDir[] = |
[email protected] | af98488 | 2013-10-21 21:08:51 | [diff] [blame] | 42 | FILE_PATH_LITERAL("/var/cache/device_local_account_extensions"); |
| 43 | |
[email protected] | 888a25f | 2013-11-05 19:30:51 | [diff] [blame] | 44 | const base::FilePath::CharType kDeviceLocalAccountExternalDataDir[] = |
| 45 | FILE_PATH_LITERAL("/var/cache/device_local_account_external_policy_data"); |
| 46 | |
[email protected] | 68a31b1 | 2014-06-20 17:12:21 | [diff] [blame] | 47 | const base::FilePath::CharType kDeviceLocalAccountComponentPolicy[] = |
| 48 | FILE_PATH_LITERAL("/var/cache/device_local_account_component_policy"); |
| 49 | |
jennyz | 26b7f43 | 2015-09-03 20:59:27 | [diff] [blame^] | 50 | const base::FilePath::CharType kDeviceExtensionLocalCache[] = |
| 51 | FILE_PATH_LITERAL("/var/cache/external_cache"); |
| 52 | |
robert.bradford | 772b479 | 2015-05-14 18:58:27 | [diff] [blame] | 53 | const base::FilePath::CharType kDeviceColorProfileDirectory[] = |
| 54 | FILE_PATH_LITERAL("/usr/share/color/icc"); |
| 55 | |
[email protected] | e1ae9fa | 2013-04-23 18:08:33 | [diff] [blame] | 56 | bool PathProvider(int key, base::FilePath* result) { |
| 57 | switch (key) { |
| 58 | case FILE_DEFAULT_APP_ORDER: |
| 59 | *result = base::FilePath(kDefaultAppOrderFileName); |
| 60 | break; |
| 61 | case DIR_USER_POLICY_KEYS: |
| 62 | *result = base::FilePath(kDefaultUserPolicyKeysDir); |
| 63 | break; |
| 64 | case FILE_OWNER_KEY: |
| 65 | *result = base::FilePath(kOwnerKeyFileName); |
| 66 | break; |
| 67 | case FILE_INSTALL_ATTRIBUTES: |
| 68 | *result = base::FilePath(kInstallAttributesFileName); |
| 69 | break; |
tnagel | 53a23380 | 2014-12-17 20:28:50 | [diff] [blame] | 70 | case FILE_MACHINE_INFO: |
| 71 | *result = base::FilePath(kMachineHardwareInfoFileName); |
| 72 | break; |
[email protected] | e1ae9fa | 2013-04-23 18:08:33 | [diff] [blame] | 73 | case FILE_UPTIME: |
| 74 | *result = base::FilePath(kUptimeFileName); |
| 75 | break; |
| 76 | case FILE_UPDATE_REBOOT_NEEDED_UPTIME: |
| 77 | *result = base::FilePath(kUpdateRebootNeededUptimeFile); |
| 78 | break; |
[email protected] | 888a25f | 2013-11-05 19:30:51 | [diff] [blame] | 79 | case DIR_DEVICE_LOCAL_ACCOUNT_EXTENSIONS: |
| 80 | *result = base::FilePath(kDeviceLocalAccountExtensionDir); |
| 81 | break; |
| 82 | case DIR_DEVICE_LOCAL_ACCOUNT_EXTERNAL_DATA: |
| 83 | *result = base::FilePath(kDeviceLocalAccountExternalDataDir); |
[email protected] | af98488 | 2013-10-21 21:08:51 | [diff] [blame] | 84 | break; |
[email protected] | 68a31b1 | 2014-06-20 17:12:21 | [diff] [blame] | 85 | case DIR_DEVICE_LOCAL_ACCOUNT_COMPONENT_POLICY: |
| 86 | *result = base::FilePath(kDeviceLocalAccountComponentPolicy); |
| 87 | break; |
robert.bradford | 772b479 | 2015-05-14 18:58:27 | [diff] [blame] | 88 | case DIR_DEVICE_COLOR_CALIBRATION_PROFILES: |
| 89 | *result = base::FilePath(kDeviceColorProfileDirectory); |
robert.bradford | 5849cfec | 2015-05-19 17:28:52 | [diff] [blame] | 90 | break; |
jennyz | 26b7f43 | 2015-09-03 20:59:27 | [diff] [blame^] | 91 | case DIR_DEVICE_EXTENSION_LOCAL_CACHE: |
| 92 | *result = base::FilePath(kDeviceExtensionLocalCache); |
| 93 | break; |
[email protected] | e1ae9fa | 2013-04-23 18:08:33 | [diff] [blame] | 94 | default: |
| 95 | return false; |
| 96 | } |
| 97 | return true; |
| 98 | } |
| 99 | |
| 100 | } // namespace |
| 101 | |
| 102 | void RegisterPathProvider() { |
| 103 | PathService::RegisterProvider(PathProvider, PATH_START, PATH_END); |
| 104 | } |
| 105 | |
[email protected] | ff9ed9f | 2014-05-02 17:59:42 | [diff] [blame] | 106 | void RegisterStubPathOverrides(const base::FilePath& stubs_dir) { |
| 107 | CHECK(!base::SysInfo::IsRunningOnChromeOS()); |
| 108 | // Override these paths on the desktop, so that enrollment and cloud |
| 109 | // policy work and can be tested. |
| 110 | base::FilePath parent = base::MakeAbsoluteFilePath(stubs_dir); |
| 111 | PathService::Override( |
| 112 | DIR_USER_POLICY_KEYS, |
| 113 | parent.AppendASCII("stub_user_policy")); |
| 114 | const bool is_absolute = true; |
| 115 | const bool create = false; |
| 116 | PathService::OverrideAndCreateIfNeeded( |
| 117 | FILE_OWNER_KEY, |
| 118 | parent.AppendASCII("stub_owner.key"), |
| 119 | is_absolute, |
| 120 | create); |
| 121 | PathService::OverrideAndCreateIfNeeded( |
| 122 | FILE_INSTALL_ATTRIBUTES, |
| 123 | parent.AppendASCII("stub_install_attributes.pb"), |
| 124 | is_absolute, |
| 125 | create); |
tnagel | 53a23380 | 2014-12-17 20:28:50 | [diff] [blame] | 126 | PathService::OverrideAndCreateIfNeeded( |
| 127 | FILE_MACHINE_INFO, |
| 128 | parent.AppendASCII("stub_machine-info"), |
| 129 | is_absolute, |
| 130 | create); |
[email protected] | 68a31b1 | 2014-06-20 17:12:21 | [diff] [blame] | 131 | PathService::Override( |
| 132 | DIR_DEVICE_LOCAL_ACCOUNT_EXTENSIONS, |
| 133 | parent.AppendASCII("stub_device_local_account_extensions")); |
| 134 | PathService::Override( |
| 135 | DIR_DEVICE_LOCAL_ACCOUNT_EXTERNAL_DATA, |
| 136 | parent.AppendASCII("stub_device_local_account_external_data")); |
| 137 | PathService::Override( |
| 138 | DIR_DEVICE_LOCAL_ACCOUNT_COMPONENT_POLICY, |
| 139 | parent.AppendASCII("stub_device_local_account_component_policy")); |
jennyz | 26b7f43 | 2015-09-03 20:59:27 | [diff] [blame^] | 140 | PathService::Override( |
| 141 | DIR_DEVICE_EXTENSION_LOCAL_CACHE, |
| 142 | parent.AppendASCII("stub_device_local_extension_cache")); |
[email protected] | ff9ed9f | 2014-05-02 17:59:42 | [diff] [blame] | 143 | } |
| 144 | |
[email protected] | e1ae9fa | 2013-04-23 18:08:33 | [diff] [blame] | 145 | } // namespace chromeos |