Chromium Code Reviews| 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..6f61502d97a39713577e04358a0e7a64e622a6e9 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. |
|
bartfab (slow)
2015/09/14 14:42:27
You can leave the comment here if you want but in
fhorschig
2015/09/16 13:52:05
This value is far less important for the Equality.
|
| + // 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,33 @@ const base::Value* PolicyMap::GetValue(const std::string& policy) const { |
| return entry == map_.end() ? NULL : entry->second.value; |
| } |
| +void PolicyMap::ApplySourceToEntries(PolicySource source) { |
| + for (auto& map_entry : map_) { |
| + if (map_entry.second.source == POLICY_SOURCE_UNKNOWN) |
| + map_entry.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 +121,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, |
|
bartfab (slow)
2015/09/14 14:42:27
Nit: s/NULL/nullptr/
fhorschig
2015/09/16 13:52:05
Done.
|
| + entry.source); |
| } |
| } |
| @@ -115,10 +139,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, |
|
bartfab (slow)
2015/09/14 14:42:27
Nit: s/NULL/nullptr/
fhorschig
2015/09/16 13:52:05
Done.
|
| + it->second.source); |
| } |
| } |
| } |