Commit cf4b83a3 authored by Maksim Ivanov's avatar Maksim Ivanov Committed by Commit Bot

Use base::PathService::CheckedGet in /policy/

Refactor the code of form "CHECK(base::PathService::Get(...))" with the
alias function base::PathService::CheckedGet().

This is a pure refactoring CL - no change of functionality is expected.

Bug: none
Change-Id: Ia4a04a51fd6f3c7ec4fca0a9bf5cb27224dfc5f0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2288631
Commit-Queue: Maksim Ivanov <emaxx@chromium.org>
Reviewed-by: default avatarAlexander Hendrich <hendrich@chromium.org>
Auto-Submit: Maksim Ivanov <emaxx@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790810}
parent 732bd007
......@@ -146,9 +146,9 @@ BrowserPolicyConnectorChromeOS::BrowserPolicyConnectorChromeOS() {
state_keys_broker_ = std::make_unique<ServerBackedStateKeysBroker>(
chromeos::SessionManagerClient::Get());
base::FilePath device_policy_external_data_path;
CHECK(base::PathService::Get(chromeos::DIR_DEVICE_POLICY_EXTERNAL_DATA,
&device_policy_external_data_path));
const base::FilePath device_policy_external_data_path =
base::PathService::CheckedGet(
chromeos::DIR_DEVICE_POLICY_EXTERNAL_DATA);
auto external_data_manager =
std::make_unique<DevicePolicyCloudExternalDataManager>(
......
......@@ -175,9 +175,9 @@ void DeviceCloudPolicyManagerChromeOS::StartConnection(
// Create the component cloud policy service for fetching, caching and
// exposing policy for extensions.
if (!component_policy_disabled_for_testing_) {
base::FilePath component_policy_cache_dir;
CHECK(base::PathService::Get(chromeos::DIR_SIGNIN_PROFILE_COMPONENT_POLICY,
&component_policy_cache_dir));
const base::FilePath component_policy_cache_dir =
base::PathService::CheckedGet(
chromeos::DIR_SIGNIN_PROFILE_COMPONENT_POLICY);
CHECK(signin_profile_forwarding_schema_registry_);
CreateComponentCloudPolicyService(
dm_protocol::kChromeSigninExtensionPolicyType,
......
......@@ -25,9 +25,8 @@ DeviceLocalAccountExternalDataService::DeviceLocalAccountExternalDataService(
DeviceLocalAccountPolicyService* parent,
scoped_refptr<base::SequencedTaskRunner> backend_task_runner)
: parent_(parent), backend_task_runner_(std::move(backend_task_runner)) {
base::FilePath cache_dir;
CHECK(base::PathService::Get(chromeos::DIR_DEVICE_LOCAL_ACCOUNT_EXTERNAL_DATA,
&cache_dir));
const base::FilePath cache_dir = base::PathService::CheckedGet(
chromeos::DIR_DEVICE_LOCAL_ACCOUNT_EXTERNAL_DATA);
resource_cache_.reset(new ResourceCache(cache_dir, backend_task_runner_,
/* max_cache_size */ base::nullopt));
parent_->AddObserver(this);
......
......@@ -116,11 +116,10 @@ void DeleteOrphanedCaches(
// directory. No cache belonging to |account_id_to_delete| may be running while
// the removal is in progress.
void DeleteObsoleteExtensionCache(const std::string& account_id_to_delete) {
base::FilePath cache_root_dir;
CHECK(base::PathService::Get(chromeos::DIR_DEVICE_LOCAL_ACCOUNT_EXTENSIONS,
&cache_root_dir));
const base::FilePath path = cache_root_dir.Append(
GetCacheSubdirectoryForAccountID(account_id_to_delete));
const base::FilePath path =
base::PathService::CheckedGet(
chromeos::DIR_DEVICE_LOCAL_ACCOUNT_EXTENSIONS)
.Append(GetCacheSubdirectoryForAccountID(account_id_to_delete));
if (base::DirectoryExists(path))
base::DeletePathRecursively(path);
}
......@@ -154,13 +153,11 @@ DeviceLocalAccountPolicyBroker::DeviceLocalAccountPolicyBroker(
extension_tracker_.reset(new DeviceLocalAccountExtensionTracker(
account, store_.get(), &schema_registry_));
}
base::FilePath cache_root_dir;
CHECK(base::PathService::Get(chromeos::DIR_DEVICE_LOCAL_ACCOUNT_EXTENSIONS,
&cache_root_dir));
extension_loader_ = new chromeos::DeviceLocalAccountExternalPolicyLoader(
store_.get(),
cache_root_dir.Append(
GetCacheSubdirectoryForAccountID(account.account_id)));
base::PathService::CheckedGet(
chromeos::DIR_DEVICE_LOCAL_ACCOUNT_EXTENSIONS)
.Append(GetCacheSubdirectoryForAccountID(account.account_id)));
store_->AddObserver(this);
// Unblock the |schema_registry_| so that the |component_policy_service_|
......@@ -287,10 +284,9 @@ DeviceLocalAccountPolicyService::DeviceLocalAccountPolicyService(
chromeos::kAccountsPrefDeviceLocalAccounts,
base::Bind(
&DeviceLocalAccountPolicyService::UpdateAccountListIfNonePending,
base::Unretained(this)))) {
CHECK(base::PathService::Get(
chromeos::DIR_DEVICE_LOCAL_ACCOUNT_COMPONENT_POLICY,
&component_policy_cache_root_));
base::Unretained(this)))),
component_policy_cache_root_(base::PathService::CheckedGet(
chromeos::DIR_DEVICE_LOCAL_ACCOUNT_COMPONENT_POLICY)) {
external_data_service_ =
std::make_unique<DeviceLocalAccountExternalDataService>(
this, std::move(external_data_service_backend_task_runner));
......@@ -512,9 +508,8 @@ void DeviceLocalAccountPolicyService::UpdateAccountList() {
// cache directory.
orphan_extension_cache_deletion_state_ = IN_PROGRESS;
base::FilePath cache_root_dir;
CHECK(base::PathService::Get(chromeos::DIR_DEVICE_LOCAL_ACCOUNT_EXTENSIONS,
&cache_root_dir));
const base::FilePath cache_root_dir = base::PathService::CheckedGet(
chromeos::DIR_DEVICE_LOCAL_ACCOUNT_EXTENSIONS);
extension_cache_task_runner_->PostTaskAndReply(
FROM_HERE,
base::BindOnce(&DeleteOrphanedCaches, cache_root_dir,
......
......@@ -276,7 +276,7 @@ class DeviceLocalAccountPolicyService {
// Path to the directory that contains the cached policy for components
// for device-local accounts.
base::FilePath component_policy_cache_root_;
const base::FilePath component_policy_cache_root_;
base::WeakPtrFactory<DeviceLocalAccountPolicyService> weak_factory_{this};
......
......@@ -114,9 +114,9 @@ class DevicePolicyCloudExternalDataManagerTest
}
int64_t ComputeExternalDataCacheDirectorySize() {
base::FilePath device_policy_external_data_path;
CHECK(base::PathService::Get(chromeos::DIR_DEVICE_POLICY_EXTERNAL_DATA,
&device_policy_external_data_path));
const base::FilePath device_policy_external_data_path =
base::PathService::CheckedGet(
chromeos::DIR_DEVICE_POLICY_EXTERNAL_DATA);
base::ScopedAllowBlockingForTesting allow_blocking;
return base::ComputeDirectorySize(device_policy_external_data_path);
}
......
......@@ -110,9 +110,8 @@ void PreSigninPolicyFetcher::OnCachedPolicyRetrieved(
// not joined to Active Directory (policy blobs from Active Directory servers
// are not signed).
if (!policy_blob.empty() && !is_active_directory_managed_) {
base::FilePath policy_key_dir;
CHECK(base::PathService::Get(chromeos::dbus_paths::DIR_USER_POLICY_KEYS,
&policy_key_dir));
const base::FilePath policy_key_dir = base::PathService::CheckedGet(
chromeos::dbus_paths::DIR_USER_POLICY_KEYS);
cached_policy_key_loader_ = std::make_unique<CachedPolicyKeyLoaderChromeOS>(
cryptohome_client_, task_runner_, account_id_, policy_key_dir);
cached_policy_key_loader_->EnsurePolicyKeyLoaded(base::BindOnce(
......
......@@ -200,19 +200,14 @@ class SigninProfileExtensionsPolicyTest
DISALLOW_COPY_AND_ASSIGN(SigninProfileExtensionsPolicyTest);
};
base::FilePath GetTestDataDir() {
base::FilePath test_data_dir;
EXPECT_TRUE(base::PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir));
return test_data_dir;
}
} // namespace
// Tests that a whitelisted app gets installed.
IN_PROC_BROWSER_TEST_F(SigninProfileExtensionsPolicyTest,
WhitelistedAppInstallation) {
EXPECT_TRUE(extension_force_install_mixin_.ForceInstallFromCrx(
GetTestDataDir().AppendASCII(kWhitelistedAppCrxPath),
base::PathService::CheckedGet(chrome::DIR_TEST_DATA)
.AppendASCII(kWhitelistedAppCrxPath),
ExtensionForceInstallMixin::WaitMode::kLoad));
const extensions::Extension* extension =
extension_force_install_mixin_.GetEnabledExtension(kWhitelistedAppId);
......@@ -228,8 +223,10 @@ IN_PROC_BROWSER_TEST_F(SigninProfileExtensionsPolicyTest,
ExtensionInstallErrorObserver install_error_observer(profile,
kNotWhitelistedAppId);
EXPECT_TRUE(extension_force_install_mixin_.ForceInstallFromSourceDir(
GetTestDataDir().AppendASCII(kNotWhitelistedAppPath),
GetTestDataDir().AppendASCII(kNotWhitelistedAppPemPath),
base::PathService::CheckedGet(chrome::DIR_TEST_DATA)
.AppendASCII(kNotWhitelistedAppPath),
base::PathService::CheckedGet(chrome::DIR_TEST_DATA)
.AppendASCII(kNotWhitelistedAppPemPath),
ExtensionForceInstallMixin::WaitMode::kNone));
install_error_observer.Wait();
EXPECT_FALSE(extension_force_install_mixin_.GetInstalledExtension(
......@@ -242,7 +239,8 @@ IN_PROC_BROWSER_TEST_F(SigninProfileExtensionsPolicyTest,
IN_PROC_BROWSER_TEST_F(SigninProfileExtensionsPolicyTest,
WhitelistedExtensionInstallation) {
EXPECT_TRUE(extension_force_install_mixin_.ForceInstallFromCrx(
GetTestDataDir().AppendASCII(kWhitelistedExtensionCrxPath),
base::PathService::CheckedGet(chrome::DIR_TEST_DATA)
.AppendASCII(kWhitelistedExtensionCrxPath),
ExtensionForceInstallMixin::WaitMode::kLoad));
const extensions::Extension* extension =
......@@ -260,8 +258,10 @@ IN_PROC_BROWSER_TEST_F(SigninProfileExtensionsPolicyTest,
ExtensionInstallErrorObserver install_error_observer(
profile, kNotWhitelistedExtensionId);
EXPECT_TRUE(extension_force_install_mixin_.ForceInstallFromSourceDir(
GetTestDataDir().AppendASCII(kNotWhitelistedExtensionPath),
GetTestDataDir().AppendASCII(kNotWhitelistedExtensionPemPath),
base::PathService::CheckedGet(chrome::DIR_TEST_DATA)
.AppendASCII(kNotWhitelistedExtensionPath),
base::PathService::CheckedGet(chrome::DIR_TEST_DATA)
.AppendASCII(kNotWhitelistedExtensionPemPath),
ExtensionForceInstallMixin::WaitMode::kNone));
install_error_observer.Wait();
EXPECT_FALSE(extension_force_install_mixin_.GetInstalledExtension(
......@@ -282,7 +282,8 @@ IN_PROC_BROWSER_TEST_F(SigninProfileExtensionsPolicyTest, BackgroundPage) {
EXPECT_FALSE(
chromeos::ProfileHelper::SigninProfileHasLoginScreenExtensions());
EXPECT_TRUE(extension_force_install_mixin_.ForceInstallFromCrx(
GetTestDataDir().AppendASCII(kWhitelistedAppCrxPath),
base::PathService::CheckedGet(chrome::DIR_TEST_DATA)
.AppendASCII(kWhitelistedAppCrxPath),
ExtensionForceInstallMixin::WaitMode::kBackgroundPageReady));
EXPECT_TRUE(extension_force_install_mixin_.IsExtensionBackgroundPageReady(
kWhitelistedAppId));
......@@ -293,10 +294,12 @@ IN_PROC_BROWSER_TEST_F(SigninProfileExtensionsPolicyTest, BackgroundPage) {
IN_PROC_BROWSER_TEST_F(SigninProfileExtensionsPolicyTest,
MultipleAppsOrExtensions) {
EXPECT_TRUE(extension_force_install_mixin_.ForceInstallFromCrx(
GetTestDataDir().AppendASCII(kWhitelistedAppCrxPath),
base::PathService::CheckedGet(chrome::DIR_TEST_DATA)
.AppendASCII(kWhitelistedAppCrxPath),
ExtensionForceInstallMixin::WaitMode::kLoad));
EXPECT_TRUE(extension_force_install_mixin_.ForceInstallFromCrx(
GetTestDataDir().AppendASCII(kWhitelistedExtensionCrxPath),
base::PathService::CheckedGet(chrome::DIR_TEST_DATA)
.AppendASCII(kWhitelistedExtensionCrxPath),
ExtensionForceInstallMixin::WaitMode::kLoad));
EXPECT_TRUE(
......@@ -312,10 +315,12 @@ IN_PROC_BROWSER_TEST_F(SigninProfileExtensionsPolicyTest,
Profile* profile = GetInitialProfile();
EXPECT_TRUE(extension_force_install_mixin_.ForceInstallFromCrx(
GetTestDataDir().AppendASCII(kWhitelistedAppCrxPath),
base::PathService::CheckedGet(chrome::DIR_TEST_DATA)
.AppendASCII(kWhitelistedAppCrxPath),
ExtensionForceInstallMixin::WaitMode::kBackgroundPageReady));
EXPECT_TRUE(extension_force_install_mixin_.ForceInstallFromCrx(
GetTestDataDir().AppendASCII(kWhitelistedExtensionCrxPath),
base::PathService::CheckedGet(chrome::DIR_TEST_DATA)
.AppendASCII(kWhitelistedExtensionCrxPath),
ExtensionForceInstallMixin::WaitMode::kBackgroundPageReady));
content::StoragePartition* storage_partition_for_app =
......@@ -350,7 +355,8 @@ class SigninProfileExtensionsPolicyOfflineLaunchTest
kWhitelistedAppId);
EXPECT_TRUE(extension_force_install_mixin_.ForceInstallFromCrx(
GetTestDataDir().AppendASCII(kWhitelistedAppCrxPath),
base::PathService::CheckedGet(chrome::DIR_TEST_DATA)
.AppendASCII(kWhitelistedAppCrxPath),
ExtensionForceInstallMixin::WaitMode::kNone));
// In the non-PRE test, this simulates inability to make network requests
......
......@@ -265,9 +265,8 @@ void CreateConfigurationPolicyProvider(
profile_dir.Append(kPolicy).Append(kComponentsDir);
const base::FilePath external_data_dir =
profile_dir.Append(kPolicy).Append(kPolicyExternalDataDir);
base::FilePath policy_key_dir;
CHECK(base::PathService::Get(chromeos::dbus_paths::DIR_USER_POLICY_KEYS,
&policy_key_dir));
const base::FilePath policy_key_dir =
base::PathService::CheckedGet(chromeos::dbus_paths::DIR_USER_POLICY_KEYS);
std::unique_ptr<UserCloudPolicyStoreChromeOS> store =
std::make_unique<UserCloudPolicyStoreChromeOS>(
......
......@@ -91,9 +91,8 @@ LocalPolicyTestServer::LocalPolicyTestServer(
: net::LocalTestServer(net::BaseTestServer::TYPE_HTTP, base::FilePath()) {
// Read configuration from a file under |source_root|.
base::ScopedAllowBlockingForTesting allow_blocking;
base::FilePath source_root;
CHECK(base::PathService::Get(base::DIR_SOURCE_ROOT, &source_root));
config_file_ = source_root.AppendASCII(source_root_relative_config_file);
config_file_ = base::PathService::CheckedGet(base::DIR_SOURCE_ROOT)
.AppendASCII(source_root_relative_config_file);
}
LocalPolicyTestServer::~LocalPolicyTestServer() {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment