OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/search_engines/default_search_policy_handler.h" | 5 #include "components/search_engines/default_search_policy_handler.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
13 #include "base/stl_util.h" | |
14 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
16 #include "components/policy/core/browser/policy_error_map.h" | 15 #include "components/policy/core/browser/policy_error_map.h" |
17 #include "components/policy/core/common/policy_map.h" | 16 #include "components/policy/core/common/policy_map.h" |
18 #include "components/policy/policy_constants.h" | 17 #include "components/policy/policy_constants.h" |
19 #include "components/prefs/pref_value_map.h" | 18 #include "components/prefs/pref_value_map.h" |
20 #include "components/search_engines/default_search_manager.h" | 19 #include "components/search_engines/default_search_manager.h" |
21 #include "components/search_engines/search_engines_pref_names.h" | 20 #include "components/search_engines/search_engines_pref_names.h" |
22 #include "components/search_engines/search_terms_data.h" | 21 #include "components/search_engines/search_terms_data.h" |
23 #include "components/search_engines/template_url.h" | 22 #include "components/search_engines/template_url.h" |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 prefs->SetString(prefs::kDefaultSearchProviderEncodings, encodings); | 178 prefs->SetString(prefs::kDefaultSearchProviderEncodings, encodings); |
180 } | 179 } |
181 | 180 |
182 | 181 |
183 // DefaultSearchPolicyHandler implementation ----------------------------------- | 182 // DefaultSearchPolicyHandler implementation ----------------------------------- |
184 | 183 |
185 DefaultSearchPolicyHandler::DefaultSearchPolicyHandler() { | 184 DefaultSearchPolicyHandler::DefaultSearchPolicyHandler() { |
186 for (size_t i = 0; i < arraysize(kDefaultSearchPolicyMap); ++i) { | 185 for (size_t i = 0; i < arraysize(kDefaultSearchPolicyMap); ++i) { |
187 const char* policy_name = kDefaultSearchPolicyMap[i].policy_name; | 186 const char* policy_name = kDefaultSearchPolicyMap[i].policy_name; |
188 if (policy_name == key::kDefaultSearchProviderEncodings) { | 187 if (policy_name == key::kDefaultSearchProviderEncodings) { |
189 handlers_.push_back(new DefaultSearchEncodingsPolicyHandler()); | 188 handlers_.push_back( |
189 base::MakeUnique<DefaultSearchEncodingsPolicyHandler>()); | |
190 } else { | 190 } else { |
191 handlers_.push_back(new SimplePolicyHandler( | 191 handlers_.push_back(base::MakeUnique<SimplePolicyHandler>( |
192 policy_name, | 192 policy_name, kDefaultSearchPolicyMap[i].preference_path, |
193 kDefaultSearchPolicyMap[i].preference_path, | |
194 kDefaultSearchPolicyMap[i].value_type)); | 193 kDefaultSearchPolicyMap[i].value_type)); |
195 } | 194 } |
196 } | 195 } |
197 } | 196 } |
198 | 197 |
199 DefaultSearchPolicyHandler::~DefaultSearchPolicyHandler() { | 198 DefaultSearchPolicyHandler::~DefaultSearchPolicyHandler() {} |
200 base::STLDeleteElements(&handlers_); | |
201 } | |
202 | 199 |
203 bool DefaultSearchPolicyHandler::CheckPolicySettings(const PolicyMap& policies, | 200 bool DefaultSearchPolicyHandler::CheckPolicySettings(const PolicyMap& policies, |
204 PolicyErrorMap* errors) { | 201 PolicyErrorMap* errors) { |
205 if (!CheckIndividualPolicies(policies, errors)) | 202 if (!CheckIndividualPolicies(policies, errors)) |
206 return false; | 203 return false; |
207 | 204 |
208 if (DefaultSearchProviderIsDisabled(policies)) { | 205 if (DefaultSearchProviderIsDisabled(policies)) { |
209 // Add an error for all specified default search policies except | 206 // Add an error for all specified default search policies except |
210 // DefaultSearchProviderEnabled. | 207 // DefaultSearchProviderEnabled. |
211 | 208 |
212 for (std::vector<TypeCheckingPolicyHandler*>::const_iterator handler = | 209 for (auto& handler : handlers_) { |
Peter Kasting
2016/08/31 04:12:56
Nit: Seems like this could be const auto&.
Avi (use Gerrit)
2016/09/01 00:34:26
Done.
| |
213 handlers_.begin(); | 210 const char* policy_name = handler->policy_name(); |
214 handler != handlers_.end(); ++handler) { | |
215 const char* policy_name = (*handler)->policy_name(); | |
216 if (policy_name != key::kDefaultSearchProviderEnabled && | 211 if (policy_name != key::kDefaultSearchProviderEnabled && |
217 HasDefaultSearchPolicy(policies, policy_name)) { | 212 HasDefaultSearchPolicy(policies, policy_name)) { |
218 errors->AddError(policy_name, IDS_POLICY_DEFAULT_SEARCH_DISABLED); | 213 errors->AddError(policy_name, IDS_POLICY_DEFAULT_SEARCH_DISABLED); |
219 } | 214 } |
220 } | 215 } |
221 return true; | 216 return true; |
222 } | 217 } |
223 | 218 |
224 const base::Value* url; | 219 const base::Value* url; |
225 std::string dummy; | 220 std::string dummy; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 dict->SetString(DefaultSearchManager::kShortName, host); | 294 dict->SetString(DefaultSearchManager::kShortName, host); |
300 if (keyword.empty()) | 295 if (keyword.empty()) |
301 dict->SetString(DefaultSearchManager::kKeyword, host); | 296 dict->SetString(DefaultSearchManager::kKeyword, host); |
302 | 297 |
303 DefaultSearchManager::AddPrefValueToMap(std::move(dict), prefs); | 298 DefaultSearchManager::AddPrefValueToMap(std::move(dict), prefs); |
304 } | 299 } |
305 | 300 |
306 bool DefaultSearchPolicyHandler::CheckIndividualPolicies( | 301 bool DefaultSearchPolicyHandler::CheckIndividualPolicies( |
307 const PolicyMap& policies, | 302 const PolicyMap& policies, |
308 PolicyErrorMap* errors) { | 303 PolicyErrorMap* errors) { |
309 for (std::vector<TypeCheckingPolicyHandler*>::const_iterator handler = | 304 for (auto& handler : handlers_) { |
310 handlers_.begin(); | 305 if (!handler->CheckPolicySettings(policies, errors)) |
311 handler != handlers_.end(); ++handler) { | |
312 if (!(*handler)->CheckPolicySettings(policies, errors)) | |
313 return false; | 306 return false; |
314 } | 307 } |
315 return true; | 308 return true; |
316 } | 309 } |
317 | 310 |
318 bool DefaultSearchPolicyHandler::HasDefaultSearchPolicy( | 311 bool DefaultSearchPolicyHandler::HasDefaultSearchPolicy( |
319 const PolicyMap& policies, | 312 const PolicyMap& policies, |
320 const char* policy_name) { | 313 const char* policy_name) { |
321 return policies.Get(policy_name) != NULL; | 314 return policies.Get(policy_name) != NULL; |
322 } | 315 } |
323 | 316 |
324 bool DefaultSearchPolicyHandler::AnyDefaultSearchPoliciesSpecified( | 317 bool DefaultSearchPolicyHandler::AnyDefaultSearchPoliciesSpecified( |
325 const PolicyMap& policies) { | 318 const PolicyMap& policies) { |
326 for (std::vector<TypeCheckingPolicyHandler*>::const_iterator handler = | 319 for (auto& handler : handlers_) { |
Peter Kasting
2016/08/31 04:12:56
Nit: Seems like this could be const auto&.
Avi (use Gerrit)
2016/09/01 00:34:26
Done.
| |
327 handlers_.begin(); | 320 if (policies.Get(handler->policy_name())) |
328 handler != handlers_.end(); ++handler) { | |
329 if (policies.Get((*handler)->policy_name())) | |
330 return true; | 321 return true; |
331 } | 322 } |
332 return false; | 323 return false; |
333 } | 324 } |
334 | 325 |
335 bool DefaultSearchPolicyHandler::DefaultSearchProviderIsDisabled( | 326 bool DefaultSearchPolicyHandler::DefaultSearchProviderIsDisabled( |
336 const PolicyMap& policies) { | 327 const PolicyMap& policies) { |
337 const base::Value* provider_enabled = | 328 const base::Value* provider_enabled = |
338 policies.GetValue(key::kDefaultSearchProviderEnabled); | 329 policies.GetValue(key::kDefaultSearchProviderEnabled); |
339 bool enabled = true; | 330 bool enabled = true; |
(...skipping 26 matching lines...) Expand all Loading... | |
366 void DefaultSearchPolicyHandler::EnsureListPrefExists( | 357 void DefaultSearchPolicyHandler::EnsureListPrefExists( |
367 PrefValueMap* prefs, | 358 PrefValueMap* prefs, |
368 const std::string& path) { | 359 const std::string& path) { |
369 base::Value* value; | 360 base::Value* value; |
370 base::ListValue* list_value; | 361 base::ListValue* list_value; |
371 if (!prefs->GetValue(path, &value) || !value->GetAsList(&list_value)) | 362 if (!prefs->GetValue(path, &value) || !value->GetAsList(&list_value)) |
372 prefs->SetValue(path, base::WrapUnique(new base::ListValue())); | 363 prefs->SetValue(path, base::WrapUnique(new base::ListValue())); |
373 } | 364 } |
374 | 365 |
375 } // namespace policy | 366 } // namespace policy |
OLD | NEW |