OLD | NEW |
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 <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/gtest_prod_util.h" | 13 #include "base/observer_list.h" |
14 #include "base/scoped_ptr.h" | 14 #include "base/scoped_ptr.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "chrome/browser/policy/configuration_policy_provider.h" | 16 #include "chrome/browser/policy/configuration_policy_provider.h" |
17 #include "chrome/browser/policy/configuration_policy_store_interface.h" | 17 #include "chrome/browser/policy/configuration_policy_store_interface.h" |
| 18 #include "chrome/common/notification_observer.h" |
| 19 #include "chrome/common/notification_registrar.h" |
18 #include "chrome/common/pref_store.h" | 20 #include "chrome/common/pref_store.h" |
19 | 21 |
20 class Profile; | 22 class Profile; |
21 | 23 |
22 namespace policy { | 24 namespace policy { |
23 | 25 |
24 // An implementation of the |PrefStore| that holds a Dictionary | 26 class ConfigurationPolicyPrefKeeper; |
25 // created through applied policy. | 27 |
| 28 // An implementation of PrefStore that bridges policy settings as read from a |
| 29 // ConfigurationPolicyProvider to preferences. |
26 class ConfigurationPolicyPrefStore : public PrefStore, | 30 class ConfigurationPolicyPrefStore : public PrefStore, |
27 public ConfigurationPolicyStoreInterface { | 31 public NotificationObserver { |
28 public: | 32 public: |
29 typedef std::set<const char*> ProxyPreferenceSet; | |
30 | |
31 // The ConfigurationPolicyPrefStore does not take ownership of the | 33 // The ConfigurationPolicyPrefStore does not take ownership of the |
32 // passed-in |provider|. | 34 // passed-in |provider|. |
33 explicit ConfigurationPolicyPrefStore(ConfigurationPolicyProvider* provider); | 35 explicit ConfigurationPolicyPrefStore(ConfigurationPolicyProvider* provider); |
34 virtual ~ConfigurationPolicyPrefStore(); | 36 virtual ~ConfigurationPolicyPrefStore(); |
35 | 37 |
36 // PrefStore methods: | 38 // PrefStore methods: |
| 39 virtual void AddObserver(Observer* observer); |
| 40 virtual void RemoveObserver(Observer* observer); |
| 41 virtual bool IsInitializationComplete() const; |
37 virtual ReadResult GetValue(const std::string& key, Value** result) const; | 42 virtual ReadResult GetValue(const std::string& key, Value** result) const; |
38 | 43 |
39 virtual DictionaryValue* prefs() const; | |
40 | |
41 // ConfigurationPolicyStore methods: | |
42 virtual void Apply(ConfigurationPolicyType setting, Value* value); | |
43 | |
44 // Creates a ConfigurationPolicyPrefStore that reads managed platform policy. | 44 // Creates a ConfigurationPolicyPrefStore that reads managed platform policy. |
45 static ConfigurationPolicyPrefStore* CreateManagedPlatformPolicyPrefStore(); | 45 static ConfigurationPolicyPrefStore* CreateManagedPlatformPolicyPrefStore(); |
46 | 46 |
47 // Creates a ConfigurationPolicyPrefStore that supplies policy from | 47 // Creates a ConfigurationPolicyPrefStore that supplies policy from |
48 // the device management server. | 48 // the device management server. |
49 static ConfigurationPolicyPrefStore* CreateDeviceManagementPolicyPrefStore( | 49 static ConfigurationPolicyPrefStore* CreateDeviceManagementPolicyPrefStore( |
50 Profile* profile); | 50 Profile* profile); |
51 | 51 |
52 // Creates a ConfigurationPolicyPrefStore that reads recommended policy. | 52 // Creates a ConfigurationPolicyPrefStore that reads recommended policy. |
53 static ConfigurationPolicyPrefStore* CreateRecommendedPolicyPrefStore(); | 53 static ConfigurationPolicyPrefStore* CreateRecommendedPolicyPrefStore(); |
54 | 54 |
55 // Returns the default policy definition list for Chrome. | 55 // Returns the default policy definition list for Chrome. |
56 static const ConfigurationPolicyProvider::PolicyDefinitionList* | 56 static const ConfigurationPolicyProvider::PolicyDefinitionList* |
57 GetChromePolicyDefinitionList(); | 57 GetChromePolicyDefinitionList(); |
58 | 58 |
59 // Returns the set of preference paths that can be affected by a proxy | 59 private: |
60 // policy. | 60 // TODO(mnissler): Remove after provider has proper observer interface. |
61 static void GetProxyPreferenceSet(ProxyPreferenceSet* proxy_pref_set); | 61 // NotificationObserver overrides: |
| 62 void Observe(NotificationType type, |
| 63 const NotificationSource& source, |
| 64 const NotificationDetails& details); |
62 | 65 |
63 private: | 66 // Refreshes policy information, rereading policy from the provider and |
64 // Policies that map to a single preference are handled | 67 // sending out change notifications as appropriate. |
65 // by an automated converter. Each one of these policies | 68 void Refresh(); |
66 // has an entry in |simple_policy_map_| with the following type. | |
67 struct PolicyToPreferenceMapEntry { | |
68 Value::ValueType value_type; | |
69 ConfigurationPolicyType policy_type; | |
70 const char* preference_path; // A DictionaryValue path, not a file path. | |
71 }; | |
72 | 69 |
73 static const PolicyToPreferenceMapEntry kSimplePolicyMap[]; | |
74 static const PolicyToPreferenceMapEntry kProxyPolicyMap[]; | |
75 static const PolicyToPreferenceMapEntry kDefaultSearchPolicyMap[]; | |
76 static const ConfigurationPolicyProvider::PolicyDefinitionList | 70 static const ConfigurationPolicyProvider::PolicyDefinitionList |
77 kPolicyDefinitionList; | 71 kPolicyDefinitionList; |
78 | 72 |
| 73 // The policy provider from which policy settings are read. |
79 ConfigurationPolicyProvider* provider_; | 74 ConfigurationPolicyProvider* provider_; |
80 scoped_ptr<DictionaryValue> prefs_; | |
81 | 75 |
82 // Set to false until the first proxy-relevant policy is applied. At that | 76 // Initialization status as reported by the policy provider the last time we |
83 // time, default values are provided for all proxy-relevant prefs | 77 // queried it. |
84 // to override any values set from stores with a lower priority. | 78 bool initialization_complete_; |
85 bool lower_priority_proxy_settings_overridden_; | |
86 | 79 |
87 // The following are used to track what proxy-relevant policy has been applied | 80 // Current policy preferences. |
88 // accross calls to Apply to provide a warning if a policy specifies a | 81 scoped_ptr<ConfigurationPolicyPrefKeeper> policy_keeper_; |
89 // contradictory proxy configuration. |proxy_disabled_| is set to true if and | |
90 // only if the kPolicyNoProxyServer has been applied, | |
91 // |proxy_configuration_specified_| is set to true if and only if any other | |
92 // proxy policy other than kPolicyNoProxyServer has been applied. | |
93 bool proxy_disabled_; | |
94 bool proxy_configuration_specified_; | |
95 | 82 |
96 // Set to true if a the proxy mode policy has been set to force Chrome | 83 // TODO(mnissler): Remove after provider has proper observer interface. |
97 // to use the system proxy. | 84 NotificationRegistrar registrar_; |
98 bool use_system_proxy_; | |
99 | 85 |
100 // Returns the map entry that corresponds to |policy| in the map. | 86 ObserverList<Observer, true> observers_; |
101 const PolicyToPreferenceMapEntry* FindPolicyInMap( | |
102 ConfigurationPolicyType policy, | |
103 const PolicyToPreferenceMapEntry* map, | |
104 int size) const; | |
105 | |
106 // Remove the preferences found in the map from |prefs_|. Returns true if | |
107 // any such preferences were found and removed. | |
108 bool RemovePreferencesOfMap(const PolicyToPreferenceMapEntry* map, | |
109 int table_size); | |
110 | |
111 bool ApplyPolicyFromMap(ConfigurationPolicyType policy, | |
112 Value* value, | |
113 const PolicyToPreferenceMapEntry* map, | |
114 int size); | |
115 | |
116 // Processes proxy-specific policies. Returns true if the specified policy | |
117 // is a proxy-related policy. ApplyProxyPolicy assumes the ownership | |
118 // of |value| in the case that the policy is proxy-specific. | |
119 bool ApplyProxyPolicy(ConfigurationPolicyType policy, Value* value); | |
120 | |
121 // Handles sync-related policies. Returns true if the policy was handled. | |
122 // Assumes ownership of |value| in that case. | |
123 bool ApplySyncPolicy(ConfigurationPolicyType policy, Value* value); | |
124 | |
125 // Handles policies that affect AutoFill. Returns true if the policy was | |
126 // handled and assumes ownership of |value| in that case. | |
127 bool ApplyAutoFillPolicy(ConfigurationPolicyType policy, Value* value); | |
128 | |
129 // Make sure that the |path| if present in |prefs_|. If not, set it to | |
130 // a blank string. | |
131 void EnsureStringPrefExists(const std::string& path); | |
132 | |
133 // If the required entries for default search are specified and valid, | |
134 // finalizes the policy-specified configuration by initializing the | |
135 // unspecified map entries. Otherwise wipes all default search related | |
136 // map entries from |prefs_|. | |
137 void FinalizeDefaultSearchPolicySettings(); | |
138 | 87 |
139 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyPrefStore); | 88 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyPrefStore); |
140 }; | 89 }; |
141 | 90 |
142 } // namespace policy | 91 } // namespace policy |
143 | 92 |
144 #endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PREF_STORE_H_ | 93 #endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PREF_STORE_H_ |
OLD | NEW |