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

Side by Side Diff: chrome/browser/policy/policy_map.h

Issue 9111022: Removed ConfigurationPolicyType and extended PolicyMap. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed builds, rebased Created 8 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 CHROME_BROWSER_POLICY_POLICY_MAP_H_ 5 #ifndef CHROME_BROWSER_POLICY_POLICY_MAP_H_
6 #define CHROME_BROWSER_POLICY_POLICY_MAP_H_ 6 #define CHROME_BROWSER_POLICY_POLICY_MAP_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <set>
11 #include <string>
10 12
11 #include "base/values.h" 13 #include "base/values.h"
12 #include "policy/configuration_policy_type.h"
13 14
14 namespace policy { 15 namespace policy {
15 16
16 struct PolicyDefinitionList; 17 struct PolicyDefinitionList;
17 18
18 // Wrapper class around a std::map<ConfigurationPolicyType, Value*> that 19 // The level of a policy determines its enforceability and whether users can
19 // properly cleans up after itself when going out of scope. 20 // override it or not. The values are listed in increasing order of priority.
20 // Exposes interesting methods of the underlying std::map. 21 enum PolicyLevel {
22 // RECOMMENDED policies can be overridden by users. They are meant as a
23 // default value configured by admins, that users can customize.
24 POLICY_LEVEL_RECOMMENDED = 0,
Mattias Nissler (ping if slow) 2012/01/17 09:52:45 don't need the = 0
Joao da Silva 2012/01/17 13:09:29 Done.
25
26 // MANDATORY policies must be enforced and users can't circumvent them.
27 POLICY_LEVEL_MANDATORY,
28 };
29
30 // Most Chrome policies apply to the "user", but some can apply to the "device",
31 // particularly on ChromeOS. The scope of a policy determines where it should
32 // be applied. The values are listed in increasing order of priority.
Mattias Nissler (ping if slow) 2012/01/17 09:52:45 I don't think that description matches what the po
Joao da Silva 2012/01/17 13:09:29 Rewrote the comments. Renaming SCOPE_DEVICE to SCO
33 enum PolicyScope {
34 // USER policies apply to sessions of the current user.
35 POLICY_SCOPE_USER = 0,
Mattias Nissler (ping if slow) 2012/01/17 09:52:45 ditto
Joao da Silva 2012/01/17 13:09:29 Done.
36
37 // DEVICE policies apply to any users of the current device.
38 POLICY_SCOPE_DEVICE,
39
Mattias Nissler (ping if slow) 2012/01/17 09:52:45 stray newline
Joao da Silva 2012/01/17 13:09:29 Done.
40 };
41
42 // A mapping of policy names to policy values for a given policy namespace.
21 class PolicyMap { 43 class PolicyMap {
22 public: 44 public:
23 typedef std::map<ConfigurationPolicyType, Value*> PolicyMapType; 45 // Each policy maps to an Entry which keeps the policy value as well as other
46 // relevant data about the policy.
47 struct Entry {
48 PolicyLevel level;
49 PolicyScope scope;
50 Value* value;
51
52 // Returns true if |this| has higher priority than |other|.
53 bool has_higher_priority_than(const Entry& other) const;
54
55 // Returns true if |this| equals |other|.
56 bool equals(const Entry& other) const;
Mattias Nissler (ping if slow) 2012/01/17 09:52:45 Should be Equals?
Joao da Silva 2012/01/17 13:09:29 Done.
57 };
58
59 typedef std::map<std::string, Entry> PolicyMapType;
24 typedef PolicyMapType::const_iterator const_iterator; 60 typedef PolicyMapType::const_iterator const_iterator;
25 61
26 PolicyMap(); 62 PolicyMap();
27 virtual ~PolicyMap(); 63 virtual ~PolicyMap();
28 64
29 // Returns a weak reference to the value currently stored for key |policy|. 65 // Returns a weak reference to the entry currently stored for key |policy|,
30 // Ownership is retained by PolicyMap; callers should use Value::DeepCopy 66 // or NULL if not found. Ownership is retained by the PolicyMap.
31 // if they need a copy that they own themselves. 67 const Entry* Get(const std::string& policy) const;
32 // Returns NULL if the map does not contain a value for |policy|. 68
33 const Value* Get(ConfigurationPolicyType policy) const; 69 // Returns a weak reference to the value currently stored for key |policy|,
70 // or NULL if not found. Ownership is retained by the PolicyMap.
71 // This is equivalent to Get(policy)->value, when it doesn't return NULL.
72 const Value* GetValue(const std::string& policy) const;
73
34 // Takes ownership of |value|. Overwrites any existing value stored in the 74 // Takes ownership of |value|. Overwrites any existing value stored in the
35 // map for the key |policy|. 75 // map for the key |policy|.
36 void Set(ConfigurationPolicyType policy, Value* value); 76 void Set(const std::string& policy,
37 void Erase(ConfigurationPolicyType policy); 77 PolicyLevel level,
78 PolicyScope scope,
79 Value* value);
38 80
81 // Erase the given |policy|, if it exists in this map.
82 void Erase(const std::string& policy);
83
84 // Swaps the internal representation of |this| with |other|.
39 void Swap(PolicyMap* other); 85 void Swap(PolicyMap* other);
86
87 // |this| becomes a copy of |other|. Any existing policies are dropped.
40 void CopyFrom(const PolicyMap& other); 88 void CopyFrom(const PolicyMap& other);
41 89
42 // Similar to CopyFrom, but doesn't Clear() |this| before merging, and only 90 // Similar to CopyFrom, but doesn't Clear() |this| before merging, and only
43 // merges keys that aren't already contained in |this|. 91 // merges keys that aren't already contained in |this|.
92
93 // Merges policies from |other| into |this|. Existing policies are only
94 // overridden by those in |other| if they have a higher priority, as defined
95 // by Entry::has_higher_priority_than(). If a policy is contained in both
96 // maps with the same priority, the current value in |this| is preserved.
44 void MergeFrom(const PolicyMap& other); 97 void MergeFrom(const PolicyMap& other);
45 98
46 // Loads the values in |policies| into this PolicyMap, mapped to their 99 // Loads the values in |policies| into this PolicyMap, mapped to their
47 // corresponding policy type. The policies to load, and their types, are 100 // corresponding policy type. The policies to load, and their types, are
48 // listed in |list|. 101 // listed in |list|. All policies loaded will have |level| and |scope| in
102 // their entries.
49 void LoadFrom(const DictionaryValue* policies, 103 void LoadFrom(const DictionaryValue* policies,
50 const PolicyDefinitionList* list); 104 const PolicyDefinitionList* list,
105 PolicyLevel level,
106 PolicyScope scope);
107
108 // Compares this value map against |other| and stores all key names that have
109 // different values in |differing_keys|. This includes keys that are present
110 // only in one of the maps. |differing_keys| is not cleared before the keys
111 // are added.
112 void GetDifferingKeys(const PolicyMap& other,
113 std::set<std::string>* differing_keys) const;
114
115 // Removes all policies that don't have the specified |level|. This is a
116 // temporary helper method, until providers aren't split into mandatory and
Mattias Nissler (ping if slow) 2012/01/17 09:52:45 had to re-read the sentence. Perhaps: "until manda
Joao da Silva 2012/01/17 13:09:29 Done.
117 // recommended levels.
118 // TODO(joaodasilva): Remove this. http://crbug.com/108999
119 void FilterLevel(PolicyLevel level);
51 120
52 bool Equals(const PolicyMap& other) const; 121 bool Equals(const PolicyMap& other) const;
53 bool empty() const; 122 bool empty() const;
54 size_t size() const; 123 size_t size() const;
55 124
56 const_iterator begin() const; 125 const_iterator begin() const;
57 const_iterator end() const; 126 const_iterator end() const;
58 void Clear(); 127 void Clear();
59 128
60 private: 129 private:
61 // Helper function for Equals(...). 130 // Helper function for Equals().
62 static bool MapEntryEquals(const PolicyMapType::value_type& a, 131 static bool MapEntryEquals(const PolicyMapType::value_type& a,
63 const PolicyMapType::value_type& b); 132 const PolicyMapType::value_type& b);
64 133
65 PolicyMapType map_; 134 PolicyMapType map_;
66 135
67 DISALLOW_COPY_AND_ASSIGN(PolicyMap); 136 DISALLOW_COPY_AND_ASSIGN(PolicyMap);
68 }; 137 };
69 138
70 } // namespace policy 139 } // namespace policy
71 140
72 #endif // CHROME_BROWSER_POLICY_POLICY_MAP_H_ 141 #endif // CHROME_BROWSER_POLICY_POLICY_MAP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698