Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/policy/core/common/configuration_policy_provider.h" | 5 #include "components/policy/core/common/configuration_policy_provider.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "components/policy/core/common/external_data_fetcher.h" | 8 #include "components/policy/core/common/external_data_fetcher.h" |
| 9 #include "components/policy/core/common/policy_map.h" | 9 #include "components/policy/core/common/policy_map.h" |
| 10 | 10 |
| 11 namespace policy { | 11 namespace policy { |
| 12 | 12 |
| 13 ConfigurationPolicyProvider::Observer::~Observer() {} | 13 ConfigurationPolicyProvider::Observer::~Observer() {} |
| 14 | 14 |
| 15 ConfigurationPolicyProvider::ConfigurationPolicyProvider() | 15 ConfigurationPolicyProvider::ConfigurationPolicyProvider() |
| 16 : initialized_(false), | 16 : source_(POLICY_SOURCE_UNKNOWN), |
| 17 initialized_(false), | |
| 17 schema_registry_(NULL) {} | 18 schema_registry_(NULL) {} |
| 18 | 19 |
| 19 ConfigurationPolicyProvider::~ConfigurationPolicyProvider() { | 20 ConfigurationPolicyProvider::~ConfigurationPolicyProvider() { |
| 20 DCHECK(!initialized_); | 21 DCHECK(!initialized_); |
| 21 } | 22 } |
| 22 | 23 |
| 23 void ConfigurationPolicyProvider::Init(SchemaRegistry* registry) { | 24 void ConfigurationPolicyProvider::Init(SchemaRegistry* registry) { |
| 24 schema_registry_ = registry; | 25 schema_registry_ = registry; |
| 25 schema_registry_->AddObserver(this); | 26 schema_registry_->AddObserver(this); |
| 26 initialized_ = true; | 27 initialized_ = true; |
| 27 } | 28 } |
| 28 | 29 |
| 29 void ConfigurationPolicyProvider::Shutdown() { | 30 void ConfigurationPolicyProvider::Shutdown() { |
| 30 initialized_ = false; | 31 initialized_ = false; |
| 31 if (schema_registry_) { | 32 if (schema_registry_) { |
| 32 // Unit tests don't initialize the BrowserPolicyConnector but call | 33 // Unit tests don't initialize the BrowserPolicyConnector but call |
| 33 // shutdown; handle that. | 34 // shutdown; handle that. |
| 34 schema_registry_->RemoveObserver(this); | 35 schema_registry_->RemoveObserver(this); |
| 35 schema_registry_ = NULL; | 36 schema_registry_ = NULL; |
| 36 } | 37 } |
| 37 } | 38 } |
| 38 | 39 |
| 39 bool ConfigurationPolicyProvider::IsInitializationComplete( | 40 bool ConfigurationPolicyProvider::IsInitializationComplete( |
| 40 PolicyDomain domain) const { | 41 PolicyDomain domain) const { |
| 41 return true; | 42 return true; |
| 42 } | 43 } |
| 43 | 44 |
| 44 void ConfigurationPolicyProvider::UpdatePolicy( | 45 void ConfigurationPolicyProvider::UpdatePolicy( |
| 45 scoped_ptr<PolicyBundle> bundle) { | 46 scoped_ptr<PolicyBundle> bundle) { |
| 46 if (bundle.get()) | 47 if (bundle.get()) { |
| 47 policy_bundle_.Swap(bundle.get()); | 48 policy_bundle_.Swap(bundle.get()); |
| 48 else | 49 SetPolicySources(); |
| 50 } else { | |
| 49 policy_bundle_.Clear(); | 51 policy_bundle_.Clear(); |
| 52 } | |
| 50 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer, | 53 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer, |
| 51 observer_list_, | 54 observer_list_, |
| 52 OnUpdatePolicy(this)); | 55 OnUpdatePolicy(this)); |
| 53 } | 56 } |
| 54 | 57 |
| 58 void ConfigurationPolicyProvider::SetPolicySources() { | |
| 59 for (PolicyBundle::iterator it = policy_bundle_.begin(); | |
|
Thiemo Nagel
2015/09/04 20:15:53
I'd suggest a range-based loop to improve readabil
fhorschig
2015/09/07 14:09:34
Wow, it works !? Awesome! Done.
| |
| 60 it != policy_bundle_.end(); ++it) { | |
| 61 it->second->SetEntrySources(source_); | |
| 62 } | |
| 63 } | |
| 64 | |
| 55 SchemaRegistry* ConfigurationPolicyProvider::schema_registry() const { | 65 SchemaRegistry* ConfigurationPolicyProvider::schema_registry() const { |
| 56 return schema_registry_; | 66 return schema_registry_; |
| 57 } | 67 } |
| 58 | 68 |
| 59 const scoped_refptr<SchemaMap>& | 69 const scoped_refptr<SchemaMap>& |
| 60 ConfigurationPolicyProvider::schema_map() const { | 70 ConfigurationPolicyProvider::schema_map() const { |
| 61 return schema_registry_->schema_map(); | 71 return schema_registry_->schema_map(); |
| 62 } | 72 } |
| 63 | 73 |
| 64 void ConfigurationPolicyProvider::AddObserver(Observer* observer) { | 74 void ConfigurationPolicyProvider::AddObserver(Observer* observer) { |
| 65 observer_list_.AddObserver(observer); | 75 observer_list_.AddObserver(observer); |
| 66 } | 76 } |
| 67 | 77 |
| 68 void ConfigurationPolicyProvider::RemoveObserver(Observer* observer) { | 78 void ConfigurationPolicyProvider::RemoveObserver(Observer* observer) { |
| 69 observer_list_.RemoveObserver(observer); | 79 observer_list_.RemoveObserver(observer); |
| 70 } | 80 } |
| 71 | 81 |
| 72 void ConfigurationPolicyProvider::OnSchemaRegistryUpdated( | 82 void ConfigurationPolicyProvider::OnSchemaRegistryUpdated( |
| 73 bool has_new_schemas) {} | 83 bool has_new_schemas) {} |
| 74 | 84 |
| 75 void ConfigurationPolicyProvider::OnSchemaRegistryReady() {} | 85 void ConfigurationPolicyProvider::OnSchemaRegistryReady() {} |
| 76 | 86 |
| 77 } // namespace policy | 87 } // namespace policy |
| OLD | NEW |