Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(516)

Unified Diff: components/policy/core/common/policy_map.cc

Issue 1304843004: Add source column to chrome://policy showing the origins of policies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed browsertest and removed unnecessary string for default values. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..aa3786fc0955561574a9ceff0ce71d642d22be8d 100644
--- a/components/policy/core/common/policy_map.cc
+++ b/components/policy/core/common/policy_map.cc
@@ -14,6 +14,7 @@ namespace policy {
PolicyMap::Entry::Entry()
: level(POLICY_LEVEL_RECOMMENDED),
scope(POLICY_SCOPE_USER),
+ source(POLICY_SOURCE_DEFAULT),
value(NULL),
external_data_fetcher(NULL) {}
@@ -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) {
@@ -46,9 +48,8 @@ bool PolicyMap::Entry::has_higher_priority_than(
}
bool PolicyMap::Entry::Equals(const PolicyMap::Entry& other) const {
- return level == other.level &&
- scope == other.scope &&
- base::Value::Equals(value, other.value) &&
+ return level == other.level && scope == other.scope &&
+ source == other.source && base::Value::Equals(value, other.value) &&
Thiemo Nagel 2015/09/01 17:40:37 I'm somehow split about this. Since the source is
fhorschig 2015/09/04 06:53:54 Done.
ExternalDataFetcher::Equals(external_data_fetcher,
other.external_data_fetcher);
}
@@ -70,15 +71,35 @@ const base::Value* PolicyMap::GetValue(const std::string& policy) const {
return entry == map_.end() ? NULL : entry->second.value;
}
+void PolicyMap::SetSources(PolicySource source) {
+ for (PolicyMapType::iterator it = map_.begin(); it != map_.end(); ++it) {
+ if (source != POLICY_SOURCE_PLATFORM &&
Thiemo Nagel 2015/09/01 17:40:37 This deserves a comment!
fhorschig 2015/09/04 06:53:54 Done.
+ it->second.source == POLICY_SOURCE_ENTERPRISE_DEFAULT)
+ continue;
+ it->second.source = source;
+ }
+}
+
void PolicyMap::Set(const std::string& policy,
PolicyLevel level,
PolicyScope scope,
base::Value* value,
ExternalDataFetcher* external_data_fetcher) {
+ Set(policy, level, scope, value, external_data_fetcher,
+ POLICY_SOURCE_DEFAULT);
+}
+
+void PolicyMap::Set(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 +120,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);
+ Set(it->first, entry.level, entry.scope, entry.value->DeepCopy(),
+ entry.external_data_fetcher
+ ? new ExternalDataFetcher(*entry.external_data_fetcher)
+ : NULL,
+ entry.source);
}
}
@@ -116,9 +139,11 @@ void PolicyMap::MergeFrom(const PolicyMap& other) {
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);
+ it->second.value->DeepCopy(),
+ it->second.external_data_fetcher
+ ? new ExternalDataFetcher(*it->second.external_data_fetcher)
+ : NULL,
+ it->second.source);
}
}
}
@@ -127,9 +152,16 @@ void PolicyMap::LoadFrom(
const base::DictionaryValue* policies,
PolicyLevel level,
PolicyScope scope) {
+ LoadFrom(policies, level, scope, POLICY_SOURCE_DEFAULT);
+}
+
+void PolicyMap::LoadFrom(const base::DictionaryValue* policies,
+ PolicyLevel level,
+ PolicyScope scope,
+ PolicySource source) {
for (base::DictionaryValue::Iterator it(*policies);
!it.IsAtEnd(); it.Advance()) {
- Set(it.key(), level, scope, it.value().DeepCopy(), NULL);
+ Set(it.key(), level, scope, it.value().DeepCopy(), NULL, source);
}
}

Powered by Google App Engine
This is Rietveld 408576698