[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 | |
glevin | 5dd01a7 | 2016-03-23 23:08:12 | [diff] [blame] | 50 | const base::FilePath::CharType kDeviceDisplayProfileDirectory[] = |
| 51 | FILE_PATH_LITERAL("/var/cache/display_profiles"); |
jennyz | 26b7f43 | 2015-09-03 20:59:27 | [diff] [blame] | 52 | |
glevin | 5dd01a7 | 2016-03-23 23:08:12 | [diff] [blame] | 53 | const base::FilePath::CharType kDeviceExtensionLocalCache[] = |
| 54 | FILE_PATH_LITERAL("/var/cache/external_cache"); |
| 55 | |
emaxx | ebe5cbc | 2016-11-10 03:39:30 | [diff] [blame] | 56 | const base::FilePath::CharType kSigninProfileComponentPolicy[] = |
| 57 | FILE_PATH_LITERAL("/var/cache/signin_profile_component_policy"); |
| 58 | |
[email protected] | e1ae9fa | 2013-04-23 18:08:33 | [diff] [blame] | 59 | bool 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; |
tnagel | 53a23380 | 2014-12-17 20:28:50 | [diff] [blame] | 73 | case FILE_MACHINE_INFO: |
| 74 | *result = base::FilePath(kMachineHardwareInfoFileName); |
| 75 | break; |
[email protected] | e1ae9fa | 2013-04-23 18:08:33 | [diff] [blame] | 76 | 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] | 888a25f | 2013-11-05 19:30:51 | [diff] [blame] | 82 | 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] | af98488 | 2013-10-21 21:08:51 | [diff] [blame] | 87 | break; |
[email protected] | 68a31b1 | 2014-06-20 17:12:21 | [diff] [blame] | 88 | case DIR_DEVICE_LOCAL_ACCOUNT_COMPONENT_POLICY: |
| 89 | *result = base::FilePath(kDeviceLocalAccountComponentPolicy); |
| 90 | break; |
glevin | 5dd01a7 | 2016-03-23 23:08:12 | [diff] [blame] | 91 | case DIR_DEVICE_DISPLAY_PROFILES: |
| 92 | *result = base::FilePath(kDeviceDisplayProfileDirectory); |
| 93 | break; |
jennyz | 26b7f43 | 2015-09-03 20:59:27 | [diff] [blame] | 94 | case DIR_DEVICE_EXTENSION_LOCAL_CACHE: |
| 95 | *result = base::FilePath(kDeviceExtensionLocalCache); |
| 96 | break; |
emaxx | ebe5cbc | 2016-11-10 03:39:30 | [diff] [blame] | 97 | case DIR_SIGNIN_PROFILE_COMPONENT_POLICY: |
| 98 | *result = base::FilePath(kSigninProfileComponentPolicy); |
| 99 | break; |
[email protected] | e1ae9fa | 2013-04-23 18:08:33 | [diff] [blame] | 100 | default: |
| 101 | return false; |
| 102 | } |
| 103 | return true; |
| 104 | } |
| 105 | |
| 106 | } // namespace |
| 107 | |
| 108 | void RegisterPathProvider() { |
| 109 | PathService::RegisterProvider(PathProvider, PATH_START, PATH_END); |
| 110 | } |
| 111 | |
[email protected] | ff9ed9f | 2014-05-02 17:59:42 | [diff] [blame] | 112 | void 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); |
tnagel | 53a23380 | 2014-12-17 20:28:50 | [diff] [blame] | 132 | PathService::OverrideAndCreateIfNeeded( |
| 133 | FILE_MACHINE_INFO, |
| 134 | parent.AppendASCII("stub_machine-info"), |
| 135 | is_absolute, |
| 136 | create); |
[email protected] | 68a31b1 | 2014-06-20 17:12:21 | [diff] [blame] | 137 | 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")); |
jennyz | 26b7f43 | 2015-09-03 20:59:27 | [diff] [blame] | 146 | PathService::Override( |
| 147 | DIR_DEVICE_EXTENSION_LOCAL_CACHE, |
| 148 | parent.AppendASCII("stub_device_local_extension_cache")); |
emaxx | ebe5cbc | 2016-11-10 03:39:30 | [diff] [blame] | 149 | PathService::Override( |
| 150 | DIR_SIGNIN_PROFILE_COMPONENT_POLICY, |
| 151 | parent.AppendASCII("stub_signin_profile_component_policy")); |
[email protected] | ff9ed9f | 2014-05-02 17:59:42 | [diff] [blame] | 152 | } |
| 153 | |
[email protected] | e1ae9fa | 2013-04-23 18:08:33 | [diff] [blame] | 154 | } // namespace chromeos |