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 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 5 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
6 | 6 |
7 #include <set> | |
8 #include <string> | |
9 #include <vector> | |
10 | |
7 #include "base/command_line.h" | 11 #include "base/command_line.h" |
8 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
9 #include "base/logging.h" | 13 #include "base/logging.h" |
10 #include "base/path_service.h" | 14 #include "base/path_service.h" |
11 #include "base/stl_util-inl.h" | 15 #include "base/stl_util-inl.h" |
12 #include "base/string16.h" | 16 #include "base/string16.h" |
13 #include "base/string_util.h" | 17 #include "base/string_util.h" |
14 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
15 #include "base/values.h" | 19 #include "base/values.h" |
16 #include "chrome/browser/prefs/proxy_prefs.h" | |
17 #include "chrome/browser/profiles/profile.h" | |
18 #include "chrome/browser/policy/configuration_policy_provider.h" | 20 #include "chrome/browser/policy/configuration_policy_provider.h" |
19 #if defined(OS_WIN) | 21 #if defined(OS_WIN) |
20 #include "chrome/browser/policy/configuration_policy_provider_win.h" | 22 #include "chrome/browser/policy/configuration_policy_provider_win.h" |
21 #elif defined(OS_MACOSX) | 23 #elif defined(OS_MACOSX) |
22 #include "chrome/browser/policy/configuration_policy_provider_mac.h" | 24 #include "chrome/browser/policy/configuration_policy_provider_mac.h" |
23 #elif defined(OS_POSIX) | 25 #elif defined(OS_POSIX) |
24 #include "chrome/browser/policy/config_dir_policy_provider.h" | 26 #include "chrome/browser/policy/config_dir_policy_provider.h" |
25 #endif | 27 #endif |
26 #include "chrome/browser/policy/device_management_policy_provider.h" | 28 #include "chrome/browser/policy/device_management_policy_provider.h" |
27 #include "chrome/browser/policy/dummy_configuration_policy_provider.h" | 29 #include "chrome/browser/policy/dummy_configuration_policy_provider.h" |
28 #include "chrome/browser/policy/profile_policy_context.h" | 30 #include "chrome/browser/policy/profile_policy_context.h" |
31 #include "chrome/browser/prefs/pref_value_map.h" | |
32 #include "chrome/browser/prefs/proxy_prefs.h" | |
33 #include "chrome/browser/profiles/profile.h" | |
29 #include "chrome/browser/search_engines/search_terms_data.h" | 34 #include "chrome/browser/search_engines/search_terms_data.h" |
30 #include "chrome/browser/search_engines/template_url.h" | 35 #include "chrome/browser/search_engines/template_url.h" |
31 #include "chrome/common/chrome_paths.h" | 36 #include "chrome/common/chrome_paths.h" |
32 #include "chrome/common/chrome_switches.h" | 37 #include "chrome/common/chrome_switches.h" |
38 #include "chrome/common/notification_service.h" | |
33 #include "chrome/common/policy_constants.h" | 39 #include "chrome/common/policy_constants.h" |
34 #include "chrome/common/pref_names.h" | 40 #include "chrome/common/pref_names.h" |
35 | 41 |
36 namespace policy { | 42 namespace policy { |
37 | 43 |
38 // Manages the lifecycle of the shared platform-specific policy providers for | 44 // Accepts policy settings from a ConfigurationPolicyProvider, converts them |
39 // managed platform, device management and recommended policy. Instantiated as a | 45 // to preferences and caches the result. |
40 // Singleton. | 46 class ConfigurationPolicyPrefKeeper |
41 class ConfigurationPolicyProviderKeeper { | 47 : private ConfigurationPolicyStoreInterface { |
42 public: | 48 public: |
43 ConfigurationPolicyProviderKeeper() | 49 explicit ConfigurationPolicyPrefKeeper(ConfigurationPolicyProvider* provider); |
44 : managed_platform_provider_(CreateManagedPlatformProvider()), | 50 virtual ~ConfigurationPolicyPrefKeeper(); |
45 device_management_provider_(CreateDeviceManagementProvider()), | |
46 recommended_provider_(CreateRecommendedProvider()) {} | |
47 virtual ~ConfigurationPolicyProviderKeeper() {} | |
48 | 51 |
49 ConfigurationPolicyProvider* managed_platform_provider() const { | 52 // Get a preference value. |
50 return managed_platform_provider_.get(); | 53 PrefStore::ReadResult GetValue(const std::string& key, Value** result) const; |
51 } | |
52 | 54 |
53 ConfigurationPolicyProvider* device_management_provider() const { | 55 // Compute the set of preference names that are different in |keeper|. This |
54 return device_management_provider_.get(); | 56 // includes preferences that are missing in either one. |
55 } | 57 void GetDifferingPrefPaths(const ConfigurationPolicyPrefKeeper* other, |
56 | 58 std::vector<std::string>* differing_prefs) const; |
57 ConfigurationPolicyProvider* recommended_provider() const { | |
58 return recommended_provider_.get(); | |
59 } | |
60 | 59 |
61 private: | 60 private: |
62 scoped_ptr<ConfigurationPolicyProvider> managed_platform_provider_; | 61 // ConfigurationPolicyStore methods: |
63 scoped_ptr<ConfigurationPolicyProvider> device_management_provider_; | 62 virtual void Apply(ConfigurationPolicyType setting, Value* value); |
64 scoped_ptr<ConfigurationPolicyProvider> recommended_provider_; | |
65 | 63 |
66 static ConfigurationPolicyProvider* CreateManagedPlatformProvider(); | 64 // Policies that map to a single preference are handled |
67 static ConfigurationPolicyProvider* CreateDeviceManagementProvider(); | 65 // by an automated converter. Each one of these policies |
68 static ConfigurationPolicyProvider* CreateRecommendedProvider(); | 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 }; | |
69 | 72 |
70 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyProviderKeeper); | 73 typedef std::set<const char*> ProxyPreferenceSet; |
74 | |
75 // Returns the map entry that corresponds to |policy| in the map. | |
76 const PolicyToPreferenceMapEntry* FindPolicyInMap( | |
77 ConfigurationPolicyType policy, | |
78 const PolicyToPreferenceMapEntry* map, | |
79 int size) const; | |
80 | |
81 // Remove the preferences found in the map from |prefs_|. Returns true if | |
danno
2010/12/23 12:16:33
nit: comment indentation
| |
82 // any such preferences were found and removed. | |
83 bool RemovePreferencesOfMap(const PolicyToPreferenceMapEntry* map, | |
84 int table_size); | |
85 | |
86 bool ApplyPolicyFromMap(ConfigurationPolicyType policy, | |
87 Value* value, | |
88 const PolicyToPreferenceMapEntry* map, | |
89 int size); | |
90 | |
91 // Processes proxy-specific policies. Returns true if the specified policy | |
92 // is a proxy-related policy. ApplyProxyPolicy assumes the ownership | |
93 // of |value| in the case that the policy is proxy-specific. | |
94 bool ApplyProxyPolicy(ConfigurationPolicyType policy, Value* value); | |
95 | |
96 // Handles sync-related policies. Returns true if the policy was handled. | |
97 // Assumes ownership of |value| in that case. | |
98 bool ApplySyncPolicy(ConfigurationPolicyType policy, Value* value); | |
99 | |
100 // Handles policies that affect AutoFill. Returns true if the policy was | |
101 // handled and assumes ownership of |value| in that case. | |
102 bool ApplyAutoFillPolicy(ConfigurationPolicyType policy, Value* value); | |
103 | |
104 // Make sure that the |path| if present in |prefs_|. If not, set it to | |
105 // a blank string. | |
106 void EnsureStringPrefExists(const std::string& path); | |
107 | |
108 // If the required entries for default search are specified and valid, | |
109 // finalizes the policy-specified configuration by initializing the | |
110 // unspecified map entries. Otherwise wipes all default search related | |
111 // map entries from |prefs_|. | |
112 void FinalizeDefaultSearchPolicySettings(); | |
113 | |
114 // If the required entries for the proxy settings are specified and valid, | |
115 // finalizes the policy-specified configuration by initializing the | |
116 // respective values in |prefs_|. | |
117 void FinalizeProxyPolicySettings(); | |
118 | |
119 // Returns true if the policy values stored in proxy_* represent a valid | |
120 // proxy configuration. | |
121 bool CheckProxySettings(); | |
122 | |
123 // Assumes CheckProxySettings returns true and applies the values stored | |
124 // in proxy_*. | |
125 void ApplyProxySettings(); | |
126 | |
127 bool HasProxyPolicy(ConfigurationPolicyType policy) const; | |
128 | |
129 // Temporary cache that stores values until FinalizeProxyPolicySettings() | |
130 // is called. | |
131 std::map<ConfigurationPolicyType, Value*> proxy_policies_; | |
132 | |
133 // Set to false until the first proxy-relevant policy is applied. At that | |
134 // time, default values are provided for all proxy-relevant prefs | |
135 // to override any values set from stores with a lower priority. | |
136 bool lower_priority_proxy_settings_overridden_; | |
137 | |
138 // The following are used to track what proxy-relevant policy has been applied | |
139 // accross calls to Apply to provide a warning if a policy specifies a | |
140 // contradictory proxy configuration. |proxy_disabled_| is set to true if and | |
141 // only if the kPolicyNoProxyServer has been applied, | |
142 // |proxy_configuration_specified_| is set to true if and only if any other | |
143 // proxy policy other than kPolicyNoProxyServer has been applied. | |
144 bool proxy_disabled_; | |
145 bool proxy_configuration_specified_; | |
146 | |
147 // Set to true if a the proxy mode policy has been set to force Chrome | |
148 // to use the system proxy. | |
149 bool use_system_proxy_; | |
150 | |
151 PrefValueMap prefs_; | |
152 | |
153 static const PolicyToPreferenceMapEntry kSimplePolicyMap[]; | |
154 static const PolicyToPreferenceMapEntry kProxyPolicyMap[]; | |
155 static const PolicyToPreferenceMapEntry kDefaultSearchPolicyMap[]; | |
156 | |
157 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyPrefKeeper); | |
71 }; | 158 }; |
72 | 159 |
73 static base::LazyInstance<ConfigurationPolicyProviderKeeper> | 160 const ConfigurationPolicyPrefKeeper::PolicyToPreferenceMapEntry |
74 g_configuration_policy_provider_keeper(base::LINKER_INITIALIZED); | 161 ConfigurationPolicyPrefKeeper::kSimplePolicyMap[] = { |
75 | |
76 ConfigurationPolicyProvider* | |
77 ConfigurationPolicyProviderKeeper::CreateManagedPlatformProvider() { | |
78 const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list = | |
79 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(); | |
80 #if defined(OS_WIN) | |
81 return new ConfigurationPolicyProviderWin(policy_list); | |
82 #elif defined(OS_MACOSX) | |
83 return new ConfigurationPolicyProviderMac(policy_list); | |
84 #elif defined(OS_POSIX) | |
85 FilePath config_dir_path; | |
86 if (PathService::Get(chrome::DIR_POLICY_FILES, &config_dir_path)) { | |
87 return new ConfigDirPolicyProvider( | |
88 policy_list, | |
89 config_dir_path.Append(FILE_PATH_LITERAL("managed"))); | |
90 } else { | |
91 return new DummyConfigurationPolicyProvider(policy_list); | |
92 } | |
93 #else | |
94 return new DummyConfigurationPolicyProvider(policy_list); | |
95 #endif | |
96 } | |
97 | |
98 ConfigurationPolicyProvider* | |
99 ConfigurationPolicyProviderKeeper::CreateDeviceManagementProvider() { | |
100 return new DummyConfigurationPolicyProvider( | |
101 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList()); | |
102 } | |
103 | |
104 ConfigurationPolicyProvider* | |
105 ConfigurationPolicyProviderKeeper::CreateRecommendedProvider() { | |
106 const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list = | |
107 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(); | |
108 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
109 FilePath config_dir_path; | |
110 if (PathService::Get(chrome::DIR_POLICY_FILES, &config_dir_path)) { | |
111 return new ConfigDirPolicyProvider( | |
112 policy_list, | |
113 config_dir_path.Append(FILE_PATH_LITERAL("recommended"))); | |
114 } else { | |
115 return new DummyConfigurationPolicyProvider(policy_list); | |
116 } | |
117 #else | |
118 return new DummyConfigurationPolicyProvider(policy_list); | |
119 #endif | |
120 } | |
121 | |
122 const ConfigurationPolicyPrefStore::PolicyToPreferenceMapEntry | |
123 ConfigurationPolicyPrefStore::kSimplePolicyMap[] = { | |
124 { Value::TYPE_STRING, kPolicyHomePage, prefs::kHomePage }, | 162 { Value::TYPE_STRING, kPolicyHomePage, prefs::kHomePage }, |
125 { Value::TYPE_BOOLEAN, kPolicyHomepageIsNewTabPage, | 163 { Value::TYPE_BOOLEAN, kPolicyHomepageIsNewTabPage, |
126 prefs::kHomePageIsNewTabPage }, | 164 prefs::kHomePageIsNewTabPage }, |
127 { Value::TYPE_INTEGER, kPolicyRestoreOnStartup, | 165 { Value::TYPE_INTEGER, kPolicyRestoreOnStartup, |
128 prefs::kRestoreOnStartup}, | 166 prefs::kRestoreOnStartup}, |
129 { Value::TYPE_LIST, kPolicyURLsToRestoreOnStartup, | 167 { Value::TYPE_LIST, kPolicyURLsToRestoreOnStartup, |
130 prefs::kURLsToRestoreOnStartup }, | 168 prefs::kURLsToRestoreOnStartup }, |
131 { Value::TYPE_BOOLEAN, kPolicyAlternateErrorPagesEnabled, | 169 { Value::TYPE_BOOLEAN, kPolicyAlternateErrorPagesEnabled, |
132 prefs::kAlternateErrorPagesEnabled }, | 170 prefs::kAlternateErrorPagesEnabled }, |
133 { Value::TYPE_BOOLEAN, kPolicySearchSuggestEnabled, | 171 { Value::TYPE_BOOLEAN, kPolicySearchSuggestEnabled, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 prefs::kGSSAPILibraryName }, | 232 prefs::kGSSAPILibraryName }, |
195 { Value::TYPE_BOOLEAN, kPolicyDisable3DAPIs, | 233 { Value::TYPE_BOOLEAN, kPolicyDisable3DAPIs, |
196 prefs::kDisable3DAPIs }, | 234 prefs::kDisable3DAPIs }, |
197 | 235 |
198 #if defined(OS_CHROMEOS) | 236 #if defined(OS_CHROMEOS) |
199 { Value::TYPE_BOOLEAN, kPolicyChromeOsLockOnIdleSuspend, | 237 { Value::TYPE_BOOLEAN, kPolicyChromeOsLockOnIdleSuspend, |
200 prefs::kEnableScreenLock }, | 238 prefs::kEnableScreenLock }, |
201 #endif | 239 #endif |
202 }; | 240 }; |
203 | 241 |
204 const ConfigurationPolicyPrefStore::PolicyToPreferenceMapEntry | 242 const ConfigurationPolicyPrefKeeper::PolicyToPreferenceMapEntry |
205 ConfigurationPolicyPrefStore::kDefaultSearchPolicyMap[] = { | 243 ConfigurationPolicyPrefKeeper::kDefaultSearchPolicyMap[] = { |
206 { Value::TYPE_BOOLEAN, kPolicyDefaultSearchProviderEnabled, | 244 { Value::TYPE_BOOLEAN, kPolicyDefaultSearchProviderEnabled, |
207 prefs::kDefaultSearchProviderEnabled }, | 245 prefs::kDefaultSearchProviderEnabled }, |
208 { Value::TYPE_STRING, kPolicyDefaultSearchProviderName, | 246 { Value::TYPE_STRING, kPolicyDefaultSearchProviderName, |
209 prefs::kDefaultSearchProviderName }, | 247 prefs::kDefaultSearchProviderName }, |
210 { Value::TYPE_STRING, kPolicyDefaultSearchProviderKeyword, | 248 { Value::TYPE_STRING, kPolicyDefaultSearchProviderKeyword, |
211 prefs::kDefaultSearchProviderKeyword }, | 249 prefs::kDefaultSearchProviderKeyword }, |
212 { Value::TYPE_STRING, kPolicyDefaultSearchProviderSearchURL, | 250 { Value::TYPE_STRING, kPolicyDefaultSearchProviderSearchURL, |
213 prefs::kDefaultSearchProviderSearchURL }, | 251 prefs::kDefaultSearchProviderSearchURL }, |
214 { Value::TYPE_STRING, kPolicyDefaultSearchProviderSuggestURL, | 252 { Value::TYPE_STRING, kPolicyDefaultSearchProviderSuggestURL, |
215 prefs::kDefaultSearchProviderSuggestURL }, | 253 prefs::kDefaultSearchProviderSuggestURL }, |
216 { Value::TYPE_STRING, kPolicyDefaultSearchProviderIconURL, | 254 { Value::TYPE_STRING, kPolicyDefaultSearchProviderIconURL, |
217 prefs::kDefaultSearchProviderIconURL }, | 255 prefs::kDefaultSearchProviderIconURL }, |
218 { Value::TYPE_STRING, kPolicyDefaultSearchProviderEncodings, | 256 { Value::TYPE_STRING, kPolicyDefaultSearchProviderEncodings, |
219 prefs::kDefaultSearchProviderEncodings }, | 257 prefs::kDefaultSearchProviderEncodings }, |
220 }; | 258 }; |
221 | 259 |
222 const ConfigurationPolicyPrefStore::PolicyToPreferenceMapEntry | 260 const ConfigurationPolicyPrefKeeper::PolicyToPreferenceMapEntry |
223 ConfigurationPolicyPrefStore::kProxyPolicyMap[] = { | 261 ConfigurationPolicyPrefKeeper::kProxyPolicyMap[] = { |
224 { Value::TYPE_STRING, kPolicyProxyServer, prefs::kProxyServer }, | 262 { Value::TYPE_STRING, kPolicyProxyServer, prefs::kProxyServer }, |
225 { Value::TYPE_STRING, kPolicyProxyPacUrl, prefs::kProxyPacUrl }, | 263 { Value::TYPE_STRING, kPolicyProxyPacUrl, prefs::kProxyPacUrl }, |
226 { Value::TYPE_STRING, kPolicyProxyBypassList, prefs::kProxyBypassList } | 264 { Value::TYPE_STRING, kPolicyProxyBypassList, prefs::kProxyBypassList } |
227 }; | 265 }; |
228 | 266 |
229 /* static */ | 267 ConfigurationPolicyPrefKeeper::ConfigurationPolicyPrefKeeper( |
230 const ConfigurationPolicyProvider::PolicyDefinitionList* | |
231 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList() { | |
232 static ConfigurationPolicyProvider::PolicyDefinitionList::Entry entries[] = { | |
233 { kPolicyHomePage, Value::TYPE_STRING, key::kHomepageLocation }, | |
234 { kPolicyHomepageIsNewTabPage, Value::TYPE_BOOLEAN, | |
235 key::kHomepageIsNewTabPage }, | |
236 { kPolicyRestoreOnStartup, Value::TYPE_INTEGER, key::kRestoreOnStartup }, | |
237 { kPolicyURLsToRestoreOnStartup, Value::TYPE_LIST, | |
238 key::kURLsToRestoreOnStartup }, | |
239 { kPolicyDefaultSearchProviderEnabled, Value::TYPE_BOOLEAN, | |
240 key::kDefaultSearchProviderEnabled }, | |
241 { kPolicyDefaultSearchProviderName, Value::TYPE_STRING, | |
242 key::kDefaultSearchProviderName }, | |
243 { kPolicyDefaultSearchProviderKeyword, Value::TYPE_STRING, | |
244 key::kDefaultSearchProviderKeyword }, | |
245 { kPolicyDefaultSearchProviderSearchURL, Value::TYPE_STRING, | |
246 key::kDefaultSearchProviderSearchURL }, | |
247 { kPolicyDefaultSearchProviderSuggestURL, Value::TYPE_STRING, | |
248 key::kDefaultSearchProviderSuggestURL }, | |
249 { kPolicyDefaultSearchProviderIconURL, Value::TYPE_STRING, | |
250 key::kDefaultSearchProviderIconURL }, | |
251 { kPolicyDefaultSearchProviderEncodings, Value::TYPE_STRING, | |
252 key::kDefaultSearchProviderEncodings }, | |
253 { kPolicyProxyMode, Value::TYPE_INTEGER, key::kProxyMode }, | |
254 { kPolicyProxyServer, Value::TYPE_STRING, key::kProxyServer }, | |
255 { kPolicyProxyPacUrl, Value::TYPE_STRING, key::kProxyPacUrl }, | |
256 { kPolicyProxyBypassList, Value::TYPE_STRING, key::kProxyBypassList }, | |
257 { kPolicyAlternateErrorPagesEnabled, Value::TYPE_BOOLEAN, | |
258 key::kAlternateErrorPagesEnabled }, | |
259 { kPolicySearchSuggestEnabled, Value::TYPE_BOOLEAN, | |
260 key::kSearchSuggestEnabled }, | |
261 { kPolicyDnsPrefetchingEnabled, Value::TYPE_BOOLEAN, | |
262 key::kDnsPrefetchingEnabled }, | |
263 { kPolicyDisableSpdy, Value::TYPE_BOOLEAN, key::kDisableSpdy }, | |
264 { kPolicySafeBrowsingEnabled, Value::TYPE_BOOLEAN, | |
265 key::kSafeBrowsingEnabled }, | |
266 { kPolicyMetricsReportingEnabled, Value::TYPE_BOOLEAN, | |
267 key::kMetricsReportingEnabled }, | |
268 { kPolicyPasswordManagerEnabled, Value::TYPE_BOOLEAN, | |
269 key::kPasswordManagerEnabled }, | |
270 { kPolicyPasswordManagerAllowShowPasswords, Value::TYPE_BOOLEAN, | |
271 key::kPasswordManagerAllowShowPasswords }, | |
272 { kPolicyAutoFillEnabled, Value::TYPE_BOOLEAN, key::kAutoFillEnabled }, | |
273 { kPolicyDisabledPlugins, Value::TYPE_LIST, key::kDisabledPlugins }, | |
274 { kPolicyApplicationLocale, Value::TYPE_STRING, | |
275 key::kApplicationLocaleValue }, | |
276 { kPolicySyncDisabled, Value::TYPE_BOOLEAN, key::kSyncDisabled }, | |
277 { kPolicyExtensionInstallAllowList, Value::TYPE_LIST, | |
278 key::kExtensionInstallAllowList }, | |
279 { kPolicyExtensionInstallDenyList, Value::TYPE_LIST, | |
280 key::kExtensionInstallDenyList }, | |
281 { kPolicyExtensionInstallForceList, Value::TYPE_LIST, | |
282 key::kExtensionInstallForceList }, | |
283 { kPolicyShowHomeButton, Value::TYPE_BOOLEAN, key::kShowHomeButton }, | |
284 { kPolicyPrintingEnabled, Value::TYPE_BOOLEAN, key::kPrintingEnabled }, | |
285 { kPolicyJavascriptEnabled, Value::TYPE_BOOLEAN, key::kJavascriptEnabled }, | |
286 { kPolicySavingBrowserHistoryDisabled, Value::TYPE_BOOLEAN, | |
287 key::kSavingBrowserHistoryDisabled }, | |
288 { kPolicyDeveloperToolsDisabled, Value::TYPE_BOOLEAN, | |
289 key::kDeveloperToolsDisabled }, | |
290 { kPolicyBlockThirdPartyCookies, Value::TYPE_BOOLEAN, | |
291 key::kBlockThirdPartyCookies }, | |
292 { kPolicyDefaultCookiesSetting, Value::TYPE_INTEGER, | |
293 key::kDefaultCookiesSetting }, | |
294 { kPolicyDefaultImagesSetting, Value::TYPE_INTEGER, | |
295 key::kDefaultImagesSetting }, | |
296 { kPolicyDefaultJavaScriptSetting, Value::TYPE_INTEGER, | |
297 key::kDefaultJavaScriptSetting }, | |
298 { kPolicyDefaultPluginsSetting, Value::TYPE_INTEGER, | |
299 key::kDefaultPluginsSetting }, | |
300 { kPolicyDefaultPopupsSetting, Value::TYPE_INTEGER, | |
301 key::kDefaultPopupsSetting }, | |
302 { kPolicyDefaultNotificationSetting, Value::TYPE_INTEGER, | |
303 key::kDefaultNotificationSetting }, | |
304 { kPolicyDefaultGeolocationSetting, Value::TYPE_INTEGER, | |
305 key::kDefaultGeolocationSetting }, | |
306 { kPolicyAuthSchemes, Value::TYPE_STRING, key::kAuthSchemes }, | |
307 { kPolicyDisableAuthNegotiateCnameLookup, Value::TYPE_BOOLEAN, | |
308 key::kDisableAuthNegotiateCnameLookup }, | |
309 { kPolicyEnableAuthNegotiatePort, Value::TYPE_BOOLEAN, | |
310 key::kEnableAuthNegotiatePort }, | |
311 { kPolicyAuthServerWhitelist, Value::TYPE_STRING, | |
312 key::kAuthServerWhitelist }, | |
313 { kPolicyAuthNegotiateDelegateWhitelist, Value::TYPE_STRING, | |
314 key::kAuthNegotiateDelegateWhitelist }, | |
315 { kPolicyGSSAPILibraryName, Value::TYPE_STRING, | |
316 key::kGSSAPILibraryName }, | |
317 { kPolicyDisable3DAPIs, Value::TYPE_BOOLEAN, | |
318 key::kDisable3DAPIs }, | |
319 | |
320 #if defined(OS_CHROMEOS) | |
321 { kPolicyChromeOsLockOnIdleSuspend, Value::TYPE_BOOLEAN, | |
322 key::kChromeOsLockOnIdleSuspend }, | |
323 #endif | |
324 }; | |
325 | |
326 static ConfigurationPolicyProvider::PolicyDefinitionList policy_list = { | |
327 entries, | |
328 entries + arraysize(entries), | |
329 }; | |
330 return &policy_list; | |
331 } | |
332 | |
333 ConfigurationPolicyPrefStore::ConfigurationPolicyPrefStore( | |
334 ConfigurationPolicyProvider* provider) | 268 ConfigurationPolicyProvider* provider) |
335 : provider_(provider), | 269 : lower_priority_proxy_settings_overridden_(false), |
336 prefs_(new DictionaryValue()) { | 270 proxy_disabled_(false), |
337 if (!provider_->Provide(this)) | 271 proxy_configuration_specified_(false), |
272 use_system_proxy_(false) { | |
273 if (!provider->Provide(this)) | |
338 LOG(WARNING) << "Failed to get policy from provider."; | 274 LOG(WARNING) << "Failed to get policy from provider."; |
339 FinalizeProxyPolicySettings(); | 275 FinalizeProxyPolicySettings(); |
340 FinalizeDefaultSearchPolicySettings(); | 276 FinalizeDefaultSearchPolicySettings(); |
341 } | 277 } |
342 | 278 |
343 ConfigurationPolicyPrefStore::~ConfigurationPolicyPrefStore() { | 279 ConfigurationPolicyPrefKeeper::~ConfigurationPolicyPrefKeeper() { |
344 DCHECK(proxy_policies_.empty()); | 280 DCHECK(proxy_policies_.empty()); |
345 } | 281 } |
346 | 282 |
347 PrefStore::ReadResult ConfigurationPolicyPrefStore::GetValue( | 283 PrefStore::ReadResult |
348 const std::string& key, | 284 ConfigurationPolicyPrefKeeper::GetValue(const std::string& key, |
349 Value** value) const { | 285 Value** result) const { |
350 Value* configured_value = NULL; | 286 Value* stored_value = NULL; |
351 if (!prefs_->Get(key, &configured_value) || !configured_value) | 287 if (!prefs_.GetValue(key, &stored_value)) |
352 return READ_NO_VALUE; | 288 return PrefStore::READ_NO_VALUE; |
353 | 289 |
354 // Check whether there's a default value, which indicates READ_USE_DEFAULT | 290 // Check whether there's a default value, which indicates READ_USE_DEFAULT |
355 // should be returned. | 291 // should be returned. |
356 if (configured_value->IsType(Value::TYPE_NULL)) | 292 if (stored_value->IsType(Value::TYPE_NULL)) |
357 return READ_USE_DEFAULT; | 293 return PrefStore::READ_USE_DEFAULT; |
358 | 294 |
359 *value = configured_value; | 295 *result = stored_value; |
360 return READ_OK; | 296 return PrefStore::READ_OK; |
361 } | 297 } |
362 | 298 |
363 DictionaryValue* ConfigurationPolicyPrefStore::prefs() const { | 299 void ConfigurationPolicyPrefKeeper::GetDifferingPrefPaths( |
364 return prefs_.get(); | 300 const ConfigurationPolicyPrefKeeper* other, |
301 std::vector<std::string>* differing_prefs) const { | |
302 prefs_.GetDifferingKeys(&other->prefs_, differing_prefs); | |
365 } | 303 } |
366 | 304 |
367 void ConfigurationPolicyPrefStore::Apply(ConfigurationPolicyType policy, | 305 void ConfigurationPolicyPrefKeeper::Apply(ConfigurationPolicyType policy, |
368 Value* value) { | 306 Value* value) { |
369 if (ApplyProxyPolicy(policy, value)) | 307 if (ApplyProxyPolicy(policy, value)) |
370 return; | 308 return; |
371 | 309 |
372 if (ApplySyncPolicy(policy, value)) | 310 if (ApplySyncPolicy(policy, value)) |
373 return; | 311 return; |
374 | 312 |
375 if (ApplyAutoFillPolicy(policy, value)) | 313 if (ApplyAutoFillPolicy(policy, value)) |
376 return; | 314 return; |
377 | 315 |
378 if (ApplyPolicyFromMap(policy, value, kDefaultSearchPolicyMap, | 316 if (ApplyPolicyFromMap(policy, value, kDefaultSearchPolicyMap, |
379 arraysize(kDefaultSearchPolicyMap))) | 317 arraysize(kDefaultSearchPolicyMap))) |
380 return; | 318 return; |
381 | 319 |
382 if (ApplyPolicyFromMap(policy, value, kSimplePolicyMap, | 320 if (ApplyPolicyFromMap(policy, value, kSimplePolicyMap, |
383 arraysize(kSimplePolicyMap))) | 321 arraysize(kSimplePolicyMap))) |
384 return; | 322 return; |
385 | 323 |
386 // Other policy implementations go here. | 324 // Other policy implementations go here. |
387 NOTIMPLEMENTED(); | 325 NOTIMPLEMENTED(); |
388 delete value; | 326 delete value; |
389 } | 327 } |
390 | 328 |
391 // static | 329 const ConfigurationPolicyPrefKeeper::PolicyToPreferenceMapEntry* |
392 ConfigurationPolicyPrefStore* | 330 ConfigurationPolicyPrefKeeper::FindPolicyInMap( |
393 ConfigurationPolicyPrefStore::CreateManagedPlatformPolicyPrefStore() { | |
394 return new ConfigurationPolicyPrefStore( | |
395 g_configuration_policy_provider_keeper.Get().managed_platform_provider()); | |
396 } | |
397 | |
398 // static | |
399 ConfigurationPolicyPrefStore* | |
400 ConfigurationPolicyPrefStore::CreateDeviceManagementPolicyPrefStore( | |
401 Profile* profile) { | |
402 ConfigurationPolicyProviderKeeper* keeper = | |
403 g_configuration_policy_provider_keeper.Pointer(); | |
404 ConfigurationPolicyProvider* provider = NULL; | |
405 if (profile) | |
406 provider = profile->GetPolicyContext()->GetDeviceManagementPolicyProvider(); | |
407 if (!provider) | |
408 provider = keeper->device_management_provider(); | |
409 return new ConfigurationPolicyPrefStore(provider); | |
410 } | |
411 | |
412 // static | |
413 ConfigurationPolicyPrefStore* | |
414 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore() { | |
415 return new ConfigurationPolicyPrefStore( | |
416 g_configuration_policy_provider_keeper.Get().recommended_provider()); | |
417 } | |
418 | |
419 const ConfigurationPolicyPrefStore::PolicyToPreferenceMapEntry* | |
420 ConfigurationPolicyPrefStore::FindPolicyInMap( | |
421 ConfigurationPolicyType policy, | 331 ConfigurationPolicyType policy, |
422 const PolicyToPreferenceMapEntry* map, | 332 const PolicyToPreferenceMapEntry* map, |
423 int table_size) const { | 333 int table_size) const { |
424 for (int i = 0; i < table_size; ++i) { | 334 for (int i = 0; i < table_size; ++i) { |
425 if (map[i].policy_type == policy) | 335 if (map[i].policy_type == policy) |
426 return map + i; | 336 return map + i; |
427 } | 337 } |
428 return NULL; | 338 return NULL; |
429 } | 339 } |
430 | 340 |
431 bool ConfigurationPolicyPrefStore::RemovePreferencesOfMap( | 341 bool ConfigurationPolicyPrefKeeper::RemovePreferencesOfMap( |
432 const PolicyToPreferenceMapEntry* map, int table_size) { | 342 const PolicyToPreferenceMapEntry* map, int table_size) { |
433 bool found_any = false; | 343 bool found_any = false; |
434 for (int i = 0; i < table_size; ++i) { | 344 for (int i = 0; i < table_size; ++i) { |
435 if (prefs_->Remove(map[i].preference_path, NULL)) | 345 if (prefs_.RemoveValue(map[i].preference_path)) |
436 found_any = true; | 346 found_any = true; |
437 } | 347 } |
438 return found_any; | 348 return found_any; |
439 } | 349 } |
440 | 350 |
441 bool ConfigurationPolicyPrefStore::ApplyPolicyFromMap( | 351 bool ConfigurationPolicyPrefKeeper::ApplyPolicyFromMap( |
442 ConfigurationPolicyType policy, | 352 ConfigurationPolicyType policy, |
443 Value* value, | 353 Value* value, |
444 const PolicyToPreferenceMapEntry* map, | 354 const PolicyToPreferenceMapEntry* map, |
445 int size) { | 355 int size) { |
446 for (int current = 0; current < size; ++current) { | 356 for (int current = 0; current < size; ++current) { |
447 if (map[current].policy_type == policy) { | 357 if (map[current].policy_type == policy) { |
448 DCHECK_EQ(map[current].value_type, value->GetType()) | 358 DCHECK_EQ(map[current].value_type, value->GetType()) |
449 << "mismatch in provided and expected policy value for preferences" | 359 << "mismatch in provided and expected policy value for preferences" |
450 << map[current].preference_path << ". expected = " | 360 << map[current].preference_path << ". expected = " |
451 << map[current].value_type << ", actual = "<< value->GetType(); | 361 << map[current].value_type << ", actual = "<< value->GetType(); |
452 prefs_->Set(map[current].preference_path, value); | 362 prefs_.SetValue(map[current].preference_path, value); |
453 return true; | 363 return true; |
454 } | 364 } |
455 } | 365 } |
456 return false; | 366 return false; |
457 } | 367 } |
458 | 368 |
459 bool ConfigurationPolicyPrefStore::ApplyProxyPolicy( | 369 bool ConfigurationPolicyPrefKeeper::ApplyProxyPolicy( |
460 ConfigurationPolicyType policy, | 370 ConfigurationPolicyType policy, |
461 Value* value) { | 371 Value* value) { |
462 // We only collect the values until we have sufficient information when | 372 // We only collect the values until we have sufficient information when |
463 // FinalizeProxyPolicySettings() is called to determine whether the presented | 373 // FinalizeProxyPolicySettings() is called to determine whether the presented |
464 // values were correct and apply them in that case. | 374 // values were correct and apply them in that case. |
465 if (policy == kPolicyProxyMode || | 375 if (policy == kPolicyProxyMode || |
466 policy == kPolicyProxyServer || | 376 policy == kPolicyProxyServer || |
467 policy == kPolicyProxyPacUrl || | 377 policy == kPolicyProxyPacUrl || |
468 policy == kPolicyProxyBypassList) { | 378 policy == kPolicyProxyBypassList) { |
469 delete proxy_policies_[policy]; | 379 delete proxy_policies_[policy]; |
470 proxy_policies_[policy] = value; | 380 proxy_policies_[policy] = value; |
471 return true; | 381 return true; |
472 } | 382 } |
473 // We are not interested in this policy. | 383 // We are not interested in this policy. |
474 return false; | 384 return false; |
475 } | 385 } |
476 | 386 |
477 void ConfigurationPolicyPrefStore::FinalizeProxyPolicySettings() { | 387 bool ConfigurationPolicyPrefKeeper::ApplySyncPolicy( |
388 ConfigurationPolicyType policy, Value* value) { | |
389 if (policy == kPolicySyncDisabled) { | |
390 bool disable_sync; | |
391 if (value->GetAsBoolean(&disable_sync) && disable_sync) | |
392 prefs_.SetValue(prefs::kSyncManaged, value); | |
393 else | |
394 delete value; | |
395 return true; | |
396 } | |
397 return false; | |
398 } | |
399 | |
400 bool ConfigurationPolicyPrefKeeper::ApplyAutoFillPolicy( | |
401 ConfigurationPolicyType policy, Value* value) { | |
402 if (policy == kPolicyAutoFillEnabled) { | |
403 bool auto_fill_enabled; | |
404 if (value->GetAsBoolean(&auto_fill_enabled) && !auto_fill_enabled) | |
405 prefs_.SetValue(prefs::kAutoFillEnabled, | |
406 Value::CreateBooleanValue(false)); | |
407 delete value; | |
408 return true; | |
409 } | |
410 return false; | |
411 } | |
412 | |
413 void ConfigurationPolicyPrefKeeper::EnsureStringPrefExists( | |
414 const std::string& path) { | |
415 std::string value; | |
416 if (!prefs_.GetString(path, &value)) | |
417 prefs_.SetString(path, value); | |
418 } | |
419 | |
420 namespace { | |
421 | |
422 // Implementation of SearchTermsData just for validation. | |
423 class SearchTermsDataForValidation : public SearchTermsData { | |
424 public: | |
425 SearchTermsDataForValidation() {} | |
426 | |
427 // Implementation of SearchTermsData. | |
428 virtual std::string GoogleBaseURLValue() const { | |
429 return "http://www.google.com/"; | |
430 } | |
431 virtual std::string GetApplicationLocale() const { | |
432 return "en"; | |
433 } | |
434 #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) | |
435 virtual std::wstring GetRlzParameterValue() const { | |
436 return std::wstring(); | |
437 } | |
438 #endif | |
439 private: | |
440 DISALLOW_COPY_AND_ASSIGN(SearchTermsDataForValidation); | |
441 }; | |
442 | |
443 } // namepsace | |
444 | |
445 void ConfigurationPolicyPrefKeeper::FinalizeDefaultSearchPolicySettings() { | |
446 bool enabled = true; | |
447 if (prefs_.GetBoolean(prefs::kDefaultSearchProviderEnabled, &enabled) && | |
448 !enabled) { | |
449 // If default search is disabled, we ignore the other fields. | |
450 prefs_.SetString(prefs::kDefaultSearchProviderName, std::string()); | |
451 prefs_.SetString(prefs::kDefaultSearchProviderSearchURL, std::string()); | |
452 prefs_.SetString(prefs::kDefaultSearchProviderSuggestURL, std::string()); | |
453 prefs_.SetString(prefs::kDefaultSearchProviderIconURL, std::string()); | |
454 prefs_.SetString(prefs::kDefaultSearchProviderEncodings, std::string()); | |
455 prefs_.SetString(prefs::kDefaultSearchProviderKeyword, std::string()); | |
456 return; | |
457 } | |
458 std::string search_url; | |
459 // The search URL is required. | |
460 if (prefs_.GetString(prefs::kDefaultSearchProviderSearchURL, &search_url) && | |
461 !search_url.empty()) { | |
462 SearchTermsDataForValidation search_terms_data; | |
463 const TemplateURLRef search_url_ref(search_url, 0, 0); | |
464 // It must support replacement (which implies it is valid). | |
465 if (search_url_ref.SupportsReplacementUsingTermsData(search_terms_data)) { | |
466 // The other entries are optional. Just make sure that they are all | |
467 // specified via policy, so that we don't use regular prefs. | |
468 EnsureStringPrefExists(prefs::kDefaultSearchProviderSuggestURL); | |
469 EnsureStringPrefExists(prefs::kDefaultSearchProviderIconURL); | |
470 EnsureStringPrefExists(prefs::kDefaultSearchProviderEncodings); | |
471 EnsureStringPrefExists(prefs::kDefaultSearchProviderKeyword); | |
472 | |
473 // For the name, default to the host if not specified. | |
474 std::string name; | |
475 if (!prefs_.GetString(prefs::kDefaultSearchProviderName, &name) || | |
476 name.empty()) | |
477 prefs_.SetString(prefs::kDefaultSearchProviderName, | |
478 GURL(search_url).host()); | |
479 | |
480 // And clear the IDs since these are not specified via policy. | |
481 prefs_.SetString(prefs::kDefaultSearchProviderID, std::string()); | |
482 prefs_.SetString(prefs::kDefaultSearchProviderPrepopulateID, | |
483 std::string()); | |
484 return; | |
485 } | |
486 } | |
487 // Required entries are not there. Remove any related entries. | |
488 RemovePreferencesOfMap(kDefaultSearchPolicyMap, | |
489 arraysize(kDefaultSearchPolicyMap)); | |
490 } | |
491 | |
492 void ConfigurationPolicyPrefKeeper::FinalizeProxyPolicySettings() { | |
478 if (CheckProxySettings()) | 493 if (CheckProxySettings()) |
479 ApplyProxySettings(); | 494 ApplyProxySettings(); |
480 | 495 |
481 STLDeleteContainerPairSecondPointers(proxy_policies_.begin(), | 496 STLDeleteContainerPairSecondPointers(proxy_policies_.begin(), |
482 proxy_policies_.end()); | 497 proxy_policies_.end()); |
483 proxy_policies_.clear(); | 498 proxy_policies_.clear(); |
484 } | 499 } |
485 | 500 |
486 bool ConfigurationPolicyPrefStore::HasProxyPolicy( | 501 bool ConfigurationPolicyPrefKeeper::CheckProxySettings() { |
487 ConfigurationPolicyType policy) const { | |
488 std::map<ConfigurationPolicyType, Value*>::const_iterator iter; | |
489 iter = proxy_policies_.find(policy); | |
490 return iter != proxy_policies_.end() && | |
491 iter->second && !iter->second->IsType(Value::TYPE_NULL); | |
492 } | |
493 | |
494 bool ConfigurationPolicyPrefStore::CheckProxySettings() { | |
495 bool mode = HasProxyPolicy(kPolicyProxyMode); | 502 bool mode = HasProxyPolicy(kPolicyProxyMode); |
496 bool server = HasProxyPolicy(kPolicyProxyServer); | 503 bool server = HasProxyPolicy(kPolicyProxyServer); |
497 bool pac_url = HasProxyPolicy(kPolicyProxyPacUrl); | 504 bool pac_url = HasProxyPolicy(kPolicyProxyPacUrl); |
498 bool bypass_list = HasProxyPolicy(kPolicyProxyBypassList); | 505 bool bypass_list = HasProxyPolicy(kPolicyProxyBypassList); |
499 | 506 |
500 if ((server || pac_url || bypass_list) && !mode) { | 507 if ((server || pac_url || bypass_list) && !mode) { |
501 LOG(WARNING) << "A centrally-administered policy defines proxy setting" | 508 LOG(WARNING) << "A centrally-administered policy defines proxy setting" |
502 << " details without setting a proxy mode."; | 509 << " details without setting a proxy mode."; |
503 return false; | 510 return false; |
504 } | 511 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
551 return false; | 558 return false; |
552 } | 559 } |
553 break; | 560 break; |
554 default: | 561 default: |
555 LOG(WARNING) << "Invalid proxy mode " << mode_value; | 562 LOG(WARNING) << "Invalid proxy mode " << mode_value; |
556 return false; | 563 return false; |
557 } | 564 } |
558 return true; | 565 return true; |
559 } | 566 } |
560 | 567 |
561 void ConfigurationPolicyPrefStore::ApplyProxySettings() { | 568 void ConfigurationPolicyPrefKeeper::ApplyProxySettings() { |
562 if (!HasProxyPolicy(kPolicyProxyMode)) | 569 if (!HasProxyPolicy(kPolicyProxyMode)) |
563 return; | 570 return; |
564 | 571 |
565 int int_mode; | 572 int int_mode; |
566 CHECK(proxy_policies_[kPolicyProxyMode]->GetAsInteger(&int_mode)); | 573 CHECK(proxy_policies_[kPolicyProxyMode]->GetAsInteger(&int_mode)); |
567 ProxyPrefs::ProxyMode mode; | 574 ProxyPrefs::ProxyMode mode; |
568 switch (int_mode) { | 575 switch (int_mode) { |
569 case kPolicyNoProxyServerMode: | 576 case kPolicyNoProxyServerMode: |
570 mode = ProxyPrefs::MODE_DIRECT; | 577 mode = ProxyPrefs::MODE_DIRECT; |
571 break; | 578 break; |
572 case kPolicyAutoDetectProxyMode: | 579 case kPolicyAutoDetectProxyMode: |
573 mode = ProxyPrefs::MODE_AUTO_DETECT; | 580 mode = ProxyPrefs::MODE_AUTO_DETECT; |
574 if (HasProxyPolicy(kPolicyProxyPacUrl)) | 581 if (HasProxyPolicy(kPolicyProxyPacUrl)) |
575 mode = ProxyPrefs::MODE_PAC_SCRIPT; | 582 mode = ProxyPrefs::MODE_PAC_SCRIPT; |
576 break; | 583 break; |
577 case kPolicyManuallyConfiguredProxyMode: | 584 case kPolicyManuallyConfiguredProxyMode: |
578 mode = ProxyPrefs::MODE_FIXED_SERVERS; | 585 mode = ProxyPrefs::MODE_FIXED_SERVERS; |
579 break; | 586 break; |
580 case kPolicyUseSystemProxyMode: | 587 case kPolicyUseSystemProxyMode: |
581 mode = ProxyPrefs::MODE_SYSTEM; | 588 mode = ProxyPrefs::MODE_SYSTEM; |
582 break; | 589 break; |
583 default: | 590 default: |
584 mode = ProxyPrefs::MODE_DIRECT; | 591 mode = ProxyPrefs::MODE_DIRECT; |
585 NOTREACHED(); | 592 NOTREACHED(); |
586 } | 593 } |
587 prefs_->Set(prefs::kProxyMode, Value::CreateIntegerValue(mode)); | 594 prefs_.SetValue(prefs::kProxyMode, Value::CreateIntegerValue(mode)); |
588 | 595 |
589 if (HasProxyPolicy(kPolicyProxyServer)) { | 596 if (HasProxyPolicy(kPolicyProxyServer)) { |
590 prefs_->Set(prefs::kProxyServer, proxy_policies_[kPolicyProxyServer]); | 597 prefs_.SetValue(prefs::kProxyServer, proxy_policies_[kPolicyProxyServer]); |
591 proxy_policies_[kPolicyProxyServer] = NULL; | 598 proxy_policies_[kPolicyProxyServer] = NULL; |
592 } else { | 599 } else { |
593 prefs_->Set(prefs::kProxyServer, Value::CreateNullValue()); | 600 prefs_.SetValue(prefs::kProxyServer, Value::CreateNullValue()); |
594 } | 601 } |
595 if (HasProxyPolicy(kPolicyProxyPacUrl)) { | 602 if (HasProxyPolicy(kPolicyProxyPacUrl)) { |
596 prefs_->Set(prefs::kProxyPacUrl, proxy_policies_[kPolicyProxyPacUrl]); | 603 prefs_.SetValue(prefs::kProxyPacUrl, proxy_policies_[kPolicyProxyPacUrl]); |
597 proxy_policies_[kPolicyProxyPacUrl] = NULL; | 604 proxy_policies_[kPolicyProxyPacUrl] = NULL; |
598 } else { | 605 } else { |
599 prefs_->Set(prefs::kProxyPacUrl, Value::CreateNullValue()); | 606 prefs_.SetValue(prefs::kProxyPacUrl, Value::CreateNullValue()); |
600 } | 607 } |
601 if (HasProxyPolicy(kPolicyProxyBypassList)) { | 608 if (HasProxyPolicy(kPolicyProxyBypassList)) { |
602 prefs_->Set(prefs::kProxyBypassList, | 609 prefs_.SetValue(prefs::kProxyBypassList, |
603 proxy_policies_[kPolicyProxyBypassList]); | 610 proxy_policies_[kPolicyProxyBypassList]); |
604 proxy_policies_[kPolicyProxyBypassList] = NULL; | 611 proxy_policies_[kPolicyProxyBypassList] = NULL; |
605 } else { | 612 } else { |
606 prefs_->Set(prefs::kProxyBypassList, Value::CreateNullValue()); | 613 prefs_.SetValue(prefs::kProxyBypassList, Value::CreateNullValue()); |
607 } | 614 } |
608 } | 615 } |
609 | 616 |
610 bool ConfigurationPolicyPrefStore::ApplySyncPolicy( | 617 bool ConfigurationPolicyPrefKeeper::HasProxyPolicy( |
611 ConfigurationPolicyType policy, Value* value) { | 618 ConfigurationPolicyType policy) const { |
612 if (policy == kPolicySyncDisabled) { | 619 std::map<ConfigurationPolicyType, Value*>::const_iterator iter; |
613 bool disable_sync; | 620 iter = proxy_policies_.find(policy); |
614 if (value->GetAsBoolean(&disable_sync) && disable_sync) | 621 return iter != proxy_policies_.end() && |
615 prefs_->Set(prefs::kSyncManaged, value); | 622 iter->second && !iter->second->IsType(Value::TYPE_NULL); |
616 else | |
617 delete value; | |
618 return true; | |
619 } | |
620 return false; | |
621 } | |
622 | |
623 bool ConfigurationPolicyPrefStore::ApplyAutoFillPolicy( | |
624 ConfigurationPolicyType policy, Value* value) { | |
625 if (policy == kPolicyAutoFillEnabled) { | |
626 bool auto_fill_enabled; | |
627 if (value->GetAsBoolean(&auto_fill_enabled) && !auto_fill_enabled) | |
628 prefs_->Set(prefs::kAutoFillEnabled, Value::CreateBooleanValue(false)); | |
629 delete value; | |
630 return true; | |
631 } | |
632 return false; | |
633 } | |
634 | |
635 void ConfigurationPolicyPrefStore::EnsureStringPrefExists( | |
636 const std::string& path) { | |
637 std::string value; | |
638 if (!prefs_->GetString(path, &value)) | |
639 prefs_->SetString(path, value); | |
640 } | 623 } |
641 | 624 |
642 namespace { | 625 namespace { |
643 | 626 |
644 // Implementation of SearchTermsData just for validation. | 627 // Manages the lifecycle of the shared platform-specific policy providers for |
645 class SearchTermsDataForValidation : public SearchTermsData { | 628 // managed platform, device management and recommended policy. Instantiated as a |
629 // Singleton. | |
630 class ConfigurationPolicyProviderKeeper { | |
646 public: | 631 public: |
647 SearchTermsDataForValidation() {} | 632 ConfigurationPolicyProviderKeeper() |
648 | 633 : managed_platform_provider_(CreateManagedPlatformProvider()), |
649 // Implementation of SearchTermsData. | 634 device_management_provider_(CreateDeviceManagementProvider()), |
650 virtual std::string GoogleBaseURLValue() const { | 635 recommended_provider_(CreateRecommendedProvider()) {} |
651 return "http://www.google.com/"; | 636 virtual ~ConfigurationPolicyProviderKeeper() {} |
652 } | 637 |
653 virtual std::string GetApplicationLocale() const { | 638 ConfigurationPolicyProvider* managed_platform_provider() const { |
654 return "en"; | 639 return managed_platform_provider_.get(); |
655 } | 640 } |
656 #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) | 641 |
657 virtual std::wstring GetRlzParameterValue() const { | 642 ConfigurationPolicyProvider* device_management_provider() const { |
658 return std::wstring(); | 643 return device_management_provider_.get(); |
659 } | 644 } |
645 | |
646 ConfigurationPolicyProvider* recommended_provider() const { | |
647 return recommended_provider_.get(); | |
648 } | |
649 | |
650 private: | |
651 scoped_ptr<ConfigurationPolicyProvider> managed_platform_provider_; | |
652 scoped_ptr<ConfigurationPolicyProvider> device_management_provider_; | |
653 scoped_ptr<ConfigurationPolicyProvider> recommended_provider_; | |
654 | |
655 static ConfigurationPolicyProvider* CreateManagedPlatformProvider(); | |
656 static ConfigurationPolicyProvider* CreateDeviceManagementProvider(); | |
657 static ConfigurationPolicyProvider* CreateRecommendedProvider(); | |
658 | |
659 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyProviderKeeper); | |
660 }; | |
661 | |
662 static base::LazyInstance<ConfigurationPolicyProviderKeeper> | |
663 g_configuration_policy_provider_keeper(base::LINKER_INITIALIZED); | |
664 | |
665 ConfigurationPolicyProvider* | |
666 ConfigurationPolicyProviderKeeper::CreateManagedPlatformProvider() { | |
667 const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list = | |
668 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(); | |
669 #if defined(OS_WIN) | |
670 return new ConfigurationPolicyProviderWin(policy_list); | |
671 #elif defined(OS_MACOSX) | |
672 return new ConfigurationPolicyProviderMac(policy_list); | |
673 #elif defined(OS_POSIX) | |
674 FilePath config_dir_path; | |
675 if (PathService::Get(chrome::DIR_POLICY_FILES, &config_dir_path)) { | |
676 return new ConfigDirPolicyProvider( | |
677 policy_list, | |
678 config_dir_path.Append(FILE_PATH_LITERAL("managed"))); | |
679 } else { | |
680 return new DummyConfigurationPolicyProvider(policy_list); | |
681 } | |
682 #else | |
683 return new DummyConfigurationPolicyProvider(policy_list); | |
660 #endif | 684 #endif |
661 private: | 685 } |
662 DISALLOW_COPY_AND_ASSIGN(SearchTermsDataForValidation); | 686 |
663 }; | 687 ConfigurationPolicyProvider* |
664 | 688 ConfigurationPolicyProviderKeeper::CreateDeviceManagementProvider() { |
665 } // namepsace | 689 return new DummyConfigurationPolicyProvider( |
666 | 690 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList()); |
667 void ConfigurationPolicyPrefStore::FinalizeDefaultSearchPolicySettings() { | 691 } |
668 bool enabled = true; | 692 |
669 if (prefs_->GetBoolean(prefs::kDefaultSearchProviderEnabled, &enabled) && | 693 ConfigurationPolicyProvider* |
670 !enabled) { | 694 ConfigurationPolicyProviderKeeper::CreateRecommendedProvider() { |
671 // If default search is disabled, we ignore the other fields. | 695 const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list = |
672 prefs_->SetString(prefs::kDefaultSearchProviderName, std::string()); | 696 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(); |
673 prefs_->SetString(prefs::kDefaultSearchProviderSearchURL, std::string()); | 697 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
674 prefs_->SetString(prefs::kDefaultSearchProviderSuggestURL, std::string()); | 698 FilePath config_dir_path; |
675 prefs_->SetString(prefs::kDefaultSearchProviderIconURL, std::string()); | 699 if (PathService::Get(chrome::DIR_POLICY_FILES, &config_dir_path)) { |
676 prefs_->SetString(prefs::kDefaultSearchProviderEncodings, std::string()); | 700 return new ConfigDirPolicyProvider( |
677 prefs_->SetString(prefs::kDefaultSearchProviderKeyword, std::string()); | 701 policy_list, |
678 return; | 702 config_dir_path.Append(FILE_PATH_LITERAL("recommended"))); |
679 } | 703 } else { |
680 std::string search_url; | 704 return new DummyConfigurationPolicyProvider(policy_list); |
681 // The search URL is required. | 705 } |
682 if (prefs_->GetString(prefs::kDefaultSearchProviderSearchURL, &search_url) && | 706 #else |
683 !search_url.empty()) { | 707 return new DummyConfigurationPolicyProvider(policy_list); |
684 SearchTermsDataForValidation search_terms_data; | 708 #endif |
685 const TemplateURLRef search_url_ref(search_url, 0, 0); | 709 } |
686 // It must support replacement (which implies it is valid). | 710 |
687 if (search_url_ref.SupportsReplacementUsingTermsData(search_terms_data)) { | 711 } |
688 // The other entries are optional. Just make sure that they are all | 712 |
689 // specified via policy, so that we don't use regular prefs. | 713 ConfigurationPolicyPrefStore::ConfigurationPolicyPrefStore( |
690 EnsureStringPrefExists(prefs::kDefaultSearchProviderSuggestURL); | 714 ConfigurationPolicyProvider* provider) |
691 EnsureStringPrefExists(prefs::kDefaultSearchProviderIconURL); | 715 : provider_(provider), |
692 EnsureStringPrefExists(prefs::kDefaultSearchProviderEncodings); | 716 initialization_complete_(provider->IsInitializationComplete()) { |
693 EnsureStringPrefExists(prefs::kDefaultSearchProviderKeyword); | 717 // Read initial policy. |
694 | 718 policy_keeper_.reset(new ConfigurationPolicyPrefKeeper(provider)); |
695 // For the name, default to the host if not specified. | 719 |
696 std::string name; | 720 // TODO(mnissler): Remove after provider has proper observer interface. |
697 if (!prefs_->GetString(prefs::kDefaultSearchProviderName, &name) || | 721 registrar_.Add(this, |
698 name.empty()) | 722 NotificationType(NotificationType::POLICY_CHANGED), |
699 prefs_->SetString(prefs::kDefaultSearchProviderName, | 723 NotificationService::AllSources()); |
700 GURL(search_url).host()); | 724 } |
701 | 725 |
702 // And clear the IDs since these are not specified via policy. | 726 ConfigurationPolicyPrefStore::~ConfigurationPolicyPrefStore() { |
703 prefs_->SetString(prefs::kDefaultSearchProviderID, std::string()); | 727 } |
704 prefs_->SetString(prefs::kDefaultSearchProviderPrepopulateID, | 728 |
705 std::string()); | 729 void ConfigurationPolicyPrefStore::AddObserver(PrefStore::Observer* observer) { |
706 return; | 730 observers_.AddObserver(observer); |
707 } | 731 } |
708 } | 732 |
709 // Required entries are not there. Remove any related entries. | 733 void ConfigurationPolicyPrefStore::RemoveObserver( |
710 RemovePreferencesOfMap(kDefaultSearchPolicyMap, | 734 PrefStore::Observer* observer) { |
711 arraysize(kDefaultSearchPolicyMap)); | 735 observers_.RemoveObserver(observer); |
736 } | |
737 | |
738 bool ConfigurationPolicyPrefStore::IsInitializationComplete() const { | |
739 return initialization_complete_; | |
740 } | |
741 | |
742 PrefStore::ReadResult | |
743 ConfigurationPolicyPrefStore::GetValue(const std::string& key, | |
744 Value** value) const { | |
745 return policy_keeper_->GetValue(key, value); | |
746 } | |
747 | |
748 // static | |
749 ConfigurationPolicyPrefStore* | |
750 ConfigurationPolicyPrefStore::CreateManagedPlatformPolicyPrefStore() { | |
751 return new ConfigurationPolicyPrefStore( | |
752 g_configuration_policy_provider_keeper.Get().managed_platform_provider()); | |
753 } | |
754 | |
755 // static | |
756 ConfigurationPolicyPrefStore* | |
757 ConfigurationPolicyPrefStore::CreateDeviceManagementPolicyPrefStore( | |
758 Profile* profile) { | |
759 ConfigurationPolicyProviderKeeper* keeper = | |
760 g_configuration_policy_provider_keeper.Pointer(); | |
761 ConfigurationPolicyProvider* provider = NULL; | |
762 if (profile) | |
763 provider = profile->GetPolicyContext()->GetDeviceManagementPolicyProvider(); | |
764 if (!provider) | |
765 provider = keeper->device_management_provider(); | |
766 return new ConfigurationPolicyPrefStore(provider); | |
767 } | |
768 | |
769 // static | |
770 ConfigurationPolicyPrefStore* | |
771 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore() { | |
772 return new ConfigurationPolicyPrefStore( | |
773 g_configuration_policy_provider_keeper.Get().recommended_provider()); | |
774 } | |
775 | |
776 /* static */ | |
777 const ConfigurationPolicyProvider::PolicyDefinitionList* | |
778 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList() { | |
779 static ConfigurationPolicyProvider::PolicyDefinitionList::Entry entries[] = { | |
780 { kPolicyHomePage, Value::TYPE_STRING, key::kHomepageLocation }, | |
781 { kPolicyHomepageIsNewTabPage, Value::TYPE_BOOLEAN, | |
782 key::kHomepageIsNewTabPage }, | |
783 { kPolicyRestoreOnStartup, Value::TYPE_INTEGER, key::kRestoreOnStartup }, | |
784 { kPolicyURLsToRestoreOnStartup, Value::TYPE_LIST, | |
785 key::kURLsToRestoreOnStartup }, | |
786 { kPolicyDefaultSearchProviderEnabled, Value::TYPE_BOOLEAN, | |
787 key::kDefaultSearchProviderEnabled }, | |
788 { kPolicyDefaultSearchProviderName, Value::TYPE_STRING, | |
789 key::kDefaultSearchProviderName }, | |
790 { kPolicyDefaultSearchProviderKeyword, Value::TYPE_STRING, | |
791 key::kDefaultSearchProviderKeyword }, | |
792 { kPolicyDefaultSearchProviderSearchURL, Value::TYPE_STRING, | |
793 key::kDefaultSearchProviderSearchURL }, | |
794 { kPolicyDefaultSearchProviderSuggestURL, Value::TYPE_STRING, | |
795 key::kDefaultSearchProviderSuggestURL }, | |
796 { kPolicyDefaultSearchProviderIconURL, Value::TYPE_STRING, | |
797 key::kDefaultSearchProviderIconURL }, | |
798 { kPolicyDefaultSearchProviderEncodings, Value::TYPE_STRING, | |
799 key::kDefaultSearchProviderEncodings }, | |
800 { kPolicyProxyMode, Value::TYPE_INTEGER, key::kProxyMode }, | |
801 { kPolicyProxyServer, Value::TYPE_STRING, key::kProxyServer }, | |
802 { kPolicyProxyPacUrl, Value::TYPE_STRING, key::kProxyPacUrl }, | |
803 { kPolicyProxyBypassList, Value::TYPE_STRING, key::kProxyBypassList }, | |
804 { kPolicyAlternateErrorPagesEnabled, Value::TYPE_BOOLEAN, | |
805 key::kAlternateErrorPagesEnabled }, | |
806 { kPolicySearchSuggestEnabled, Value::TYPE_BOOLEAN, | |
807 key::kSearchSuggestEnabled }, | |
808 { kPolicyDnsPrefetchingEnabled, Value::TYPE_BOOLEAN, | |
809 key::kDnsPrefetchingEnabled }, | |
810 { kPolicyDisableSpdy, Value::TYPE_BOOLEAN, key::kDisableSpdy }, | |
811 { kPolicySafeBrowsingEnabled, Value::TYPE_BOOLEAN, | |
812 key::kSafeBrowsingEnabled }, | |
813 { kPolicyMetricsReportingEnabled, Value::TYPE_BOOLEAN, | |
814 key::kMetricsReportingEnabled }, | |
815 { kPolicyPasswordManagerEnabled, Value::TYPE_BOOLEAN, | |
816 key::kPasswordManagerEnabled }, | |
817 { kPolicyPasswordManagerAllowShowPasswords, Value::TYPE_BOOLEAN, | |
818 key::kPasswordManagerAllowShowPasswords }, | |
819 { kPolicyAutoFillEnabled, Value::TYPE_BOOLEAN, key::kAutoFillEnabled }, | |
820 { kPolicyDisabledPlugins, Value::TYPE_LIST, key::kDisabledPlugins }, | |
821 { kPolicyApplicationLocale, Value::TYPE_STRING, | |
822 key::kApplicationLocaleValue }, | |
823 { kPolicySyncDisabled, Value::TYPE_BOOLEAN, key::kSyncDisabled }, | |
824 { kPolicyExtensionInstallAllowList, Value::TYPE_LIST, | |
825 key::kExtensionInstallAllowList }, | |
826 { kPolicyExtensionInstallDenyList, Value::TYPE_LIST, | |
827 key::kExtensionInstallDenyList }, | |
828 { kPolicyExtensionInstallForceList, Value::TYPE_LIST, | |
829 key::kExtensionInstallForceList }, | |
830 { kPolicyShowHomeButton, Value::TYPE_BOOLEAN, key::kShowHomeButton }, | |
831 { kPolicyPrintingEnabled, Value::TYPE_BOOLEAN, key::kPrintingEnabled }, | |
832 { kPolicyJavascriptEnabled, Value::TYPE_BOOLEAN, key::kJavascriptEnabled }, | |
833 { kPolicySavingBrowserHistoryDisabled, Value::TYPE_BOOLEAN, | |
834 key::kSavingBrowserHistoryDisabled }, | |
835 { kPolicyDeveloperToolsDisabled, Value::TYPE_BOOLEAN, | |
836 key::kDeveloperToolsDisabled }, | |
837 { kPolicyBlockThirdPartyCookies, Value::TYPE_BOOLEAN, | |
838 key::kBlockThirdPartyCookies }, | |
839 { kPolicyDefaultCookiesSetting, Value::TYPE_INTEGER, | |
840 key::kDefaultCookiesSetting }, | |
841 { kPolicyDefaultImagesSetting, Value::TYPE_INTEGER, | |
842 key::kDefaultImagesSetting }, | |
843 { kPolicyDefaultJavaScriptSetting, Value::TYPE_INTEGER, | |
844 key::kDefaultJavaScriptSetting }, | |
845 { kPolicyDefaultPluginsSetting, Value::TYPE_INTEGER, | |
846 key::kDefaultPluginsSetting }, | |
847 { kPolicyDefaultPopupsSetting, Value::TYPE_INTEGER, | |
848 key::kDefaultPopupsSetting }, | |
849 { kPolicyDefaultNotificationSetting, Value::TYPE_INTEGER, | |
850 key::kDefaultNotificationSetting }, | |
851 { kPolicyDefaultGeolocationSetting, Value::TYPE_INTEGER, | |
852 key::kDefaultGeolocationSetting }, | |
853 { kPolicyAuthSchemes, Value::TYPE_STRING, key::kAuthSchemes }, | |
854 { kPolicyDisableAuthNegotiateCnameLookup, Value::TYPE_BOOLEAN, | |
855 key::kDisableAuthNegotiateCnameLookup }, | |
856 { kPolicyEnableAuthNegotiatePort, Value::TYPE_BOOLEAN, | |
857 key::kEnableAuthNegotiatePort }, | |
858 { kPolicyAuthServerWhitelist, Value::TYPE_STRING, | |
859 key::kAuthServerWhitelist }, | |
860 { kPolicyAuthNegotiateDelegateWhitelist, Value::TYPE_STRING, | |
861 key::kAuthNegotiateDelegateWhitelist }, | |
862 { kPolicyGSSAPILibraryName, Value::TYPE_STRING, | |
863 key::kGSSAPILibraryName }, | |
864 { kPolicyDisable3DAPIs, Value::TYPE_BOOLEAN, | |
865 key::kDisable3DAPIs }, | |
866 | |
867 #if defined(OS_CHROMEOS) | |
868 { kPolicyChromeOsLockOnIdleSuspend, Value::TYPE_BOOLEAN, | |
869 key::kChromeOsLockOnIdleSuspend }, | |
870 #endif | |
871 }; | |
872 | |
873 static ConfigurationPolicyProvider::PolicyDefinitionList policy_list = { | |
874 entries, | |
875 entries + arraysize(entries), | |
876 }; | |
877 return &policy_list; | |
878 } | |
879 | |
880 void ConfigurationPolicyPrefStore::Observe(NotificationType type, | |
881 const NotificationSource& source, | |
882 const NotificationDetails& details) { | |
883 if (type == NotificationType::POLICY_CHANGED) | |
884 Refresh(); | |
885 } | |
886 | |
887 void ConfigurationPolicyPrefStore::Refresh() { | |
888 // Construct a new keeper, determine what changed and swap the keeper in. | |
889 scoped_ptr<ConfigurationPolicyPrefKeeper> new_keeper( | |
890 new ConfigurationPolicyPrefKeeper(provider_)); | |
891 std::vector<std::string> changed_prefs; | |
892 new_keeper->GetDifferingPrefPaths(policy_keeper_.get(), &changed_prefs); | |
893 policy_keeper_.reset(new_keeper.release()); | |
894 | |
895 // Send out change notifications. | |
896 for (std::vector<std::string>::const_iterator pref(changed_prefs.begin()); | |
897 pref != changed_prefs.end(); | |
898 ++pref) { | |
899 FOR_EACH_OBSERVER(PrefStore::Observer, observers_, | |
900 OnPrefValueChanged(*pref)); | |
901 } | |
902 | |
903 // Update the initialization flag. | |
904 if (!initialization_complete_ && | |
905 provider_->IsInitializationComplete()) { | |
906 initialization_complete_ = true; | |
907 FOR_EACH_OBSERVER(PrefStore::Observer, observers_, | |
908 OnInitializationCompleted()); | |
909 } | |
712 } | 910 } |
713 | 911 |
714 } // namespace policy | 912 } // namespace policy |
OLD | NEW |