| 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> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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 std::unique_ptr<base::Value> value; |
| 32 ExternalDataFetcher* external_data_fetcher; | 32 std::unique_ptr<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 ~Entry(); |
| 38 | 39 |
| 39 // Deletes all members owned by |this|. | 40 Entry(Entry&&); |
| 40 void DeleteOwnedMembers(); | 41 Entry& operator=(Entry&&); |
| 41 | 42 |
| 42 // Returns a copy of |this|. | 43 // Returns a copy of |this|. |
| 43 std::unique_ptr<Entry> DeepCopy() const; | 44 Entry DeepCopy() const; |
| 44 | 45 |
| 45 // Returns true if |this| has higher priority than |other|. | 46 // Returns true if |this| has higher priority than |other|. |
| 46 bool has_higher_priority_than(const Entry& other) const; | 47 bool has_higher_priority_than(const Entry& other) const; |
| 47 | 48 |
| 48 // Returns true if |this| equals |other|. | 49 // Returns true if |this| equals |other|. |
| 49 bool Equals(const Entry& other) const; | 50 bool Equals(const Entry& other) const; |
| 50 }; | 51 }; |
| 51 | 52 |
| 52 typedef std::map<std::string, Entry> PolicyMapType; | 53 typedef std::map<std::string, Entry> PolicyMapType; |
| 53 typedef PolicyMapType::const_iterator const_iterator; | 54 typedef PolicyMapType::const_iterator const_iterator; |
| 54 | 55 |
| 55 PolicyMap(); | 56 PolicyMap(); |
| 56 virtual ~PolicyMap(); | 57 virtual ~PolicyMap(); |
| 57 | 58 |
| 58 // Returns a weak reference to the entry currently stored for key |policy|, | 59 // Returns a weak reference to the entry currently stored for key |policy|, |
| 59 // or NULL if not found. Ownership is retained by the PolicyMap. | 60 // or NULL if not found. Ownership is retained by the PolicyMap. |
| 60 const Entry* Get(const std::string& policy) const; | 61 const Entry* Get(const std::string& policy) const; |
| 61 | 62 |
| 62 // Returns a weak reference to the value currently stored for key |policy|, | 63 // Returns a weak reference to the value currently stored for key |policy|, |
| 63 // or NULL if not found. Ownership is retained by the PolicyMap. | 64 // or NULL if not found. Ownership is retained by the PolicyMap. |
| 64 // This is equivalent to Get(policy)->value, when it doesn't return NULL. | 65 // This is equivalent to Get(policy)->value, when it doesn't return NULL. |
| 65 const base::Value* GetValue(const std::string& policy) const; | 66 const base::Value* GetValue(const std::string& policy) const; |
| 66 | 67 |
| 67 // Takes ownership of |value| and |external_data_fetcher|. Overwrites any | 68 // Overwrites any existing information stored in the map for the key |policy|. |
| 68 // existing information stored in the map for the key |policy|. | |
| 69 void Set(const std::string& policy, | 69 void Set(const std::string& policy, |
| 70 PolicyLevel level, | 70 PolicyLevel level, |
| 71 PolicyScope scope, | 71 PolicyScope scope, |
| 72 PolicySource source, | 72 PolicySource source, |
| 73 base::Value* value, | 73 std::unique_ptr<base::Value> value, |
| 74 ExternalDataFetcher* external_data_fetcher); | 74 std::unique_ptr<ExternalDataFetcher> external_data_fetcher); |
| 75 void Set(const std::string& policy, Entry entry); |
| 75 | 76 |
| 76 // Erase the given |policy|, if it exists in this map. | 77 // Erase the given |policy|, if it exists in this map. |
| 77 void Erase(const std::string& policy); | 78 void Erase(const std::string& policy); |
| 78 | 79 |
| 79 // Swaps the internal representation of |this| with |other|. | 80 // Swaps the internal representation of |this| with |other|. |
| 80 void Swap(PolicyMap* other); | 81 void Swap(PolicyMap* other); |
| 81 | 82 |
| 82 // |this| becomes a copy of |other|. Any existing policies are dropped. | 83 // |this| becomes a copy of |other|. Any existing policies are dropped. |
| 83 void CopyFrom(const PolicyMap& other); | 84 void CopyFrom(const PolicyMap& other); |
| 84 | 85 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 const PolicyMapType::value_type& b); | 127 const PolicyMapType::value_type& b); |
| 127 | 128 |
| 128 PolicyMapType map_; | 129 PolicyMapType map_; |
| 129 | 130 |
| 130 DISALLOW_COPY_AND_ASSIGN(PolicyMap); | 131 DISALLOW_COPY_AND_ASSIGN(PolicyMap); |
| 131 }; | 132 }; |
| 132 | 133 |
| 133 } // namespace policy | 134 } // namespace policy |
| 134 | 135 |
| 135 #endif // COMPONENTS_POLICY_CORE_COMMON_POLICY_MAP_H_ | 136 #endif // COMPONENTS_POLICY_CORE_COMMON_POLICY_MAP_H_ |
| OLD | NEW |