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

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

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

Powered by Google App Engine
This is Rietveld 408576698