This source file includes following definitions.
- state_
- Init
- IsInitializationComplete
- RefreshPolicies
- OnSchemaRegistryReady
- OnSchemaRegistryUpdated
- OnUpdatePolicy
#include "components/policy/core/common/forwarding_policy_provider.h"
#include "components/policy/core/common/schema_map.h"
#include "components/policy/core/common/schema_registry.h"
namespace policy {
ForwardingPolicyProvider::ForwardingPolicyProvider(
ConfigurationPolicyProvider* delegate)
: delegate_(delegate), state_(WAITING_FOR_REGISTRY_READY) {
delegate_->AddObserver(this);
OnUpdatePolicy(delegate_);
}
ForwardingPolicyProvider::~ForwardingPolicyProvider() {
delegate_->RemoveObserver(this);
}
void ForwardingPolicyProvider::Init(SchemaRegistry* registry) {
ConfigurationPolicyProvider::Init(registry);
if (registry->IsReady())
OnSchemaRegistryReady();
}
bool ForwardingPolicyProvider::IsInitializationComplete(PolicyDomain domain)
const {
if (domain == POLICY_DOMAIN_CHROME)
return delegate_->IsInitializationComplete(domain);
return state_ == READY;
}
void ForwardingPolicyProvider::RefreshPolicies() {
delegate_->RefreshPolicies();
}
void ForwardingPolicyProvider::OnSchemaRegistryReady() {
DCHECK_EQ(WAITING_FOR_REGISTRY_READY, state_);
if (!schema_map()->HasComponents()) {
state_ = READY;
OnUpdatePolicy(delegate_);
return;
}
state_ = WAITING_FOR_REFRESH;
RefreshPolicies();
}
void ForwardingPolicyProvider::OnSchemaRegistryUpdated(bool has_new_schemas) {
if (state_ != READY)
return;
if (has_new_schemas) {
RefreshPolicies();
} else {
OnUpdatePolicy(delegate_);
}
}
void ForwardingPolicyProvider::OnUpdatePolicy(
ConfigurationPolicyProvider* provider) {
DCHECK_EQ(delegate_, provider);
if (state_ == WAITING_FOR_REFRESH)
state_ = READY;
scoped_ptr<PolicyBundle> bundle(new PolicyBundle());
if (state_ == READY) {
bundle->CopyFrom(delegate_->policies());
schema_map()->FilterBundle(bundle.get());
} else {
const PolicyNamespace chrome_ns(POLICY_DOMAIN_CHROME, "");
bundle->Get(chrome_ns).CopyFrom(delegate_->policies().Get(chrome_ns));
}
UpdatePolicy(bundle.Pass());
}
}