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

Unified Diff: chrome/browser/policy/policy_map.cc

Issue 6532019: New policy protobuf protocol. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix one more leak Created 9 years, 10 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: chrome/browser/policy/policy_map.cc
diff --git a/chrome/browser/policy/policy_map.cc b/chrome/browser/policy/policy_map.cc
new file mode 100644
index 0000000000000000000000000000000000000000..50c8c429f5824cac3d098ed9c8ac12f0843860c1
--- /dev/null
+++ b/chrome/browser/policy/policy_map.cc
@@ -0,0 +1,73 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/policy/policy_map.h"
+
+#include <algorithm>
+
+#include "base/stl_util-inl.h"
+
+namespace policy {
+
+PolicyMap::PolicyMap() {
+}
+
+PolicyMap::~PolicyMap() {
+ Clear();
+}
+
+const Value* PolicyMap::Get(ConfigurationPolicyType policy) const {
+ PolicyMapType::const_iterator entry = map_.find(policy);
+ return entry == map_.end() ? NULL : entry->second;
+}
+
+void PolicyMap::Set(ConfigurationPolicyType policy, Value* value) {
+ std::swap(map_[policy], value);
+ delete value;
+}
+
+void PolicyMap::Erase(ConfigurationPolicyType policy) {
+ const const_iterator entry = map_.find(policy);
+ if (entry != map_.end()) {
+ delete entry->second;
+ map_.erase(entry->first);
+ }
+}
+
+void PolicyMap::Swap(PolicyMap* other) {
+ map_.swap(other->map_);
+}
+
+bool PolicyMap::Equals(const PolicyMap& other) const {
+ return other.map_.size() == map_.size() &&
+ std::equal(map_.begin(), map_.end(), other.map_.begin(), MapEntryEquals);
+}
+
+bool PolicyMap::empty() const {
+ return map_.empty();
+}
+
+size_t PolicyMap::size() const {
+ return map_.size();
+}
+
+PolicyMap::const_iterator PolicyMap::begin() const {
+ return map_.begin();
+}
+
+PolicyMap::const_iterator PolicyMap::end() const {
+ return map_.end();
+}
+
+void PolicyMap::Clear() {
+ STLDeleteValues(&map_);
+}
+
+// static
+bool PolicyMap::MapEntryEquals(const PolicyMap::PolicyMapType::value_type& a,
+ const PolicyMap::PolicyMapType::value_type& b) {
+ return a.first == b.first && Value::Equals(a.second, b.second);
+}
+
+} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698