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

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

Issue 88423002: Add CloudExternalDataPolicyObserverChromeOS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed suggestion. Created 7 years, 1 month 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
« no previous file with comments | « components/policy/core/common/policy_map.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 a7e6a16ccf4c34ea4a45553408cad3de83d0aa24..40cf73352f7970c7e67e1e52d39681a7fe17633d 100644
--- a/components/policy/core/common/policy_map.cc
+++ b/components/policy/core/common/policy_map.cc
@@ -11,6 +11,26 @@
namespace policy {
+void PolicyMap::Entry::DeleteOwnedMembers() {
+ delete value;
+ value = NULL;
+ delete external_data_fetcher;
+ external_data_fetcher = NULL;
+}
+
+scoped_ptr<PolicyMap::Entry> PolicyMap::Entry::DeepCopy() const {
+ scoped_ptr<Entry> copy(new Entry);
+ copy->level = level;
+ copy->scope = scope;
+ if (value)
+ copy->value = value->DeepCopy();
+ if (external_data_fetcher) {
+ copy->external_data_fetcher =
+ new ExternalDataFetcher(*external_data_fetcher);
+ }
+ return copy.Pass();
+}
+
bool PolicyMap::Entry::has_higher_priority_than(
const PolicyMap::Entry& other) const {
if (level == other.level)
@@ -50,8 +70,7 @@ void PolicyMap::Set(const std::string& policy,
Value* value,
ExternalDataFetcher* external_data_fetcher) {
Entry& entry = map_[policy];
- delete entry.value;
- delete entry.external_data_fetcher;
+ entry.DeleteOwnedMembers();
entry.level = level;
entry.scope = scope;
entry.value = value;
@@ -61,8 +80,7 @@ void PolicyMap::Set(const std::string& policy,
void PolicyMap::Erase(const std::string& policy) {
PolicyMapType::iterator it = map_.find(policy);
if (it != map_.end()) {
- delete it->second.value;
- delete it->second.external_data_fetcher;
+ it->second.DeleteOwnedMembers();
map_.erase(it);
}
}
@@ -139,8 +157,7 @@ void PolicyMap::FilterLevel(PolicyLevel level) {
PolicyMapType::iterator iter(map_.begin());
while (iter != map_.end()) {
if (iter->second.level != level) {
- delete iter->second.value;
- delete iter->second.external_data_fetcher;
+ iter->second.DeleteOwnedMembers();
map_.erase(iter++);
} else {
++iter;
@@ -170,10 +187,8 @@ PolicyMap::const_iterator PolicyMap::end() const {
}
void PolicyMap::Clear() {
- for (PolicyMapType::iterator it = map_.begin(); it != map_.end(); ++it) {
- delete it->second.value;
- delete it->second.external_data_fetcher;
- }
+ for (PolicyMapType::iterator it = map_.begin(); it != map_.end(); ++it)
+ it->second.DeleteOwnedMembers();
map_.clear();
}
« no previous file with comments | « components/policy/core/common/policy_map.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698