| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 5 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 bool enabled = true; | 437 bool enabled = true; |
| 438 if (prefs_.GetBoolean(prefs::kDefaultSearchProviderEnabled, &enabled) && | 438 if (prefs_.GetBoolean(prefs::kDefaultSearchProviderEnabled, &enabled) && |
| 439 !enabled) { | 439 !enabled) { |
| 440 // If default search is disabled, we ignore the other fields. | 440 // If default search is disabled, we ignore the other fields. |
| 441 prefs_.SetString(prefs::kDefaultSearchProviderName, std::string()); | 441 prefs_.SetString(prefs::kDefaultSearchProviderName, std::string()); |
| 442 prefs_.SetString(prefs::kDefaultSearchProviderSearchURL, std::string()); | 442 prefs_.SetString(prefs::kDefaultSearchProviderSearchURL, std::string()); |
| 443 prefs_.SetString(prefs::kDefaultSearchProviderSuggestURL, std::string()); | 443 prefs_.SetString(prefs::kDefaultSearchProviderSuggestURL, std::string()); |
| 444 prefs_.SetString(prefs::kDefaultSearchProviderIconURL, std::string()); | 444 prefs_.SetString(prefs::kDefaultSearchProviderIconURL, std::string()); |
| 445 prefs_.SetString(prefs::kDefaultSearchProviderEncodings, std::string()); | 445 prefs_.SetString(prefs::kDefaultSearchProviderEncodings, std::string()); |
| 446 prefs_.SetString(prefs::kDefaultSearchProviderKeyword, std::string()); | 446 prefs_.SetString(prefs::kDefaultSearchProviderKeyword, std::string()); |
| 447 prefs_.SetString(prefs::kDefaultSearchProviderInstantURL, std::string()); |
| 447 return; | 448 return; |
| 448 } | 449 } |
| 449 std::string search_url; | 450 std::string search_url; |
| 450 // The search URL is required. | 451 // The search URL is required. |
| 451 if (prefs_.GetString(prefs::kDefaultSearchProviderSearchURL, &search_url) && | 452 if (prefs_.GetString(prefs::kDefaultSearchProviderSearchURL, &search_url) && |
| 452 !search_url.empty()) { | 453 !search_url.empty()) { |
| 453 SearchTermsDataForValidation search_terms_data; | 454 SearchTermsDataForValidation search_terms_data; |
| 454 const TemplateURLRef search_url_ref(search_url, 0, 0); | 455 const TemplateURLRef search_url_ref(search_url, 0, 0); |
| 455 // It must support replacement (which implies it is valid). | 456 // It must support replacement (which implies it is valid). |
| 456 if (search_url_ref.SupportsReplacementUsingTermsData(search_terms_data)) { | 457 if (search_url_ref.SupportsReplacementUsingTermsData(search_terms_data)) { |
| 457 // The other entries are optional. Just make sure that they are all | 458 // The other entries are optional. Just make sure that they are all |
| 458 // specified via policy, so that we don't use regular prefs. | 459 // specified via policy, so that we don't use regular prefs. |
| 459 EnsureStringPrefExists(prefs::kDefaultSearchProviderSuggestURL); | 460 EnsureStringPrefExists(prefs::kDefaultSearchProviderSuggestURL); |
| 460 EnsureStringPrefExists(prefs::kDefaultSearchProviderIconURL); | 461 EnsureStringPrefExists(prefs::kDefaultSearchProviderIconURL); |
| 461 EnsureStringPrefExists(prefs::kDefaultSearchProviderEncodings); | 462 EnsureStringPrefExists(prefs::kDefaultSearchProviderEncodings); |
| 462 EnsureStringPrefExists(prefs::kDefaultSearchProviderKeyword); | 463 EnsureStringPrefExists(prefs::kDefaultSearchProviderKeyword); |
| 464 EnsureStringPrefExists(prefs::kDefaultSearchProviderInstantURL); |
| 463 | 465 |
| 464 // For the name, default to the host if not specified. | 466 // For the name, default to the host if not specified. |
| 465 std::string name; | 467 std::string name; |
| 466 if (!prefs_.GetString(prefs::kDefaultSearchProviderName, &name) || | 468 if (!prefs_.GetString(prefs::kDefaultSearchProviderName, &name) || |
| 467 name.empty()) | 469 name.empty()) |
| 468 prefs_.SetString(prefs::kDefaultSearchProviderName, | 470 prefs_.SetString(prefs::kDefaultSearchProviderName, |
| 469 GURL(search_url).host()); | 471 GURL(search_url).host()); |
| 470 | 472 |
| 471 // And clear the IDs since these are not specified via policy. | 473 // And clear the IDs since these are not specified via policy. |
| 472 prefs_.SetString(prefs::kDefaultSearchProviderID, std::string()); | 474 prefs_.SetString(prefs::kDefaultSearchProviderID, std::string()); |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 { kPolicyDefaultSearchProviderEnabled, Value::TYPE_BOOLEAN, | 698 { kPolicyDefaultSearchProviderEnabled, Value::TYPE_BOOLEAN, |
| 697 key::kDefaultSearchProviderEnabled }, | 699 key::kDefaultSearchProviderEnabled }, |
| 698 { kPolicyDefaultSearchProviderName, Value::TYPE_STRING, | 700 { kPolicyDefaultSearchProviderName, Value::TYPE_STRING, |
| 699 key::kDefaultSearchProviderName }, | 701 key::kDefaultSearchProviderName }, |
| 700 { kPolicyDefaultSearchProviderKeyword, Value::TYPE_STRING, | 702 { kPolicyDefaultSearchProviderKeyword, Value::TYPE_STRING, |
| 701 key::kDefaultSearchProviderKeyword }, | 703 key::kDefaultSearchProviderKeyword }, |
| 702 { kPolicyDefaultSearchProviderSearchURL, Value::TYPE_STRING, | 704 { kPolicyDefaultSearchProviderSearchURL, Value::TYPE_STRING, |
| 703 key::kDefaultSearchProviderSearchURL }, | 705 key::kDefaultSearchProviderSearchURL }, |
| 704 { kPolicyDefaultSearchProviderSuggestURL, Value::TYPE_STRING, | 706 { kPolicyDefaultSearchProviderSuggestURL, Value::TYPE_STRING, |
| 705 key::kDefaultSearchProviderSuggestURL }, | 707 key::kDefaultSearchProviderSuggestURL }, |
| 708 { kPolicyDefaultSearchProviderInstantURL, Value::TYPE_STRING, |
| 709 key::kDefaultSearchProviderInstantURL }, |
| 706 { kPolicyDefaultSearchProviderIconURL, Value::TYPE_STRING, | 710 { kPolicyDefaultSearchProviderIconURL, Value::TYPE_STRING, |
| 707 key::kDefaultSearchProviderIconURL }, | 711 key::kDefaultSearchProviderIconURL }, |
| 708 { kPolicyDefaultSearchProviderEncodings, Value::TYPE_STRING, | 712 { kPolicyDefaultSearchProviderEncodings, Value::TYPE_STRING, |
| 709 key::kDefaultSearchProviderEncodings }, | 713 key::kDefaultSearchProviderEncodings }, |
| 710 { kPolicyProxyMode, Value::TYPE_INTEGER, key::kProxyMode }, | 714 { kPolicyProxyMode, Value::TYPE_INTEGER, key::kProxyMode }, |
| 711 { kPolicyProxyServer, Value::TYPE_STRING, key::kProxyServer }, | 715 { kPolicyProxyServer, Value::TYPE_STRING, key::kProxyServer }, |
| 712 { kPolicyProxyPacUrl, Value::TYPE_STRING, key::kProxyPacUrl }, | 716 { kPolicyProxyPacUrl, Value::TYPE_STRING, key::kProxyPacUrl }, |
| 713 { kPolicyProxyBypassList, Value::TYPE_STRING, key::kProxyBypassList }, | 717 { kPolicyProxyBypassList, Value::TYPE_STRING, key::kProxyBypassList }, |
| 714 { kPolicyAlternateErrorPagesEnabled, Value::TYPE_BOOLEAN, | 718 { kPolicyAlternateErrorPagesEnabled, Value::TYPE_BOOLEAN, |
| 715 key::kAlternateErrorPagesEnabled }, | 719 key::kAlternateErrorPagesEnabled }, |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 // Update the initialization flag. | 813 // Update the initialization flag. |
| 810 if (!initialization_complete_ && | 814 if (!initialization_complete_ && |
| 811 provider_->IsInitializationComplete()) { | 815 provider_->IsInitializationComplete()) { |
| 812 initialization_complete_ = true; | 816 initialization_complete_ = true; |
| 813 FOR_EACH_OBSERVER(PrefStore::Observer, observers_, | 817 FOR_EACH_OBSERVER(PrefStore::Observer, observers_, |
| 814 OnInitializationCompleted()); | 818 OnInitializationCompleted()); |
| 815 } | 819 } |
| 816 } | 820 } |
| 817 | 821 |
| 818 } // namespace policy | 822 } // namespace policy |
| OLD | NEW |