Commit 1383ac8f authored by Tommy Li's avatar Tommy Li Committed by Chromium LUCI CQ

[search_engines] Protect DSE from removal by the SearchEngineTabHelper

Two weeks ago we added a CHECK to verify in production our assumption
that the default search provider was never Remove()-ed.

This turned out to be violated in SearchEngineTabHelper.

This CL fixes that violation. We don't need to call Remove() from that
tab helper anyways, since a call to Add() will remove duplicates if
possible, and will preserve the DSE.

Bug: 1166372
Change-Id: Ia3d145ddc457d901fbb81c94487cee28b2792cca
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2637957Reviewed-by: default avatarOrin Jaworski <orinj@chromium.org>
Commit-Queue: Tommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#844883}
parent ad1d11b7
...@@ -204,13 +204,10 @@ void SearchEngineTabHelper::GenerateKeywordIfNecessary( ...@@ -204,13 +204,10 @@ void SearchEngineTabHelper::GenerateKeywordIfNecessary(
if (!url_service->CanAddAutogeneratedKeyword(keyword, url, &current_url)) if (!url_service->CanAddAutogeneratedKeyword(keyword, url, &current_url))
return; return;
if (current_url) { if (current_url && current_url->originating_url().is_valid()) {
if (current_url->originating_url().is_valid()) { // The existing keyword was generated from an OpenSearch description
// The existing keyword was generated from an OpenSearch description // document, don't regenerate.
// document, don't regenerate. return;
return;
}
url_service->Remove(current_url);
} }
TemplateURLData data; TemplateURLData data;
...@@ -233,6 +230,9 @@ void SearchEngineTabHelper::GenerateKeywordIfNecessary( ...@@ -233,6 +230,9 @@ void SearchEngineTabHelper::GenerateKeywordIfNecessary(
} }
data.safe_for_autoreplace = true; data.safe_for_autoreplace = true;
data.input_encodings.push_back(handle->GetSearchableFormEncoding()); data.input_encodings.push_back(handle->GetSearchableFormEncoding());
// This Add() call may displace the previously auto-generated TemplateURL,
// and that's expected. But it will never displace the default search engine.
url_service->Add(std::make_unique<TemplateURL>(data)); url_service->Add(std::make_unique<TemplateURL>(data));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment