Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 COMPONENTS_POLICY_CORE_COMMON_POLICY_MAP_H_ | 5 #ifndef COMPONENTS_POLICY_CORE_COMMON_POLICY_MAP_H_ |
| 6 #define COMPONENTS_POLICY_CORE_COMMON_POLICY_MAP_H_ | 6 #define COMPONENTS_POLICY_CORE_COMMON_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 "components/policy/core/common/external_data_fetcher.h" | 14 #include "components/policy/core/common/external_data_fetcher.h" |
| 15 #include "components/policy/core/common/policy_types.h" | 15 #include "components/policy/core/common/policy_types.h" |
| 16 #include "components/policy/policy_export.h" | 16 #include "components/policy/policy_export.h" |
| 17 | 17 |
| 18 namespace policy { | 18 namespace policy { |
| 19 | 19 |
| 20 // A mapping of policy names to policy values for a given policy namespace. | 20 // A mapping of policy names to policy values for a given policy namespace. |
| 21 class POLICY_EXPORT PolicyMap { | 21 class POLICY_EXPORT PolicyMap { |
| 22 public: | 22 public: |
| 23 // Each policy maps to an Entry which keeps the policy value as well as other | 23 // Each policy maps to an Entry which keeps the policy value as well as other |
| 24 // relevant data about the policy. | 24 // relevant data about the policy. |
| 25 struct POLICY_EXPORT Entry { | 25 struct POLICY_EXPORT Entry { |
| 26 PolicyLevel level; | 26 PolicyLevel level; |
| 27 PolicyScope scope; | 27 PolicyScope scope; |
| 28 PolicySource source; | |
|
Thiemo Nagel
2015/09/01 17:40:37
Please annotate that this is for debugging/display
fhorschig
2015/09/04 06:53:54
Done.
| |
| 28 base::Value* value; | 29 base::Value* value; |
| 29 ExternalDataFetcher* external_data_fetcher; | 30 ExternalDataFetcher* external_data_fetcher; |
| 30 | 31 |
| 31 Entry(); | 32 Entry(); |
| 32 | 33 |
| 33 // Deletes all members owned by |this|. | 34 // Deletes all members owned by |this|. |
| 34 void DeleteOwnedMembers(); | 35 void DeleteOwnedMembers(); |
| 35 | 36 |
| 36 // Returns a copy of |this|. | 37 // Returns a copy of |this|. |
| 37 scoped_ptr<Entry> DeepCopy() const; | 38 scoped_ptr<Entry> DeepCopy() const; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 51 | 52 |
| 52 // Returns a weak reference to the entry currently stored for key |policy|, | 53 // Returns a weak reference to the entry currently stored for key |policy|, |
| 53 // or NULL if not found. Ownership is retained by the PolicyMap. | 54 // or NULL if not found. Ownership is retained by the PolicyMap. |
| 54 const Entry* Get(const std::string& policy) const; | 55 const Entry* Get(const std::string& policy) const; |
| 55 | 56 |
| 56 // Returns a weak reference to the value currently stored for key |policy|, | 57 // Returns a weak reference to the value currently stored for key |policy|, |
| 57 // or NULL if not found. Ownership is retained by the PolicyMap. | 58 // or NULL if not found. Ownership is retained by the PolicyMap. |
| 58 // This is equivalent to Get(policy)->value, when it doesn't return NULL. | 59 // This is equivalent to Get(policy)->value, when it doesn't return NULL. |
| 59 const base::Value* GetValue(const std::string& policy) const; | 60 const base::Value* GetValue(const std::string& policy) const; |
| 60 | 61 |
| 62 // Sets the source of every Entry in the Map to the passed |source|. | |
| 63 void SetSources(PolicySource source); | |
|
Thiemo Nagel
2015/09/01 17:40:37
SetSource would seem easier understandable to me.
fhorschig
2015/09/04 06:53:54
Obviously misleading name. It sets the sources of
| |
| 64 | |
| 65 // Calls |Set| with default source. | |
| 66 void Set(const std::string& policy, | |
| 67 PolicyLevel level, | |
| 68 PolicyScope scope, | |
| 69 base::Value* value, | |
| 70 ExternalDataFetcher* external_data_fetcher); | |
| 71 | |
| 61 // Takes ownership of |value| and |external_data_fetcher|. Overwrites any | 72 // Takes ownership of |value| and |external_data_fetcher|. Overwrites any |
| 62 // existing information stored in the map for the key |policy|. | 73 // existing information stored in the map for the key |policy|. |
| 63 void Set(const std::string& policy, | 74 void Set(const std::string& policy, |
|
Thiemo Nagel
2015/09/01 17:40:37
Function overloading is frowned upon, cf. http://g
fhorschig
2015/09/04 06:53:54
SetSources manipulates ALL entries. We don't want
| |
| 64 PolicyLevel level, | 75 PolicyLevel level, |
| 65 PolicyScope scope, | 76 PolicyScope scope, |
| 66 base::Value* value, | 77 base::Value* value, |
| 67 ExternalDataFetcher* external_data_fetcher); | 78 ExternalDataFetcher* external_data_fetcher, |
| 79 PolicySource source); | |
| 68 | 80 |
| 69 // Erase the given |policy|, if it exists in this map. | 81 // Erase the given |policy|, if it exists in this map. |
| 70 void Erase(const std::string& policy); | 82 void Erase(const std::string& policy); |
| 71 | 83 |
| 72 // Swaps the internal representation of |this| with |other|. | 84 // Swaps the internal representation of |this| with |other|. |
| 73 void Swap(PolicyMap* other); | 85 void Swap(PolicyMap* other); |
| 74 | 86 |
| 75 // |this| becomes a copy of |other|. Any existing policies are dropped. | 87 // |this| becomes a copy of |other|. Any existing policies are dropped. |
| 76 void CopyFrom(const PolicyMap& other); | 88 void CopyFrom(const PolicyMap& other); |
| 77 | 89 |
| 78 // Returns a copy of |this|. | 90 // Returns a copy of |this|. |
| 79 scoped_ptr<PolicyMap> DeepCopy() const; | 91 scoped_ptr<PolicyMap> DeepCopy() const; |
| 80 | 92 |
| 81 // Merges policies from |other| into |this|. Existing policies are only | 93 // Merges policies from |other| into |this|. Existing policies are only |
| 82 // overridden by those in |other| if they have a higher priority, as defined | 94 // overridden by those in |other| if they have a higher priority, as defined |
| 83 // by Entry::has_higher_priority_than(). If a policy is contained in both | 95 // by Entry::has_higher_priority_than(). If a policy is contained in both |
| 84 // maps with the same priority, the current value in |this| is preserved. | 96 // maps with the same priority, the current value in |this| is preserved. |
| 85 void MergeFrom(const PolicyMap& other); | 97 void MergeFrom(const PolicyMap& other); |
| 86 | 98 |
| 87 // Loads the values in |policies| into this PolicyMap. All policies loaded | 99 // Calls |LoadFrom| with default source. |
| 88 // will have |level| and |scope| in their entries. Existing entries are | |
| 89 // replaced. | |
| 90 void LoadFrom(const base::DictionaryValue* policies, | 100 void LoadFrom(const base::DictionaryValue* policies, |
| 91 PolicyLevel level, | 101 PolicyLevel level, |
| 92 PolicyScope scope); | 102 PolicyScope scope); |
| 103 // Loads the values in |policies| into this PolicyMap. All policies loaded | |
|
Thiemo Nagel
2015/09/01 17:40:37
Again, please don't overload.
fhorschig
2015/09/04 06:53:54
Done.
| |
| 104 // will have |level| and |scope| in their entries and originate from |source|. | |
| 105 // Existing entries are replaced. | |
| 106 void LoadFrom(const base::DictionaryValue* policies, | |
| 107 PolicyLevel level, | |
| 108 PolicyScope scope, | |
| 109 PolicySource source); | |
| 93 | 110 |
| 94 // Compares this value map against |other| and stores all key names that have | 111 // Compares this value map against |other| and stores all key names that have |
| 95 // different values or reference different external data in |differing_keys|. | 112 // different values or reference different external data in |differing_keys|. |
| 96 // This includes keys that are present only in one of the maps. | 113 // This includes keys that are present only in one of the maps. |
| 97 // |differing_keys| is not cleared before the keys are added. | 114 // |differing_keys| is not cleared before the keys are added. |
| 98 void GetDifferingKeys(const PolicyMap& other, | 115 void GetDifferingKeys(const PolicyMap& other, |
| 99 std::set<std::string>* differing_keys) const; | 116 std::set<std::string>* differing_keys) const; |
| 100 | 117 |
| 101 // Removes all policies that don't have the specified |level|. This is a | 118 // Removes all policies that don't have the specified |level|. This is a |
| 102 // temporary helper method, until mandatory and recommended levels are served | 119 // temporary helper method, until mandatory and recommended levels are served |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 118 const PolicyMapType::value_type& b); | 135 const PolicyMapType::value_type& b); |
| 119 | 136 |
| 120 PolicyMapType map_; | 137 PolicyMapType map_; |
| 121 | 138 |
| 122 DISALLOW_COPY_AND_ASSIGN(PolicyMap); | 139 DISALLOW_COPY_AND_ASSIGN(PolicyMap); |
| 123 }; | 140 }; |
| 124 | 141 |
| 125 } // namespace policy | 142 } // namespace policy |
| 126 | 143 |
| 127 #endif // COMPONENTS_POLICY_CORE_COMMON_POLICY_MAP_H_ | 144 #endif // COMPONENTS_POLICY_CORE_COMMON_POLICY_MAP_H_ |
| OLD | NEW |