| Index: components/policy/core/common/policy_map.h
|
| diff --git a/components/policy/core/common/policy_map.h b/components/policy/core/common/policy_map.h
|
| index 9af8c53dee57075d9f82b5a8de97b167a61c4f7d..bd9d291d071db56f10e47f5e68c6e4f2b84265c3 100644
|
| --- a/components/policy/core/common/policy_map.h
|
| +++ b/components/policy/core/common/policy_map.h
|
| @@ -49,23 +49,45 @@ class POLICY_EXPORT PolicyMap {
|
| bool Equals(const Entry& other) const;
|
| };
|
|
|
| - typedef std::map<std::string, Entry> PolicyMapType;
|
| + struct PolicyMapKey {
|
| + std::string name;
|
| +
|
| + // POLICY_LEVEL_COUNT nominally has highest priority in PolicyLevel. Having
|
| + // this as default allows us to use lower_bound() to search by |name| only.
|
| + PolicyLevel level = POLICY_LEVEL_COUNT;
|
| +
|
| + PolicyMapKey();
|
| +
|
| + explicit PolicyMapKey(const std::string& name_in);
|
| +
|
| + PolicyMapKey(const std::string& name_in, PolicyLevel level_in);
|
| +
|
| + bool operator==(const PolicyMapKey& other) const;
|
| +
|
| + bool operator<(const PolicyMapKey& other) const;
|
| +
|
| + int compare(const PolicyMapKey& other) const;
|
| + };
|
| +
|
| + typedef std::map<PolicyMapKey, Entry> PolicyMapType;
|
| typedef PolicyMapType::const_iterator const_iterator;
|
|
|
| PolicyMap();
|
| virtual ~PolicyMap();
|
|
|
| - // Returns a weak reference to the entry currently stored for key |policy|,
|
| - // or NULL if not found. Ownership is retained by the PolicyMap.
|
| + // Returns a weak reference to the highest priority entry currently stored
|
| + // for key |policy|, or null if not found. Ownership is retained by the
|
| + // PolicyMap.
|
| const Entry* Get(const std::string& policy) const;
|
|
|
| - // Returns a weak reference to the value currently stored for key |policy|,
|
| - // or NULL if not found. Ownership is retained by the PolicyMap.
|
| - // This is equivalent to Get(policy)->value, when it doesn't return NULL.
|
| + // Returns a weak reference to the highest priority entry currently stored
|
| + // under key |policy|, or null if not found. Ownership is retained by the
|
| + // PolicyMap.
|
| + // This is equivalent to Get(policy)->value, when it doesn't return null.
|
| const base::Value* GetValue(const std::string& policy) const;
|
|
|
| // Takes ownership of |value| and |external_data_fetcher|. Overwrites any
|
| - // existing information stored in the map for the key |policy|.
|
| + // existing information stored in the map for the key (|policy|, |level|).
|
| void Set(const std::string& policy,
|
| PolicyLevel level,
|
| PolicyScope scope,
|
| @@ -73,7 +95,7 @@ class POLICY_EXPORT PolicyMap {
|
| base::Value* value,
|
| ExternalDataFetcher* external_data_fetcher);
|
|
|
| - // Erase the given |policy|, if it exists in this map.
|
| + // Erase all given |policy| that exists in this map.
|
| void Erase(const std::string& policy);
|
|
|
| // Swaps the internal representation of |this| with |other|.
|
| @@ -85,6 +107,7 @@ class POLICY_EXPORT PolicyMap {
|
| // Returns a copy of |this|.
|
| scoped_ptr<PolicyMap> DeepCopy() const;
|
|
|
| + // TODO(huangs): Update comment.
|
| // Merges policies from |other| into |this|. Existing policies are only
|
| // overridden by those in |other| if they have a higher priority, as defined
|
| // by Entry::has_higher_priority_than(). If a policy is contained in both
|
| @@ -104,7 +127,10 @@ class POLICY_EXPORT PolicyMap {
|
| // This includes keys that are present only in one of the maps.
|
| // |differing_keys| is not cleared before the keys are added.
|
| void GetDifferingKeys(const PolicyMap& other,
|
| - std::set<std::string>* differing_keys) const;
|
| + std::set<PolicyMapKey>* differing_keys) const;
|
| +
|
| + void GetDifferingKeyNames(const PolicyMap& other,
|
| + std::set<std::string>* differing_key_names) const;
|
|
|
| // Removes all policies that don't have the specified |level|. This is a
|
| // temporary helper method, until mandatory and recommended levels are served
|
| @@ -118,6 +144,9 @@ class POLICY_EXPORT PolicyMap {
|
|
|
| const_iterator begin() const;
|
| const_iterator end() const;
|
| + void next_dominant(const_iterator* it) const;
|
| + void next_all(const_iterator* it) const;
|
| +
|
| void Clear();
|
|
|
| private:
|
| @@ -125,6 +154,10 @@ class POLICY_EXPORT PolicyMap {
|
| static bool MapEntryEquals(const PolicyMapType::value_type& a,
|
| const PolicyMapType::value_type& b);
|
|
|
| + PolicyMapType::iterator lower_bound(const std::string& policy);
|
| +
|
| + const_iterator lower_bound(const std::string& policy) const;
|
| +
|
| PolicyMapType map_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(PolicyMap);
|
|
|