[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 | |
[email protected] | e1ae9fa | 2013-04-23 18:08:33 | [diff] [blame] | 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[] = |
| 24 | FILE_PATH_LITERAL("/var/run/user_policy"); |
| 25 | |
| 26 | const base::FilePath::CharType kOwnerKeyFileName[] = |
| 27 | FILE_PATH_LITERAL("/var/lib/whitelist/owner.key"); |
| 28 | |
| 29 | const base::FilePath::CharType kInstallAttributesFileName[] = |
| 30 | FILE_PATH_LITERAL("/var/run/lockbox/install_attributes.pb"); |
| 31 | |
| 32 | const base::FilePath::CharType kUptimeFileName[] = |
| 33 | FILE_PATH_LITERAL("/proc/uptime"); |
| 34 | |
| 35 | const base::FilePath::CharType kUpdateRebootNeededUptimeFile[] = |
| 36 | FILE_PATH_LITERAL("/var/run/chrome/update_reboot_needed_uptime"); |
| 37 | |
[email protected] | 888a25f | 2013-11-05 19:30:51 | [diff] [blame] | 38 | const base::FilePath::CharType kDeviceLocalAccountExtensionDir[] = |
[email protected] | af98488 | 2013-10-21 21:08:51 | [diff] [blame] | 39 | FILE_PATH_LITERAL("/var/cache/device_local_account_extensions"); |
| 40 | |
[email protected] | 888a25f | 2013-11-05 19:30:51 | [diff] [blame] | 41 | const base::FilePath::CharType kDeviceLocalAccountExternalDataDir[] = |
| 42 | FILE_PATH_LITERAL("/var/cache/device_local_account_external_policy_data"); |
| 43 | |
[email protected] | 68a31b1 | 2014-06-20 17:12:21 | [diff] [blame] | 44 | const base::FilePath::CharType kDeviceLocalAccountComponentPolicy[] = |
| 45 | FILE_PATH_LITERAL("/var/cache/device_local_account_component_policy"); |
| 46 | |
[email protected] | e1ae9fa | 2013-04-23 18:08:33 | [diff] [blame] | 47 | bool PathProvider(int key, base::FilePath* result) { |
| 48 | switch (key) { |
| 49 | case FILE_DEFAULT_APP_ORDER: |
| 50 | *result = base::FilePath(kDefaultAppOrderFileName); |
| 51 | break; |
| 52 | case DIR_USER_POLICY_KEYS: |
| 53 | *result = base::FilePath(kDefaultUserPolicyKeysDir); |
| 54 | break; |
| 55 | case FILE_OWNER_KEY: |
| 56 | *result = base::FilePath(kOwnerKeyFileName); |
| 57 | break; |
| 58 | case FILE_INSTALL_ATTRIBUTES: |
| 59 | *result = base::FilePath(kInstallAttributesFileName); |
| 60 | break; |
| 61 | case FILE_UPTIME: |
| 62 | *result = base::FilePath(kUptimeFileName); |
| 63 | break; |
| 64 | case FILE_UPDATE_REBOOT_NEEDED_UPTIME: |
| 65 | *result = base::FilePath(kUpdateRebootNeededUptimeFile); |
| 66 | break; |
[email protected] | 888a25f | 2013-11-05 19:30:51 | [diff] [blame] | 67 | case DIR_DEVICE_LOCAL_ACCOUNT_EXTENSIONS: |
| 68 | *result = base::FilePath(kDeviceLocalAccountExtensionDir); |
| 69 | break; |
| 70 | case DIR_DEVICE_LOCAL_ACCOUNT_EXTERNAL_DATA: |
| 71 | *result = base::FilePath(kDeviceLocalAccountExternalDataDir); |
[email protected] | af98488 | 2013-10-21 21:08:51 | [diff] [blame] | 72 | break; |
[email protected] | 68a31b1 | 2014-06-20 17:12:21 | [diff] [blame] | 73 | case DIR_DEVICE_LOCAL_ACCOUNT_COMPONENT_POLICY: |
| 74 | *result = base::FilePath(kDeviceLocalAccountComponentPolicy); |
| 75 | break; |
[email protected] | e1ae9fa | 2013-04-23 18:08:33 | [diff] [blame] | 76 | default: |
| 77 | return false; |
| 78 | } |
| 79 | return true; |
| 80 | } |
| 81 | |
| 82 | } // namespace |
| 83 | |
| 84 | void RegisterPathProvider() { |
| 85 | PathService::RegisterProvider(PathProvider, PATH_START, PATH_END); |
| 86 | } |
| 87 | |
[email protected] | ff9ed9f | 2014-05-02 17:59:42 | [diff] [blame] | 88 | void RegisterStubPathOverrides(const base::FilePath& stubs_dir) { |
| 89 | CHECK(!base::SysInfo::IsRunningOnChromeOS()); |
| 90 | // Override these paths on the desktop, so that enrollment and cloud |
| 91 | // policy work and can be tested. |
| 92 | base::FilePath parent = base::MakeAbsoluteFilePath(stubs_dir); |
| 93 | PathService::Override( |
| 94 | DIR_USER_POLICY_KEYS, |
| 95 | parent.AppendASCII("stub_user_policy")); |
| 96 | const bool is_absolute = true; |
| 97 | const bool create = false; |
| 98 | PathService::OverrideAndCreateIfNeeded( |
| 99 | FILE_OWNER_KEY, |
| 100 | parent.AppendASCII("stub_owner.key"), |
| 101 | is_absolute, |
| 102 | create); |
| 103 | PathService::OverrideAndCreateIfNeeded( |
| 104 | FILE_INSTALL_ATTRIBUTES, |
| 105 | parent.AppendASCII("stub_install_attributes.pb"), |
| 106 | is_absolute, |
| 107 | create); |
[email protected] | 68a31b1 | 2014-06-20 17:12:21 | [diff] [blame] | 108 | PathService::Override( |
| 109 | DIR_DEVICE_LOCAL_ACCOUNT_EXTENSIONS, |
| 110 | parent.AppendASCII("stub_device_local_account_extensions")); |
| 111 | PathService::Override( |
| 112 | DIR_DEVICE_LOCAL_ACCOUNT_EXTERNAL_DATA, |
| 113 | parent.AppendASCII("stub_device_local_account_external_data")); |
| 114 | PathService::Override( |
| 115 | DIR_DEVICE_LOCAL_ACCOUNT_COMPONENT_POLICY, |
| 116 | parent.AppendASCII("stub_device_local_account_component_policy")); |
[email protected] | ff9ed9f | 2014-05-02 17:59:42 | [diff] [blame] | 117 | } |
| 118 | |
[email protected] | e1ae9fa | 2013-04-23 18:08:33 | [diff] [blame] | 119 | } // namespace chromeos |