| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_POLICY_POLICY_MAP_H_ | 5 #ifndef CHROME_BROWSER_POLICY_POLICY_MAP_H_ |
| 6 #define CHROME_BROWSER_POLICY_POLICY_MAP_H_ | 6 #define CHROME_BROWSER_POLICY_POLICY_MAP_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/policy/configuration_policy_provider.h" | |
| 12 #include "policy/configuration_policy_type.h" | 11 #include "policy/configuration_policy_type.h" |
| 13 | 12 |
| 14 namespace policy { | 13 namespace policy { |
| 15 | 14 |
| 15 struct PolicyDefinitionList; |
| 16 |
| 16 // Wrapper class around a std::map<ConfigurationPolicyType, Value*> that | 17 // Wrapper class around a std::map<ConfigurationPolicyType, Value*> that |
| 17 // properly cleans up after itself when going out of scope. | 18 // properly cleans up after itself when going out of scope. |
| 18 // Exposes interesting methods of the underlying std::map. | 19 // Exposes interesting methods of the underlying std::map. |
| 19 class PolicyMap { | 20 class PolicyMap { |
| 20 public: | 21 public: |
| 21 typedef std::map<ConfigurationPolicyType, Value*> PolicyMapType; | 22 typedef std::map<ConfigurationPolicyType, Value*> PolicyMapType; |
| 22 typedef PolicyMapType::const_iterator const_iterator; | 23 typedef PolicyMapType::const_iterator const_iterator; |
| 23 | 24 |
| 24 PolicyMap(); | 25 PolicyMap(); |
| 25 virtual ~PolicyMap(); | 26 virtual ~PolicyMap(); |
| 26 | 27 |
| 27 // Returns a weak reference to the value currently stored for key |policy|. | 28 // Returns a weak reference to the value currently stored for key |policy|. |
| 28 // Ownership is retained by PolicyMap; callers should use Value::DeepCopy | 29 // Ownership is retained by PolicyMap; callers should use Value::DeepCopy |
| 29 // if they need a copy that they own themselves. | 30 // if they need a copy that they own themselves. |
| 30 // Returns NULL if the map does not contain a value for |policy|. | 31 // Returns NULL if the map does not contain a value for |policy|. |
| 31 const Value* Get(ConfigurationPolicyType policy) const; | 32 const Value* Get(ConfigurationPolicyType policy) const; |
| 32 // Takes ownership of |value|. Overwrites any existing value stored in the | 33 // Takes ownership of |value|. Overwrites any existing value stored in the |
| 33 // map for the key |policy|. | 34 // map for the key |policy|. |
| 34 void Set(ConfigurationPolicyType policy, Value* value); | 35 void Set(ConfigurationPolicyType policy, Value* value); |
| 35 void Erase(ConfigurationPolicyType policy); | 36 void Erase(ConfigurationPolicyType policy); |
| 36 | 37 |
| 37 void Swap(PolicyMap* other); | 38 void Swap(PolicyMap* other); |
| 38 void CopyFrom(const PolicyMap& other); | 39 void CopyFrom(const PolicyMap& other); |
| 39 | 40 |
| 40 // Loads the values in |policies| into this PolicyMap, mapped to their | 41 // Loads the values in |policies| into this PolicyMap, mapped to their |
| 41 // corresponding policy type. The policies to load, and their types, are | 42 // corresponding policy type. The policies to load, and their types, are |
| 42 // listed in |list|. | 43 // listed in |list|. |
| 43 void LoadFrom(const DictionaryValue* policies, | 44 void LoadFrom(const DictionaryValue* policies, |
| 44 const ConfigurationPolicyProvider::PolicyDefinitionList* list); | 45 const PolicyDefinitionList* list); |
| 45 | 46 |
| 46 bool Equals(const PolicyMap& other) const; | 47 bool Equals(const PolicyMap& other) const; |
| 47 bool empty() const; | 48 bool empty() const; |
| 48 size_t size() const; | 49 size_t size() const; |
| 49 | 50 |
| 50 const_iterator begin() const; | 51 const_iterator begin() const; |
| 51 const_iterator end() const; | 52 const_iterator end() const; |
| 52 void Clear(); | 53 void Clear(); |
| 53 | 54 |
| 54 private: | 55 private: |
| 55 // Helper function for Equals(...). | 56 // Helper function for Equals(...). |
| 56 static bool MapEntryEquals(const PolicyMapType::value_type& a, | 57 static bool MapEntryEquals(const PolicyMapType::value_type& a, |
| 57 const PolicyMapType::value_type& b); | 58 const PolicyMapType::value_type& b); |
| 58 | 59 |
| 59 PolicyMapType map_; | 60 PolicyMapType map_; |
| 60 | 61 |
| 61 DISALLOW_COPY_AND_ASSIGN(PolicyMap); | 62 DISALLOW_COPY_AND_ASSIGN(PolicyMap); |
| 62 }; | 63 }; |
| 63 | 64 |
| 64 } // namespace policy | 65 } // namespace policy |
| 65 | 66 |
| 66 #endif // CHROME_BROWSER_POLICY_POLICY_MAP_H_ | 67 #endif // CHROME_BROWSER_POLICY_POLICY_MAP_H_ |
| OLD | NEW |