| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/policy/policy_types.h" | 14 #include "chrome/browser/policy/policy_types.h" |
| 15 | 15 |
| 16 namespace policy { | 16 namespace policy { |
| 17 | 17 |
| 18 // A mapping of policy names to policy values for a given policy namespace. | 18 // A mapping of policy names to policy values for a given policy namespace. |
| 19 class PolicyMap { | 19 class PolicyMap { |
| 20 public: | 20 public: |
| 21 // Each policy maps to an Entry which keeps the policy value as well as other | 21 // Each policy maps to an Entry which keeps the policy value as well as other |
| 22 // relevant data about the policy. | 22 // relevant data about the policy. |
| 23 struct Entry { | 23 struct Entry { |
| 24 PolicyLevel level; | 24 PolicyLevel level; |
| 25 PolicyScope scope; | 25 PolicyScope scope; |
| 26 Value* value; | 26 base::Value* value; |
| 27 | 27 |
| 28 Entry() | 28 Entry() |
| 29 : level(POLICY_LEVEL_RECOMMENDED), | 29 : level(POLICY_LEVEL_RECOMMENDED), |
| 30 scope(POLICY_SCOPE_USER), | 30 scope(POLICY_SCOPE_USER), |
| 31 value(NULL) {} | 31 value(NULL) {} |
| 32 | 32 |
| 33 // Returns true if |this| has higher priority than |other|. | 33 // Returns true if |this| has higher priority than |other|. |
| 34 bool has_higher_priority_than(const Entry& other) const; | 34 bool has_higher_priority_than(const Entry& other) const; |
| 35 | 35 |
| 36 // Returns true if |this| equals |other|. | 36 // Returns true if |this| equals |other|. |
| 37 bool Equals(const Entry& other) const; | 37 bool Equals(const Entry& other) const; |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 typedef std::map<std::string, Entry> PolicyMapType; | 40 typedef std::map<std::string, Entry> PolicyMapType; |
| 41 typedef PolicyMapType::const_iterator const_iterator; | 41 typedef PolicyMapType::const_iterator const_iterator; |
| 42 | 42 |
| 43 PolicyMap(); | 43 PolicyMap(); |
| 44 virtual ~PolicyMap(); | 44 virtual ~PolicyMap(); |
| 45 | 45 |
| 46 // Returns a weak reference to the entry currently stored for key |policy|, | 46 // Returns a weak reference to the entry currently stored for key |policy|, |
| 47 // or NULL if not found. Ownership is retained by the PolicyMap. | 47 // or NULL if not found. Ownership is retained by the PolicyMap. |
| 48 const Entry* Get(const std::string& policy) const; | 48 const Entry* Get(const std::string& policy) const; |
| 49 | 49 |
| 50 // Returns a weak reference to the value currently stored for key |policy|, | 50 // Returns a weak reference to the value currently stored for key |policy|, |
| 51 // or NULL if not found. Ownership is retained by the PolicyMap. | 51 // or NULL if not found. Ownership is retained by the PolicyMap. |
| 52 // This is equivalent to Get(policy)->value, when it doesn't return NULL. | 52 // This is equivalent to Get(policy)->value, when it doesn't return NULL. |
| 53 const Value* GetValue(const std::string& policy) const; | 53 const base::Value* GetValue(const std::string& policy) const; |
| 54 | 54 |
| 55 // Takes ownership of |value|. Overwrites any existing value stored in the | 55 // Takes ownership of |value|. Overwrites any existing value stored in the |
| 56 // map for the key |policy|. | 56 // map for the key |policy|. |
| 57 void Set(const std::string& policy, | 57 void Set(const std::string& policy, |
| 58 PolicyLevel level, | 58 PolicyLevel level, |
| 59 PolicyScope scope, | 59 PolicyScope scope, |
| 60 Value* value); | 60 base::Value* value); |
| 61 | 61 |
| 62 // Erase the given |policy|, if it exists in this map. | 62 // Erase the given |policy|, if it exists in this map. |
| 63 void Erase(const std::string& policy); | 63 void Erase(const std::string& policy); |
| 64 | 64 |
| 65 // Swaps the internal representation of |this| with |other|. | 65 // Swaps the internal representation of |this| with |other|. |
| 66 void Swap(PolicyMap* other); | 66 void Swap(PolicyMap* other); |
| 67 | 67 |
| 68 // |this| becomes a copy of |other|. Any existing policies are dropped. | 68 // |this| becomes a copy of |other|. Any existing policies are dropped. |
| 69 void CopyFrom(const PolicyMap& other); | 69 void CopyFrom(const PolicyMap& other); |
| 70 | 70 |
| 71 // Returns a copy of |this|. | 71 // Returns a copy of |this|. |
| 72 scoped_ptr<PolicyMap> DeepCopy() const; | 72 scoped_ptr<PolicyMap> DeepCopy() const; |
| 73 | 73 |
| 74 // Merges policies from |other| into |this|. Existing policies are only | 74 // Merges policies from |other| into |this|. Existing policies are only |
| 75 // overridden by those in |other| if they have a higher priority, as defined | 75 // overridden by those in |other| if they have a higher priority, as defined |
| 76 // by Entry::has_higher_priority_than(). If a policy is contained in both | 76 // by Entry::has_higher_priority_than(). If a policy is contained in both |
| 77 // maps with the same priority, the current value in |this| is preserved. | 77 // maps with the same priority, the current value in |this| is preserved. |
| 78 void MergeFrom(const PolicyMap& other); | 78 void MergeFrom(const PolicyMap& other); |
| 79 | 79 |
| 80 // Loads the values in |policies| into this PolicyMap. All policies loaded | 80 // Loads the values in |policies| into this PolicyMap. All policies loaded |
| 81 // will have |level| and |scope| in their entries. Existing entries are | 81 // will have |level| and |scope| in their entries. Existing entries are |
| 82 // replaced. | 82 // replaced. |
| 83 void LoadFrom(const DictionaryValue* policies, | 83 void LoadFrom(const base::DictionaryValue* policies, |
| 84 PolicyLevel level, | 84 PolicyLevel level, |
| 85 PolicyScope scope); | 85 PolicyScope scope); |
| 86 | 86 |
| 87 // Compares this value map against |other| and stores all key names that have | 87 // Compares this value map against |other| and stores all key names that have |
| 88 // different values in |differing_keys|. This includes keys that are present | 88 // different values in |differing_keys|. This includes keys that are present |
| 89 // only in one of the maps. |differing_keys| is not cleared before the keys | 89 // only in one of the maps. |differing_keys| is not cleared before the keys |
| 90 // are added. | 90 // are added. |
| 91 void GetDifferingKeys(const PolicyMap& other, | 91 void GetDifferingKeys(const PolicyMap& other, |
| 92 std::set<std::string>* differing_keys) const; | 92 std::set<std::string>* differing_keys) const; |
| 93 | 93 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 111 const PolicyMapType::value_type& b); | 111 const PolicyMapType::value_type& b); |
| 112 | 112 |
| 113 PolicyMapType map_; | 113 PolicyMapType map_; |
| 114 | 114 |
| 115 DISALLOW_COPY_AND_ASSIGN(PolicyMap); | 115 DISALLOW_COPY_AND_ASSIGN(PolicyMap); |
| 116 }; | 116 }; |
| 117 | 117 |
| 118 } // namespace policy | 118 } // namespace policy |
| 119 | 119 |
| 120 #endif // CHROME_BROWSER_POLICY_POLICY_MAP_H_ | 120 #endif // CHROME_BROWSER_POLICY_POLICY_MAP_H_ |
| OLD | NEW |