| 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 <memory> |
| 12 #include <set> | 12 #include <set> |
| 13 #include <string> | 13 #include <string> |
| 14 | 14 |
| 15 #include "base/callback.h" |
| 15 #include "base/macros.h" | 16 #include "base/macros.h" |
| 16 #include "base/values.h" | 17 #include "base/values.h" |
| 17 #include "components/policy/core/common/external_data_fetcher.h" | 18 #include "components/policy/core/common/external_data_fetcher.h" |
| 18 #include "components/policy/core/common/policy_types.h" | 19 #include "components/policy/core/common/policy_types.h" |
| 19 #include "components/policy/policy_export.h" | 20 #include "components/policy/policy_export.h" |
| 20 | 21 |
| 21 namespace policy { | 22 namespace policy { |
| 22 | 23 |
| 23 // A mapping of policy names to policy values for a given policy namespace. | 24 // A mapping of policy names to policy values for a given policy namespace. |
| 24 class POLICY_EXPORT PolicyMap { | 25 class POLICY_EXPORT PolicyMap { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 PolicyLevel level, | 71 PolicyLevel level, |
| 71 PolicyScope scope, | 72 PolicyScope scope, |
| 72 PolicySource source, | 73 PolicySource source, |
| 73 std::unique_ptr<base::Value> value, | 74 std::unique_ptr<base::Value> value, |
| 74 std::unique_ptr<ExternalDataFetcher> external_data_fetcher); | 75 std::unique_ptr<ExternalDataFetcher> external_data_fetcher); |
| 75 void Set(const std::string& policy, Entry entry); | 76 void Set(const std::string& policy, Entry entry); |
| 76 | 77 |
| 77 // Erase the given |policy|, if it exists in this map. | 78 // Erase the given |policy|, if it exists in this map. |
| 78 void Erase(const std::string& policy); | 79 void Erase(const std::string& policy); |
| 79 | 80 |
| 81 // Erase all entries for which |filter| returns false. |
| 82 void EraseNonmatching( |
| 83 const base::Callback<bool(const const_iterator)>& filter); |
| 84 |
| 80 // Swaps the internal representation of |this| with |other|. | 85 // Swaps the internal representation of |this| with |other|. |
| 81 void Swap(PolicyMap* other); | 86 void Swap(PolicyMap* other); |
| 82 | 87 |
| 83 // |this| becomes a copy of |other|. Any existing policies are dropped. | 88 // |this| becomes a copy of |other|. Any existing policies are dropped. |
| 84 void CopyFrom(const PolicyMap& other); | 89 void CopyFrom(const PolicyMap& other); |
| 85 | 90 |
| 86 // Returns a copy of |this|. | 91 // Returns a copy of |this|. |
| 87 std::unique_ptr<PolicyMap> DeepCopy() const; | 92 std::unique_ptr<PolicyMap> DeepCopy() const; |
| 88 | 93 |
| 89 // Merges policies from |other| into |this|. Existing policies are only | 94 // Merges policies from |other| into |this|. Existing policies are only |
| (...skipping 10 matching lines...) Expand all Loading... |
| 100 PolicyScope scope, | 105 PolicyScope scope, |
| 101 PolicySource source); | 106 PolicySource source); |
| 102 | 107 |
| 103 // Compares this value map against |other| and stores all key names that have | 108 // Compares this value map against |other| and stores all key names that have |
| 104 // different values or reference different external data in |differing_keys|. | 109 // different values or reference different external data in |differing_keys|. |
| 105 // This includes keys that are present only in one of the maps. | 110 // This includes keys that are present only in one of the maps. |
| 106 // |differing_keys| is not cleared before the keys are added. | 111 // |differing_keys| is not cleared before the keys are added. |
| 107 void GetDifferingKeys(const PolicyMap& other, | 112 void GetDifferingKeys(const PolicyMap& other, |
| 108 std::set<std::string>* differing_keys) const; | 113 std::set<std::string>* differing_keys) const; |
| 109 | 114 |
| 110 // Removes all policies that don't have the specified |level|. This is a | |
| 111 // temporary helper method, until mandatory and recommended levels are served | |
| 112 // by a single provider. | |
| 113 // TODO(joaodasilva): Remove this. http://crbug.com/108999 | |
| 114 void FilterLevel(PolicyLevel level); | |
| 115 | |
| 116 bool Equals(const PolicyMap& other) const; | 115 bool Equals(const PolicyMap& other) const; |
| 117 bool empty() const; | 116 bool empty() const; |
| 118 size_t size() const; | 117 size_t size() const; |
| 119 | 118 |
| 120 const_iterator begin() const; | 119 const_iterator begin() const; |
| 121 const_iterator end() const; | 120 const_iterator end() const; |
| 122 void Clear(); | 121 void Clear(); |
| 123 | 122 |
| 124 private: | 123 private: |
| 125 // Helper function for Equals(). | 124 // Helper function for Equals(). |
| 126 static bool MapEntryEquals(const PolicyMapType::value_type& a, | 125 static bool MapEntryEquals(const PolicyMapType::value_type& a, |
| 127 const PolicyMapType::value_type& b); | 126 const PolicyMapType::value_type& b); |
| 128 | 127 |
| 129 PolicyMapType map_; | 128 PolicyMapType map_; |
| 130 | 129 |
| 131 DISALLOW_COPY_AND_ASSIGN(PolicyMap); | 130 DISALLOW_COPY_AND_ASSIGN(PolicyMap); |
| 132 }; | 131 }; |
| 133 | 132 |
| 134 } // namespace policy | 133 } // namespace policy |
| 135 | 134 |
| 136 #endif // COMPONENTS_POLICY_CORE_COMMON_POLICY_MAP_H_ | 135 #endif // COMPONENTS_POLICY_CORE_COMMON_POLICY_MAP_H_ |
| OLD | NEW |