summaryrefslogtreecommitdiff
path: root/chromium/components/search_engines
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-07-12 14:07:37 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-07-17 10:29:26 +0000
commitec02ee4181c49b61fce1c8fb99292dbb8139cc90 (patch)
tree25cde714b2b71eb639d1cd53f5a22e9ba76e14ef /chromium/components/search_engines
parentbb09965444b5bb20b096a291445170876225268d (diff)
downloadqtwebengine-chromium-ec02ee4181c49b61fce1c8fb99292dbb8139cc90.tar.gz
BASELINE: Update Chromium to 59.0.3071.134
Change-Id: Id02ef6fb2204c5fd21668a1c3e6911c83b17585a Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/components/search_engines')
-rw-r--r--chromium/components/search_engines/default_search_manager_unittest.cc10
-rw-r--r--chromium/components/search_engines/default_search_policy_handler_unittest.cc24
-rw-r--r--chromium/components/search_engines/keyword_table.cc3
-rw-r--r--chromium/components/search_engines/prepopulated_engines.json81
-rw-r--r--chromium/components/search_engines/search_engines_test_util.cc4
-rw-r--r--chromium/components/search_engines/template_url.cc4
-rw-r--r--chromium/components/search_engines/template_url_data_util.cc4
-rw-r--r--chromium/components/search_engines/template_url_fetcher.cc2
-rw-r--r--chromium/components/search_engines/template_url_prepopulate_data_unittest.cc20
-rw-r--r--chromium/components/search_engines/template_url_service.cc191
-rw-r--r--chromium/components/search_engines/template_url_service.h24
-rw-r--r--chromium/components/search_engines/template_url_service_observer.h5
-rw-r--r--chromium/components/search_engines/template_url_unittest.cc8
13 files changed, 225 insertions, 155 deletions
diff --git a/chromium/components/search_engines/default_search_manager_unittest.cc b/chromium/components/search_engines/default_search_manager_unittest.cc
index f2a12757b92..5e72128e705 100644
--- a/chromium/components/search_engines/default_search_manager_unittest.cc
+++ b/chromium/components/search_engines/default_search_manager_unittest.cc
@@ -7,9 +7,11 @@
#include <stddef.h>
#include <memory>
+#include <utility>
#include "base/files/scoped_temp_dir.h"
#include "base/macros.h"
+#include "base/memory/ptr_util.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
@@ -30,8 +32,8 @@ namespace {
void SetOverrides(sync_preferences::TestingPrefServiceSyncable* prefs,
bool update) {
prefs->SetUserPref(prefs::kSearchProviderOverridesVersion,
- new base::Value(1));
- base::ListValue* overrides = new base::ListValue;
+ base::MakeUnique<base::Value>(1));
+ auto overrides = base::MakeUnique<base::ListValue>();
std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue);
entry->SetString("name", update ? "new_foo" : "foo");
@@ -59,7 +61,7 @@ void SetOverrides(sync_preferences::TestingPrefServiceSyncable* prefs,
entry->SetString("keyword", "bazk");
entry->SetString("encoding", "UTF-8");
overrides->Append(entry->CreateDeepCopy());
- prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides);
+ prefs->SetUserPref(prefs::kSearchProviderOverrides, std::move(overrides));
}
void SetPolicy(sync_preferences::TestingPrefServiceSyncable* prefs,
@@ -74,7 +76,7 @@ void SetPolicy(sync_preferences::TestingPrefServiceSyncable* prefs,
entry->SetBoolean(DefaultSearchManager::kDisabledByPolicy, !enabled);
prefs->SetManagedPref(
DefaultSearchManager::kDefaultSearchProviderDataPrefName,
- entry.release());
+ std::move(entry));
}
} // namespace
diff --git a/chromium/components/search_engines/default_search_policy_handler_unittest.cc b/chromium/components/search_engines/default_search_policy_handler_unittest.cc
index 02b9dcdf5cc..a8c86e13def 100644
--- a/chromium/components/search_engines/default_search_policy_handler_unittest.cc
+++ b/chromium/components/search_engines/default_search_policy_handler_unittest.cc
@@ -84,19 +84,19 @@ void DefaultSearchPolicyHandlerTest::
base::MakeUnique<base::Value>(true), nullptr);
policy->Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
- base::MakeUnique<base::StringValue>(kSearchURL), nullptr);
+ base::MakeUnique<base::Value>(kSearchURL), nullptr);
policy->Set(key::kDefaultSearchProviderName, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
- base::MakeUnique<base::StringValue>(kName), nullptr);
+ base::MakeUnique<base::Value>(kName), nullptr);
policy->Set(key::kDefaultSearchProviderKeyword, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
- base::MakeUnique<base::StringValue>(kKeyword), nullptr);
+ base::MakeUnique<base::Value>(kKeyword), nullptr);
policy->Set(key::kDefaultSearchProviderSuggestURL, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
- base::MakeUnique<base::StringValue>(kSuggestURL), nullptr);
+ base::MakeUnique<base::Value>(kSuggestURL), nullptr);
policy->Set(key::kDefaultSearchProviderIconURL, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
- base::MakeUnique<base::StringValue>(kIconURL), nullptr);
+ base::MakeUnique<base::Value>(kIconURL), nullptr);
policy->Set(key::kDefaultSearchProviderEncodings, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
base::WrapUnique(encodings), nullptr);
@@ -105,16 +105,16 @@ void DefaultSearchPolicyHandlerTest::
default_alternate_urls_.CreateDeepCopy(), nullptr);
policy->Set(key::kDefaultSearchProviderSearchTermsReplacementKey,
POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
- base::MakeUnique<base::StringValue>(kReplacementKey), nullptr);
+ base::MakeUnique<base::Value>(kReplacementKey), nullptr);
policy->Set(key::kDefaultSearchProviderImageURL, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
- base::MakeUnique<base::StringValue>(kImageURL), nullptr);
+ base::MakeUnique<base::Value>(kImageURL), nullptr);
policy->Set(key::kDefaultSearchProviderImageURLPostParams,
POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
- base::MakeUnique<base::StringValue>(kImageParams), nullptr);
+ base::MakeUnique<base::Value>(kImageParams), nullptr);
policy->Set(key::kDefaultSearchProviderNewTabURL, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
- base::MakeUnique<base::StringValue>(kNewTabURL), nullptr);
+ base::MakeUnique<base::Value>(kNewTabURL), nullptr);
}
// Checks that if the default search policy is missing, that no elements of the
@@ -138,7 +138,7 @@ TEST_F(DefaultSearchPolicyHandlerTest, Invalid) {
const char bad_search_url[] = "http://test.com/noSearchTerms";
policy.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
- base::WrapUnique(new base::StringValue(bad_search_url)), nullptr);
+ base::WrapUnique(new base::Value(bad_search_url)), nullptr);
UpdateProviderPolicy(policy);
const base::Value* temp = nullptr;
@@ -285,7 +285,7 @@ TEST_F(DefaultSearchPolicyHandlerTest, MinimallyDefined) {
base::WrapUnique(new base::Value(true)), nullptr);
policy.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
- base::WrapUnique(new base::StringValue(kSearchURL)), nullptr);
+ base::WrapUnique(new base::Value(kSearchURL)), nullptr);
UpdateProviderPolicy(policy);
const base::Value* temp = NULL;
@@ -344,7 +344,7 @@ TEST_F(DefaultSearchPolicyHandlerTest, FileURL) {
base::WrapUnique(new base::Value(true)), nullptr);
policy.Set(key::kDefaultSearchProviderSearchURL, POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
- base::WrapUnique(new base::StringValue(kFileSearchURL)), nullptr);
+ base::WrapUnique(new base::Value(kFileSearchURL)), nullptr);
UpdateProviderPolicy(policy);
const base::Value* temp = NULL;
diff --git a/chromium/components/search_engines/keyword_table.cc b/chromium/components/search_engines/keyword_table.cc
index 8ca529c1fb1..a9348870641 100644
--- a/chromium/components/search_engines/keyword_table.cc
+++ b/chromium/components/search_engines/keyword_table.cc
@@ -13,6 +13,7 @@
#include "base/json/json_writer.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_piece.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
@@ -37,7 +38,7 @@ namespace {
const char kBuiltinKeywordVersion[] = "Builtin Keyword Version";
const std::string ColumnsForVersion(int version, bool concatenated) {
- std::vector<std::string> columns;
+ std::vector<base::StringPiece> columns;
columns.push_back("id");
columns.push_back("short_name");
diff --git a/chromium/components/search_engines/prepopulated_engines.json b/chromium/components/search_engines/prepopulated_engines.json
index 3409ecc4a77..3ebf56b8918 100644
--- a/chromium/components/search_engines/prepopulated_engines.json
+++ b/chromium/components/search_engines/prepopulated_engines.json
@@ -30,7 +30,7 @@
// Increment this if you change the data in ways that mean users with
// existing data should get a new version.
- "kCurrentDataVersion": 97
+ "kCurrentDataVersion": 98
},
// The following engines are included in country lists and are added to the
@@ -39,8 +39,8 @@
"aol": {
"name": "AOL",
"keyword": "aol.com",
- "favicon_url": "http://search.aol.com/favicon.ico",
- "search_url": "http://search.aol.com/aol/search?q={searchTerms}",
+ "favicon_url": "https://search.aol.com/favicon.ico",
+ "search_url": "https://search.aol.com/aol/search?q={searchTerms}",
"suggest_url": "http://autocomplete.search.aol.com/autocomplete/get?output=json&it=&q={searchTerms}",
"type": "SEARCH_ENGINE_AOL",
"id": 35
@@ -78,8 +78,8 @@
"baidu": {
"name": "\u767e\u5ea6",
"keyword": "baidu.com",
- "favicon_url": "http://www.baidu.com/favicon.ico",
- "search_url": "http://www.baidu.com/#ie={inputEncoding}&wd={searchTerms}",
+ "favicon_url": "https://www.baidu.com/favicon.ico",
+ "search_url": "https://www.baidu.com/#ie={inputEncoding}&wd={searchTerms}",
"suggest_url": "http://suggestion.baidu.com/su?wd={searchTerms}&action=opensearch&ie={inputEncoding}",
"type": "SEARCH_ENGINE_BAIDU",
"id": 21
@@ -134,8 +134,8 @@
"kvasir": {
"name": "Kvasir",
"keyword": "kvasir.no",
- "favicon_url": "http://kvasir.no/grafikk/favicon.ico",
- "search_url": "http://kvasir.no/alle?q={searchTerms}",
+ "favicon_url": "https://kvasir.no/grafikk/favicon.ico",
+ "search_url": "https://kvasir.no/alle?q={searchTerms}",
"type": "SEARCH_ENGINE_KVASIR",
"id": 73
},
@@ -143,10 +143,10 @@
"mail_ru": {
"name": "@MAIL.RU",
"keyword": "mail.ru",
- "favicon_url": "http://go.imgsmail.ru/favicon.ico",
- "search_url": "http://go.mail.ru/search?q={searchTerms}",
+ "favicon_url": "https://go.imgsmail.ru/favicon.ico",
+ "search_url": "https://go.mail.ru/search?q={searchTerms}",
"encoding": "windows-1251",
- "suggest_url": "http://suggests.go.mail.ru/chrome?q={searchTerms}",
+ "suggest_url": "https://suggests.go.mail.ru/chrome?q={searchTerms}",
"type": "SEARCH_ENGINE_MAILRU",
"id": 83
},
@@ -154,8 +154,8 @@
"najdi": {
"name": "Najdi.si",
"keyword": "najdi.si",
- "favicon_url": "http://www.najdi.si/assets/PROD-1.4.10/ctx/images/favicon.ico",
- "search_url": "http://www.najdi.si/search.jsp?q={searchTerms}",
+ "favicon_url": "https://www.najdi.si/assets/PROD-1.5.16/ctx/images/favicon.ico",
+ "search_url": "https://www.najdi.si/search.jsp?q={searchTerms}",
"type": "SEARCH_ENGINE_NAJDI",
"id": 87
},
@@ -182,9 +182,9 @@
"seznam": {
"name": "Seznam",
"keyword": "seznam.cz",
- "favicon_url": "http://search.seznam.cz/r/img/favicon.ico",
- "search_url": "http://search.seznam.cz/?q={searchTerms}",
- "suggest_url": "http://suggest.fulltext.seznam.cz/fulltext_ff?phrase={searchTerms}",
+ "favicon_url": "https://search.seznam.cz/r/img/favicon.ico",
+ "search_url": "https://search.seznam.cz/?q={searchTerms}",
+ "suggest_url": "https://suggest.fulltext.seznam.cz/fulltext_ff?phrase={searchTerms}",
"type": "SEARCH_ENGINE_SEZNAM",
"id": 25
},
@@ -212,8 +212,8 @@
"vinden": {
"name": "Vinden.nl",
"keyword": "vinden.nl",
- "favicon_url": "http://www.vinden.nl/favicon.ico",
- "search_url": "http://www.vinden.nl/?q={searchTerms}",
+ "favicon_url": "https://www.vinden.nl/favicon.ico",
+ "search_url": "https://www.vinden.nl/?q={searchTerms}",
"type": "SEARCH_ENGINE_VINDEN",
"id": 53
},
@@ -412,9 +412,9 @@
"yahoo_jp": {
"name": "Yahoo! JAPAN",
"keyword": "yahoo.co.jp",
- "favicon_url": "http://search.yahoo.co.jp/favicon.ico",
- "search_url": "http://search.yahoo.co.jp/search?ei={inputEncoding}&fr=crmas&p={searchTerms}",
- "suggest_url": "http://search.yahooapis.jp/AssistSearchService/V2/webassistSearch?p={searchTerms}&appid=oQsoxcyxg66enp0TYoirkKoryq6rF8bK76mW0KYxZ0v0WPLtn.Lix6wy8F_LwGWHUII-&output=fxjson&fr=crmas",
+ "favicon_url": "https://search.yahoo.co.jp/favicon.ico",
+ "search_url": "https://search.yahoo.co.jp/search?ei={inputEncoding}&fr=crmas&p={searchTerms}",
+ "suggest_url": "https://search.yahooapis.jp/AssistSearchService/V2/webassistSearch?p={searchTerms}&appid=oQsoxcyxg66enp0TYoirkKoryq6rF8bK76mW0KYxZ0v0WPLtn.Lix6wy8F_LwGWHUII-&output=fxjson&fr=crmas",
"type": "SEARCH_ENGINE_YAHOO",
"id": 2
},
@@ -683,7 +683,9 @@
"search_url": "http://search.avg.com/search?q={searchTerms}",
"alternate_urls": [
"http://isearch.avg.com/search?q={searchTerms}",
- "http://search.avg.com/route/?q={searchTerms}&lng={language}"
+ "http://search.avg.com/route/?q={searchTerms}&lng={language}",
+ "https://isearch.avg.com/search?q={searchTerms}",
+ "https://search.avg.com/route/?q={searchTerms}&lng={language}"
],
"type": "SEARCH_ENGINE_AVG",
"id": 50
@@ -767,9 +769,13 @@
"goo": {
"name": "goo",
"keyword": "search.goo.ne.jp",
- "favicon_url": "http://goo.ne.jp/favicon.ico",
- "search_url": "http://search.goo.ne.jp/web.jsp?MT={searchTerms}&IE={inputEncoding}",
- "suggest_url": "http://search.goo.ne.jp/sgt.jsp?MT={searchTerms}&CL=plugin&FM=json&IE={inputEncoding}",
+ "favicon_url": "https://search.goo.ne.jp/cdn/common/img/favicon.ico",
+ "search_url": "https://search.goo.ne.jp/web.jsp?MT={searchTerms}&IE={inputEncoding}",
+ "suggest_url": "https://search.goo.ne.jp/sgt.jsp?MT={searchTerms}&CL=plugin&FM=json&IE={inputEncoding}",
+ "alternate_urls": [
+ "http://search.goo.ne.jp/web.jsp?MT={searchTerms}&IE={inputEncoding}",
+ "http://search.goo.ne.jp/sgt.jsp?MT={searchTerms}&CL=plugin&FM=json&IE={inputEncoding}"
+ ],
"encoding": "EUC-JP",
"type": "SEARCH_ENGINE_GOO",
"id": 23
@@ -837,6 +843,10 @@
"favicon_url": "http://www.neti.ee/favicon.ico",
"search_url": "http://www.neti.ee/cgi-bin/otsing?query={searchTerms}",
"suggest_url": "http://www.neti.ee/api/suggestOS?suggestQuery={searchTerms}",
+ "alternate_urls": [
+ "https://www.neti.ee/cgi-bin/otsing?query={searchTerms}&src=web",
+ "https://www.neti.ee/api/suggestOS?suggestVersion=1&suggestQuery={searchTerms}"
+ ],
"encoding": "ISO-8859-1",
"type": "SEARCH_ENGINE_NETI",
"id": 44
@@ -865,9 +875,13 @@
"rambler": {
"name": "\u0420\u0430\u043c\u0431\u043b\u0435\u0440",
"keyword": "rambler.ru",
- "favicon_url": "http://nova.rambler.ru/static/blocks/images/favicon.ico",
+ "favicon_url": "http://i.rl0.ru/2011/icons/rambler.ico",
"search_url": "http://nova.rambler.ru/search?query={searchTerms}",
"suggest_url": "http://nova.rambler.ru/suggest?v=3&query={searchTerms}",
+ "alternate_urls": [
+ "https://nova.rambler.ru/search?query={searchTerms}",
+ "https://nova.rambler.ru/suggest?v=3&query={searchTerms}"
+ ],
"type": "SEARCH_ENGINE_RAMBLER",
"id": 16
},
@@ -927,7 +941,13 @@
"http://www.softonic.com/s/{searchTerms}",
"http://www.softonic.com.br/s/{searchTerms}",
"http://buscador.softonic.com/?q={searchTerms}",
- "http://nl.softonic.com/s/{searchTerms}"
+ "http://nl.softonic.com/s/{searchTerms}",
+ "https://search.softonic.com/?q={searchTerms}",
+ "https://en.softonic.com/s/{searchTerms}",
+ "https://www.softonic.com/s/{searchTerms}",
+ "https://www.softonic.com.br/s/{searchTerms}",
+ "https://buscador.softonic.com/?q={searchTerms}",
+ "https://nl.softonic.com/s/{searchTerms}"
],
"type": "SEARCH_ENGINE_SOFTONIC",
"id": 80
@@ -960,6 +980,9 @@
"keyword": "terra.com.ar",
"favicon_url": "http://buscar.terra.com.ar/favicon.ico",
"search_url": "http://buscar.terra.com.ar/Default.aspx?source=Search&ca=s&query={searchTerms}",
+ "alternate_urls": [
+ "https://buscador.terra.com.ar/Default.aspx?source=Search&ca=s&query={searchTerms}"
+ ],
"encoding": "ISO-8859-1",
"type": "SEARCH_ENGINE_TERRA",
"id": 90
@@ -970,6 +993,9 @@
"keyword": "terra.es",
"favicon_url": "http://buscador.terra.es/favicon.ico",
"search_url": "http://buscador.terra.es/Default.aspx?source=Search&ca=s&query={searchTerms}",
+ "alternate_urls": [
+ "https://buscador.terra.es/Default.aspx?source=Search&ca=s&query={searchTerms}"
+ ],
"encoding": "ISO-8859-1",
"type": "SEARCH_ENGINE_TERRA",
"id": 90
@@ -990,6 +1016,9 @@
"keyword": "walla.co.il",
"favicon_url": "http://www.walla.co.il/favicon.ico",
"search_url": "http://search.walla.co.il/?q={searchTerms}",
+ "alternate_urls": [
+ "https://search.walla.co.il/?q={searchTerms}"
+ ],
"type": "SEARCH_ENGINE_WALLA",
"id": 55
},
diff --git a/chromium/components/search_engines/search_engines_test_util.cc b/chromium/components/search_engines/search_engines_test_util.cc
index 1d54c7cce1d..b1b005d680e 100644
--- a/chromium/components/search_engines/search_engines_test_util.cc
+++ b/chromium/components/search_engines/search_engines_test_util.cc
@@ -4,6 +4,8 @@
#include "components/search_engines/search_engines_test_util.h"
+#include <utility>
+
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/strings/utf_string_conversions.h"
@@ -66,7 +68,7 @@ void SetExtensionDefaultSearchInPrefs(
TemplateURLDataToDictionary(data);
prefs->SetExtensionPref(
DefaultSearchManager::kDefaultSearchProviderDataPrefName,
- entry.release());
+ std::move(entry));
}
void RemoveExtensionDefaultSearchFromPrefs(
diff --git a/chromium/components/search_engines/template_url.cc b/chromium/components/search_engines/template_url.cc
index da62aaa3c13..a3a162a0a26 100644
--- a/chromium/components/search_engines/template_url.cc
+++ b/chromium/components/search_engines/template_url.cc
@@ -505,7 +505,9 @@ bool TemplateURLRef::ExtractSearchTermsFromURL(
// suffix, then this is not a match.
base::StringPiece search_term =
base::StringPiece(source).substr(value.begin, value.len);
- if (!search_term.starts_with(search_term_value_prefix_) ||
+ if (search_term.size() < (search_term_value_prefix_.size() +
+ search_term_value_suffix_.size()) ||
+ !search_term.starts_with(search_term_value_prefix_) ||
!search_term.ends_with(search_term_value_suffix_))
continue;
diff --git a/chromium/components/search_engines/template_url_data_util.cc b/chromium/components/search_engines/template_url_data_util.cc
index ab76c92ab57..fd3138b7bc7 100644
--- a/chromium/components/search_engines/template_url_data_util.cc
+++ b/chromium/components/search_engines/template_url_data_util.cc
@@ -90,7 +90,7 @@ std::unique_ptr<TemplateURLData> TemplateURLDataFromDictionary(
if (dict.GetList(DefaultSearchManager::kAlternateURLs, &alternate_urls)) {
for (const auto& it : *alternate_urls) {
std::string alternate_url;
- if (it->GetAsString(&alternate_url))
+ if (it.GetAsString(&alternate_url))
result->alternate_urls.push_back(std::move(alternate_url));
}
}
@@ -99,7 +99,7 @@ std::unique_ptr<TemplateURLData> TemplateURLDataFromDictionary(
if (dict.GetList(DefaultSearchManager::kInputEncodings, &encodings)) {
for (const auto& it : *encodings) {
std::string encoding;
- if (it->GetAsString(&encoding))
+ if (it.GetAsString(&encoding))
result->input_encodings.push_back(std::move(encoding));
}
}
diff --git a/chromium/components/search_engines/template_url_fetcher.cc b/chromium/components/search_engines/template_url_fetcher.cc
index 0db1184388f..eb9e90af07e 100644
--- a/chromium/components/search_engines/template_url_fetcher.cc
+++ b/chromium/components/search_engines/template_url_fetcher.cc
@@ -32,7 +32,7 @@ constexpr net::NetworkTrafficAnnotationTag kTrafficAnnotation =
"corresponding search engine is added to the list in the browser "
"settings (chrome://settings/searchEngines)."
trigger:
- "User visits a web page containing a <link rel="search"> tag."
+ "User visits a web page containing a <link rel=\"search\"> tag."
data: "None"
destination: WEBSITE
}
diff --git a/chromium/components/search_engines/template_url_prepopulate_data_unittest.cc b/chromium/components/search_engines/template_url_prepopulate_data_unittest.cc
index 44ac82702f9..08c323e07c3 100644
--- a/chromium/components/search_engines/template_url_prepopulate_data_unittest.cc
+++ b/chromium/components/search_engines/template_url_prepopulate_data_unittest.cc
@@ -120,8 +120,8 @@ TEST_F(TemplateURLPrepopulateDataTest, UniqueIDs) {
// override the built-in ones.
TEST_F(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) {
prefs_.SetUserPref(prefs::kSearchProviderOverridesVersion,
- new base::Value(1));
- base::ListValue* overrides = new base::ListValue;
+ base::MakeUnique<base::Value>(1));
+ auto overrides = base::MakeUnique<base::ListValue>();
std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue);
// Set only the minimal required settings for a search provider configuration.
entry->SetString("name", "foo");
@@ -131,7 +131,7 @@ TEST_F(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) {
entry->SetString("encoding", "UTF-8");
entry->SetInteger("id", 1001);
overrides->Append(entry->CreateDeepCopy());
- prefs_.SetUserPref(prefs::kSearchProviderOverrides, overrides);
+ prefs_.SetUserPref(prefs::kSearchProviderOverrides, std::move(overrides));
int version = TemplateURLPrepopulateData::GetDataVersion(&prefs_);
EXPECT_EQ(1, version);
@@ -163,9 +163,9 @@ TEST_F(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) {
alternate_urls->AppendString("http://foo.com/alternate?q={searchTerms}");
entry->Set("alternate_urls", alternate_urls);
entry->SetString("search_terms_replacement_key", "espv");
- overrides = new base::ListValue;
+ overrides = base::MakeUnique<base::ListValue>();
overrides->Append(entry->CreateDeepCopy());
- prefs_.SetUserPref(prefs::kSearchProviderOverrides, overrides);
+ prefs_.SetUserPref(prefs::kSearchProviderOverrides, std::move(overrides));
t_urls = TemplateURLPrepopulateData::GetPrepopulatedEngines(
&prefs_, &default_index);
@@ -187,7 +187,7 @@ TEST_F(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) {
// Test that subsequent providers are loaded even if an intermediate
// provider has an incomplete configuration.
- overrides = new base::ListValue;
+ overrides = base::MakeUnique<base::ListValue>();
overrides->Append(entry->CreateDeepCopy());
entry->SetInteger("id", 1002);
entry->SetString("name", "bar");
@@ -199,7 +199,7 @@ TEST_F(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) {
entry->SetString("keyword", "bazk");
entry->SetString("encoding", "UTF-8");
overrides->Append(entry->CreateDeepCopy());
- prefs_.SetUserPref(prefs::kSearchProviderOverrides, overrides);
+ prefs_.SetUserPref(prefs::kSearchProviderOverrides, std::move(overrides));
t_urls =
TemplateURLPrepopulateData::GetPrepopulatedEngines(&prefs_,
@@ -209,8 +209,8 @@ TEST_F(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) {
TEST_F(TemplateURLPrepopulateDataTest, ClearProvidersFromPrefs) {
prefs_.SetUserPref(prefs::kSearchProviderOverridesVersion,
- new base::Value(1));
- base::ListValue* overrides = new base::ListValue;
+ base::MakeUnique<base::Value>(1));
+ auto overrides = base::MakeUnique<base::ListValue>();
std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue);
// Set only the minimal required settings for a search provider configuration.
entry->SetString("name", "foo");
@@ -220,7 +220,7 @@ TEST_F(TemplateURLPrepopulateDataTest, ClearProvidersFromPrefs) {
entry->SetString("encoding", "UTF-8");
entry->SetInteger("id", 1001);
overrides->Append(std::move(entry));
- prefs_.SetUserPref(prefs::kSearchProviderOverrides, overrides);
+ prefs_.SetUserPref(prefs::kSearchProviderOverrides, std::move(overrides));
int version = TemplateURLPrepopulateData::GetDataVersion(&prefs_);
EXPECT_EQ(1, version);
diff --git a/chromium/components/search_engines/template_url_service.cc b/chromium/components/search_engines/template_url_service.cc
index bd5e5d66486..a4db5e184d0 100644
--- a/chromium/components/search_engines/template_url_service.cc
+++ b/chromium/components/search_engines/template_url_service.cc
@@ -11,6 +11,8 @@
#include "base/callback.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
+#include "base/debug/crash_logging.h"
+#include "base/format_macros.h"
#include "base/guid.h"
#include "base/i18n/case_conversion.h"
#include "base/memory/ptr_util.h"
@@ -18,6 +20,7 @@
#include "base/profiler/scoped_tracker.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
+#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/default_clock.h"
#include "base/time/time.h"
@@ -364,12 +367,12 @@ bool TemplateURLService::CanAddAutogeneratedKeyword(
}
bool TemplateURLService::IsPrepopulatedOrCreatedByPolicy(
- const TemplateURL* t_url) {
+ const TemplateURL* t_url) const {
return (t_url->prepopulate_id() > 0 || t_url->created_by_policy()) &&
t_url->SupportsReplacement(search_terms_data());
}
-bool TemplateURLService::ShowInDefaultList(const TemplateURL* t_url) {
+bool TemplateURLService::ShowInDefaultList(const TemplateURL* t_url) const {
return t_url == default_search_provider_ ||
IsPrepopulatedOrCreatedByPolicy(t_url);
}
@@ -567,7 +570,7 @@ void TemplateURLService::ResetTemplateURL(TemplateURL* url,
NotifyObservers();
}
-bool TemplateURLService::CanMakeDefault(const TemplateURL* url) {
+bool TemplateURLService::CanMakeDefault(const TemplateURL* url) const {
return
((default_search_provider_source_ == DefaultSearchManager::FROM_USER) ||
(default_search_provider_source_ ==
@@ -618,7 +621,7 @@ bool TemplateURLService::IsSearchResultsPageFromDefaultSearchProvider(
default_provider->IsSearchURL(url, search_terms_data());
}
-bool TemplateURLService::IsExtensionControlledDefaultSearch() {
+bool TemplateURLService::IsExtensionControlledDefaultSearch() const {
return default_search_provider_source_ ==
DefaultSearchManager::FROM_EXTENSION;
}
@@ -668,18 +671,7 @@ void TemplateURLService::RepairPrepopulatedSearchEngines() {
default_search_manager_.ClearUserSelectedDefaultSearchEngine();
- if (!default_search_provider_) {
- // If the default search provider came from a user pref we would have been
- // notified of the new (fallback-provided) value in
- // ClearUserSelectedDefaultSearchEngine() above. Since we are here, the
- // value was presumably originally a fallback value (which may have been
- // repaired).
- DefaultSearchManager::Source source;
- const TemplateURLData* new_dse =
- default_search_manager_.GetDefaultSearchEngine(&source);
- // ApplyDefaultSearchChange will notify observers once it is done.
- ApplyDefaultSearchChange(new_dse, source);
- } else {
+ if (default_search_provider_) {
// Set fallback engine as user selected, because repair is considered a user
// action and we are expected to sync new fallback engine to other devices.
const TemplateURLData* fallback_engine_data =
@@ -689,7 +681,7 @@ void TemplateURLService::RepairPrepopulatedSearchEngines() {
FindPrepopulatedTemplateURL(fallback_engine_data->prepopulate_id);
// The fallback engine is created from built-in/override data that should
// always have a prepopulate ID, so this engine should always exist after
- // a repair."
+ // a repair.
DCHECK(fallback_engine);
// Write the fallback engine's GUID to prefs, which will cause
// OnSyncedDefaultSearchProviderGUIDChanged() to set it as the new
@@ -698,6 +690,18 @@ void TemplateURLService::RepairPrepopulatedSearchEngines() {
fallback_engine->sync_guid());
}
NotifyObservers();
+ RequestGoogleURLTrackerServerCheckIfNecessary();
+ } else {
+ // If the default search provider came from a user pref we would have been
+ // notified of the new (fallback-provided) value in
+ // ClearUserSelectedDefaultSearchEngine() above. Since we are here, the
+ // value was presumably originally a fallback value (which may have been
+ // repaired).
+ DefaultSearchManager::Source source;
+ const TemplateURLData* new_dse =
+ default_search_manager_.GetDefaultSearchEngine(&source);
+ // ApplyDefaultSearchChange will notify observers once it is done.
+ ApplyDefaultSearchChange(new_dse, source);
}
}
@@ -846,8 +850,11 @@ void TemplateURLService::OnWebDataServiceRequestDone(
base::string16 TemplateURLService::GetKeywordShortName(
const base::string16& keyword,
- bool* is_omnibox_api_extension_keyword) {
- const TemplateURL* template_url = GetTemplateURLForKeyword(keyword);
+ bool* is_omnibox_api_extension_keyword) const {
+ // TODO(jeffschiller): Make GetTemplateURLForKeyword const and remove the
+ // const_cast.
+ const TemplateURL* template_url =
+ const_cast<TemplateURLService*>(this)->GetTemplateURLForKeyword(keyword);
// TODO(sky): Once LocationBarView adds a listener to the TemplateURLService
// to track changes to the model, this should become a DCHECK.
@@ -868,6 +875,9 @@ void TemplateURLService::OnHistoryURLVisited(const URLVisitedDetails& details) {
}
void TemplateURLService::Shutdown() {
+ for (auto& observer : model_observers_)
+ observer.OnTemplateURLServiceShuttingDown();
+
if (client_)
client_->Shutdown();
// This check has to be done at Shutdown() instead of in the dtor to ensure
@@ -1437,6 +1447,10 @@ TemplateURL* TemplateURLService::BestEngineForKeyword(TemplateURL* engine1,
DCHECK(engine2);
DCHECK_EQ(engine1->keyword(), engine2->keyword());
+ // We should only have overlapping keywords when at least one comes from
+ // an extension.
+ DCHECK(IsCreatedByExtension(engine1) || IsCreatedByExtension(engine2));
+
// TODO(a-v-y) Remove following code for non extension engines when reasons
// for crash https://bugs.chromium.org/p/chromium/issues/detail?id=697745
// become clear.
@@ -1462,11 +1476,9 @@ void TemplateURLService::RemoveFromMaps(TemplateURL* template_url) {
DCHECK_NE(0U, keyword_to_turl_and_length_.count(keyword));
if (keyword_to_turl_and_length_[keyword].first == template_url) {
// We need to check whether the keyword can now be provided by another
- // TemplateURL. See the comments in AddToMaps() for more information on
- // extension keywords and how they can coexist with non-extension keywords.
- // In the case of more than one extension, we use the most recently
- // installed (which will be the most recently added, which will have the
- // highest ID).
+ // TemplateURL. See the comments for BestEngineForKeyword() for more
+ // information on extension keywords and how they can coexist with
+ // non-extension keywords.
TemplateURL* best_fallback = nullptr;
for (const auto& turl : template_urls_) {
if ((turl.get() != template_url) && (turl->keyword() == keyword)) {
@@ -1507,6 +1519,7 @@ void TemplateURLService::AddToMaps(TemplateURL* template_url) {
AddToDomainMap(template_url);
} else {
TemplateURL* existing_url = i->second.first;
+ DCHECK_NE(existing_url, template_url);
if (BestEngineForKeyword(existing_url, template_url) != existing_url) {
RemoveFromDomainMap(existing_url);
AddToMap(template_url);
@@ -1619,7 +1632,7 @@ void TemplateURLService::ChangeToLoadedState() {
}
bool TemplateURLService::CanAddAutogeneratedKeywordForHost(
- const std::string& host) {
+ const std::string& host) const {
const TemplateURLSet* urls = provider_map_->GetURLsForHost(host);
if (!urls)
return true;
@@ -1630,7 +1643,7 @@ bool TemplateURLService::CanAddAutogeneratedKeywordForHost(
return true;
}
-bool TemplateURLService::CanReplace(const TemplateURL* t_url) {
+bool TemplateURLService::CanReplace(const TemplateURL* t_url) const {
return !ShowInDefaultList(t_url) && t_url->safe_for_autoreplace();
}
@@ -1652,80 +1665,60 @@ TemplateURL* TemplateURLService::FindNonExtensionTemplateURLForKeyword(
bool TemplateURLService::UpdateNoNotify(TemplateURL* existing_turl,
const TemplateURL& new_values) {
DCHECK(existing_turl);
+ DCHECK(!IsCreatedByExtension(existing_turl));
if (!Contains(&template_urls_, existing_turl))
return false;
- DCHECK(!IsCreatedByExtension(existing_turl));
-
- base::string16 old_keyword(existing_turl->keyword());
- keyword_to_turl_and_length_.erase(old_keyword);
- RemoveFromDomainMap(existing_turl);
- if (!existing_turl->sync_guid().empty())
- guid_to_turl_.erase(existing_turl->sync_guid());
-
- // |provider_map_| is only initialized after loading has completed.
- if (loaded_)
- provider_map_->Remove(existing_turl);
-
+ base::string16 old_keyword = existing_turl->keyword();
TemplateURLID previous_id = existing_turl->id();
+ RemoveFromMaps(existing_turl);
+
+ // Check if new keyword conflicts with another normal engine.
+ // This is possible when autogeneration of the keyword for a Google default
+ // search provider at load time causes it to conflict with an existing
+ // keyword. In this case we delete the existing keyword if it's replaceable,
+ // or else undo the change in keyword for |existing_turl|.
+ // Conflicts with extension engines are handled in AddToMaps/RemoveFromMaps
+ // functions.
+ // Search for conflicting keyword turl before updating values of
+ // existing_turl.
+ TemplateURL* conflicting_keyword_turl =
+ FindNonExtensionTemplateURLForKeyword(new_values.keyword());
+
+ // Update existing turl with new values.
existing_turl->CopyFrom(new_values);
existing_turl->data_.id = previous_id;
- if (loaded_) {
- provider_map_->Add(existing_turl, search_terms_data());
+ if (conflicting_keyword_turl && conflicting_keyword_turl != existing_turl) {
+ if (CanReplace(conflicting_keyword_turl))
+ RemoveNoNotify(conflicting_keyword_turl);
+ else
+ existing_turl->data_.SetKeyword(old_keyword);
}
- const base::string16& keyword = existing_turl->keyword();
- KeywordToTURLAndMeaningfulLength::const_iterator i =
- keyword_to_turl_and_length_.find(keyword);
- if (i == keyword_to_turl_and_length_.end()) {
- AddToMap(existing_turl);
- AddToDomainMap(existing_turl);
- } else {
- // We can theoretically reach here in two cases:
- // * There is an existing extension keyword and sync brings in a rename of
- // a non-extension keyword to match. In this case we just need to pick
- // which keyword has priority to update the keyword map.
- // * Autogeneration of the keyword for a Google default search provider
- // at load time causes it to conflict with an existing keyword. In this
- // case we delete the existing keyword if it's replaceable, or else undo
- // the change in keyword for |existing_turl|.
- TemplateURL* existing_keyword_turl = i->second.first;
- if (existing_keyword_turl->type() != TemplateURL::NORMAL) {
- if (!CanReplace(existing_turl)) {
- AddToMap(existing_turl);
- AddToDomainMap(existing_turl);
- }
- } else {
- if (CanReplace(existing_keyword_turl)) {
- RemoveNoNotify(existing_keyword_turl);
- } else {
- existing_turl->data_.SetKeyword(old_keyword);
- AddToMap(existing_turl);
- AddToDomainMap(existing_turl);
- }
- }
- }
- if (!existing_turl->sync_guid().empty())
- guid_to_turl_[existing_turl->sync_guid()] = existing_turl;
+ AddToMaps(existing_turl);
- if (web_data_service_.get())
- web_data_service_->UpdateKeyword(existing_turl->data());
+ if (existing_turl->type() == TemplateURL::NORMAL) {
+ if (web_data_service_)
+ web_data_service_->UpdateKeyword(existing_turl->data());
- // Inform sync of the update.
- ProcessTemplateURLChange(
- FROM_HERE, existing_turl, syncer::SyncChange::ACTION_UPDATE);
+ // Inform sync of the update.
+ ProcessTemplateURLChange(FROM_HERE, existing_turl,
+ syncer::SyncChange::ACTION_UPDATE);
+ }
if (default_search_provider_ == existing_turl &&
default_search_provider_source_ == DefaultSearchManager::FROM_USER) {
default_search_manager_.SetUserSelectedDefaultSearchEngine(
default_search_provider_->data());
}
+
+ DCHECK(!HasDuplicateKeywords());
return true;
}
bool TemplateURLService::Update(TemplateURL* existing_turl,
- const TemplateURL& new_values) {
+ const TemplateURL& new_values) {
const bool updated = UpdateNoNotify(existing_turl, new_values);
if (updated)
NotifyObservers();
@@ -1791,7 +1784,8 @@ void TemplateURLService::UpdateKeywordSearchTermsForURL(
// later after iteration.
// Note: UpdateNoNotify() will replace the entry from the container of
// this iterator, so update here directly will cause an error about it.
- visited_url = *i;
+ if (!IsCreatedByExtension(*i))
+ visited_url = *i;
}
}
if (visited_url)
@@ -1829,7 +1823,7 @@ void TemplateURLService::RequestGoogleURLTrackerServerCheckIfNecessary() {
if (default_search_provider_ &&
default_search_provider_->HasGoogleBaseURLs(search_terms_data()) &&
google_url_tracker_)
- google_url_tracker_->RequestServerCheck(false);
+ google_url_tracker_->RequestServerCheck();
}
void TemplateURLService::GoogleBaseURLChanged() {
@@ -2055,6 +2049,7 @@ TemplateURL* TemplateURLService::AddNoNotify(
// |initial_default_search_provider_| and the web data version of itself.
TemplateURL* existing_turl =
FindNonExtensionTemplateURLForKeyword(template_url->keyword());
+
if (existing_turl && Contains(&template_urls_, existing_turl)) {
DCHECK_NE(existing_turl, template_url.get());
if (CanReplace(existing_turl)) {
@@ -2066,6 +2061,7 @@ TemplateURL* TemplateURLService::AddNoNotify(
base::string16 new_keyword = UniquifyKeyword(*existing_turl, false);
ResetTemplateURLNoNotify(existing_turl, existing_turl->short_name(),
new_keyword, existing_turl->url());
+ DCHECK_EQ(new_keyword, existing_turl->keyword());
}
}
}
@@ -2082,7 +2078,7 @@ TemplateURL* TemplateURLService::AddNoNotify(
ProcessTemplateURLChange(FROM_HERE, template_url_ptr,
syncer::SyncChange::ACTION_ADD);
}
-
+ DCHECK(!HasDuplicateKeywords());
return template_url_ptr;
}
@@ -2121,6 +2117,7 @@ bool TemplateURLService::ResetTemplateURLNoNotify(
const base::string16& title,
const base::string16& keyword,
const std::string& search_url) {
+ DCHECK(!IsCreatedByExtension(url));
DCHECK(!keyword.empty());
DCHECK(!search_url.empty());
TemplateURLData data(url->data());
@@ -2216,8 +2213,7 @@ base::string16 TemplateURLService::UniquifyKeyword(const TemplateURL& turl,
if (!GetTemplateURLForKeyword(turl.keyword()))
return turl.keyword();
- // First, try to return the generated keyword for the TemplateURL (except
- // for extensions, as their keywords are not associated with their URLs).
+ // First, try to return the generated keyword for the TemplateURL.
GURL gurl(turl.url());
if (gurl.is_valid()) {
base::string16 keyword_candidate = TemplateURL::GenerateKeyword(gurl);
@@ -2237,10 +2233,14 @@ base::string16 TemplateURLService::UniquifyKeyword(const TemplateURL& turl,
return keyword_candidate;
}
-bool TemplateURLService::IsLocalTemplateURLBetter(const TemplateURL* local_turl,
- const TemplateURL* sync_turl,
- bool prefer_local_default) {
- DCHECK(GetTemplateURLForGUID(local_turl->sync_guid()));
+bool TemplateURLService::IsLocalTemplateURLBetter(
+ const TemplateURL* local_turl,
+ const TemplateURL* sync_turl,
+ bool prefer_local_default) const {
+ // TODO(jeffschiller): Make GetTemplateURLForKeyword const and remove the
+ // const_cast.
+ DCHECK(const_cast<TemplateURLService*>(this)->GetTemplateURLForGUID(
+ local_turl->sync_guid()));
return local_turl->last_modified() > sync_turl->last_modified() ||
local_turl->created_by_policy() ||
(prefer_local_default && local_turl == GetDefaultSearchProvider());
@@ -2482,3 +2482,18 @@ TemplateURL* TemplateURLService::FindMatchingDefaultExtensionTemplateURL(
}
return nullptr;
}
+
+bool TemplateURLService::HasDuplicateKeywords() const {
+ std::map<base::string16, TemplateURL*> keyword_to_template_url;
+ for (const auto& template_url : template_urls_) {
+ // Validate no duplicate normal engines with same keyword.
+ if (!IsCreatedByExtension(template_url.get())) {
+ if (keyword_to_template_url.find(template_url->keyword()) !=
+ keyword_to_template_url.end()) {
+ return true;
+ }
+ keyword_to_template_url[template_url->keyword()] = template_url.get();
+ }
+ }
+ return false;
+}
diff --git a/chromium/components/search_engines/template_url_service.h b/chromium/components/search_engines/template_url_service.h
index ca11382e5e1..4187327f06a 100644
--- a/chromium/components/search_engines/template_url_service.h
+++ b/chromium/components/search_engines/template_url_service.h
@@ -135,14 +135,14 @@ class TemplateURLService : public WebDataServiceConsumer,
// Returns whether the engine is a "pre-existing" engine, either from the
// prepopulate list or created by policy.
- bool IsPrepopulatedOrCreatedByPolicy(const TemplateURL* template_url);
+ bool IsPrepopulatedOrCreatedByPolicy(const TemplateURL* template_url) const;
// Returns whether |template_url| should be shown in the list of engines
// most likely to be selected as a default engine. This is meant to highlight
// the current default, as well as the other most likely choices of default
// engine, separately from a full list of all TemplateURLs (which might be
// very long).
- bool ShowInDefaultList(const TemplateURL* template_url);
+ bool ShowInDefaultList(const TemplateURL* template_url) const;
// Adds to |matches| all TemplateURLs whose keywords begin with |prefix|,
// sorted shortest-keyword-first. If |supports_replacement_only| is true, only
@@ -248,7 +248,7 @@ class TemplateURLService : public WebDataServiceConsumer,
// Return true if the given |url| can be made the default. This returns false
// regardless of |url| if the default search provider is managed by policy or
// controlled by an extension.
- bool CanMakeDefault(const TemplateURL* url);
+ bool CanMakeDefault(const TemplateURL* url) const;
// Set the default search provider. |url| may be null.
// This will assert if the default search is managed; the UI should not be
@@ -274,7 +274,7 @@ class TemplateURLService : public WebDataServiceConsumer,
}
// Returns true if the default search provider is controlled by an extension.
- bool IsExtensionControlledDefaultSearch();
+ bool IsExtensionControlledDefaultSearch() const;
// Returns the default search specified in the prepopulated data, if it
// exists. If not, returns first URL in |template_urls_|, or NULL if that's
@@ -330,8 +330,9 @@ class TemplateURLService : public WebDataServiceConsumer,
// Returns the locale-direction-adjusted short name for the given keyword.
// Also sets the out param to indicate whether the keyword belongs to an
// Omnibox extension.
- base::string16 GetKeywordShortName(const base::string16& keyword,
- bool* is_omnibox_api_extension_keyword);
+ base::string16 GetKeywordShortName(
+ const base::string16& keyword,
+ bool* is_omnibox_api_extension_keyword) const;
// Called by the history service when a URL is visited.
void OnHistoryURLVisited(const URLVisitedDetails& details);
@@ -543,13 +544,13 @@ class TemplateURLService : public WebDataServiceConsumer,
// Returns false if there is a TemplateURL that has a search url with the
// specified host and that TemplateURL has been manually modified.
- bool CanAddAutogeneratedKeywordForHost(const std::string& host);
+ bool CanAddAutogeneratedKeywordForHost(const std::string& host) const;
// Returns true if the TemplateURL is replaceable. This doesn't look at the
// uniqueness of the keyword or host and is intended to be called after those
// checks have been done. This returns true if the TemplateURL doesn't appear
// in the default list and is marked as safe_for_autoreplace.
- bool CanReplace(const TemplateURL* t_url);
+ bool CanReplace(const TemplateURL* t_url) const;
// Like GetTemplateURLForKeyword(), but ignores extension-provided keywords.
TemplateURL* FindNonExtensionTemplateURLForKeyword(
@@ -661,7 +662,7 @@ class TemplateURLService : public WebDataServiceConsumer,
// search provider
bool IsLocalTemplateURLBetter(const TemplateURL* local_turl,
const TemplateURL* sync_turl,
- bool prefer_local_default = true);
+ bool prefer_local_default = true) const;
// Given two synced TemplateURLs with a conflicting keyword, one of which
// needs to be added to or updated in the local model (|unapplied_sync_turl|)
@@ -725,6 +726,11 @@ class TemplateURLService : public WebDataServiceConsumer,
TemplateURL* FindMatchingDefaultExtensionTemplateURL(
const TemplateURLData& data);
+ // Returns whether |template_urls_| contains more than one normal engine with
+ // same keyword. Used to validate state after search engines are
+ // added/updated.
+ bool HasDuplicateKeywords() const;
+
// ---------- Browser state related members ---------------------------------
PrefService* prefs_;
diff --git a/chromium/components/search_engines/template_url_service_observer.h b/chromium/components/search_engines/template_url_service_observer.h
index acd016f583d..eb3ba6667d0 100644
--- a/chromium/components/search_engines/template_url_service_observer.h
+++ b/chromium/components/search_engines/template_url_service_observer.h
@@ -12,6 +12,11 @@ class TemplateURLServiceObserver {
// Notification that the template url model has changed in some way.
virtual void OnTemplateURLServiceChanged() = 0;
+ // Notification that the template url service is shutting down. Observers that
+ // might outlive the service can use this to clear out any raw pointers to the
+ // service.
+ virtual void OnTemplateURLServiceShuttingDown() {}
+
protected:
virtual ~TemplateURLServiceObserver() {}
};
diff --git a/chromium/components/search_engines/template_url_unittest.cc b/chromium/components/search_engines/template_url_unittest.cc
index 170807f17f3..31774626760 100644
--- a/chromium/components/search_engines/template_url_unittest.cc
+++ b/chromium/components/search_engines/template_url_unittest.cc
@@ -1267,6 +1267,14 @@ TEST_F(TemplateURLTest, ExtractSearchTermsWithPrefixAndSuffix) {
// Don't match if the prefix and suffix aren't there.
EXPECT_FALSE(url.ExtractSearchTermsFromURL(
GURL("http://www.example.com/?q=invalid"), search_terms_data_, &result));
+
+ // Don't match if the prefix and suffix overlap.
+ TemplateURLData data_with_overlap;
+ data.alternate_urls.push_back(
+ "http://www.example.com/?q=goo{searchTerms}oogle");
+ TemplateURL url_with_overlap(data);
+ EXPECT_FALSE(url_with_overlap.ExtractSearchTermsFromURL(
+ GURL("http://www.example.com/?q=google"), search_terms_data_, &result));
}
TEST_F(TemplateURLTest, HasSearchTermsReplacementKey) {