Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: components/policy/core/common/policy_map.h

Issue 1825173003: [Policy Experimental] Add "recommended" policies for URL exceptions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 // Returns a copy of |this|. 42 // Returns a copy of |this|.
43 scoped_ptr<Entry> DeepCopy() const; 43 scoped_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 struct PolicyMapKey {
53 std::string name;
54
55 // POLICY_LEVEL_COUNT nominally has highest priority in PolicyLevel. Having
56 // this as default allows us to use lower_bound() to search by |name| only.
57 PolicyLevel level = POLICY_LEVEL_COUNT;
58
59 PolicyMapKey();
60
61 explicit PolicyMapKey(const std::string& name_in);
62
63 PolicyMapKey(const std::string& name_in, PolicyLevel level_in);
64
65 bool operator==(const PolicyMapKey& other) const;
66
67 bool operator<(const PolicyMapKey& other) const;
68
69 int compare(const PolicyMapKey& other) const;
70 };
71
72 typedef std::map<PolicyMapKey, Entry> PolicyMapType;
53 typedef PolicyMapType::const_iterator const_iterator; 73 typedef PolicyMapType::const_iterator const_iterator;
54 74
55 PolicyMap(); 75 PolicyMap();
56 virtual ~PolicyMap(); 76 virtual ~PolicyMap();
57 77
58 // Returns a weak reference to the entry currently stored for key |policy|, 78 // Returns a weak reference to the highest priority entry currently stored
59 // or NULL if not found. Ownership is retained by the PolicyMap. 79 // for key |policy|, or null if not found. Ownership is retained by the
80 // PolicyMap.
60 const Entry* Get(const std::string& policy) const; 81 const Entry* Get(const std::string& policy) const;
61 82
62 // Returns a weak reference to the value currently stored for key |policy|, 83 // Returns a weak reference to the highest priority entry currently stored
63 // or NULL if not found. Ownership is retained by the PolicyMap. 84 // under key |policy|, or null if not found. Ownership is retained by the
64 // This is equivalent to Get(policy)->value, when it doesn't return NULL. 85 // PolicyMap.
86 // This is equivalent to Get(policy)->value, when it doesn't return null.
65 const base::Value* GetValue(const std::string& policy) const; 87 const base::Value* GetValue(const std::string& policy) const;
66 88
67 // Takes ownership of |value| and |external_data_fetcher|. Overwrites any 89 // Takes ownership of |value| and |external_data_fetcher|. Overwrites any
68 // existing information stored in the map for the key |policy|. 90 // existing information stored in the map for the key (|policy|, |level|).
69 void Set(const std::string& policy, 91 void Set(const std::string& policy,
70 PolicyLevel level, 92 PolicyLevel level,
71 PolicyScope scope, 93 PolicyScope scope,
72 PolicySource source, 94 PolicySource source,
73 base::Value* value, 95 base::Value* value,
74 ExternalDataFetcher* external_data_fetcher); 96 ExternalDataFetcher* external_data_fetcher);
75 97
76 // Erase the given |policy|, if it exists in this map. 98 // Erase all given |policy| that exists in this map.
77 void Erase(const std::string& policy); 99 void Erase(const std::string& policy);
78 100
79 // Swaps the internal representation of |this| with |other|. 101 // Swaps the internal representation of |this| with |other|.
80 void Swap(PolicyMap* other); 102 void Swap(PolicyMap* other);
81 103
82 // |this| becomes a copy of |other|. Any existing policies are dropped. 104 // |this| becomes a copy of |other|. Any existing policies are dropped.
83 void CopyFrom(const PolicyMap& other); 105 void CopyFrom(const PolicyMap& other);
84 106
85 // Returns a copy of |this|. 107 // Returns a copy of |this|.
86 scoped_ptr<PolicyMap> DeepCopy() const; 108 scoped_ptr<PolicyMap> DeepCopy() const;
87 109
110 // TODO(huangs): Update comment.
88 // Merges policies from |other| into |this|. Existing policies are only 111 // Merges policies from |other| into |this|. Existing policies are only
89 // overridden by those in |other| if they have a higher priority, as defined 112 // 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 113 // 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. 114 // maps with the same priority, the current value in |this| is preserved.
92 void MergeFrom(const PolicyMap& other); 115 void MergeFrom(const PolicyMap& other);
93 116
94 // Loads the values in |policies| into this PolicyMap. All policies loaded 117 // Loads the values in |policies| into this PolicyMap. All policies loaded
95 // will have |level|, |scope| and |source| in their entries. Existing entries 118 // will have |level|, |scope| and |source| in their entries. Existing entries
96 // are replaced. 119 // are replaced.
97 void LoadFrom(const base::DictionaryValue* policies, 120 void LoadFrom(const base::DictionaryValue* policies,
98 PolicyLevel level, 121 PolicyLevel level,
99 PolicyScope scope, 122 PolicyScope scope,
100 PolicySource source); 123 PolicySource source);
101 124
102 // Compares this value map against |other| and stores all key names that have 125 // Compares this value map against |other| and stores all key names that have
103 // different values or reference different external data in |differing_keys|. 126 // different values or reference different external data in |differing_keys|.
104 // This includes keys that are present only in one of the maps. 127 // This includes keys that are present only in one of the maps.
105 // |differing_keys| is not cleared before the keys are added. 128 // |differing_keys| is not cleared before the keys are added.
106 void GetDifferingKeys(const PolicyMap& other, 129 void GetDifferingKeys(const PolicyMap& other,
107 std::set<std::string>* differing_keys) const; 130 std::set<PolicyMapKey>* differing_keys) const;
131
132 void GetDifferingKeyNames(const PolicyMap& other,
133 std::set<std::string>* differing_key_names) const;
108 134
109 // Removes all policies that don't have the specified |level|. This is a 135 // Removes all policies that don't have the specified |level|. This is a
110 // temporary helper method, until mandatory and recommended levels are served 136 // temporary helper method, until mandatory and recommended levels are served
111 // by a single provider. 137 // by a single provider.
112 // TODO(joaodasilva): Remove this. http://crbug.com/108999 138 // TODO(joaodasilva): Remove this. http://crbug.com/108999
113 void FilterLevel(PolicyLevel level); 139 void FilterLevel(PolicyLevel level);
114 140
115 bool Equals(const PolicyMap& other) const; 141 bool Equals(const PolicyMap& other) const;
116 bool empty() const; 142 bool empty() const;
117 size_t size() const; 143 size_t size() const;
118 144
119 const_iterator begin() const; 145 const_iterator begin() const;
120 const_iterator end() const; 146 const_iterator end() const;
147 void next_dominant(const_iterator* it) const;
148 void next_all(const_iterator* it) const;
149
121 void Clear(); 150 void Clear();
122 151
123 private: 152 private:
124 // Helper function for Equals(). 153 // Helper function for Equals().
125 static bool MapEntryEquals(const PolicyMapType::value_type& a, 154 static bool MapEntryEquals(const PolicyMapType::value_type& a,
126 const PolicyMapType::value_type& b); 155 const PolicyMapType::value_type& b);
127 156
157 PolicyMapType::iterator lower_bound(const std::string& policy);
158
159 const_iterator lower_bound(const std::string& policy) const;
160
128 PolicyMapType map_; 161 PolicyMapType map_;
129 162
130 DISALLOW_COPY_AND_ASSIGN(PolicyMap); 163 DISALLOW_COPY_AND_ASSIGN(PolicyMap);
131 }; 164 };
132 165
133 } // namespace policy 166 } // namespace policy
134 167
135 #endif // COMPONENTS_POLICY_CORE_COMMON_POLICY_MAP_H_ 168 #endif // COMPONENTS_POLICY_CORE_COMMON_POLICY_MAP_H_
OLDNEW
« no previous file with comments | « components/policy/core/browser/configuration_policy_pref_store.cc ('k') | components/policy/core/common/policy_map.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698