| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> |
| 11 #include <set> | 12 #include <set> |
| 12 #include <string> | 13 #include <string> |
| 13 | 14 |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 15 #include "base/memory/scoped_ptr.h" | |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "components/policy/core/common/external_data_fetcher.h" | 17 #include "components/policy/core/common/external_data_fetcher.h" |
| 18 #include "components/policy/core/common/policy_types.h" | 18 #include "components/policy/core/common/policy_types.h" |
| 19 #include "components/policy/policy_export.h" | 19 #include "components/policy/policy_export.h" |
| 20 | 20 |
| 21 namespace policy { | 21 namespace policy { |
| 22 | 22 |
| 23 // A mapping of policy names to policy values for a given policy namespace. | 23 // A mapping of policy names to policy values for a given policy namespace. |
| 24 class POLICY_EXPORT PolicyMap { | 24 class POLICY_EXPORT PolicyMap { |
| 25 public: | 25 public: |
| 26 // Each policy maps to an Entry which keeps the policy value as well as other | 26 // Each policy maps to an Entry which keeps the policy value as well as other |
| 27 // relevant data about the policy. | 27 // relevant data about the policy. |
| 28 struct POLICY_EXPORT Entry { | 28 struct POLICY_EXPORT Entry { |
| 29 PolicyLevel level; | 29 PolicyLevel level; |
| 30 PolicyScope scope; | 30 PolicyScope scope; |
| 31 base::Value* value; | 31 base::Value* value; |
| 32 ExternalDataFetcher* external_data_fetcher; | 32 ExternalDataFetcher* external_data_fetcher; |
| 33 | 33 |
| 34 // For debugging and displaying only. Set by provider delivering the policy. | 34 // For debugging and displaying only. Set by provider delivering the policy. |
| 35 PolicySource source; | 35 PolicySource source; |
| 36 | 36 |
| 37 Entry(); | 37 Entry(); |
| 38 | 38 |
| 39 // Deletes all members owned by |this|. | 39 // Deletes all members owned by |this|. |
| 40 void DeleteOwnedMembers(); | 40 void DeleteOwnedMembers(); |
| 41 | 41 |
| 42 // Returns a copy of |this|. | 42 // Returns a copy of |this|. |
| 43 scoped_ptr<Entry> DeepCopy() const; | 43 std::unique_ptr<Entry> DeepCopy() const; |
| 44 | 44 |
| 45 // Returns true if |this| has higher priority than |other|. | 45 // Returns true if |this| has higher priority than |other|. |
| 46 bool has_higher_priority_than(const Entry& other) const; | 46 bool has_higher_priority_than(const Entry& other) const; |
| 47 | 47 |
| 48 // Returns true if |this| equals |other|. | 48 // Returns true if |this| equals |other|. |
| 49 bool Equals(const Entry& other) const; | 49 bool Equals(const Entry& other) const; |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 typedef std::map<std::string, Entry> PolicyMapType; | 52 typedef std::map<std::string, Entry> PolicyMapType; |
| 53 typedef PolicyMapType::const_iterator const_iterator; | 53 typedef PolicyMapType::const_iterator const_iterator; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 76 // Erase the given |policy|, if it exists in this map. | 76 // Erase the given |policy|, if it exists in this map. |
| 77 void Erase(const std::string& policy); | 77 void Erase(const std::string& policy); |
| 78 | 78 |
| 79 // Swaps the internal representation of |this| with |other|. | 79 // Swaps the internal representation of |this| with |other|. |
| 80 void Swap(PolicyMap* other); | 80 void Swap(PolicyMap* other); |
| 81 | 81 |
| 82 // |this| becomes a copy of |other|. Any existing policies are dropped. | 82 // |this| becomes a copy of |other|. Any existing policies are dropped. |
| 83 void CopyFrom(const PolicyMap& other); | 83 void CopyFrom(const PolicyMap& other); |
| 84 | 84 |
| 85 // Returns a copy of |this|. | 85 // Returns a copy of |this|. |
| 86 scoped_ptr<PolicyMap> DeepCopy() const; | 86 std::unique_ptr<PolicyMap> DeepCopy() const; |
| 87 | 87 |
| 88 // Merges policies from |other| into |this|. Existing policies are only | 88 // Merges policies from |other| into |this|. Existing policies are only |
| 89 // overridden by those in |other| if they have a higher priority, as defined | 89 // overridden by those in |other| if they have a higher priority, as defined |
| 90 // by Entry::has_higher_priority_than(). If a policy is contained in both | 90 // by Entry::has_higher_priority_than(). If a policy is contained in both |
| 91 // maps with the same priority, the current value in |this| is preserved. | 91 // maps with the same priority, the current value in |this| is preserved. |
| 92 void MergeFrom(const PolicyMap& other); | 92 void MergeFrom(const PolicyMap& other); |
| 93 | 93 |
| 94 // Loads the values in |policies| into this PolicyMap. All policies loaded | 94 // Loads the values in |policies| into this PolicyMap. All policies loaded |
| 95 // will have |level|, |scope| and |source| in their entries. Existing entries | 95 // will have |level|, |scope| and |source| in their entries. Existing entries |
| 96 // are replaced. | 96 // are replaced. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 126 const PolicyMapType::value_type& b); | 126 const PolicyMapType::value_type& b); |
| 127 | 127 |
| 128 PolicyMapType map_; | 128 PolicyMapType map_; |
| 129 | 129 |
| 130 DISALLOW_COPY_AND_ASSIGN(PolicyMap); | 130 DISALLOW_COPY_AND_ASSIGN(PolicyMap); |
| 131 }; | 131 }; |
| 132 | 132 |
| 133 } // namespace policy | 133 } // namespace policy |
| 134 | 134 |
| 135 #endif // COMPONENTS_POLICY_CORE_COMMON_POLICY_MAP_H_ | 135 #endif // COMPONENTS_POLICY_CORE_COMMON_POLICY_MAP_H_ |
| OLD | NEW |