OLD | NEW |
(Empty) | |
| 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 "chrome/browser/policy/forwarding_policy_provider.h" |
| 6 |
| 7 #include "chrome/browser/policy/schema_map.h" |
| 8 #include "chrome/browser/policy/schema_registry.h" |
| 9 |
| 10 namespace policy { |
| 11 |
| 12 ForwardingPolicyProvider::ForwardingPolicyProvider( |
| 13 ConfigurationPolicyProvider* delegate) |
| 14 : delegate_(delegate), state_(WAITING_FOR_REGISTRY_READY) { |
| 15 delegate_->AddObserver(this); |
| 16 // Serve the initial |delegate_| policies. |
| 17 OnUpdatePolicy(delegate_); |
| 18 } |
| 19 |
| 20 ForwardingPolicyProvider::~ForwardingPolicyProvider() { |
| 21 delegate_->RemoveObserver(this); |
| 22 } |
| 23 |
| 24 void ForwardingPolicyProvider::Init(SchemaRegistry* registry) { |
| 25 ConfigurationPolicyProvider::Init(registry); |
| 26 if (registry->IsReady()) |
| 27 OnSchemaRegistryReady(); |
| 28 } |
| 29 |
| 30 bool ForwardingPolicyProvider::IsInitializationComplete(PolicyDomain domain) |
| 31 const { |
| 32 if (domain == POLICY_DOMAIN_CHROME) |
| 33 return delegate_->IsInitializationComplete(domain); |
| 34 // This provider keeps its own state for all the other domains. |
| 35 return state_ == READY; |
| 36 } |
| 37 |
| 38 void ForwardingPolicyProvider::RefreshPolicies() { |
| 39 delegate_->RefreshPolicies(); |
| 40 } |
| 41 |
| 42 void ForwardingPolicyProvider::OnSchemaRegistryReady() { |
| 43 DCHECK_EQ(WAITING_FOR_REGISTRY_READY, state_); |
| 44 // This provider's registry is ready, meaning that it has all the initial |
| 45 // components schemas; the delegate's registry should also see them now, |
| 46 // since it's tracking the former. |
| 47 // Asking the delegate to RefreshPolicies now means that the next |
| 48 // OnUpdatePolicy from the delegate will have the initial policy for |
| 49 // components. |
| 50 if (!schema_map()->HasComponents()) { |
| 51 // If there are no component registered for this provider then there's no |
| 52 // need to reload. |
| 53 state_ = READY; |
| 54 OnUpdatePolicy(delegate_); |
| 55 return; |
| 56 } |
| 57 |
| 58 state_ = WAITING_FOR_REFRESH; |
| 59 RefreshPolicies(); |
| 60 } |
| 61 |
| 62 void ForwardingPolicyProvider::OnSchemaRegistryUpdated(bool has_new_schemas) { |
| 63 if (!has_new_schemas || state_ != READY) |
| 64 return; |
| 65 RefreshPolicies(); |
| 66 } |
| 67 |
| 68 void ForwardingPolicyProvider::OnUpdatePolicy( |
| 69 ConfigurationPolicyProvider* provider) { |
| 70 DCHECK_EQ(delegate_, provider); |
| 71 |
| 72 if (state_ == WAITING_FOR_REFRESH) |
| 73 state_ = READY; |
| 74 |
| 75 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); |
| 76 if (state_ == READY) { |
| 77 bundle->CopyFrom(delegate_->policies()); |
| 78 schema_map()->FilterBundle(bundle.get()); |
| 79 } else { |
| 80 // Always forward the Chrome policy, even if the components are not ready |
| 81 // yet. |
| 82 const PolicyNamespace chrome_ns(POLICY_DOMAIN_CHROME, ""); |
| 83 bundle->Get(chrome_ns).CopyFrom(delegate_->policies().Get(chrome_ns)); |
| 84 } |
| 85 |
| 86 UpdatePolicy(bundle.Pass()); |
| 87 } |
| 88 |
| 89 } // namespace policy |
OLD | NEW |