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

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: Increased ID range for Messages. Created 5 years, 3 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..4459dfeb970842c743665c811336f077c306c5b8 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,7 @@ 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 observer updates.
Thiemo Nagel 2015/09/04 20:15:54 It would be nice to mention which observer benefit
fhorschig 2015/09/07 14:09:34 Done.
base::Value::Equals(value, other.value) &&
ExternalDataFetcher::Equals(external_data_fetcher,
other.external_data_fetcher);
@@ -70,15 +73,37 @@ const base::Value* PolicyMap::GetValue(const std::string& policy) const {
return entry == map_.end() ? NULL : entry->second.value;
}
+void PolicyMap::SetEntrySources(PolicySource source) {
+ for (PolicyMapType::iterator it = map_.begin(); it != map_.end(); ++it) {
Thiemo Nagel 2015/09/04 20:15:54 Please use range loop.
fhorschig 2015/09/07 14:09:34 Done.
+ if (source != POLICY_SOURCE_PLATFORM &&
+ (it->second.source == POLICY_SOURCE_ENTERPRISE_DEFAULT ||
Thiemo Nagel 2015/09/04 20:15:54 I still don't get what's happening here. It seems
fhorschig 2015/09/07 14:09:34 Currently, Yes. (If policies were set multiple tim
+ it->second.source == POLICY_SOURCE_ENFORCED))
+ continue; // Enterprise and enforced policies can only be overridden by
+ // platform-specific configurations (Like debug JSONs).
+ it->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 +124,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 +142,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);
}
}
}

Powered by Google App Engine
This is Rietveld 408576698