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

Side by Side 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 memory leaks by introducing PolicyMap 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5
Mattias Nissler (ping if slow) 2011/02/17 09:27:20 excess whitespace
Jakob Kummerow 2011/02/17 09:47:14 Done.
6 #include "chrome/browser/policy/policy_map.h"
7
8 #include <algorithm>
9
10 #include "base/stl_util-inl.h"
11
12 namespace policy {
13
14 PolicyMap::PolicyMap() {
15 }
16
17 PolicyMap::~PolicyMap() {
18 clear();
19 }
20
21 const Value* PolicyMap::Get(ConfigurationPolicyType policy) const {
22 PolicyMapType::const_iterator entry = map_.find(policy);
23 return entry == map_.end() ? NULL : entry->second;
24 }
25
26 void PolicyMap::Set(ConfigurationPolicyType policy, Value* value) {
27 std::swap(map_[policy], value);
28 delete value;
29 }
30
31 void PolicyMap::Erase(ConfigurationPolicyType policy) {
32 const const_iterator entry = map_.find(policy);
33 if (entry != map_.end()) {
34 delete entry->second;
35 map_.erase(entry->first);
36 }
37 }
38
39 void PolicyMap::Swap(PolicyMap* other) {
40 map_.swap(other->map_);
41 }
42
43 bool PolicyMap::Equals(const PolicyMap& other) const {
44 return other.map_.size() == map_.size() &&
45 std::equal(map_.begin(), map_.end(), other.map_.begin(), MapEntryEquals);
46 }
47
48 bool PolicyMap::empty() const {
49 return map_.empty();
50 }
51
52 size_t PolicyMap::size() const {
53 return map_.size();
54 }
55
56 PolicyMap::const_iterator PolicyMap::begin() const {
57 return map_.begin();
58 }
59
60 PolicyMap::const_iterator PolicyMap::end() const {
61 return map_.end();
62 }
63
64 void PolicyMap::clear() {
65 STLDeleteValues(&map_);
66 }
67
68 // static
69 bool PolicyMap::MapEntryEquals(const PolicyMap::PolicyMapType::value_type& a,
70 const PolicyMap::PolicyMapType::value_type& b) {
71 return a.first == b.first && Value::Equals(a.second, b.second);
72 }
73
74 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698