blob: ab0e9f82be8a793a8b35fdd00a775bc55cb3848b [file] [log] [blame]
[email protected]61dc220c2012-01-05 19:03:101// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]f86369722011-02-17 13:25:232// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_POLICY_POLICY_MAP_H_
6#define CHROME_BROWSER_POLICY_POLICY_MAP_H_
[email protected]f04d73f2011-10-25 15:07:127#pragma once
[email protected]f86369722011-02-17 13:25:238
9#include <map>
10
11#include "base/values.h"
12#include "policy/configuration_policy_type.h"
13
14namespace policy {
15
[email protected]aea9fa12011-10-13 22:12:3916struct PolicyDefinitionList;
17
[email protected]f86369722011-02-17 13:25:2318// Wrapper class around a std::map<ConfigurationPolicyType, Value*> that
19// properly cleans up after itself when going out of scope.
20// Exposes interesting methods of the underlying std::map.
21class PolicyMap {
22 public:
23 typedef std::map<ConfigurationPolicyType, Value*> PolicyMapType;
24 typedef PolicyMapType::const_iterator const_iterator;
25
26 PolicyMap();
27 virtual ~PolicyMap();
28
29 // Returns a weak reference to the value currently stored for key |policy|.
30 // Ownership is retained by PolicyMap; callers should use Value::DeepCopy
31 // if they need a copy that they own themselves.
32 // Returns NULL if the map does not contain a value for |policy|.
33 const Value* Get(ConfigurationPolicyType policy) const;
34 // Takes ownership of |value|. Overwrites any existing value stored in the
35 // map for the key |policy|.
36 void Set(ConfigurationPolicyType policy, Value* value);
37 void Erase(ConfigurationPolicyType policy);
38
39 void Swap(PolicyMap* other);
[email protected]5e61ad92011-09-12 16:47:2540 void CopyFrom(const PolicyMap& other);
[email protected]f86369722011-02-17 13:25:2341
[email protected]61dc220c2012-01-05 19:03:1042 // Similar to CopyFrom, but doesn't Clear() |this| before merging, and only
43 // merges keys that aren't already contained in |this|.
44 void MergeFrom(const PolicyMap& other);
45
[email protected]b6e695a92011-09-29 15:08:3346 // Loads the values in |policies| into this PolicyMap, mapped to their
47 // corresponding policy type. The policies to load, and their types, are
48 // listed in |list|.
49 void LoadFrom(const DictionaryValue* policies,
[email protected]aea9fa12011-10-13 22:12:3950 const PolicyDefinitionList* list);
[email protected]b6e695a92011-09-29 15:08:3351
[email protected]f86369722011-02-17 13:25:2352 bool Equals(const PolicyMap& other) const;
53 bool empty() const;
54 size_t size() const;
55
56 const_iterator begin() const;
57 const_iterator end() const;
58 void Clear();
59
60 private:
61 // Helper function for Equals(...).
62 static bool MapEntryEquals(const PolicyMapType::value_type& a,
63 const PolicyMapType::value_type& b);
64
65 PolicyMapType map_;
66
67 DISALLOW_COPY_AND_ASSIGN(PolicyMap);
68};
69
70} // namespace policy
71
72#endif // CHROME_BROWSER_POLICY_POLICY_MAP_H_