| 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 "chrome/browser/search_engines/default_search_manager.h" | 5 #include "chrome/browser/search_engines/default_search_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/i18n/case_conversion.h" | 11 #include "base/i18n/case_conversion.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "base/prefs/pref_value_map.h" |
| 13 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
| 16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/search_engines/template_url.h" | 21 #include "chrome/browser/search_engines/template_url.h" |
| 21 #include "chrome/browser/search_engines/template_url_service.h" | 22 #include "chrome/browser/search_engines/template_url_service.h" |
| 22 #include "chrome/browser/search_engines/util.h" | 23 #include "chrome/browser/search_engines/util.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 const char DefaultSearchManager::kInputEncodings[] = "input_encodings"; | 61 const char DefaultSearchManager::kInputEncodings[] = "input_encodings"; |
| 61 | 62 |
| 62 const char DefaultSearchManager::kDateCreated[] = "date_created"; | 63 const char DefaultSearchManager::kDateCreated[] = "date_created"; |
| 63 const char DefaultSearchManager::kLastModified[] = "last_modified"; | 64 const char DefaultSearchManager::kLastModified[] = "last_modified"; |
| 64 | 65 |
| 65 const char DefaultSearchManager::kUsageCount[] = "usage_count"; | 66 const char DefaultSearchManager::kUsageCount[] = "usage_count"; |
| 66 const char DefaultSearchManager::kAlternateURLs[] = "alternate_urls"; | 67 const char DefaultSearchManager::kAlternateURLs[] = "alternate_urls"; |
| 67 const char DefaultSearchManager::kSearchTermsReplacementKey[] = | 68 const char DefaultSearchManager::kSearchTermsReplacementKey[] = |
| 68 "search_terms_replacement_key"; | 69 "search_terms_replacement_key"; |
| 69 const char DefaultSearchManager::kCreatedByPolicy[] = "created_by_policy"; | 70 const char DefaultSearchManager::kCreatedByPolicy[] = "created_by_policy"; |
| 71 const char DefaultSearchManager::kDisabledByPolicy[] = "disabled_by_policy"; |
| 70 | 72 |
| 71 DefaultSearchManager::DefaultSearchManager(PrefService* pref_service) | 73 DefaultSearchManager::DefaultSearchManager(PrefService* pref_service) |
| 72 : pref_service_(pref_service) { | 74 : pref_service_(pref_service) { |
| 73 DCHECK(pref_service_); | 75 DCHECK(pref_service_); |
| 74 } | 76 } |
| 75 | 77 |
| 76 DefaultSearchManager::~DefaultSearchManager() { | 78 DefaultSearchManager::~DefaultSearchManager() { |
| 77 } | 79 } |
| 78 | 80 |
| 79 // static | 81 // static |
| 80 void DefaultSearchManager::RegisterProfilePrefs( | 82 void DefaultSearchManager::RegisterProfilePrefs( |
| 81 user_prefs::PrefRegistrySyncable* registry) { | 83 user_prefs::PrefRegistrySyncable* registry) { |
| 82 registry->RegisterDictionaryPref( | 84 registry->RegisterDictionaryPref( |
| 83 kDefaultSearchProviderData, | 85 kDefaultSearchProviderData, |
| 84 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 86 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 85 } | 87 } |
| 86 | 88 |
| 89 // static |
| 90 void DefaultSearchManager::AddPrefValueToMap(base::DictionaryValue* value, |
| 91 PrefValueMap* pref_value_map) { |
| 92 pref_value_map->SetValue(kDefaultSearchProviderData, value); |
| 93 } |
| 94 |
| 87 bool DefaultSearchManager::GetDefaultSearchEngine(TemplateURLData* data) { | 95 bool DefaultSearchManager::GetDefaultSearchEngine(TemplateURLData* data) { |
| 88 const base::DictionaryValue* url_dict = | 96 const base::DictionaryValue* url_dict = |
| 89 pref_service_->GetDictionary(kDefaultSearchProviderData); | 97 pref_service_->GetDictionary(kDefaultSearchProviderData); |
| 90 | 98 |
| 91 if (url_dict->empty()) | 99 if (url_dict->empty()) |
| 92 return false; | 100 return false; |
| 93 | 101 |
| 94 std::string search_url; | 102 std::string search_url; |
| 95 base::string16 keyword; | 103 base::string16 keyword; |
| 96 url_dict->GetString(kURL, &search_url); | 104 url_dict->GetString(kURL, &search_url); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 data.search_terms_replacement_key); | 225 data.search_terms_replacement_key); |
| 218 | 226 |
| 219 url_dict.SetBoolean(kCreatedByPolicy, data.created_by_policy); | 227 url_dict.SetBoolean(kCreatedByPolicy, data.created_by_policy); |
| 220 | 228 |
| 221 pref_service_->Set(kDefaultSearchProviderData, url_dict); | 229 pref_service_->Set(kDefaultSearchProviderData, url_dict); |
| 222 } | 230 } |
| 223 | 231 |
| 224 void DefaultSearchManager::ClearUserSelectedDefaultSearchEngine() { | 232 void DefaultSearchManager::ClearUserSelectedDefaultSearchEngine() { |
| 225 pref_service_->ClearPref(kDefaultSearchProviderData); | 233 pref_service_->ClearPref(kDefaultSearchProviderData); |
| 226 } | 234 } |
| OLD | NEW |