OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 5 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/singleton.h" | 9 #include "base/singleton.h" |
10 #include "base/string16.h" | 10 #include "base/string16.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
29 | 29 |
30 namespace policy { | 30 namespace policy { |
31 | 31 |
32 // Manages the lifecycle of the shared platform-specific policy providers | 32 // Manages the lifecycle of the shared platform-specific policy providers |
33 // for managed and recommended policy. Instantiated as a Singleton. | 33 // for managed and recommended policy. Instantiated as a Singleton. |
34 class ConfigurationPolicyProviderKeeper { | 34 class ConfigurationPolicyProviderKeeper { |
35 public: | 35 public: |
36 ConfigurationPolicyProviderKeeper() | 36 ConfigurationPolicyProviderKeeper() |
37 : managed_provider_(CreateManagedProvider()), | 37 : managed_provider_(CreateManagedProvider()), |
38 recommended_provider_(CreateRecommendedProvider()) { | 38 recommended_provider_(CreateRecommendedProvider()) {} |
39 } | |
40 virtual ~ConfigurationPolicyProviderKeeper() {} | 39 virtual ~ConfigurationPolicyProviderKeeper() {} |
41 | 40 |
42 ConfigurationPolicyProvider* managed_provider() const { | 41 ConfigurationPolicyProvider* managed_provider() const { |
43 return managed_provider_.get(); | 42 return managed_provider_.get(); |
44 } | 43 } |
45 | 44 |
46 ConfigurationPolicyProvider* recommended_provider() const { | 45 ConfigurationPolicyProvider* recommended_provider() const { |
47 return recommended_provider_.get(); | 46 return recommended_provider_.get(); |
48 } | 47 } |
49 | 48 |
50 private: | 49 private: |
51 scoped_ptr<ConfigurationPolicyProvider> managed_provider_; | 50 scoped_ptr<ConfigurationPolicyProvider> managed_provider_; |
52 scoped_ptr<ConfigurationPolicyProvider> recommended_provider_; | 51 scoped_ptr<ConfigurationPolicyProvider> recommended_provider_; |
53 | 52 |
54 static ConfigurationPolicyProvider* CreateManagedProvider() { | 53 static ConfigurationPolicyProvider* CreateManagedProvider(); |
55 const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list = | 54 static ConfigurationPolicyProvider* CreateRecommendedProvider(); |
56 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(); | |
57 #if defined(OS_WIN) | |
58 return new ConfigurationPolicyProviderWin(policy_list); | |
59 #elif defined(OS_MACOSX) | |
60 return new ConfigurationPolicyProviderMac(policy_list); | |
61 #elif defined(OS_POSIX) | |
62 FilePath config_dir_path; | |
63 if (PathService::Get(chrome::DIR_POLICY_FILES, &config_dir_path)) { | |
64 return new ConfigDirPolicyProvider(policy_list, | |
65 config_dir_path.Append(FILE_PATH_LITERAL("managed"))); | |
66 } else { | |
67 return new DummyConfigurationPolicyProvider(policy_list); | |
68 } | |
69 #else | |
70 return new DummyConfigurationPolicyProvider(policy_list); | |
71 #endif | |
72 } | |
73 | |
74 static ConfigurationPolicyProvider* CreateRecommendedProvider() { | |
75 const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list = | |
76 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(); | |
77 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
78 FilePath config_dir_path; | |
79 if (PathService::Get(chrome::DIR_POLICY_FILES, &config_dir_path)) { | |
80 return new ConfigDirPolicyProvider(policy_list, | |
81 config_dir_path.Append(FILE_PATH_LITERAL("recommended"))); | |
82 } else { | |
83 return new DummyConfigurationPolicyProvider(policy_list); | |
84 } | |
85 #else | |
86 return new DummyConfigurationPolicyProvider(policy_list); | |
87 #endif | |
88 } | |
89 | 55 |
90 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyProviderKeeper); | 56 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyProviderKeeper); |
91 }; | 57 }; |
92 | 58 |
| 59 |
| 60 ConfigurationPolicyProvider* |
| 61 ConfigurationPolicyProviderKeeper::CreateManagedProvider() { |
| 62 const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list = |
| 63 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(); |
| 64 #if defined(OS_WIN) |
| 65 return new ConfigurationPolicyProviderWin(policy_list); |
| 66 #elif defined(OS_MACOSX) |
| 67 return new ConfigurationPolicyProviderMac(policy_list); |
| 68 #elif defined(OS_POSIX) |
| 69 FilePath config_dir_path; |
| 70 if (PathService::Get(chrome::DIR_POLICY_FILES, &config_dir_path)) { |
| 71 return new ConfigDirPolicyProvider( |
| 72 policy_list, |
| 73 config_dir_path.Append(FILE_PATH_LITERAL("managed"))); |
| 74 } else { |
| 75 return new DummyConfigurationPolicyProvider(policy_list); |
| 76 } |
| 77 #else |
| 78 return new DummyConfigurationPolicyProvider(policy_list); |
| 79 #endif |
| 80 } |
| 81 |
| 82 ConfigurationPolicyProvider* |
| 83 ConfigurationPolicyProviderKeeper::CreateRecommendedProvider() { |
| 84 const ConfigurationPolicyProvider::PolicyDefinitionList* policy_list = |
| 85 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(); |
| 86 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 87 FilePath config_dir_path; |
| 88 if (PathService::Get(chrome::DIR_POLICY_FILES, &config_dir_path)) { |
| 89 return new ConfigDirPolicyProvider( |
| 90 policy_list, |
| 91 config_dir_path.Append(FILE_PATH_LITERAL("recommended"))); |
| 92 } else { |
| 93 return new DummyConfigurationPolicyProvider(policy_list); |
| 94 } |
| 95 #else |
| 96 return new DummyConfigurationPolicyProvider(policy_list); |
| 97 #endif |
| 98 } |
| 99 |
93 const ConfigurationPolicyPrefStore::PolicyToPreferenceMapEntry | 100 const ConfigurationPolicyPrefStore::PolicyToPreferenceMapEntry |
94 ConfigurationPolicyPrefStore::simple_policy_map_[] = { | 101 ConfigurationPolicyPrefStore::kSimplePolicyMap[] = { |
95 { Value::TYPE_STRING, kPolicyHomePage, prefs::kHomePage }, | 102 { Value::TYPE_STRING, kPolicyHomePage, prefs::kHomePage }, |
96 { Value::TYPE_BOOLEAN, kPolicyHomepageIsNewTabPage, | 103 { Value::TYPE_BOOLEAN, kPolicyHomepageIsNewTabPage, |
97 prefs::kHomePageIsNewTabPage }, | 104 prefs::kHomePageIsNewTabPage }, |
98 { Value::TYPE_INTEGER, kPolicyRestoreOnStartup, | 105 { Value::TYPE_INTEGER, kPolicyRestoreOnStartup, |
99 prefs::kRestoreOnStartup}, | 106 prefs::kRestoreOnStartup}, |
100 { Value::TYPE_LIST, kPolicyURLsToRestoreOnStartup, | 107 { Value::TYPE_LIST, kPolicyURLsToRestoreOnStartup, |
101 prefs::kURLsToRestoreOnStartup }, | 108 prefs::kURLsToRestoreOnStartup }, |
102 { Value::TYPE_BOOLEAN, kPolicyAlternateErrorPagesEnabled, | 109 { Value::TYPE_BOOLEAN, kPolicyAlternateErrorPagesEnabled, |
103 prefs::kAlternateErrorPagesEnabled }, | 110 prefs::kAlternateErrorPagesEnabled }, |
104 { Value::TYPE_BOOLEAN, kPolicySearchSuggestEnabled, | 111 { Value::TYPE_BOOLEAN, kPolicySearchSuggestEnabled, |
105 prefs::kSearchSuggestEnabled }, | 112 prefs::kSearchSuggestEnabled }, |
106 { Value::TYPE_BOOLEAN, kPolicyDnsPrefetchingEnabled, | 113 { Value::TYPE_BOOLEAN, kPolicyDnsPrefetchingEnabled, |
107 prefs::kDnsPrefetchingEnabled }, | 114 prefs::kDnsPrefetchingEnabled }, |
108 { Value::TYPE_BOOLEAN, kPolicyDisableSpdy, | 115 { Value::TYPE_BOOLEAN, kPolicyDisableSpdy, |
109 prefs::kDisableSpdy }, | 116 prefs::kDisableSpdy }, |
110 { Value::TYPE_BOOLEAN, kPolicySafeBrowsingEnabled, | 117 { Value::TYPE_BOOLEAN, kPolicySafeBrowsingEnabled, |
111 prefs::kSafeBrowsingEnabled }, | 118 prefs::kSafeBrowsingEnabled }, |
112 { Value::TYPE_BOOLEAN, kPolicyPasswordManagerEnabled, | 119 { Value::TYPE_BOOLEAN, kPolicyPasswordManagerEnabled, |
113 prefs::kPasswordManagerEnabled }, | 120 prefs::kPasswordManagerEnabled }, |
114 { Value::TYPE_BOOLEAN, kPolicyPasswordManagerAllowShowPasswords, | 121 { Value::TYPE_BOOLEAN, kPolicyPasswordManagerAllowShowPasswords, |
115 prefs::kPasswordManagerAllowShowPasswords }, | 122 prefs::kPasswordManagerAllowShowPasswords }, |
116 { Value::TYPE_BOOLEAN, kPolicyPrintingEnabled, | 123 { Value::TYPE_BOOLEAN, kPolicyPrintingEnabled, |
117 prefs::kPrintingEnabled }, | 124 prefs::kPrintingEnabled }, |
118 { Value::TYPE_BOOLEAN, kPolicyMetricsReportingEnabled, | 125 { Value::TYPE_BOOLEAN, kPolicyMetricsReportingEnabled, |
119 prefs::kMetricsReportingEnabled }, | 126 prefs::kMetricsReportingEnabled }, |
120 { Value::TYPE_STRING, kPolicyApplicationLocale, | 127 { Value::TYPE_STRING, kPolicyApplicationLocale, |
121 prefs::kApplicationLocale}, | 128 prefs::kApplicationLocale}, |
122 { Value::TYPE_LIST, kPolicyExtensionInstallAllowList, | 129 { Value::TYPE_LIST, kPolicyExtensionInstallAllowList, |
123 prefs::kExtensionInstallAllowList}, | 130 prefs::kExtensionInstallAllowList}, |
124 { Value::TYPE_LIST, kPolicyExtensionInstallDenyList, | 131 { Value::TYPE_LIST, kPolicyExtensionInstallDenyList, |
125 prefs::kExtensionInstallDenyList}, | 132 prefs::kExtensionInstallDenyList}, |
126 { Value::TYPE_LIST, kPolicyDisabledPlugins, | 133 { Value::TYPE_LIST, kPolicyDisabledPlugins, |
127 prefs::kPluginsPluginsBlacklist}, | 134 prefs::kPluginsPluginsBlacklist}, |
128 { Value::TYPE_BOOLEAN, kPolicyShowHomeButton, | 135 { Value::TYPE_BOOLEAN, kPolicyShowHomeButton, |
129 prefs::kShowHomeButton }, | 136 prefs::kShowHomeButton }, |
130 { Value::TYPE_BOOLEAN, kPolicyJavascriptEnabled, | 137 { Value::TYPE_BOOLEAN, kPolicyJavascriptEnabled, |
131 prefs::kWebKitJavascriptEnabled }, | 138 prefs::kWebKitJavascriptEnabled }, |
132 { Value::TYPE_BOOLEAN, kPolicySavingBrowserHistoryDisabled, | 139 { Value::TYPE_BOOLEAN, kPolicySavingBrowserHistoryDisabled, |
133 prefs::kSavingBrowserHistoryDisabled }, | 140 prefs::kSavingBrowserHistoryDisabled }, |
134 { Value::TYPE_BOOLEAN, kPolicyDeveloperToolsDisabled, | 141 { Value::TYPE_BOOLEAN, kPolicyDeveloperToolsDisabled, |
135 prefs::kDevToolsDisabled }, | 142 prefs::kDevToolsDisabled }, |
136 { Value::TYPE_BOOLEAN, kPolicyBlockThirdPartyCookies, | 143 { Value::TYPE_BOOLEAN, kPolicyBlockThirdPartyCookies, |
137 prefs::kBlockThirdPartyCookies}, | 144 prefs::kBlockThirdPartyCookies}, |
138 | 145 |
139 #if defined(OS_CHROMEOS) | 146 #if defined(OS_CHROMEOS) |
140 { Value::TYPE_BOOLEAN, kPolicyChromeOsLockOnIdleSuspend, | 147 { Value::TYPE_BOOLEAN, kPolicyChromeOsLockOnIdleSuspend, |
141 prefs::kEnableScreenLock }, | 148 prefs::kEnableScreenLock }, |
142 #endif | 149 #endif |
143 }; | 150 }; |
144 | 151 |
145 const ConfigurationPolicyPrefStore::PolicyToPreferenceMapEntry | 152 const ConfigurationPolicyPrefStore::PolicyToPreferenceMapEntry |
146 ConfigurationPolicyPrefStore::default_search_policy_map_[] = { | 153 ConfigurationPolicyPrefStore::kDefaultSearchPolicyMap[] = { |
147 { Value::TYPE_BOOLEAN, kPolicyDefaultSearchProviderEnabled, | 154 { Value::TYPE_BOOLEAN, kPolicyDefaultSearchProviderEnabled, |
148 prefs::kDefaultSearchProviderEnabled }, | 155 prefs::kDefaultSearchProviderEnabled }, |
149 { Value::TYPE_STRING, kPolicyDefaultSearchProviderName, | 156 { Value::TYPE_STRING, kPolicyDefaultSearchProviderName, |
150 prefs::kDefaultSearchProviderName }, | 157 prefs::kDefaultSearchProviderName }, |
151 { Value::TYPE_STRING, kPolicyDefaultSearchProviderKeyword, | 158 { Value::TYPE_STRING, kPolicyDefaultSearchProviderKeyword, |
152 prefs::kDefaultSearchProviderKeyword }, | 159 prefs::kDefaultSearchProviderKeyword }, |
153 { Value::TYPE_STRING, kPolicyDefaultSearchProviderSearchURL, | 160 { Value::TYPE_STRING, kPolicyDefaultSearchProviderSearchURL, |
154 prefs::kDefaultSearchProviderSearchURL }, | 161 prefs::kDefaultSearchProviderSearchURL }, |
155 { Value::TYPE_STRING, kPolicyDefaultSearchProviderSuggestURL, | 162 { Value::TYPE_STRING, kPolicyDefaultSearchProviderSuggestURL, |
156 prefs::kDefaultSearchProviderSuggestURL }, | 163 prefs::kDefaultSearchProviderSuggestURL }, |
157 { Value::TYPE_STRING, kPolicyDefaultSearchProviderIconURL, | 164 { Value::TYPE_STRING, kPolicyDefaultSearchProviderIconURL, |
158 prefs::kDefaultSearchProviderIconURL }, | 165 prefs::kDefaultSearchProviderIconURL }, |
159 { Value::TYPE_STRING, kPolicyDefaultSearchProviderEncodings, | 166 { Value::TYPE_STRING, kPolicyDefaultSearchProviderEncodings, |
160 prefs::kDefaultSearchProviderEncodings }, | 167 prefs::kDefaultSearchProviderEncodings }, |
161 }; | 168 }; |
162 | 169 |
163 const ConfigurationPolicyPrefStore::PolicyToPreferenceMapEntry | 170 const ConfigurationPolicyPrefStore::PolicyToPreferenceMapEntry |
164 ConfigurationPolicyPrefStore::proxy_policy_map_[] = { | 171 ConfigurationPolicyPrefStore::kProxyPolicyMap[] = { |
165 { Value::TYPE_STRING, kPolicyProxyServer, prefs::kProxyServer }, | 172 { Value::TYPE_STRING, kPolicyProxyServer, prefs::kProxyServer }, |
166 { Value::TYPE_STRING, kPolicyProxyPacUrl, prefs::kProxyPacUrl }, | 173 { Value::TYPE_STRING, kPolicyProxyPacUrl, prefs::kProxyPacUrl }, |
167 { Value::TYPE_STRING, kPolicyProxyBypassList, prefs::kProxyBypassList } | 174 { Value::TYPE_STRING, kPolicyProxyBypassList, prefs::kProxyBypassList } |
168 }; | 175 }; |
169 | 176 |
170 /* static */ | 177 /* static */ |
171 ConfigurationPolicyProvider::PolicyDefinitionList* | 178 ConfigurationPolicyProvider::PolicyDefinitionList* |
172 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList() { | 179 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList() { |
173 static ConfigurationPolicyProvider::PolicyDefinitionList::Entry entries[] = { | 180 static ConfigurationPolicyProvider::PolicyDefinitionList::Entry entries[] = { |
174 { ConfigurationPolicyStore::kPolicyHomePage, | 181 { kPolicyHomePage, Value::TYPE_STRING, key::kHomepageLocation }, |
175 Value::TYPE_STRING, key::kHomepageLocation }, | 182 { kPolicyHomepageIsNewTabPage, Value::TYPE_BOOLEAN, |
176 { ConfigurationPolicyStore::kPolicyHomepageIsNewTabPage, | 183 key::kHomepageIsNewTabPage }, |
177 Value::TYPE_BOOLEAN, key::kHomepageIsNewTabPage }, | 184 { kPolicyRestoreOnStartup, Value::TYPE_INTEGER, key::kRestoreOnStartup }, |
178 { ConfigurationPolicyStore::kPolicyRestoreOnStartup, | 185 { kPolicyURLsToRestoreOnStartup, Value::TYPE_LIST, |
179 Value::TYPE_INTEGER, key::kRestoreOnStartup }, | 186 key::kURLsToRestoreOnStartup }, |
180 { ConfigurationPolicyStore::kPolicyURLsToRestoreOnStartup, | 187 { kPolicyDefaultSearchProviderEnabled, Value::TYPE_BOOLEAN, |
181 Value::TYPE_LIST, key::kURLsToRestoreOnStartup }, | 188 key::kDefaultSearchProviderEnabled }, |
182 { ConfigurationPolicyStore::kPolicyDefaultSearchProviderEnabled, | 189 { kPolicyDefaultSearchProviderName, Value::TYPE_STRING, |
183 Value::TYPE_BOOLEAN, key::kDefaultSearchProviderEnabled }, | 190 key::kDefaultSearchProviderName }, |
184 { ConfigurationPolicyStore::kPolicyDefaultSearchProviderName, | 191 { kPolicyDefaultSearchProviderKeyword, Value::TYPE_STRING, |
185 Value::TYPE_STRING, key::kDefaultSearchProviderName }, | 192 key::kDefaultSearchProviderKeyword }, |
186 { ConfigurationPolicyStore::kPolicyDefaultSearchProviderKeyword, | 193 { kPolicyDefaultSearchProviderSearchURL, Value::TYPE_STRING, |
187 Value::TYPE_STRING, key::kDefaultSearchProviderKeyword }, | 194 key::kDefaultSearchProviderSearchURL }, |
188 { ConfigurationPolicyStore::kPolicyDefaultSearchProviderSearchURL, | 195 { kPolicyDefaultSearchProviderSuggestURL, Value::TYPE_STRING, |
189 Value::TYPE_STRING, key::kDefaultSearchProviderSearchURL }, | 196 key::kDefaultSearchProviderSuggestURL }, |
190 { ConfigurationPolicyStore::kPolicyDefaultSearchProviderSuggestURL, | 197 { kPolicyDefaultSearchProviderIconURL, Value::TYPE_STRING, |
191 Value::TYPE_STRING, key::kDefaultSearchProviderSuggestURL }, | 198 key::kDefaultSearchProviderIconURL }, |
192 { ConfigurationPolicyStore::kPolicyDefaultSearchProviderIconURL, | 199 { kPolicyDefaultSearchProviderEncodings, Value::TYPE_STRING, |
193 Value::TYPE_STRING, key::kDefaultSearchProviderIconURL }, | 200 key::kDefaultSearchProviderEncodings }, |
194 { ConfigurationPolicyStore::kPolicyDefaultSearchProviderEncodings, | 201 { kPolicyProxyServerMode, Value::TYPE_INTEGER, key::kProxyServerMode }, |
195 Value::TYPE_STRING, key::kDefaultSearchProviderEncodings }, | 202 { kPolicyProxyServer, Value::TYPE_STRING, key::kProxyServer }, |
196 { ConfigurationPolicyStore::kPolicyProxyServerMode, | 203 { kPolicyProxyPacUrl, Value::TYPE_STRING, key::kProxyPacUrl }, |
197 Value::TYPE_INTEGER, key::kProxyServerMode }, | 204 { kPolicyProxyBypassList, Value::TYPE_STRING, key::kProxyBypassList }, |
198 { ConfigurationPolicyStore::kPolicyProxyServer, | 205 { kPolicyAlternateErrorPagesEnabled, Value::TYPE_BOOLEAN, |
199 Value::TYPE_STRING, key::kProxyServer }, | 206 key::kAlternateErrorPagesEnabled }, |
200 { ConfigurationPolicyStore::kPolicyProxyPacUrl, | 207 { kPolicySearchSuggestEnabled, Value::TYPE_BOOLEAN, |
201 Value::TYPE_STRING, key::kProxyPacUrl }, | 208 key::kSearchSuggestEnabled }, |
202 { ConfigurationPolicyStore::kPolicyProxyBypassList, | 209 { kPolicyDnsPrefetchingEnabled, Value::TYPE_BOOLEAN, |
203 Value::TYPE_STRING, key::kProxyBypassList }, | 210 key::kDnsPrefetchingEnabled }, |
204 { ConfigurationPolicyStore::kPolicyAlternateErrorPagesEnabled, | 211 { kPolicyDisableSpdy, Value::TYPE_BOOLEAN, key::kDisableSpdy }, |
205 Value::TYPE_BOOLEAN, key::kAlternateErrorPagesEnabled }, | 212 { kPolicySafeBrowsingEnabled, Value::TYPE_BOOLEAN, |
206 { ConfigurationPolicyStore::kPolicySearchSuggestEnabled, | 213 key::kSafeBrowsingEnabled }, |
207 Value::TYPE_BOOLEAN, key::kSearchSuggestEnabled }, | 214 { kPolicyMetricsReportingEnabled, Value::TYPE_BOOLEAN, |
208 { ConfigurationPolicyStore::kPolicyDnsPrefetchingEnabled, | 215 key::kMetricsReportingEnabled }, |
209 Value::TYPE_BOOLEAN, key::kDnsPrefetchingEnabled }, | 216 { kPolicyPasswordManagerEnabled, Value::TYPE_BOOLEAN, |
210 { ConfigurationPolicyStore::kPolicyDisableSpdy, | 217 key::kPasswordManagerEnabled }, |
211 Value::TYPE_BOOLEAN, key::kDisableSpdy }, | 218 { kPolicyPasswordManagerAllowShowPasswords, Value::TYPE_BOOLEAN, |
212 { ConfigurationPolicyStore::kPolicySafeBrowsingEnabled, | 219 key::kPasswordManagerAllowShowPasswords }, |
213 Value::TYPE_BOOLEAN, key::kSafeBrowsingEnabled }, | 220 { kPolicyAutoFillEnabled, Value::TYPE_BOOLEAN, key::kAutoFillEnabled }, |
214 { ConfigurationPolicyStore::kPolicyMetricsReportingEnabled, | 221 { kPolicyDisabledPlugins, Value::TYPE_LIST, key::kDisabledPlugins }, |
215 Value::TYPE_BOOLEAN, key::kMetricsReportingEnabled }, | 222 { kPolicyApplicationLocale, Value::TYPE_STRING, |
216 { ConfigurationPolicyStore::kPolicyPasswordManagerEnabled, | 223 key::kApplicationLocaleValue }, |
217 Value::TYPE_BOOLEAN, key::kPasswordManagerEnabled }, | 224 { kPolicySyncDisabled, Value::TYPE_BOOLEAN, key::kSyncDisabled }, |
218 { ConfigurationPolicyStore::kPolicyPasswordManagerAllowShowPasswords, | 225 { kPolicyExtensionInstallAllowList, Value::TYPE_LIST, |
219 Value::TYPE_BOOLEAN, key::kPasswordManagerAllowShowPasswords }, | 226 key::kExtensionInstallAllowList }, |
220 { ConfigurationPolicyStore::kPolicyAutoFillEnabled, | 227 { kPolicyExtensionInstallDenyList, Value::TYPE_LIST, |
221 Value::TYPE_BOOLEAN, key::kAutoFillEnabled }, | 228 key::kExtensionInstallDenyList }, |
222 { ConfigurationPolicyStore::kPolicyDisabledPlugins, | 229 { kPolicyExtensionInstallForceList, Value::TYPE_LIST, |
223 Value::TYPE_LIST, key::kDisabledPlugins }, | 230 key::kExtensionInstallForceList }, |
224 { ConfigurationPolicyStore::kPolicyApplicationLocale, | 231 { kPolicyShowHomeButton, Value::TYPE_BOOLEAN, key::kShowHomeButton }, |
225 Value::TYPE_STRING, key::kApplicationLocaleValue }, | 232 { kPolicyPrintingEnabled, Value::TYPE_BOOLEAN, key::kPrintingEnabled }, |
226 { ConfigurationPolicyStore::kPolicySyncDisabled, | 233 { kPolicyJavascriptEnabled, Value::TYPE_BOOLEAN, key::kJavascriptEnabled }, |
227 Value::TYPE_BOOLEAN, key::kSyncDisabled }, | 234 { kPolicySavingBrowserHistoryDisabled, Value::TYPE_BOOLEAN, |
228 { ConfigurationPolicyStore::kPolicyExtensionInstallAllowList, | 235 key::kSavingBrowserHistoryDisabled }, |
229 Value::TYPE_LIST, key::kExtensionInstallAllowList }, | 236 { kPolicyDeveloperToolsDisabled, Value::TYPE_BOOLEAN, |
230 { ConfigurationPolicyStore::kPolicyExtensionInstallDenyList, | 237 key::kDeveloperToolsDisabled }, |
231 Value::TYPE_LIST, key::kExtensionInstallDenyList }, | 238 { kPolicyBlockThirdPartyCookies, Value::TYPE_BOOLEAN, |
232 { ConfigurationPolicyStore::kPolicyExtensionInstallForceList, | 239 key::kBlockThirdPartyCookies }, |
233 Value::TYPE_LIST, key::kExtensionInstallForceList }, | |
234 { ConfigurationPolicyStore::kPolicyShowHomeButton, | |
235 Value::TYPE_BOOLEAN, key::kShowHomeButton }, | |
236 { ConfigurationPolicyStore::kPolicyPrintingEnabled, | |
237 Value::TYPE_BOOLEAN, key::kPrintingEnabled }, | |
238 { ConfigurationPolicyStore::kPolicyJavascriptEnabled, | |
239 Value::TYPE_BOOLEAN, key::kJavascriptEnabled }, | |
240 { ConfigurationPolicyStore::kPolicySavingBrowserHistoryDisabled, | |
241 Value::TYPE_BOOLEAN, key::kSavingBrowserHistoryDisabled }, | |
242 { ConfigurationPolicyStore::kPolicyDeveloperToolsDisabled, | |
243 Value::TYPE_BOOLEAN, key::kDeveloperToolsDisabled }, | |
244 { ConfigurationPolicyStore::kPolicyBlockThirdPartyCookies, | |
245 Value::TYPE_BOOLEAN, key::kBlockThirdPartyCookies }, | |
246 | 240 |
247 #if defined(OS_CHROMEOS) | 241 #if defined(OS_CHROMEOS) |
248 { ConfigurationPolicyStore::kPolicyChromeOsLockOnIdleSuspend, | 242 { kPolicyChromeOsLockOnIdleSuspend, Value::TYPE_BOOLEAN, |
249 Value::TYPE_BOOLEAN, key::kChromeOsLockOnIdleSuspend }, | 243 key::kChromeOsLockOnIdleSuspend }, |
250 #endif | 244 #endif |
251 }; | 245 }; |
252 | 246 |
253 static ConfigurationPolicyProvider::PolicyDefinitionList policy_list = { | 247 static ConfigurationPolicyProvider::PolicyDefinitionList policy_list = { |
254 entries, | 248 entries, |
255 entries + arraysize(entries), | 249 entries + arraysize(entries), |
256 }; | 250 }; |
257 return &policy_list; | 251 return &policy_list; |
258 } | 252 } |
259 | 253 |
260 ConfigurationPolicyPrefStore::ConfigurationPolicyPrefStore( | 254 ConfigurationPolicyPrefStore::ConfigurationPolicyPrefStore( |
261 ConfigurationPolicyProvider* provider) | 255 ConfigurationPolicyProvider* provider) |
262 : provider_(provider), | 256 : provider_(provider), |
263 prefs_(new DictionaryValue()), | 257 prefs_(new DictionaryValue()), |
264 lower_priority_proxy_settings_overridden_(false), | 258 lower_priority_proxy_settings_overridden_(false), |
265 proxy_disabled_(false), | 259 proxy_disabled_(false), |
266 proxy_configuration_specified_(false), | 260 proxy_configuration_specified_(false), |
267 use_system_proxy_(false) { | 261 use_system_proxy_(false) { |
268 } | 262 } |
269 | 263 |
270 ConfigurationPolicyPrefStore::~ConfigurationPolicyPrefStore() { | |
271 } | |
272 | |
273 PrefStore::PrefReadError ConfigurationPolicyPrefStore::ReadPrefs() { | 264 PrefStore::PrefReadError ConfigurationPolicyPrefStore::ReadPrefs() { |
274 proxy_disabled_ = false; | 265 proxy_disabled_ = false; |
275 proxy_configuration_specified_ = false; | 266 proxy_configuration_specified_ = false; |
276 lower_priority_proxy_settings_overridden_ = false; | 267 lower_priority_proxy_settings_overridden_ = false; |
277 | 268 |
278 bool success = (provider_ == NULL || provider_->Provide(this)); | 269 const bool success = (provider_ == NULL || provider_->Provide(this)); |
279 FinalizeDefaultSearchPolicySettings(); | 270 FinalizeDefaultSearchPolicySettings(); |
280 return success ? PrefStore::PREF_READ_ERROR_NONE : | 271 return success ? PrefStore::PREF_READ_ERROR_NONE : |
281 PrefStore::PREF_READ_ERROR_OTHER; | 272 PrefStore::PREF_READ_ERROR_OTHER; |
282 } | 273 } |
283 | 274 |
284 void ConfigurationPolicyPrefStore::Apply(PolicyType policy, Value* value) { | 275 void ConfigurationPolicyPrefStore::Apply(ConfigurationPolicyType policy, |
| 276 Value* value) { |
285 if (ApplyProxyPolicy(policy, value)) | 277 if (ApplyProxyPolicy(policy, value)) |
286 return; | 278 return; |
287 | 279 |
288 if (ApplySyncPolicy(policy, value)) | 280 if (ApplySyncPolicy(policy, value)) |
289 return; | 281 return; |
290 | 282 |
291 if (ApplyAutoFillPolicy(policy, value)) | 283 if (ApplyAutoFillPolicy(policy, value)) |
292 return; | 284 return; |
293 | 285 |
294 if (ApplyPolicyFromMap(policy, value, default_search_policy_map_, | 286 if (ApplyPolicyFromMap(policy, value, kDefaultSearchPolicyMap, |
295 arraysize(default_search_policy_map_))) | 287 arraysize(kDefaultSearchPolicyMap))) |
296 return; | 288 return; |
297 | 289 |
298 if (ApplyPolicyFromMap(policy, value, simple_policy_map_, | 290 if (ApplyPolicyFromMap(policy, value, kSimplePolicyMap, |
299 arraysize(simple_policy_map_))) | 291 arraysize(kSimplePolicyMap))) |
300 return; | 292 return; |
301 | 293 |
302 // Other policy implementations go here. | 294 // Other policy implementations go here. |
303 NOTIMPLEMENTED(); | 295 NOTIMPLEMENTED(); |
304 delete value; | 296 delete value; |
305 } | 297 } |
306 | 298 |
307 // static | 299 // static |
308 ConfigurationPolicyPrefStore* | 300 ConfigurationPolicyPrefStore* |
309 ConfigurationPolicyPrefStore::CreateManagedPolicyPrefStore() { | 301 ConfigurationPolicyPrefStore::CreateManagedPolicyPrefStore() { |
310 ConfigurationPolicyProviderKeeper* keeper = | 302 ConfigurationPolicyProviderKeeper* keeper = |
311 Singleton<ConfigurationPolicyProviderKeeper>::get(); | 303 Singleton<ConfigurationPolicyProviderKeeper>::get(); |
312 return new ConfigurationPolicyPrefStore(keeper->managed_provider()); | 304 return new ConfigurationPolicyPrefStore(keeper->managed_provider()); |
313 } | 305 } |
314 | 306 |
315 // static | 307 // static |
316 ConfigurationPolicyPrefStore* | 308 ConfigurationPolicyPrefStore* |
317 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore() { | 309 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore() { |
318 ConfigurationPolicyProviderKeeper* keeper = | 310 ConfigurationPolicyProviderKeeper* keeper = |
319 Singleton<ConfigurationPolicyProviderKeeper>::get(); | 311 Singleton<ConfigurationPolicyProviderKeeper>::get(); |
320 return new ConfigurationPolicyPrefStore(keeper->recommended_provider()); | 312 return new ConfigurationPolicyPrefStore(keeper->recommended_provider()); |
321 } | 313 } |
322 | 314 |
323 // static | 315 // static |
324 void ConfigurationPolicyPrefStore::GetProxyPreferenceSet( | 316 void ConfigurationPolicyPrefStore::GetProxyPreferenceSet( |
325 ProxyPreferenceSet* proxy_pref_set) { | 317 ProxyPreferenceSet* proxy_pref_set) { |
326 proxy_pref_set->clear(); | 318 proxy_pref_set->clear(); |
327 for (size_t current = 0; current < arraysize(proxy_policy_map_); ++current) { | 319 for (size_t current = 0; current < arraysize(kProxyPolicyMap); ++current) { |
328 proxy_pref_set->insert(proxy_policy_map_[current].preference_path); | 320 proxy_pref_set->insert(kProxyPolicyMap[current].preference_path); |
329 } | 321 } |
330 proxy_pref_set->insert(prefs::kNoProxyServer); | 322 proxy_pref_set->insert(prefs::kNoProxyServer); |
331 proxy_pref_set->insert(prefs::kProxyAutoDetect); | 323 proxy_pref_set->insert(prefs::kProxyAutoDetect); |
332 } | 324 } |
333 | 325 |
334 const ConfigurationPolicyPrefStore::PolicyToPreferenceMapEntry* | 326 const ConfigurationPolicyPrefStore::PolicyToPreferenceMapEntry* |
335 ConfigurationPolicyPrefStore::FindPolicyInMap(PolicyType policy, | 327 ConfigurationPolicyPrefStore::FindPolicyInMap( |
336 const PolicyToPreferenceMapEntry* map, int table_size) { | 328 ConfigurationPolicyType policy, |
| 329 const PolicyToPreferenceMapEntry* map, |
| 330 int table_size) const { |
337 for (int i = 0; i < table_size; ++i) { | 331 for (int i = 0; i < table_size; ++i) { |
338 if (map[i].policy_type == policy) | 332 if (map[i].policy_type == policy) |
339 return map + i; | 333 return map + i; |
340 } | 334 } |
341 return NULL; | 335 return NULL; |
342 } | 336 } |
343 | 337 |
344 bool ConfigurationPolicyPrefStore::RemovePreferencesOfMap( | 338 bool ConfigurationPolicyPrefStore::RemovePreferencesOfMap( |
345 const PolicyToPreferenceMapEntry* map, int table_size) { | 339 const PolicyToPreferenceMapEntry* map, int table_size) { |
346 bool found_one = false; | 340 bool found_any = false; |
347 for (int i = 0; i < table_size; ++i) { | 341 for (int i = 0; i < table_size; ++i) { |
348 if (prefs_->Remove(map[i].preference_path, NULL)) | 342 if (prefs_->Remove(map[i].preference_path, NULL)) |
349 found_one = true; | 343 found_any = true; |
350 } | 344 } |
351 return found_one; | 345 return found_any; |
352 } | 346 } |
353 | 347 |
354 bool ConfigurationPolicyPrefStore::ApplyPolicyFromMap(PolicyType policy, | 348 bool ConfigurationPolicyPrefStore::ApplyPolicyFromMap( |
355 Value* value, const PolicyToPreferenceMapEntry map[], int size) { | 349 ConfigurationPolicyType policy, |
356 const PolicyToPreferenceMapEntry* end = map + size; | 350 Value* value, |
357 for (const PolicyToPreferenceMapEntry* current = map; | 351 const PolicyToPreferenceMapEntry* map, |
358 current != end; ++current) { | 352 int size) { |
359 if (current->policy_type == policy) { | 353 for (int current = 0; current < size; ++current) { |
360 DCHECK(current->value_type == value->GetType()); | 354 if (map[current].policy_type == policy) { |
361 prefs_->Set(current->preference_path, value); | 355 DCHECK_EQ(map[current].value_type, value->GetType()) |
| 356 << "mismatch in provided and expected policy value for preferences" |
| 357 << map[current].preference_path << ". expected = " |
| 358 << map[current].value_type << ", actual = "<< value->GetType(); |
| 359 prefs_->Set(map[current].preference_path, value); |
362 return true; | 360 return true; |
363 } | 361 } |
364 } | 362 } |
365 return false; | 363 return false; |
366 } | 364 } |
367 | 365 |
368 bool ConfigurationPolicyPrefStore::ApplyProxyPolicy(PolicyType policy, | 366 bool ConfigurationPolicyPrefStore::ApplyProxyPolicy( |
369 Value* value) { | 367 ConfigurationPolicyType policy, |
| 368 Value* value) { |
370 bool result = false; | 369 bool result = false; |
371 bool warn_about_proxy_disable_config = false; | 370 bool warn_about_proxy_disable_config = false; |
372 bool warn_about_proxy_system_config = false; | 371 bool warn_about_proxy_system_config = false; |
373 | 372 |
374 const PolicyToPreferenceMapEntry* match_entry = | 373 const PolicyToPreferenceMapEntry* match_entry = |
375 FindPolicyInMap(policy, proxy_policy_map_, arraysize(proxy_policy_map_)); | 374 FindPolicyInMap(policy, kProxyPolicyMap, arraysize(kProxyPolicyMap)); |
376 | 375 |
377 // When the first proxy-related policy is applied, ALL proxy-related | 376 // When the first proxy-related policy is applied, ALL proxy-related |
378 // preferences that have been set by command-line switches, extensions, | 377 // preferences that have been set by command-line switches, extensions, |
379 // user preferences or any other mechanism are overridden. Otherwise | 378 // user preferences or any other mechanism are overridden. Otherwise |
380 // it's possible for a user to interfere with proxy policy by setting | 379 // it's possible for a user to interfere with proxy policy by setting |
381 // proxy-related command-line switches or set proxy-related prefs in an | 380 // proxy-related command-line switches or set proxy-related prefs in an |
382 // extension that are related, but not identical, to the ones set through | 381 // extension that are related, but not identical, to the ones set through |
383 // policy. | 382 // policy. |
384 if (!lower_priority_proxy_settings_overridden_ && | 383 if (!lower_priority_proxy_settings_overridden_ && |
385 (match_entry || | 384 (match_entry || |
386 policy == ConfigurationPolicyPrefStore::kPolicyProxyServerMode)) { | 385 policy == kPolicyProxyServerMode)) { |
387 ProxyPreferenceSet proxy_preference_set; | 386 ProxyPreferenceSet proxy_preference_set; |
388 GetProxyPreferenceSet(&proxy_preference_set); | 387 GetProxyPreferenceSet(&proxy_preference_set); |
389 for (ProxyPreferenceSet::const_iterator i = proxy_preference_set.begin(); | 388 for (ProxyPreferenceSet::const_iterator i = proxy_preference_set.begin(); |
390 i != proxy_preference_set.end(); ++i) { | 389 i != proxy_preference_set.end(); ++i) { |
391 prefs_->Set(*i, PrefStore::CreateUseDefaultSentinelValue()); | 390 prefs_->Set(*i, PrefStore::CreateUseDefaultSentinelValue()); |
392 } | 391 } |
393 lower_priority_proxy_settings_overridden_ = true; | 392 lower_priority_proxy_settings_overridden_ = true; |
394 } | 393 } |
395 | 394 |
396 // Translate the proxy policy into preferences. | 395 // Translate the proxy policy into preferences. |
397 if (policy == ConfigurationPolicyStore::kPolicyProxyServerMode) { | 396 if (policy == kPolicyProxyServerMode) { |
398 int int_value; | 397 int int_value; |
399 bool proxy_auto_detect = false; | 398 bool proxy_auto_detect = false; |
400 if (value->GetAsInteger(&int_value)) { | 399 if (value->GetAsInteger(&int_value)) { |
401 result = true; | 400 result = true; |
402 switch (int_value) { | 401 switch (int_value) { |
403 case ConfigurationPolicyStore::kPolicyNoProxyServerMode: | 402 case kPolicyNoProxyServerMode: |
404 if (!proxy_disabled_) { | 403 if (!proxy_disabled_) { |
405 if (proxy_configuration_specified_) | 404 if (proxy_configuration_specified_) |
406 warn_about_proxy_disable_config = true; | 405 warn_about_proxy_disable_config = true; |
407 proxy_disabled_ = true; | 406 proxy_disabled_ = true; |
408 } | 407 } |
409 break; | 408 break; |
410 case ConfigurationPolicyStore::kPolicyAutoDetectProxyMode: | 409 case kPolicyAutoDetectProxyMode: |
411 proxy_auto_detect = true; | 410 proxy_auto_detect = true; |
412 break; | 411 break; |
413 case ConfigurationPolicyStore::kPolicyManuallyConfiguredProxyMode: | 412 case kPolicyManuallyConfiguredProxyMode: |
414 break; | 413 break; |
415 case ConfigurationPolicyStore::kPolicyUseSystemProxyMode: | 414 case kPolicyUseSystemProxyMode: |
416 if (!use_system_proxy_) { | 415 if (!use_system_proxy_) { |
417 if (proxy_configuration_specified_) | 416 if (proxy_configuration_specified_) |
418 warn_about_proxy_system_config = true; | 417 warn_about_proxy_system_config = true; |
419 use_system_proxy_ = true; | 418 use_system_proxy_ = true; |
420 } | 419 } |
421 break; | 420 break; |
422 default: | 421 default: |
423 // Not a valid policy, don't assume ownership of |value| | 422 // Not a valid policy, don't assume ownership of |value| |
424 result = false; | 423 result = false; |
425 break; | 424 break; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 << " system proxy settings should be used but also specifies" | 461 << " system proxy settings should be used but also specifies" |
463 << " an explicit proxy configuration."; | 462 << " an explicit proxy configuration."; |
464 } | 463 } |
465 | 464 |
466 // If the policy was a proxy policy, cleanup |value|. | 465 // If the policy was a proxy policy, cleanup |value|. |
467 if (result && value) | 466 if (result && value) |
468 delete value; | 467 delete value; |
469 return result; | 468 return result; |
470 } | 469 } |
471 | 470 |
472 bool ConfigurationPolicyPrefStore::ApplySyncPolicy(PolicyType policy, | 471 bool ConfigurationPolicyPrefStore::ApplySyncPolicy( |
473 Value* value) { | 472 ConfigurationPolicyType policy, Value* value) { |
474 if (policy == ConfigurationPolicyStore::kPolicySyncDisabled) { | 473 if (policy == kPolicySyncDisabled) { |
475 bool disable_sync; | 474 bool disable_sync; |
476 if (value->GetAsBoolean(&disable_sync) && disable_sync) | 475 if (value->GetAsBoolean(&disable_sync) && disable_sync) |
477 prefs_->Set(prefs::kSyncManaged, value); | 476 prefs_->Set(prefs::kSyncManaged, value); |
478 else | 477 else |
479 delete value; | 478 delete value; |
480 return true; | 479 return true; |
481 } | 480 } |
482 return false; | 481 return false; |
483 } | 482 } |
484 | 483 |
485 bool ConfigurationPolicyPrefStore::ApplyAutoFillPolicy(PolicyType policy, | 484 bool ConfigurationPolicyPrefStore::ApplyAutoFillPolicy( |
486 Value* value) { | 485 ConfigurationPolicyType policy, Value* value) { |
487 if (policy == ConfigurationPolicyStore::kPolicyAutoFillEnabled) { | 486 if (policy == kPolicyAutoFillEnabled) { |
488 bool auto_fill_enabled; | 487 bool auto_fill_enabled; |
489 if (value->GetAsBoolean(&auto_fill_enabled) && !auto_fill_enabled) | 488 if (value->GetAsBoolean(&auto_fill_enabled) && !auto_fill_enabled) |
490 prefs_->Set(prefs::kAutoFillEnabled, Value::CreateBooleanValue(false)); | 489 prefs_->Set(prefs::kAutoFillEnabled, Value::CreateBooleanValue(false)); |
491 delete value; | 490 delete value; |
492 return true; | 491 return true; |
493 } | 492 } |
494 return false; | 493 return false; |
495 } | 494 } |
496 | 495 |
497 void ConfigurationPolicyPrefStore::EnsureStringPrefExists( | 496 void ConfigurationPolicyPrefStore::EnsureStringPrefExists( |
498 const std::string& path) { | 497 const std::string& path) { |
499 std::string value; | 498 std::string value; |
500 if (!prefs_->GetString(path, &value)) | 499 if (!prefs_->GetString(path, &value)) |
501 prefs_->SetString(path, value); | 500 prefs_->SetString(path, value); |
502 } | 501 } |
503 | 502 |
| 503 namespace { |
| 504 |
504 // Implementation of SearchTermsData just for validation. | 505 // Implementation of SearchTermsData just for validation. |
505 class SearchTermsDataForValidation : public SearchTermsData { | 506 class SearchTermsDataForValidation : public SearchTermsData { |
506 public: | 507 public: |
507 SearchTermsDataForValidation() {} | 508 SearchTermsDataForValidation() {} |
508 | 509 |
509 // Implementation of SearchTermsData. | 510 // Implementation of SearchTermsData. |
510 virtual std::string GoogleBaseURLValue() const { | 511 virtual std::string GoogleBaseURLValue() const { |
511 return "http://www.google.com/"; | 512 return "http://www.google.com/"; |
512 } | 513 } |
513 virtual std::string GetApplicationLocale() const { | 514 virtual std::string GetApplicationLocale() const { |
514 return "en"; | 515 return "en"; |
515 } | 516 } |
516 #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) | 517 #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) |
517 virtual std::wstring GetRlzParameterValue() const { | 518 virtual std::wstring GetRlzParameterValue() const { |
518 return L""; | 519 return std::wstring(); |
519 } | 520 } |
520 #endif | 521 #endif |
521 private: | 522 private: |
522 DISALLOW_COPY_AND_ASSIGN(SearchTermsDataForValidation); | 523 DISALLOW_COPY_AND_ASSIGN(SearchTermsDataForValidation); |
523 }; | 524 }; |
524 | 525 |
| 526 } // namepsace |
525 | 527 |
526 void ConfigurationPolicyPrefStore::FinalizeDefaultSearchPolicySettings() { | 528 void ConfigurationPolicyPrefStore::FinalizeDefaultSearchPolicySettings() { |
527 bool enabled = true; | 529 bool enabled = true; |
528 if (prefs_->GetBoolean(prefs::kDefaultSearchProviderEnabled, &enabled) && | 530 if (prefs_->GetBoolean(prefs::kDefaultSearchProviderEnabled, &enabled) && |
529 !enabled) { | 531 !enabled) { |
530 // If default search is disabled, we ignore the other fields. | 532 // If default search is disabled, we ignore the other fields. |
531 prefs_->SetString(prefs::kDefaultSearchProviderName, ""); | 533 prefs_->SetString(prefs::kDefaultSearchProviderName, std::string()); |
532 prefs_->SetString(prefs::kDefaultSearchProviderSearchURL, ""); | 534 prefs_->SetString(prefs::kDefaultSearchProviderSearchURL, std::string()); |
533 prefs_->SetString(prefs::kDefaultSearchProviderSuggestURL, ""); | 535 prefs_->SetString(prefs::kDefaultSearchProviderSuggestURL, std::string()); |
534 prefs_->SetString(prefs::kDefaultSearchProviderIconURL, ""); | 536 prefs_->SetString(prefs::kDefaultSearchProviderIconURL, std::string()); |
535 prefs_->SetString(prefs::kDefaultSearchProviderEncodings, ""); | 537 prefs_->SetString(prefs::kDefaultSearchProviderEncodings, std::string()); |
536 prefs_->SetString(prefs::kDefaultSearchProviderKeyword, ""); | 538 prefs_->SetString(prefs::kDefaultSearchProviderKeyword, std::string()); |
537 return; | 539 return; |
538 } | 540 } |
539 std::string search_url; | 541 std::string search_url; |
540 // The search URL is required. | 542 // The search URL is required. |
541 if (prefs_->GetString(prefs::kDefaultSearchProviderSearchURL, &search_url) && | 543 if (prefs_->GetString(prefs::kDefaultSearchProviderSearchURL, &search_url) && |
542 !search_url.empty()) { | 544 !search_url.empty()) { |
543 SearchTermsDataForValidation search_terms_data; | 545 SearchTermsDataForValidation search_terms_data; |
544 TemplateURLRef search_url_ref(search_url, 0, 0); | 546 const TemplateURLRef search_url_ref(search_url, 0, 0); |
545 // It must support replacement (which implies it is valid). | 547 // It must support replacement (which implies it is valid). |
546 if (search_url_ref.SupportsReplacementUsingTermsData(search_terms_data)) { | 548 if (search_url_ref.SupportsReplacementUsingTermsData(search_terms_data)) { |
547 // The other entries are optional. Just make sure that they are all | 549 // The other entries are optional. Just make sure that they are all |
548 // specified via policy, so that we don't use regular prefs. | 550 // specified via policy, so that we don't use regular prefs. |
549 EnsureStringPrefExists(prefs::kDefaultSearchProviderSuggestURL); | 551 EnsureStringPrefExists(prefs::kDefaultSearchProviderSuggestURL); |
550 EnsureStringPrefExists(prefs::kDefaultSearchProviderIconURL); | 552 EnsureStringPrefExists(prefs::kDefaultSearchProviderIconURL); |
551 EnsureStringPrefExists(prefs::kDefaultSearchProviderEncodings); | 553 EnsureStringPrefExists(prefs::kDefaultSearchProviderEncodings); |
552 EnsureStringPrefExists(prefs::kDefaultSearchProviderKeyword); | 554 EnsureStringPrefExists(prefs::kDefaultSearchProviderKeyword); |
553 | 555 |
554 // For the name, default to the host if not specified. | 556 // For the name, default to the host if not specified. |
555 std::string name; | 557 std::string name; |
556 if (!prefs_->GetString(prefs::kDefaultSearchProviderName, &name) || | 558 if (!prefs_->GetString(prefs::kDefaultSearchProviderName, &name) || |
557 name.empty()) | 559 name.empty()) |
558 prefs_->SetString(prefs::kDefaultSearchProviderName, | 560 prefs_->SetString(prefs::kDefaultSearchProviderName, |
559 GURL(search_url).host()); | 561 GURL(search_url).host()); |
560 | 562 |
561 // And clear the IDs since these are not specified via policy. | 563 // And clear the IDs since these are not specified via policy. |
562 prefs_->SetString(prefs::kDefaultSearchProviderID, ""); | 564 prefs_->SetString(prefs::kDefaultSearchProviderID, std::string()); |
563 prefs_->SetString(prefs::kDefaultSearchProviderPrepopulateID, ""); | 565 prefs_->SetString(prefs::kDefaultSearchProviderPrepopulateID, |
| 566 std::string()); |
564 return; | 567 return; |
565 } | 568 } |
566 } | 569 } |
567 // Required entries are not there. Remove any related entries. | 570 // Required entries are not there. Remove any related entries. |
568 RemovePreferencesOfMap(default_search_policy_map_, | 571 RemovePreferencesOfMap(kDefaultSearchPolicyMap, |
569 arraysize(default_search_policy_map_)); | 572 arraysize(kDefaultSearchPolicyMap)); |
570 } | 573 } |
571 | 574 |
572 } // namespace policy | 575 } // namespace policy |
OLD | NEW |