Index: components/policy/core/common/policy_map.cc |
diff --git a/components/policy/core/common/policy_map.cc b/components/policy/core/common/policy_map.cc |
index 5e1fd5b06375e385c61a8bb66bd9b67e702c1ea6..01f3986b34683e782f5107d9870a9670a4192ccc 100644 |
--- a/components/policy/core/common/policy_map.cc |
+++ b/components/policy/core/common/policy_map.cc |
@@ -15,7 +15,8 @@ PolicyMap::Entry::Entry() |
: level(POLICY_LEVEL_RECOMMENDED), |
scope(POLICY_SCOPE_USER), |
value(NULL), |
- external_data_fetcher(NULL) {} |
+ external_data_fetcher(NULL), |
+ source(POLICY_SOURCE_UNKNOWN) {} |
void PolicyMap::Entry::DeleteOwnedMembers() { |
delete value; |
@@ -28,6 +29,7 @@ scoped_ptr<PolicyMap::Entry> PolicyMap::Entry::DeepCopy() const { |
scoped_ptr<Entry> copy(new Entry); |
copy->level = level; |
copy->scope = scope; |
+ copy->source = source; |
if (value) |
copy->value = value->DeepCopy(); |
if (external_data_fetcher) { |
@@ -48,6 +50,8 @@ bool PolicyMap::Entry::has_higher_priority_than( |
bool PolicyMap::Entry::Equals(const PolicyMap::Entry& other) const { |
return level == other.level && |
scope == other.scope && |
+ source == other.source && // Necessary for PolicyUIHandler observers. |
+ // They have to update when sources change. |
base::Value::Equals(value, other.value) && |
ExternalDataFetcher::Equals(external_data_fetcher, |
other.external_data_fetcher); |
@@ -70,15 +74,34 @@ const base::Value* PolicyMap::GetValue(const std::string& policy) const { |
return entry == map_.end() ? NULL : entry->second.value; |
} |
+void PolicyMap::SetEntrySources(PolicySource source) { |
+ for (auto& policy : map_) { |
Thiemo Nagel
2015/09/07 15:18:57
This is not really a "policy", it's more a "map_en
fhorschig
2015/09/07 15:59:35
Done.
|
+ if (policy.second.source != POLICY_SOURCE_UNKNOWN) |
Thiemo Nagel
2015/09/07 15:18:57
You can save one more line of code by inverting th
fhorschig
2015/09/07 15:59:35
Done.
|
+ continue; |
+ policy.second.source = source; |
+ } |
+} |
+ |
void PolicyMap::Set(const std::string& policy, |
PolicyLevel level, |
PolicyScope scope, |
base::Value* value, |
ExternalDataFetcher* external_data_fetcher) { |
+ SetWithSource(policy, level, scope, value, external_data_fetcher, |
+ POLICY_SOURCE_UNKNOWN); |
+} |
+ |
+void PolicyMap::SetWithSource(const std::string& policy, |
+ PolicyLevel level, |
+ PolicyScope scope, |
+ base::Value* value, |
+ ExternalDataFetcher* external_data_fetcher, |
+ PolicySource source) { |
Entry& entry = map_[policy]; |
entry.DeleteOwnedMembers(); |
entry.level = level; |
entry.scope = scope; |
+ entry.source = source; |
entry.value = value; |
entry.external_data_fetcher = external_data_fetcher; |
} |
@@ -99,9 +122,11 @@ void PolicyMap::CopyFrom(const PolicyMap& other) { |
Clear(); |
for (const_iterator it = other.begin(); it != other.end(); ++it) { |
const Entry& entry = it->second; |
- Set(it->first, entry.level, entry.scope, |
- entry.value->DeepCopy(), entry.external_data_fetcher ? |
- new ExternalDataFetcher(*entry.external_data_fetcher) : NULL); |
+ SetWithSource(it->first, entry.level, entry.scope, entry.value->DeepCopy(), |
+ entry.external_data_fetcher |
+ ? new ExternalDataFetcher(*entry.external_data_fetcher) |
+ : NULL, |
+ entry.source); |
} |
} |
@@ -115,10 +140,13 @@ void PolicyMap::MergeFrom(const PolicyMap& other) { |
for (const_iterator it = other.begin(); it != other.end(); ++it) { |
const Entry* entry = Get(it->first); |
if (!entry || it->second.has_higher_priority_than(*entry)) { |
- Set(it->first, it->second.level, it->second.scope, |
- it->second.value->DeepCopy(), it->second.external_data_fetcher ? |
- new ExternalDataFetcher(*it->second.external_data_fetcher) : |
- NULL); |
+ SetWithSource(it->first, it->second.level, it->second.scope, |
+ it->second.value->DeepCopy(), |
+ it->second.external_data_fetcher |
+ ? new ExternalDataFetcher( |
+ *it->second.external_data_fetcher) |
+ : NULL, |
+ it->second.source); |
} |
} |
} |