[email protected] | 61dc220c | 2012-01-05 19:03:10 | [diff] [blame^] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | f8636972 | 2011-02-17 13:25:23 | [diff] [blame] | 2 | // 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] | f04d73f | 2011-10-25 15:07:12 | [diff] [blame] | 7 | #pragma once |
[email protected] | f8636972 | 2011-02-17 13:25:23 | [diff] [blame] | 8 | |
| 9 | #include <map> |
| 10 | |
| 11 | #include "base/values.h" |
| 12 | #include "policy/configuration_policy_type.h" |
| 13 | |
| 14 | namespace policy { |
| 15 | |
[email protected] | aea9fa1 | 2011-10-13 22:12:39 | [diff] [blame] | 16 | struct PolicyDefinitionList; |
| 17 | |
[email protected] | f8636972 | 2011-02-17 13:25:23 | [diff] [blame] | 18 | // 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. |
| 21 | class 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] | 5e61ad9 | 2011-09-12 16:47:25 | [diff] [blame] | 40 | void CopyFrom(const PolicyMap& other); |
[email protected] | f8636972 | 2011-02-17 13:25:23 | [diff] [blame] | 41 | |
[email protected] | 61dc220c | 2012-01-05 19:03:10 | [diff] [blame^] | 42 | // 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] | b6e695a9 | 2011-09-29 15:08:33 | [diff] [blame] | 46 | // 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] | aea9fa1 | 2011-10-13 22:12:39 | [diff] [blame] | 50 | const PolicyDefinitionList* list); |
[email protected] | b6e695a9 | 2011-09-29 15:08:33 | [diff] [blame] | 51 | |
[email protected] | f8636972 | 2011-02-17 13:25:23 | [diff] [blame] | 52 | 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_ |