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

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: 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
« no previous file with comments | « chrome/browser/policy/policy_error_map.cc ('k') | chrome/browser/policy/policy_map.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,
25
26 // MANDATORY policies must be enforced and users can't circumvent them.
27 POLICY_LEVEL_MANDATORY,
28 };
29
30 // The scope of a policy flags whether it is meant to be applied to the current
31 // user or to the machine.
32 enum PolicyScope {
33 // USER policies apply to sessions of the current user.
34 POLICY_SCOPE_USER,
35
36 // MACHINE policies apply to any users of the current machine.
37 POLICY_SCOPE_MACHINE,
38 };
39
40 // A mapping of policy names to policy values for a given policy namespace.
21 class PolicyMap { 41 class PolicyMap {
22 public: 42 public:
23 typedef std::map<ConfigurationPolicyType, Value*> PolicyMapType; 43 // Each policy maps to an Entry which keeps the policy value as well as other
44 // relevant data about the policy.
45 struct Entry {
46 PolicyLevel level;
47 PolicyScope scope;
48 Value* value;
49
50 Entry()
51 : level(POLICY_LEVEL_RECOMMENDED),
52 scope(POLICY_SCOPE_USER),
53 value(NULL) {}
54
55 // Returns true if |this| has higher priority than |other|.
56 bool has_higher_priority_than(const Entry& other) const;
57
58 // Returns true if |this| equals |other|.
59 bool Equals(const Entry& other) const;
60 };
61
62 typedef std::map<std::string, Entry> PolicyMapType;
24 typedef PolicyMapType::const_iterator const_iterator; 63 typedef PolicyMapType::const_iterator const_iterator;
25 64
26 PolicyMap(); 65 PolicyMap();
27 virtual ~PolicyMap(); 66 virtual ~PolicyMap();
28 67
29 // Returns a weak reference to the value currently stored for key |policy|. 68 // Returns a weak reference to the entry currently stored for key |policy|,
30 // Ownership is retained by PolicyMap; callers should use Value::DeepCopy 69 // or NULL if not found. Ownership is retained by the PolicyMap.
31 // if they need a copy that they own themselves. 70 const Entry* Get(const std::string& policy) const;
32 // Returns NULL if the map does not contain a value for |policy|. 71
33 const Value* Get(ConfigurationPolicyType policy) const; 72 // Returns a weak reference to the value currently stored for key |policy|,
73 // or NULL if not found. Ownership is retained by the PolicyMap.
74 // This is equivalent to Get(policy)->value, when it doesn't return NULL.
75 const Value* GetValue(const std::string& policy) const;
76
34 // Takes ownership of |value|. Overwrites any existing value stored in the 77 // Takes ownership of |value|. Overwrites any existing value stored in the
35 // map for the key |policy|. 78 // map for the key |policy|.
36 void Set(ConfigurationPolicyType policy, Value* value); 79 void Set(const std::string& policy,
37 void Erase(ConfigurationPolicyType policy); 80 PolicyLevel level,
81 PolicyScope scope,
82 Value* value);
38 83
84 // Erase the given |policy|, if it exists in this map.
85 void Erase(const std::string& policy);
86
87 // Swaps the internal representation of |this| with |other|.
39 void Swap(PolicyMap* other); 88 void Swap(PolicyMap* other);
89
90 // |this| becomes a copy of |other|. Any existing policies are dropped.
40 void CopyFrom(const PolicyMap& other); 91 void CopyFrom(const PolicyMap& other);
41 92
42 // Similar to CopyFrom, but doesn't Clear() |this| before merging, and only 93 // Similar to CopyFrom, but doesn't Clear() |this| before merging, and only
43 // merges keys that aren't already contained in |this|. 94 // merges keys that aren't already contained in |this|.
95
96 // Merges policies from |other| into |this|. Existing policies are only
97 // overridden by those in |other| if they have a higher priority, as defined
98 // by Entry::has_higher_priority_than(). If a policy is contained in both
99 // maps with the same priority, the current value in |this| is preserved.
44 void MergeFrom(const PolicyMap& other); 100 void MergeFrom(const PolicyMap& other);
45 101
46 // Loads the values in |policies| into this PolicyMap, mapped to their 102 // Loads the values in |policies| into this PolicyMap, mapped to their
47 // corresponding policy type. The policies to load, and their types, are 103 // corresponding policy type. The policies to load, and their types, are
48 // listed in |list|. 104 // listed in |list|. All policies loaded will have |level| and |scope| in
105 // their entries.
49 void LoadFrom(const DictionaryValue* policies, 106 void LoadFrom(const DictionaryValue* policies,
50 const PolicyDefinitionList* list); 107 const PolicyDefinitionList* list,
108 PolicyLevel level,
109 PolicyScope scope);
110
111 // Compares this value map against |other| and stores all key names that have
112 // different values in |differing_keys|. This includes keys that are present
113 // only in one of the maps. |differing_keys| is not cleared before the keys
114 // are added.
115 void GetDifferingKeys(const PolicyMap& other,
116 std::set<std::string>* differing_keys) const;
117
118 // Removes all policies that don't have the specified |level|. This is a
119 // temporary helper method, until mandatory and recommended levels are served
120 // by a single provider.
121 // TODO(joaodasilva): Remove this. http://crbug.com/108999
122 void FilterLevel(PolicyLevel level);
51 123
52 bool Equals(const PolicyMap& other) const; 124 bool Equals(const PolicyMap& other) const;
53 bool empty() const; 125 bool empty() const;
54 size_t size() const; 126 size_t size() const;
55 127
56 const_iterator begin() const; 128 const_iterator begin() const;
57 const_iterator end() const; 129 const_iterator end() const;
58 void Clear(); 130 void Clear();
59 131
60 private: 132 private:
61 // Helper function for Equals(...). 133 // Helper function for Equals().
62 static bool MapEntryEquals(const PolicyMapType::value_type& a, 134 static bool MapEntryEquals(const PolicyMapType::value_type& a,
63 const PolicyMapType::value_type& b); 135 const PolicyMapType::value_type& b);
64 136
65 PolicyMapType map_; 137 PolicyMapType map_;
66 138
67 DISALLOW_COPY_AND_ASSIGN(PolicyMap); 139 DISALLOW_COPY_AND_ASSIGN(PolicyMap);
68 }; 140 };
69 141
70 } // namespace policy 142 } // namespace policy
71 143
72 #endif // CHROME_BROWSER_POLICY_POLICY_MAP_H_ 144 #endif // CHROME_BROWSER_POLICY_POLICY_MAP_H_
OLDNEW
« no previous file with comments | « chrome/browser/policy/policy_error_map.cc ('k') | chrome/browser/policy/policy_map.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698