blob: fefe1ed2c8a02ab1289976d01d8d0bfd0d1cc901 [file] [log] [blame]
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/policy/browser_state_policy_connector.h"
#import "components/policy/core/common/policy_service_impl.h"
#import "components/policy/core/common/schema_registry.h"
#import "ios/chrome/browser/policy/browser_policy_connector_ios.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
BrowserStatePolicyConnector::BrowserStatePolicyConnector() = default;
BrowserStatePolicyConnector::~BrowserStatePolicyConnector() = default;
void BrowserStatePolicyConnector::Init(
policy::SchemaRegistry* schema_registry,
BrowserPolicyConnectorIOS* browser_policy_connector,
policy::ConfigurationPolicyProvider* user_policy_provider) {
schema_registry_ = schema_registry;
// The object returned by GetPlatformConnector() may or may not be in the list
// returned by GetPolicyProviders(). Explicitly add it to `policy_providers_`
// here in case it will not be added by the loop below (for example, this
// could happen if the platform provider is overridden for testing)..
policy::ConfigurationPolicyProvider* platform_provider =
browser_policy_connector->GetPlatformProvider();
policy_providers_.push_back(platform_provider);
for (auto* provider : browser_policy_connector->GetPolicyProviders()) {
// Skip the platform provider since it was already handled above. Do not
// reorder any of the remaining providers because the ordering in this list
// determines the precedence of the providers.
if (provider != platform_provider) {
policy_providers_.push_back(provider);
}
}
// Put `user_policy_provider` at the end of the list because it is the
// provider with the lowest priority.
if (user_policy_provider)
policy_providers_.push_back(user_policy_provider);
policy_service_ =
std::make_unique<policy::PolicyServiceImpl>(policy_providers_);
}
void BrowserStatePolicyConnector::Shutdown() {}