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

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

Issue 7972013: ConfigurationPolicyPrefStore refactoring to surface error messages. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: . Created 9 years, 3 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/stl_util.h" 15 #include "base/stl_util.h"
16 #include "base/string16.h" 16 #include "base/string16.h"
17 #include "base/string_util.h" 17 #include "base/string_util.h"
18 #include "base/utf_string_conversions.h" 18 #include "base/utf_string_conversions.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
21 #include "chrome/browser/download/download_util.h" 21 #include "chrome/browser/download/download_util.h"
22 #include "chrome/browser/policy/browser_policy_connector.h" 22 #include "chrome/browser/policy/browser_policy_connector.h"
23 #include "chrome/browser/policy/configuration_policy_handler_interface.h"
23 #include "chrome/browser/policy/configuration_policy_provider.h" 24 #include "chrome/browser/policy/configuration_policy_provider.h"
24 #include "chrome/browser/policy/policy_path_parser.h" 25 #include "chrome/browser/policy/policy_path_parser.h"
25 #include "chrome/browser/prefs/incognito_mode_prefs.h" 26 #include "chrome/browser/prefs/incognito_mode_prefs.h"
26 #include "chrome/browser/prefs/pref_value_map.h" 27 #include "chrome/browser/prefs/pref_value_map.h"
27 #include "chrome/browser/prefs/proxy_config_dictionary.h" 28 #include "chrome/browser/prefs/proxy_config_dictionary.h"
28 #include "chrome/browser/search_engines/search_terms_data.h" 29 #include "chrome/browser/search_engines/search_terms_data.h"
29 #include "chrome/browser/search_engines/template_url.h" 30 #include "chrome/browser/search_engines/template_url.h"
30 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
31 #include "content/common/notification_service.h" 32 #include "content/common/notification_service.h"
32 #include "policy/policy_constants.h" 33 #include "policy/policy_constants.h"
33 34
34 namespace policy { 35 namespace policy {
35 36
36 // Accepts policy settings from a ConfigurationPolicyProvider, converts them 37 // Accepts policy settings from a ConfigurationPolicyProvider, converts them
37 // to preferences and caches the result. 38 // to preferences and caches the result.
38 class ConfigurationPolicyPrefKeeper { 39 class ConfigurationPolicyPrefKeeper {
39 public: 40 public:
40 explicit ConfigurationPolicyPrefKeeper(ConfigurationPolicyProvider* provider); 41 explicit ConfigurationPolicyPrefKeeper(ConfigurationPolicyProvider* provider,
42 const HandlerList* policy_handlers);
41 virtual ~ConfigurationPolicyPrefKeeper(); 43 virtual ~ConfigurationPolicyPrefKeeper();
42 44
43 // Get a preference value. 45 // Get a preference value.
44 PrefStore::ReadResult GetValue(const std::string& key, 46 PrefStore::ReadResult GetValue(const std::string& key,
45 const Value** result) const; 47 const Value** result) const;
46 48
47 // Compute the set of preference names that are different in |keeper|. This 49 // Compute the set of preference names that are different in |keeper|. This
48 // includes preferences that are missing in either one. 50 // includes preferences that are missing in either one.
49 void GetDifferingPrefPaths(const ConfigurationPolicyPrefKeeper* other, 51 void GetDifferingPrefPaths(const ConfigurationPolicyPrefKeeper* other,
50 std::vector<std::string>* differing_prefs) const; 52 std::vector<std::string>* differing_prefs) const;
51 53
52 private: 54 private:
53 // Apply the policy settings stored in |policies|. 55 // Apply the policy settings stored in |policies|.
54 void Apply(PolicyMap* policies); 56 void Apply(PolicyMap* policies, const HandlerList* policy_handlers);
55
56 // Policies that map to a single preference are handled
57 // by an automated converter. Each one of these policies
58 // has an entry in |simple_policy_map_| with the following type.
59 struct PolicyToPreferenceMapEntry {
60 base::Value::Type value_type;
61 ConfigurationPolicyType policy_type;
62 const char* preference_path; // A DictionaryValue path, not a file path.
63 };
64
65 // Remove the preferences found in the map from |prefs_|. Returns true if any
66 // such preferences were found and removed.
67 bool RemovePreferencesOfMap(const PolicyToPreferenceMapEntry* map,
68 int table_size);
69
70 bool ApplyPolicyFromMap(ConfigurationPolicyType policy,
71 Value* value,
72 const PolicyToPreferenceMapEntry* map,
73 int size);
74
75 // Processes proxy-specific policies. Returns true if the specified policy
76 // is a proxy-related policy. ApplyProxyPolicy assumes the ownership
77 // of |value| in the case that the policy is proxy-specific.
78 bool ApplyProxyPolicy(ConfigurationPolicyType policy, Value* value);
79
80 // Handles sync-related policies. Returns true if the policy was handled.
81 // Assumes ownership of |value| in that case.
82 bool ApplySyncPolicy(ConfigurationPolicyType policy, Value* value);
83
84 // Handles policies that affect Autofill. Returns true if the policy was
85 // handled and assumes ownership of |value| in that case.
86 bool ApplyAutofillPolicy(ConfigurationPolicyType policy, Value* value);
87
88 // Processes download directory policy. Returns true if the specified policy
89 // is the download directory policy. ApplyDownloadDirPolicy assumes the
90 // ownership of |value| in the case that the policy is recognized.
91 bool ApplyDownloadDirPolicy(ConfigurationPolicyType policy, Value* value);
92
93 // Processes disk cache directory policy. Returns true if the specified policy
94 // is the right one. ApplyDiskCacheDirPolicy assumes the
95 // ownership of |value| in the case that the policy is recognized.
96 bool ApplyDiskCacheDirPolicy(ConfigurationPolicyType policy, Value* value);
97
98 // Processes file-selection dialogs policy. Returns true if the specified
99 // policy is the file-selection dialogs policy.
100 // ApplyFileSelectionDialogsPolicy assumes the ownership of |value| in the
101 // case that the policy is recognized.
102 bool ApplyFileSelectionDialogsPolicy(ConfigurationPolicyType policy,
103 Value* value);
104
105 // Processes default search provider policies. Returns true if the specified
106 // policy is a default search provider related policy. In that case,
107 // ApplyDefaultSearchPolicy takes ownership of |value|.
108 bool ApplyDefaultSearchPolicy(ConfigurationPolicyType policy, Value* value);
109
110 // Processes incognito mode availability related policies. Returns true if the
111 // specified policy is pertinent to incognito mode availability. In that case,
112 // the function takes ownership of |value|.
113 bool ApplyIncognitoModePolicy(ConfigurationPolicyType policy, Value* value);
114
115 // Processes a policy that can disable the bookmarks bar. It can also affect
116 // other preferences.
117 bool ApplyBookmarksPolicy(ConfigurationPolicyType policy, Value* value);
118
119 // Make sure that the |path| if present in |prefs_|. If not, set it to
120 // a blank string.
121 void EnsureStringPrefExists(const std::string& path);
122
123 // If the required entries for default search are specified and valid,
124 // finalizes the policy-specified configuration by initializing the
125 // unspecified map entries. Otherwise wipes all default search related
126 // map entries from |prefs_|.
127 void FinalizeDefaultSearchPolicySettings();
128
129 // If the required entries for the proxy settings are specified and valid,
130 // finalizes the policy-specified configuration by initializing the
131 // respective values in |prefs_|.
132 void FinalizeProxyPolicySettings();
133
134 // If the required entries for the Incognito mode availability settings
135 // are specified and valid, finalizes the policy-specified configuration
136 // by initializing the respective values in |prefs_|.
137 void FinalizeIncognitoModeSettings();
138
139 // Returns true if the policy values stored in proxy_* represent a valid proxy
140 // configuration, including the case in which there is no configuration at
141 // all.
142 bool CheckProxySettings();
143
144 // Assumes CheckProxySettings returns true and applies the values stored
145 // in proxy_*.
146 void ApplyProxySettings();
147
148 bool HasProxyPolicy(ConfigurationPolicyType policy) const;
149
150 // Temporary cache that stores values until FinalizeProxyPolicySettings()
151 // is called.
152 std::map<ConfigurationPolicyType, Value*> proxy_policies_;
153
154 // Saved state of the deprecated kPolicyIncognitoEnabled. It is still used for
155 // backward compatibility to set the new kIncognitoAvailabilityMode pref in
156 // case the corresponding policy for the latter is not specified.
157 scoped_ptr<Value> deprecated_incognito_enabled_;
158 57
159 PrefValueMap prefs_; 58 PrefValueMap prefs_;
160 59
161 static const PolicyToPreferenceMapEntry kSimplePolicyMap[];
162 static const PolicyToPreferenceMapEntry kDefaultSearchPolicyMap[];
163
164 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyPrefKeeper); 60 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyPrefKeeper);
165 }; 61 };
166 62
167 const ConfigurationPolicyPrefKeeper::PolicyToPreferenceMapEntry
168 ConfigurationPolicyPrefKeeper::kSimplePolicyMap[] = {
169 { Value::TYPE_STRING, kPolicyHomepageLocation, prefs::kHomePage },
170 { Value::TYPE_BOOLEAN, kPolicyHomepageIsNewTabPage,
171 prefs::kHomePageIsNewTabPage },
172 { Value::TYPE_INTEGER, kPolicyRestoreOnStartup,
173 prefs::kRestoreOnStartup},
174 { Value::TYPE_LIST, kPolicyRestoreOnStartupURLs,
175 prefs::kURLsToRestoreOnStartup },
176 { Value::TYPE_BOOLEAN, kPolicyAlternateErrorPagesEnabled,
177 prefs::kAlternateErrorPagesEnabled },
178 { Value::TYPE_BOOLEAN, kPolicySearchSuggestEnabled,
179 prefs::kSearchSuggestEnabled },
180 { Value::TYPE_BOOLEAN, kPolicyDnsPrefetchingEnabled,
181 prefs::kNetworkPredictionEnabled },
182 { Value::TYPE_BOOLEAN, kPolicyDisableSpdy,
183 prefs::kDisableSpdy },
184 { Value::TYPE_LIST, kPolicyDisabledSchemes,
185 prefs::kDisabledSchemes },
186 { Value::TYPE_BOOLEAN, kPolicySafeBrowsingEnabled,
187 prefs::kSafeBrowsingEnabled },
188 { Value::TYPE_BOOLEAN, kPolicyPasswordManagerEnabled,
189 prefs::kPasswordManagerEnabled },
190 { Value::TYPE_BOOLEAN, kPolicyPasswordManagerAllowShowPasswords,
191 prefs::kPasswordManagerAllowShowPasswords },
192 { Value::TYPE_BOOLEAN, kPolicyPrintingEnabled,
193 prefs::kPrintingEnabled },
194 { Value::TYPE_BOOLEAN, kPolicyMetricsReportingEnabled,
195 prefs::kMetricsReportingEnabled },
196 { Value::TYPE_STRING, kPolicyApplicationLocaleValue,
197 prefs::kApplicationLocale},
198 { Value::TYPE_LIST, kPolicyExtensionInstallWhitelist,
199 prefs::kExtensionInstallAllowList},
200 { Value::TYPE_LIST, kPolicyExtensionInstallBlacklist,
201 prefs::kExtensionInstallDenyList},
202 { Value::TYPE_LIST, kPolicyExtensionInstallForcelist,
203 prefs::kExtensionInstallForceList},
204 { Value::TYPE_LIST, kPolicyDisabledPlugins,
205 prefs::kPluginsDisabledPlugins},
206 { Value::TYPE_LIST, kPolicyDisabledPluginsExceptions,
207 prefs::kPluginsDisabledPluginsExceptions},
208 { Value::TYPE_LIST, kPolicyEnabledPlugins,
209 prefs::kPluginsEnabledPlugins},
210 { Value::TYPE_BOOLEAN, kPolicyShowHomeButton,
211 prefs::kShowHomeButton },
212 { Value::TYPE_BOOLEAN, kPolicyJavascriptEnabled,
213 prefs::kWebKitJavascriptEnabled },
214 { Value::TYPE_BOOLEAN, kPolicySavingBrowserHistoryDisabled,
215 prefs::kSavingBrowserHistoryDisabled },
216 { Value::TYPE_BOOLEAN, kPolicyClearSiteDataOnExit,
217 prefs::kClearSiteDataOnExit },
218 { Value::TYPE_BOOLEAN, kPolicyDeveloperToolsDisabled,
219 prefs::kDevToolsDisabled },
220 { Value::TYPE_BOOLEAN, kPolicyBlockThirdPartyCookies,
221 prefs::kBlockThirdPartyCookies },
222 { Value::TYPE_INTEGER, kPolicyDefaultCookiesSetting,
223 prefs::kManagedDefaultCookiesSetting },
224 { Value::TYPE_INTEGER, kPolicyDefaultImagesSetting,
225 prefs::kManagedDefaultImagesSetting },
226 { Value::TYPE_INTEGER, kPolicyDefaultJavaScriptSetting,
227 prefs::kManagedDefaultJavaScriptSetting },
228 { Value::TYPE_INTEGER, kPolicyDefaultPluginsSetting,
229 prefs::kManagedDefaultPluginsSetting },
230 { Value::TYPE_INTEGER, kPolicyDefaultPopupsSetting,
231 prefs::kManagedDefaultPopupsSetting },
232 { Value::TYPE_LIST, kPolicyAutoSelectCertificateForUrls,
233 prefs::kManagedAutoSelectCertificateForUrls},
234 { Value::TYPE_LIST, kPolicyCookiesAllowedForUrls,
235 prefs::kManagedCookiesAllowedForUrls },
236 { Value::TYPE_LIST, kPolicyCookiesBlockedForUrls,
237 prefs::kManagedCookiesBlockedForUrls },
238 { Value::TYPE_LIST, kPolicyCookiesSessionOnlyForUrls,
239 prefs::kManagedCookiesSessionOnlyForUrls },
240 { Value::TYPE_LIST, kPolicyImagesAllowedForUrls,
241 prefs::kManagedImagesAllowedForUrls },
242 { Value::TYPE_LIST, kPolicyImagesBlockedForUrls,
243 prefs::kManagedImagesBlockedForUrls },
244 { Value::TYPE_LIST, kPolicyJavaScriptAllowedForUrls,
245 prefs::kManagedJavaScriptAllowedForUrls },
246 { Value::TYPE_LIST, kPolicyJavaScriptBlockedForUrls,
247 prefs::kManagedJavaScriptBlockedForUrls },
248 { Value::TYPE_LIST, kPolicyPluginsAllowedForUrls,
249 prefs::kManagedPluginsAllowedForUrls },
250 { Value::TYPE_LIST, kPolicyPluginsBlockedForUrls,
251 prefs::kManagedPluginsBlockedForUrls },
252 { Value::TYPE_LIST, kPolicyPopupsAllowedForUrls,
253 prefs::kManagedPopupsAllowedForUrls },
254 { Value::TYPE_LIST, kPolicyPopupsBlockedForUrls,
255 prefs::kManagedPopupsBlockedForUrls },
256 { Value::TYPE_LIST, kPolicyNotificationsAllowedForUrls,
257 prefs::kManagedNotificationsAllowedForUrls },
258 { Value::TYPE_LIST, kPolicyNotificationsBlockedForUrls,
259 prefs::kManagedNotificationsBlockedForUrls },
260 { Value::TYPE_INTEGER, kPolicyDefaultNotificationsSetting,
261 prefs::kManagedDefaultNotificationsSetting },
262 { Value::TYPE_INTEGER, kPolicyDefaultGeolocationSetting,
263 prefs::kManagedDefaultGeolocationSetting },
264 { Value::TYPE_STRING, kPolicyAuthSchemes,
265 prefs::kAuthSchemes },
266 { Value::TYPE_BOOLEAN, kPolicyDisableAuthNegotiateCnameLookup,
267 prefs::kDisableAuthNegotiateCnameLookup },
268 { Value::TYPE_BOOLEAN, kPolicyEnableAuthNegotiatePort,
269 prefs::kEnableAuthNegotiatePort },
270 { Value::TYPE_STRING, kPolicyAuthServerWhitelist,
271 prefs::kAuthServerWhitelist },
272 { Value::TYPE_STRING, kPolicyAuthNegotiateDelegateWhitelist,
273 prefs::kAuthNegotiateDelegateWhitelist },
274 { Value::TYPE_STRING, kPolicyGSSAPILibraryName,
275 prefs::kGSSAPILibraryName },
276 { Value::TYPE_BOOLEAN, kPolicyAllowCrossOriginAuthPrompt,
277 prefs::kAllowCrossOriginAuthPrompt },
278 { Value::TYPE_BOOLEAN, kPolicyDisable3DAPIs,
279 prefs::kDisable3DAPIs },
280 { Value::TYPE_BOOLEAN, kPolicyDisablePluginFinder,
281 prefs::kDisablePluginFinder },
282 { Value::TYPE_INTEGER, kPolicyPolicyRefreshRate,
283 prefs::kUserPolicyRefreshRate },
284 { Value::TYPE_INTEGER, kPolicyDevicePolicyRefreshRate,
285 prefs::kDevicePolicyRefreshRate },
286 { Value::TYPE_BOOLEAN, kPolicyInstantEnabled, prefs::kInstantEnabled },
287 { Value::TYPE_BOOLEAN, kPolicyDefaultBrowserSettingEnabled,
288 prefs::kDefaultBrowserSettingEnabled },
289 { Value::TYPE_BOOLEAN, kPolicyRemoteAccessClientFirewallTraversal,
290 prefs::kRemoteAccessClientFirewallTraversal },
291 { Value::TYPE_BOOLEAN, kPolicyRemoteAccessHostFirewallTraversal,
292 prefs::kRemoteAccessHostFirewallTraversal },
293 { Value::TYPE_BOOLEAN, kPolicyCloudPrintProxyEnabled,
294 prefs::kCloudPrintProxyEnabled },
295 { Value::TYPE_BOOLEAN, kPolicyTranslateEnabled, prefs::kEnableTranslate },
296 { Value::TYPE_BOOLEAN, kPolicyAllowOutdatedPlugins,
297 prefs::kPluginsAllowOutdated },
298 { Value::TYPE_BOOLEAN, kPolicyAlwaysAuthorizePlugins,
299 prefs::kPluginsAlwaysAuthorize },
300 { Value::TYPE_BOOLEAN, kPolicyEditBookmarksEnabled,
301 prefs::kEditBookmarksEnabled },
302 { Value::TYPE_BOOLEAN, kPolicyAllowFileSelectionDialogs,
303 prefs::kAllowFileSelectionDialogs },
304 { Value::TYPE_BOOLEAN, kPolicyImportBookmarks,
305 prefs::kImportBookmarks},
306 { Value::TYPE_BOOLEAN, kPolicyImportHistory,
307 prefs::kImportHistory},
308 { Value::TYPE_BOOLEAN, kPolicyImportHomepage,
309 prefs::kImportHomepage},
310 { Value::TYPE_BOOLEAN, kPolicyImportSearchEngine,
311 prefs::kImportSearchEngine },
312 { Value::TYPE_BOOLEAN, kPolicyImportSavedPasswords,
313 prefs::kImportSavedPasswords },
314 { Value::TYPE_INTEGER, kPolicyMaxConnectionsPerProxy,
315 prefs::kMaxConnectionsPerProxy },
316 { Value::TYPE_BOOLEAN, kPolicyHideWebStorePromo,
317 prefs::kNTPHideWebStorePromo },
318 { Value::TYPE_LIST, kPolicyURLBlacklist,
319 prefs::kUrlBlacklist },
320 { Value::TYPE_LIST, kPolicyURLWhitelist,
321 prefs::kUrlWhitelist },
322
323 #if defined(OS_CHROMEOS)
324 { Value::TYPE_BOOLEAN, kPolicyChromeOsLockOnIdleSuspend,
325 prefs::kEnableScreenLock },
326 { Value::TYPE_STRING, kPolicyChromeOsReleaseChannel,
327 prefs::kChromeOsReleaseChannel },
328 #endif
329 };
330
331 const ConfigurationPolicyPrefKeeper::PolicyToPreferenceMapEntry
332 ConfigurationPolicyPrefKeeper::kDefaultSearchPolicyMap[] = {
333 { Value::TYPE_BOOLEAN, kPolicyDefaultSearchProviderEnabled,
334 prefs::kDefaultSearchProviderEnabled },
335 { Value::TYPE_STRING, kPolicyDefaultSearchProviderName,
336 prefs::kDefaultSearchProviderName },
337 { Value::TYPE_STRING, kPolicyDefaultSearchProviderKeyword,
338 prefs::kDefaultSearchProviderKeyword },
339 { Value::TYPE_STRING, kPolicyDefaultSearchProviderSearchURL,
340 prefs::kDefaultSearchProviderSearchURL },
341 { Value::TYPE_STRING, kPolicyDefaultSearchProviderSuggestURL,
342 prefs::kDefaultSearchProviderSuggestURL },
343 { Value::TYPE_STRING, kPolicyDefaultSearchProviderInstantURL,
344 prefs::kDefaultSearchProviderInstantURL },
345 { Value::TYPE_STRING, kPolicyDefaultSearchProviderIconURL,
346 prefs::kDefaultSearchProviderIconURL },
347 { Value::TYPE_LIST, kPolicyDefaultSearchProviderEncodings,
348 prefs::kDefaultSearchProviderEncodings },
349 };
350
351 ConfigurationPolicyPrefKeeper::ConfigurationPolicyPrefKeeper( 63 ConfigurationPolicyPrefKeeper::ConfigurationPolicyPrefKeeper(
352 ConfigurationPolicyProvider* provider) { 64 ConfigurationPolicyProvider* provider, const HandlerList* policy_handlers) {
353 scoped_ptr<PolicyMap> policies(new PolicyMap()); 65 scoped_ptr<PolicyMap> policies(new PolicyMap());
354 if (!provider->Provide(policies.get())) 66 if (!provider->Provide(policies.get()))
355 LOG(WARNING) << "Failed to get policy from provider."; 67 LOG(WARNING) << "Failed to get policy from provider.";
356 68
357 Apply(policies.get()); 69 Apply(policies.get(), policy_handlers);
358 FinalizeProxyPolicySettings();
359 FinalizeDefaultSearchPolicySettings();
360 FinalizeIncognitoModeSettings();
361 } 70 }
362 71
363 ConfigurationPolicyPrefKeeper::~ConfigurationPolicyPrefKeeper() { 72 ConfigurationPolicyPrefKeeper::~ConfigurationPolicyPrefKeeper() {
364 DCHECK(proxy_policies_.empty());
365 } 73 }
366 74
367 PrefStore::ReadResult 75 PrefStore::ReadResult
368 ConfigurationPolicyPrefKeeper::GetValue(const std::string& key, 76 ConfigurationPolicyPrefKeeper::GetValue(const std::string& key,
369 const Value** result) const { 77 const Value** result) const {
370 const Value* stored_value = NULL; 78 const Value* stored_value = NULL;
371 if (!prefs_.GetValue(key, &stored_value)) 79 if (!prefs_.GetValue(key, &stored_value))
372 return PrefStore::READ_NO_VALUE; 80 return PrefStore::READ_NO_VALUE;
373 81
374 // Check whether there's a default value, which indicates READ_USE_DEFAULT 82 // Check whether there's a default value, which indicates READ_USE_DEFAULT
375 // should be returned. 83 // should be returned.
376 if (stored_value->IsType(Value::TYPE_NULL)) 84 if (stored_value->IsType(Value::TYPE_NULL))
377 return PrefStore::READ_USE_DEFAULT; 85 return PrefStore::READ_USE_DEFAULT;
378 86
379 if (result) 87 if (result)
380 *result = stored_value; 88 *result = stored_value;
381 return PrefStore::READ_OK; 89 return PrefStore::READ_OK;
382 } 90 }
383 91
384 void ConfigurationPolicyPrefKeeper::GetDifferingPrefPaths( 92 void ConfigurationPolicyPrefKeeper::GetDifferingPrefPaths(
385 const ConfigurationPolicyPrefKeeper* other, 93 const ConfigurationPolicyPrefKeeper* other,
386 std::vector<std::string>* differing_prefs) const { 94 std::vector<std::string>* differing_prefs) const {
387 prefs_.GetDifferingKeys(&other->prefs_, differing_prefs); 95 prefs_.GetDifferingKeys(&other->prefs_, differing_prefs);
388 } 96 }
389 97
390 void ConfigurationPolicyPrefKeeper::Apply(PolicyMap* policies) { 98 void ConfigurationPolicyPrefKeeper::Apply(
391 PolicyMap::const_iterator current = policies->begin(); 99 PolicyMap* policies, const HandlerList* policy_handlers) {
392 for ( ; current != policies->end(); ++current) { 100 HandlerList::const_iterator handler = policy_handlers->begin();
393 // TODO(simo) Use a separate ConfigurationPolicyHandler class to apply 101 for ( ; handler != policy_handlers->end(); ++handler) {
394 // policy settings. 102 (*handler)->ApplyPolicySettings(policies, &prefs_);
Mattias Nissler (ping if slow) 2011/09/26 13:30:48 As mentioned before, maybe do the check-before-app
395 Value* value = current->second->DeepCopy();
396 if (ApplyProxyPolicy(current->first, value) ||
397 ApplySyncPolicy(current->first, value) ||
398 ApplyAutofillPolicy(current->first, value) ||
399 ApplyDownloadDirPolicy(current->first, value) ||
400 ApplyDiskCacheDirPolicy(current->first, value) ||
401 ApplyFileSelectionDialogsPolicy(current->first,
402 value) ||
403 ApplyDefaultSearchPolicy(current->first, value) ||
404 ApplyIncognitoModePolicy(current->first, value) ||
405 ApplyBookmarksPolicy(current->first, value) ||
406 ApplyPolicyFromMap(current->first, value,
407 kSimplePolicyMap, arraysize(kSimplePolicyMap))) {
408 continue;
409 }
410 delete value;
411
412 // Other policy implementations should go into the conditional above.
413 NOTIMPLEMENTED();
414 } 103 }
415 } 104 }
416 105
417 bool ConfigurationPolicyPrefKeeper::RemovePreferencesOfMap(
418 const PolicyToPreferenceMapEntry* map, int table_size) {
419 bool found_any = false;
420 for (int i = 0; i < table_size; ++i) {
421 if (prefs_.RemoveValue(map[i].preference_path))
422 found_any = true;
423 }
424 return found_any;
425 }
426
427 bool ConfigurationPolicyPrefKeeper::ApplyPolicyFromMap(
428 ConfigurationPolicyType policy,
429 Value* value,
430 const PolicyToPreferenceMapEntry* map,
431 int size) {
432 for (int current = 0; current < size; ++current) {
433 if (map[current].policy_type == policy) {
434 DCHECK_EQ(map[current].value_type, value->GetType())
435 << "mismatch in provided and expected policy value for preferences "
436 << map[current].preference_path << ". expected = "
437 << map[current].value_type << ", actual = "<< value->GetType();
438 prefs_.SetValue(map[current].preference_path, value);
439 return true;
440 }
441 }
442 return false;
443 }
444
445 bool ConfigurationPolicyPrefKeeper::ApplyProxyPolicy(
446 ConfigurationPolicyType policy,
447 Value* value) {
448 // We only collect the values until we have sufficient information when
449 // FinalizeProxyPolicySettings() is called to determine whether the presented
450 // values were correct and apply them in that case.
451 if (ConfigurationPolicyPrefStore::IsProxyPolicy(policy)) {
452 delete proxy_policies_[policy];
453 proxy_policies_[policy] = value;
454 return true;
455 }
456 // We are not interested in this policy.
457 return false;
458 }
459
460 bool ConfigurationPolicyPrefKeeper::ApplySyncPolicy(
461 ConfigurationPolicyType policy, Value* value) {
462 if (policy == kPolicySyncDisabled) {
463 bool disable_sync;
464 if (value->GetAsBoolean(&disable_sync) && disable_sync)
465 prefs_.SetValue(prefs::kSyncManaged, value);
466 else
467 delete value;
468 return true;
469 }
470 return false;
471 }
472
473 bool ConfigurationPolicyPrefKeeper::ApplyAutofillPolicy(
474 ConfigurationPolicyType policy, Value* value) {
475 if (policy == kPolicyAutoFillEnabled) {
476 bool auto_fill_enabled;
477 if (value->GetAsBoolean(&auto_fill_enabled) && !auto_fill_enabled)
478 prefs_.SetValue(prefs::kAutofillEnabled,
479 Value::CreateBooleanValue(false));
480 delete value;
481 return true;
482 }
483 return false;
484 }
485
486 bool ConfigurationPolicyPrefKeeper::ApplyDownloadDirPolicy(
487 ConfigurationPolicyType policy,
488 Value* value) {
489 // Replace the policy string which might contain some user variables to an
490 // expanded string.
491 if (policy == kPolicyDownloadDirectory) {
492 // This policy is ignored on ChromeOS because the download path there is
493 // fixed and can not be configured by the user.
494 #if !defined(OS_CHROMEOS)
495 FilePath::StringType string_value;
496 bool result = value->GetAsString(&string_value);
497 DCHECK(result);
498 FilePath::StringType expanded_value =
499 policy::path_parser::ExpandPathVariables(string_value);
500 // Leaving the policy empty would revert to the default download location
501 // else we would point in an undefined location. We do this after the
502 // path expansion because it might lead to an empty string(e.g. for "\"\"").
503 if (expanded_value.empty())
504 expanded_value = download_util::GetDefaultDownloadDirectory().value();
505 prefs_.SetValue(prefs::kDownloadDefaultDirectory,
506 Value::CreateStringValue(expanded_value));
507 prefs_.SetValue(prefs::kPromptForDownload,
508 Value::CreateBooleanValue(false));
509 #endif // !defined(OS_CHROMEOS)
510 delete value;
511 return true;
512 }
513 // We are not interested in this policy.
514 return false;
515 }
516
517 bool ConfigurationPolicyPrefKeeper::ApplyDiskCacheDirPolicy(
518 ConfigurationPolicyType policy,
519 Value* value) {
520 // Replace the policy string which might contain some user variables to an
521 // expanded string.
522 if (policy == kPolicyDiskCacheDir) {
523 FilePath::StringType string_value;
524 bool result = value->GetAsString(&string_value);
525 DCHECK(result);
526 FilePath::StringType expanded_value =
527 policy::path_parser::ExpandPathVariables(string_value);
528 prefs_.SetValue(prefs::kDiskCacheDir,
529 Value::CreateStringValue(expanded_value));
530 delete value;
531 return true;
532 }
533 // We are not interested in this policy.
534 return false;
535 }
536
537 bool ConfigurationPolicyPrefKeeper::ApplyFileSelectionDialogsPolicy(
538 ConfigurationPolicyType policy,
539 Value* value) {
540 if (policy == kPolicyAllowFileSelectionDialogs) {
541 prefs_.SetValue(prefs::kAllowFileSelectionDialogs, value);
542 // If file-selection dialogs are not allowed we forbid the user to be
543 // prompted for the download location, since this would end up in an Infobar
544 // explaining that file-selection dialogs are forbidden anyways.
545 bool allow_file_selection_dialogs = true;
546 bool result = value->GetAsBoolean(&allow_file_selection_dialogs);
547 DCHECK(result);
548 if (!allow_file_selection_dialogs) {
549 prefs_.SetValue(prefs::kPromptForDownload,
550 Value::CreateBooleanValue(false));
551 }
552 return true;
553 }
554 // We are not interested in this policy.
555 return false;
556 }
557
558 bool ConfigurationPolicyPrefKeeper::ApplyDefaultSearchPolicy(
559 ConfigurationPolicyType policy,
560 Value* value) {
561 // The DefaultSearchProviderEncodings policy has type list, but the related
562 // preference has type string. Convert one into the other here, using
563 // ';' as a separator.
564 if (policy == kPolicyDefaultSearchProviderEncodings) {
565 ListValue* list;
566 if (!value->GetAsList(&list)) {
567 NOTREACHED()
568 << "mismatch in provided and expected policy value for preferences "
569 << prefs::kDefaultSearchProviderEncodings << ". expected = "
570 << Value::TYPE_LIST << ", actual = "<< value->GetType();
571 return false;
572 }
573 ListValue::const_iterator iter(list->begin());
574 ListValue::const_iterator end(list->end());
575 std::string encodings;
576 for (; iter != end; ++iter) {
577 std::string s;
578 if ((*iter)->GetAsString(&s)) {
579 if (!encodings.empty())
580 encodings.push_back(';');
581 encodings.append(s);
582 } else {
583 NOTREACHED();
584 }
585 }
586 // We own |value|.
587 delete value;
588 prefs_.SetValue(prefs::kDefaultSearchProviderEncodings,
589 Value::CreateStringValue(encodings));
590 return true;
591 }
592
593 if (ApplyPolicyFromMap(policy, value, kDefaultSearchPolicyMap,
594 arraysize(kDefaultSearchPolicyMap))) {
595 return true;
596 }
597 return false;
598 }
599
600 bool ConfigurationPolicyPrefKeeper::ApplyIncognitoModePolicy(
601 ConfigurationPolicyType policy,
602 Value* value) {
603 if (policy == kPolicyIncognitoModeAvailability) {
604 int availability = IncognitoModePrefs::ENABLED;
605 bool result = value->GetAsInteger(&availability);
606 delete value;
607 if (result) {
608 IncognitoModePrefs::Availability availability_enum_value;
609 if (IncognitoModePrefs::IntToAvailability(availability,
610 &availability_enum_value)) {
611 prefs_.SetValue(prefs::kIncognitoModeAvailability,
612 Value::CreateIntegerValue(availability_enum_value));
613 } else {
614 LOG(WARNING) << "IncognitoModeAvailability policy value is "
615 << "out of range " << availability;
616 }
617 } else {
618 LOG(WARNING) << "IncognitoModeAvailability policy value could not be "
619 << "parsed";
620 }
621 return true;
622 }
623 if (policy == kPolicyIncognitoEnabled) {
624 deprecated_incognito_enabled_.reset(value);
625 return true;
626 }
627 // The policy is not relevant to incognito.
628 return false;
629 }
630
631 bool ConfigurationPolicyPrefKeeper::ApplyBookmarksPolicy(
632 ConfigurationPolicyType policy,
633 Value* value) {
634 if (policy != kPolicyBookmarkBarEnabled)
635 return false;
636 DCHECK_EQ(Value::TYPE_BOOLEAN, value->GetType());
637 prefs_.SetValue(prefs::kEnableBookmarkBar, value);
638 // kShowBookmarkBar is not managed directly by a policy, but when
639 // kEnableBookmarkBar is managed, kShowBookmarkBar should be false so that
640 // the bookmarks bar either is completely disabled or only shows on the NTP.
641 // This also disables the checkbox for this preference in the prefs UI.
642 prefs_.SetValue(prefs::kShowBookmarkBar, Value::CreateBooleanValue(false));
643 return true;
644 }
645
646 void ConfigurationPolicyPrefKeeper::EnsureStringPrefExists(
647 const std::string& path) {
648 std::string value;
649 if (!prefs_.GetString(path, &value))
650 prefs_.SetString(path, value);
651 }
652
653 namespace {
654
655 // Implementation of SearchTermsData just for validation.
656 class SearchTermsDataForValidation : public SearchTermsData {
657 public:
658 SearchTermsDataForValidation() {}
659
660 // Implementation of SearchTermsData.
661 virtual std::string GoogleBaseURLValue() const {
662 return "http://www.google.com/";
663 }
664 virtual std::string GetApplicationLocale() const {
665 return "en";
666 }
667 #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD)
668 virtual string16 GetRlzParameterValue() const {
669 return string16();
670 }
671 #endif
672 private:
673 DISALLOW_COPY_AND_ASSIGN(SearchTermsDataForValidation);
674 };
675
676 } // namespace
677
678 void ConfigurationPolicyPrefKeeper::FinalizeDefaultSearchPolicySettings() {
679 bool enabled = true;
680 if (prefs_.GetBoolean(prefs::kDefaultSearchProviderEnabled, &enabled) &&
681 !enabled) {
682 // If default search is disabled, we ignore the other fields.
683 prefs_.SetString(prefs::kDefaultSearchProviderName, std::string());
684 prefs_.SetString(prefs::kDefaultSearchProviderSearchURL, std::string());
685 prefs_.SetString(prefs::kDefaultSearchProviderSuggestURL, std::string());
686 prefs_.SetString(prefs::kDefaultSearchProviderIconURL, std::string());
687 prefs_.SetString(prefs::kDefaultSearchProviderEncodings, std::string());
688 prefs_.SetString(prefs::kDefaultSearchProviderKeyword, std::string());
689 prefs_.SetString(prefs::kDefaultSearchProviderInstantURL, std::string());
690 return;
691 }
692 std::string search_url;
693 // The search URL is required.
694 if (prefs_.GetString(prefs::kDefaultSearchProviderSearchURL, &search_url) &&
695 !search_url.empty()) {
696 SearchTermsDataForValidation search_terms_data;
697 const TemplateURLRef search_url_ref(search_url, 0, 0);
698 // It must support replacement (which implies it is valid).
699 if (search_url_ref.SupportsReplacementUsingTermsData(search_terms_data)) {
700 // The other entries are optional. Just make sure that they are all
701 // specified via policy, so that we don't use regular prefs.
702 EnsureStringPrefExists(prefs::kDefaultSearchProviderSuggestURL);
703 EnsureStringPrefExists(prefs::kDefaultSearchProviderIconURL);
704 EnsureStringPrefExists(prefs::kDefaultSearchProviderEncodings);
705 EnsureStringPrefExists(prefs::kDefaultSearchProviderKeyword);
706 EnsureStringPrefExists(prefs::kDefaultSearchProviderInstantURL);
707
708 // For the name, default to the host if not specified.
709 std::string name;
710 if (!prefs_.GetString(prefs::kDefaultSearchProviderName, &name) ||
711 name.empty())
712 prefs_.SetString(prefs::kDefaultSearchProviderName,
713 GURL(search_url).host());
714
715 // And clear the IDs since these are not specified via policy.
716 prefs_.SetString(prefs::kDefaultSearchProviderID, std::string());
717 prefs_.SetString(prefs::kDefaultSearchProviderPrepopulateID,
718 std::string());
719 return;
720 }
721 }
722 // Required entries are not there. Remove any related entries.
723 RemovePreferencesOfMap(kDefaultSearchPolicyMap,
724 arraysize(kDefaultSearchPolicyMap));
725 }
726
727 void ConfigurationPolicyPrefKeeper::FinalizeIncognitoModeSettings() {
728 int int_value;
729 if (!prefs_.GetInteger(prefs::kIncognitoModeAvailability, &int_value)) {
730 // If kPolicyIncognitoModeAvailability is not specified, check the obsolete
731 // kPolicyIncognitoEnabled.
732 if (deprecated_incognito_enabled_.get()) {
733 bool enabled = true;
734 if (deprecated_incognito_enabled_->GetAsBoolean(&enabled)) {
735 prefs_.SetInteger(
736 prefs::kIncognitoModeAvailability,
737 enabled ? IncognitoModePrefs::ENABLED :
738 IncognitoModePrefs::DISABLED);
739 } else {
740 LOG(WARNING) << "IncognitoEnabled policy value could not be parsed";
741 }
742 }
743 }
744 }
745
746 void ConfigurationPolicyPrefKeeper::FinalizeProxyPolicySettings() {
747 if (CheckProxySettings())
748 ApplyProxySettings();
749
750 STLDeleteContainerPairSecondPointers(proxy_policies_.begin(),
751 proxy_policies_.end());
752 proxy_policies_.clear();
753 }
754
755 bool ConfigurationPolicyPrefKeeper::CheckProxySettings() {
756 bool mode = HasProxyPolicy(kPolicyProxyMode);
757 bool server_mode = HasProxyPolicy(kPolicyProxyServerMode); // deprecated
758 bool server = HasProxyPolicy(kPolicyProxyServer);
759 bool pac_url = HasProxyPolicy(kPolicyProxyPacUrl);
760 bool bypass_list = HasProxyPolicy(kPolicyProxyBypassList);
761
762 if ((server || pac_url || bypass_list) && !(mode || server_mode)) {
763 LOG(WARNING) << "A centrally-administered policy defines proxy setting"
764 << " details without setting a proxy mode.";
765 return false;
766 }
767
768 // If there's a server mode, convert it into a mode.
769 std::string mode_value;
770 if (mode) {
771 if (server_mode)
772 LOG(WARNING) << "Both ProxyMode and ProxyServerMode policies defined, "
773 << "ignoring ProxyMode.";
774 if (!proxy_policies_[kPolicyProxyMode]->GetAsString(&mode_value)) {
775 LOG(WARNING) << "Invalid ProxyMode value.";
776 return false;
777 }
778 } else if (server_mode) {
779 int server_mode_value;
780 if (!proxy_policies_[kPolicyProxyServerMode]->GetAsInteger(
781 &server_mode_value)) {
782 LOG(WARNING) << "Invalid ProxyServerMode value.";
783 return false;
784 }
785
786 switch (server_mode_value) {
787 case kPolicyNoProxyServerMode:
788 mode_value = ProxyPrefs::kDirectProxyModeName;
789 break;
790 case kPolicyAutoDetectProxyServerMode:
791 mode_value = ProxyPrefs::kAutoDetectProxyModeName;
792 break;
793 case kPolicyManuallyConfiguredProxyServerMode:
794 if (server && pac_url) {
795 LOG(WARNING) << "A centrally-administered policy dictates that"
796 << " both fixed proxy servers and a .pac url. should"
797 << " be used for proxy configuration.";
798 return false;
799 }
800 if (!server && !pac_url) {
801 LOG(WARNING) << "A centrally-administered policy dictates that the"
802 << " proxy settings should use either fixed proxy"
803 << " servers or a .pac url, but specifies neither.";
804 return false;
805 }
806 if (pac_url)
807 mode_value = ProxyPrefs::kPacScriptProxyModeName;
808 else
809 mode_value = ProxyPrefs::kFixedServersProxyModeName;
810 break;
811 case kPolicyUseSystemProxyServerMode:
812 mode_value = ProxyPrefs::kSystemProxyModeName;
813 break;
814 default:
815 LOG(WARNING) << "Invalid proxy mode " << server_mode_value;
816 return false;
817 }
818 }
819
820 // If neither ProxyMode nor ProxyServerMode are specified, mode_value will be
821 // empty and the proxy shouldn't be configured at all.
822 if (mode_value.empty())
823 return true;
824
825 if (mode_value == ProxyPrefs::kDirectProxyModeName) {
826 if (server || pac_url || bypass_list) {
827 LOG(WARNING) << "A centrally-administered policy disables the use of"
828 << " a proxy but also specifies an explicit proxy"
829 << " configuration.";
830 return false;
831 }
832 } else if (mode_value == ProxyPrefs::kAutoDetectProxyModeName) {
833 if (server || bypass_list || pac_url) {
834 LOG(WARNING) << "A centrally-administered policy dictates that a proxy"
835 << " shall be auto configured but specifies fixed proxy"
836 << " servers, a by-pass list or a .pac script URL.";
837 return false;
838 }
839 } else if (mode_value == ProxyPrefs::kPacScriptProxyModeName) {
840 if (server || bypass_list) {
841 LOG(WARNING) << "A centrally-administered policy dictates that a .pac"
842 << " script URL should be used for proxy configuration but"
843 << " also specifies policies required only for fixed"
844 << " proxy servers.";
845 return false;
846 }
847 } else if (mode_value == ProxyPrefs::kFixedServersProxyModeName) {
848 if (pac_url) {
849 LOG(WARNING) << "A centrally-administered policy dictates that"
850 << " fixed proxy servers should be used but also"
851 << " specifies a .pac script URL.";
852 return false;
853 }
854 } else if (mode_value == ProxyPrefs::kSystemProxyModeName) {
855 if (server || pac_url || bypass_list) {
856 LOG(WARNING) << "A centrally-administered policy dictates that the"
857 << " system proxy settings should be used but also "
858 << " specifies an explicit proxy configuration.";
859 return false;
860 }
861 } else {
862 LOG(WARNING) << "Invalid proxy mode " << mode_value;
863 return false;
864 }
865 return true;
866 }
867
868 void ConfigurationPolicyPrefKeeper::ApplyProxySettings() {
869 ProxyPrefs::ProxyMode mode;
870 if (HasProxyPolicy(kPolicyProxyMode)) {
871 std::string string_mode;
872 CHECK(proxy_policies_[kPolicyProxyMode]->GetAsString(&string_mode));
873 if (!ProxyPrefs::StringToProxyMode(string_mode, &mode)) {
874 LOG(WARNING) << "A centrally-administered policy specifies a value for "
875 << "the ProxyMode policy that isn't recognized.";
876 return;
877 }
878 } else if (HasProxyPolicy(kPolicyProxyServerMode)) {
879 int int_mode = 0;
880 CHECK(proxy_policies_[kPolicyProxyServerMode]->GetAsInteger(&int_mode));
881 switch (int_mode) {
882 case kPolicyNoProxyServerMode:
883 mode = ProxyPrefs::MODE_DIRECT;
884 break;
885 case kPolicyAutoDetectProxyServerMode:
886 mode = ProxyPrefs::MODE_AUTO_DETECT;
887 break;
888 case kPolicyManuallyConfiguredProxyServerMode:
889 mode = ProxyPrefs::MODE_FIXED_SERVERS;
890 if (HasProxyPolicy(kPolicyProxyPacUrl))
891 mode = ProxyPrefs::MODE_PAC_SCRIPT;
892 break;
893 case kPolicyUseSystemProxyServerMode:
894 mode = ProxyPrefs::MODE_SYSTEM;
895 break;
896 default:
897 mode = ProxyPrefs::MODE_DIRECT;
898 NOTREACHED();
899 }
900 } else {
901 return;
902 }
903 switch (mode) {
904 case ProxyPrefs::MODE_DIRECT:
905 prefs_.SetValue(prefs::kProxy, ProxyConfigDictionary::CreateDirect());
906 break;
907 case ProxyPrefs::MODE_AUTO_DETECT:
908 prefs_.SetValue(prefs::kProxy, ProxyConfigDictionary::CreateAutoDetect());
909 break;
910 case ProxyPrefs::MODE_PAC_SCRIPT: {
911 if (!HasProxyPolicy(kPolicyProxyPacUrl)) {
912 LOG(WARNING) << "A centrally-administered policy specifies to use a "
913 << "PAC script, but doesn't supply the PAC script URL.";
914 return;
915 }
916 std::string pac_url;
917 proxy_policies_[kPolicyProxyPacUrl]->GetAsString(&pac_url);
918 prefs_.SetValue(prefs::kProxy,
919 ProxyConfigDictionary::CreatePacScript(pac_url, false));
920 break;
921 }
922 case ProxyPrefs::MODE_FIXED_SERVERS: {
923 if (!HasProxyPolicy(kPolicyProxyServer)) {
924 LOG(WARNING) << "A centrally-administered policy specifies to use a "
925 << "fixed server, but doesn't supply the server address.";
926 return;
927 }
928 std::string proxy_server;
929 proxy_policies_[kPolicyProxyServer]->GetAsString(&proxy_server);
930 std::string bypass_list;
931 if (HasProxyPolicy(kPolicyProxyBypassList))
932 proxy_policies_[kPolicyProxyBypassList]->GetAsString(&bypass_list);
933 prefs_.SetValue(prefs::kProxy,
934 ProxyConfigDictionary::CreateFixedServers(proxy_server,
935 bypass_list));
936 break;
937 }
938 case ProxyPrefs::MODE_SYSTEM:
939 prefs_.SetValue(prefs::kProxy,
940 ProxyConfigDictionary::CreateSystem());
941 break;
942 case ProxyPrefs::kModeCount:
943 NOTREACHED();
944 }
945 }
946
947 bool ConfigurationPolicyPrefKeeper::HasProxyPolicy(
948 ConfigurationPolicyType policy) const {
949 std::map<ConfigurationPolicyType, Value*>::const_iterator iter;
950 iter = proxy_policies_.find(policy);
951 std::string tmp;
952 if (iter == proxy_policies_.end() ||
953 !iter->second ||
954 iter->second->IsType(Value::TYPE_NULL) ||
955 (iter->second->IsType(Value::TYPE_STRING) &&
956 iter->second->GetAsString(&tmp) &&
957 tmp.empty())) {
958 return false;
959 }
960 return true;
961 }
962
963 ConfigurationPolicyPrefStore::ConfigurationPolicyPrefStore( 106 ConfigurationPolicyPrefStore::ConfigurationPolicyPrefStore(
964 ConfigurationPolicyProvider* provider) 107 ConfigurationPolicyProvider* provider)
965 : provider_(provider), 108 : provider_(provider),
966 initialization_complete_(false) { 109 initialization_complete_(false) {
967 if (provider_) { 110 if (provider_) {
111 const HandlerList* policy_handlers =
112 g_browser_process->browser_policy_connector()->
113 GetConfigurationPolicyHandlerList();
968 // Read initial policy. 114 // Read initial policy.
969 policy_keeper_.reset(new ConfigurationPolicyPrefKeeper(provider)); 115 policy_keeper_.reset(
116 new ConfigurationPolicyPrefKeeper(provider, policy_handlers));
970 registrar_.Init(provider_, this); 117 registrar_.Init(provider_, this);
971 initialization_complete_ = provider->IsInitializationComplete(); 118 initialization_complete_ = provider->IsInitializationComplete();
972 } else { 119 } else {
973 initialization_complete_ = true; 120 initialization_complete_ = true;
974 } 121 }
975 } 122 }
976 123
977 ConfigurationPolicyPrefStore::~ConfigurationPolicyPrefStore() { 124 ConfigurationPolicyPrefStore::~ConfigurationPolicyPrefStore() {
978 } 125 }
979 126
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
1241 return policy == kPolicyProxyMode || 388 return policy == kPolicyProxyMode ||
1242 policy == kPolicyProxyServerMode || 389 policy == kPolicyProxyServerMode ||
1243 policy == kPolicyProxyServer || 390 policy == kPolicyProxyServer ||
1244 policy == kPolicyProxyPacUrl || 391 policy == kPolicyProxyPacUrl ||
1245 policy == kPolicyProxyBypassList; 392 policy == kPolicyProxyBypassList;
1246 } 393 }
1247 394
1248 void ConfigurationPolicyPrefStore::Refresh() { 395 void ConfigurationPolicyPrefStore::Refresh() {
1249 if (!provider_) 396 if (!provider_)
1250 return; 397 return;
1251 398 const HandlerList* policy_handlers =
399 g_browser_process->browser_policy_connector()->
400 GetConfigurationPolicyHandlerList();
1252 // Construct a new keeper, determine what changed and swap the keeper in. 401 // Construct a new keeper, determine what changed and swap the keeper in.
1253 scoped_ptr<ConfigurationPolicyPrefKeeper> new_keeper( 402 scoped_ptr<ConfigurationPolicyPrefKeeper> new_keeper(
1254 new ConfigurationPolicyPrefKeeper(provider_)); 403 new ConfigurationPolicyPrefKeeper(provider_, policy_handlers));
1255 std::vector<std::string> changed_prefs; 404 std::vector<std::string> changed_prefs;
1256 new_keeper->GetDifferingPrefPaths(policy_keeper_.get(), &changed_prefs); 405 new_keeper->GetDifferingPrefPaths(policy_keeper_.get(), &changed_prefs);
1257 policy_keeper_.reset(new_keeper.release()); 406 policy_keeper_.reset(new_keeper.release());
1258 407
1259 // Send out change notifications. 408 // Send out change notifications.
1260 for (std::vector<std::string>::const_iterator pref(changed_prefs.begin()); 409 for (std::vector<std::string>::const_iterator pref(changed_prefs.begin());
1261 pref != changed_prefs.end(); 410 pref != changed_prefs.end();
1262 ++pref) { 411 ++pref) {
1263 FOR_EACH_OBSERVER(PrefStore::Observer, observers_, 412 FOR_EACH_OBSERVER(PrefStore::Observer, observers_,
1264 OnPrefValueChanged(*pref)); 413 OnPrefValueChanged(*pref));
1265 } 414 }
1266 415
1267 // Update the initialization flag. 416 // Update the initialization flag.
1268 if (!initialization_complete_ && 417 if (!initialization_complete_ &&
1269 provider_->IsInitializationComplete()) { 418 provider_->IsInitializationComplete()) {
1270 initialization_complete_ = true; 419 initialization_complete_ = true;
1271 FOR_EACH_OBSERVER(PrefStore::Observer, observers_, 420 FOR_EACH_OBSERVER(PrefStore::Observer, observers_,
1272 OnInitializationCompleted(true)); 421 OnInitializationCompleted(true));
1273 } 422 }
1274 } 423 }
1275 424
1276 } // namespace policy 425 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698