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

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

Issue 3774003: Cleanup and style guideline conformance for policy implementation (Closed) Base URL: git://codf21.jail/chromium.git
Patch Set: fix windows build and tests Created 10 years, 1 month 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 (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_CONFIGURATION_POLICY_PREF_STORE_H_ 5 #ifndef CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PREF_STORE_H_
6 #define CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PREF_STORE_H_ 6 #define CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PREF_STORE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <set> 10 #include <set>
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/scoped_ptr.h" 13 #include "base/scoped_ptr.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/policy/configuration_policy_provider.h" 15 #include "chrome/browser/policy/configuration_policy_provider.h"
16 #include "chrome/browser/policy/configuration_policy_store.h" 16 #include "chrome/browser/policy/configuration_policy_store_interface.h"
17 #include "chrome/common/pref_store.h" 17 #include "chrome/common/pref_store.h"
18 18
19 namespace policy { 19 namespace policy {
20 20
21 // An implementation of the |PrefStore| that holds a Dictionary 21 // An implementation of the |PrefStore| that holds a Dictionary
22 // created through applied policy. 22 // created through applied policy.
23 class ConfigurationPolicyPrefStore : public PrefStore, 23 class ConfigurationPolicyPrefStore : public PrefStore,
24 public ConfigurationPolicyStore { 24 public ConfigurationPolicyStoreInterface {
25 public: 25 public:
26 typedef std::set<const char*> ProxyPreferenceSet;
27
26 // The ConfigurationPolicyPrefStore does not take ownership of the 28 // The ConfigurationPolicyPrefStore does not take ownership of the
27 // passed-in |provider|. 29 // passed-in |provider|.
28 explicit ConfigurationPolicyPrefStore(ConfigurationPolicyProvider* provider); 30 explicit ConfigurationPolicyPrefStore(ConfigurationPolicyProvider* provider);
29 virtual ~ConfigurationPolicyPrefStore(); 31 virtual ~ConfigurationPolicyPrefStore() {}
30 32
31 // PrefStore methods: 33 // PrefStore methods:
32 virtual PrefReadError ReadPrefs(); 34 virtual PrefReadError ReadPrefs();
33 virtual DictionaryValue* prefs() { return prefs_.get(); } 35 virtual DictionaryValue* prefs() const { return prefs_.get(); }
34 36
35 // ConfigurationPolicyStore methods: 37 // ConfigurationPolicyStore methods:
36 virtual void Apply(PolicyType setting, Value* value); 38 virtual void Apply(ConfigurationPolicyType setting, Value* value);
37 39
38 // Creates a ConfigurationPolicyPrefStore that reads managed policy. 40 // Creates a ConfigurationPolicyPrefStore that reads managed policy.
39 static ConfigurationPolicyPrefStore* CreateManagedPolicyPrefStore(); 41 static ConfigurationPolicyPrefStore* CreateManagedPolicyPrefStore();
40 42
41 // Creates a ConfigurationPolicyPrefStore that reads recommended policy. 43 // Creates a ConfigurationPolicyPrefStore that reads recommended policy.
42 static ConfigurationPolicyPrefStore* CreateRecommendedPolicyPrefStore(); 44 static ConfigurationPolicyPrefStore* CreateRecommendedPolicyPrefStore();
43 45
44 // Returns the default policy definition list for Chrome. 46 // Returns the default policy definition list for Chrome.
45 static ConfigurationPolicyProvider::PolicyDefinitionList* 47 static ConfigurationPolicyProvider::PolicyDefinitionList*
46 GetChromePolicyDefinitionList(); 48 GetChromePolicyDefinitionList();
47 49
48 typedef std::set<const char*> ProxyPreferenceSet;
49
50 // Returns the set of preference paths that can be affected by a proxy 50 // Returns the set of preference paths that can be affected by a proxy
51 // policy. 51 // policy.
52 static void GetProxyPreferenceSet(ProxyPreferenceSet* proxy_pref_set); 52 static void GetProxyPreferenceSet(ProxyPreferenceSet* proxy_pref_set);
53 53
54 private: 54 private:
55 // Policies that map to a single preference are handled 55 // Policies that map to a single preference are handled
56 // by an automated converter. Each one of these policies 56 // by an automated converter. Each one of these policies
57 // has an entry in |simple_policy_map_| with the following type. 57 // has an entry in |simple_policy_map_| with the following type.
58 struct PolicyToPreferenceMapEntry { 58 struct PolicyToPreferenceMapEntry {
59 Value::ValueType value_type; 59 Value::ValueType value_type;
60 PolicyType policy_type; 60 ConfigurationPolicyType policy_type;
61 const char* preference_path; // A DictionaryValue path, not a file path. 61 const char* preference_path; // A DictionaryValue path, not a file path.
62 }; 62 };
63 63
64 static const PolicyToPreferenceMapEntry simple_policy_map_[]; 64 static const PolicyToPreferenceMapEntry kSimplePolicyMap[];
65 static const PolicyToPreferenceMapEntry proxy_policy_map_[]; 65 static const PolicyToPreferenceMapEntry kProxyPolicyMap[];
66 static const PolicyToPreferenceMapEntry default_search_policy_map_[]; 66 static const PolicyToPreferenceMapEntry kDefaultSearchPolicyMap[];
67 static const ConfigurationPolicyProvider::PolicyDefinitionList 67 static const ConfigurationPolicyProvider::PolicyDefinitionList
68 policy_definition_list_; 68 kPolicyDefinitionList;
69 69
70 ConfigurationPolicyProvider* provider_; 70 ConfigurationPolicyProvider* provider_;
71 scoped_ptr<DictionaryValue> prefs_; 71 scoped_ptr<DictionaryValue> prefs_;
72 72
73 // Set to false until the first proxy-relevant policy is applied. At that 73 // Set to false until the first proxy-relevant policy is applied. At that
74 // time, default values are provided for all proxy-relevant prefs 74 // time, default values are provided for all proxy-relevant prefs
75 // to override any values set from stores with a lower priority. 75 // to override any values set from stores with a lower priority.
76 bool lower_priority_proxy_settings_overridden_; 76 bool lower_priority_proxy_settings_overridden_;
77 77
78 // The following are used to track what proxy-relevant policy has been applied 78 // The following are used to track what proxy-relevant policy has been applied
79 // accross calls to Apply to provide a warning if a policy specifies a 79 // accross calls to Apply to provide a warning if a policy specifies a
80 // contradictory proxy configuration. |proxy_disabled_| is set to true if and 80 // contradictory proxy configuration. |proxy_disabled_| is set to true if and
81 // only if the kPolicyNoProxyServer has been applied, 81 // only if the kPolicyNoProxyServer has been applied,
82 // |proxy_configuration_specified_| is set to true if and only if any other 82 // |proxy_configuration_specified_| is set to true if and only if any other
83 // proxy policy other than kPolicyNoProxyServer has been applied. 83 // proxy policy other than kPolicyNoProxyServer has been applied.
84 bool proxy_disabled_; 84 bool proxy_disabled_;
85 bool proxy_configuration_specified_; 85 bool proxy_configuration_specified_;
86 86
87 // Set to true if a the proxy mode policy has been set to force Chrome 87 // Set to true if a the proxy mode policy has been set to force Chrome
88 // to use the system proxy. 88 // to use the system proxy.
89 bool use_system_proxy_; 89 bool use_system_proxy_;
90 90
91 // Returns the map entry that corresponds to |policy| in the map. 91 // Returns the map entry that corresponds to |policy| in the map.
92 const PolicyToPreferenceMapEntry* FindPolicyInMap(PolicyType policy, 92 const PolicyToPreferenceMapEntry* FindPolicyInMap(
93 const PolicyToPreferenceMapEntry* map, int size); 93 ConfigurationPolicyType policy,
94 const PolicyToPreferenceMapEntry* map,
95 int size) const;
94 96
95 // Remove the preferences found in the map from |prefs_|. Returns true if 97 // Remove the preferences found in the map from |prefs_|. Returns true if
96 // any such preferences were found and removed. 98 // any such preferences were found and removed.
97 bool RemovePreferencesOfMap(const PolicyToPreferenceMapEntry* map, 99 bool RemovePreferencesOfMap(const PolicyToPreferenceMapEntry* map,
98 int table_size); 100 int table_size);
99 101
100 bool ApplyPolicyFromMap(PolicyType policy, Value* value, 102 bool ApplyPolicyFromMap(ConfigurationPolicyType policy,
101 const PolicyToPreferenceMapEntry map[], int size); 103 Value* value,
104 const PolicyToPreferenceMapEntry* map,
105 int size);
102 106
103 // Processes proxy-specific policies. Returns true if the specified policy 107 // Processes proxy-specific policies. Returns true if the specified policy
104 // is a proxy-related policy. ApplyProxyPolicy assumes the ownership 108 // is a proxy-related policy. ApplyProxyPolicy assumes the ownership
105 // of |value| in the case that the policy is proxy-specific. 109 // of |value| in the case that the policy is proxy-specific.
106 bool ApplyProxyPolicy(PolicyType policy, Value* value); 110 bool ApplyProxyPolicy(ConfigurationPolicyType policy, Value* value);
107 111
108 // Handles sync-related policies. Returns true if the policy was handled. 112 // Handles sync-related policies. Returns true if the policy was handled.
109 // Assumes ownership of |value| in that case. 113 // Assumes ownership of |value| in that case.
110 bool ApplySyncPolicy(PolicyType policy, Value* value); 114 bool ApplySyncPolicy(ConfigurationPolicyType policy, Value* value);
111 115
112 // Handles policies that affect AutoFill. Returns true if the policy was 116 // Handles policies that affect AutoFill. Returns true if the policy was
113 // handled and assumes ownership of |value| in that case. 117 // handled and assumes ownership of |value| in that case.
114 bool ApplyAutoFillPolicy(PolicyType policy, Value* value); 118 bool ApplyAutoFillPolicy(ConfigurationPolicyType policy, Value* value);
115 119
116 // Make sure that the |path| if present in |prefs_|. If not, set it to 120 // Make sure that the |path| if present in |prefs_|. If not, set it to
117 // a blank string. 121 // a blank string.
118 void EnsureStringPrefExists(const std::string& path); 122 void EnsureStringPrefExists(const std::string& path);
119 123
120 // If the required entries for default search are specified and valid, 124 // If the required entries for default search are specified and valid,
121 // finalizes the policy-specified configuration by initializing the 125 // finalizes the policy-specified configuration by initializing the
122 // unspecified map entries. Otherwise wipes all default search related 126 // unspecified map entries. Otherwise wipes all default search related
123 // map entries from |prefs_|. 127 // map entries from |prefs_|.
124 void FinalizeDefaultSearchPolicySettings(); 128 void FinalizeDefaultSearchPolicySettings();
125 129
126 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyPrefStore); 130 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyPrefStore);
127 }; 131 };
128 132
129 } // namespace policy 133 } // namespace policy
130 134
131 #endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PREF_STORE_H_ 135 #endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PREF_STORE_H_
OLDNEW
« no previous file with comments | « chrome/browser/policy/config_dir_policy_provider_unittest.cc ('k') | chrome/browser/policy/configuration_policy_pref_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698