diff options
author | jkummerow@chromium.org <jkummerow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-17 13:25:23 +0000 |
---|---|---|
committer | jkummerow@chromium.org <jkummerow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-17 13:25:23 +0000 |
commit | f8636972b3e1d3a9bbf7f86b6708c0f5d66571ae (patch) | |
tree | 1cc358fe9fc57efd09b612b261d484ad359bf1fe /chrome/browser/policy/policy_map.cc | |
parent | d20e0b986707dd49ae7a2cad347f4e50140ec86e (diff) | |
download | chromium_src-f8636972b3e1d3a9bbf7f86b6708c0f5d66571ae.zip chromium_src-f8636972b3e1d3a9bbf7f86b6708c0f5d66571ae.tar.gz chromium_src-f8636972b3e1d3a9bbf7f86b6708c0f5d66571ae.tar.bz2 |
New policy protobuf protocol.
(Third attempt to land http://codereview.chromium.org/6409040/ -- now without memory leaks)
- cloud_policy.proto autogenerated from policy_templates.json
- C++ method decoding the protobuf also autogenerated from policy_templates.json
- changed policy fetching mechanism to fetch new-style policy protobufs
BUG=68309, chromium-os:11253, chromium-os:11255
TEST=CloudPolicyCacheTest.*; also manual test against python testserver
Review URL: http://codereview.chromium.org/6532019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75259 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/policy/policy_map.cc')
-rw-r--r-- | chrome/browser/policy/policy_map.cc | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/chrome/browser/policy/policy_map.cc b/chrome/browser/policy/policy_map.cc new file mode 100644 index 0000000..50c8c42 --- /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 |