Commit fefec8d8 authored by Moe Ahmadi's avatar Moe Ahmadi Committed by Commit Bot

[NTP][RQ] Adds support for deletion of repeatable queries

Repeatable Queries Service now populates the destination URL for the
query suggestions which is later used from the MostVisitedSites to
delete a repeatable query.

Depending on whether the query is provided by the server or the local
history, the service issues a deletion request to the server or deletes
the suggestion from the in-memory URL DB. In both cases, all eligible
search URLs from the default search provider which produce that query
also get deleted.

Fixed: 1147119
Change-Id: I4fad9eaf209c72e735d2260c7e22b1f0af5db4ba
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2527605
Commit-Queue: Moe Ahmadi <mahmadi@chromium.org>
Reviewed-by: default avatarNicolas Ouellet-Payeur <nicolaso@chromium.org>
Reviewed-by: default avatarRamya Nagarajan <ramyan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825945}
parent b88f70c2
...@@ -51,6 +51,7 @@ source_set("unit_tests") { ...@@ -51,6 +51,7 @@ source_set("unit_tests") {
"//components/history/core/test", "//components/history/core/test",
"//components/omnibox/browser:test_support", "//components/omnibox/browser:test_support",
"//components/search_engines:search_engines", "//components/search_engines:search_engines",
"//components/search_engines:test_support",
"//components/signin/public/base:test_support", "//components/signin/public/base:test_support",
"//components/signin/public/identity_manager:test_support", "//components/signin/public/identity_manager:test_support",
"//components/variations", "//components/variations",
......
...@@ -39,7 +39,8 @@ class RepeatableQuery { ...@@ -39,7 +39,8 @@ class RepeatableQuery {
~RepeatableQuery() = default; ~RepeatableQuery() = default;
bool operator==(const RepeatableQuery& other) const { bool operator==(const RepeatableQuery& other) const {
return query == other.query && deletion_url == other.deletion_url; return query == other.query && destination_url == other.destination_url &&
deletion_url == other.deletion_url;
} }
bool operator!=(const RepeatableQuery& other) const { bool operator!=(const RepeatableQuery& other) const {
return !(this == &other); return !(this == &other);
...@@ -48,7 +49,10 @@ class RepeatableQuery { ...@@ -48,7 +49,10 @@ class RepeatableQuery {
// Repeatable query suggestion. // Repeatable query suggestion.
base::string16 query; base::string16 query;
// The endpoint used for deleting the query suggestion on the server. // The URL to navigate to when the suggestion is selected.
GURL destination_url;
// The relative endpoint used for deleting the query suggestion on the server.
// Populated for server provided queries only. // Populated for server provided queries only.
std::string deletion_url; std::string deletion_url;
}; };
...@@ -82,6 +86,13 @@ class RepeatableQueriesService : public KeyedService { ...@@ -82,6 +86,13 @@ class RepeatableQueriesService : public KeyedService {
// RepeatableQueriesServiceObserver::OnRepeatableQueriesUpdated. // RepeatableQueriesServiceObserver::OnRepeatableQueriesUpdated.
void Refresh(); void Refresh();
// Deletes the records of the repeatable query suggestion with the given
// destination URL on the server as well as on the device, whichever is
// applicable. Prevents the suggestion from being offered again by
// blocklisting it. Updates the current set of suggestions and notifies the
// observers.
void DeleteQueryWithDestinationURL(const GURL& url);
// Add/remove observers. // Add/remove observers.
void AddObserver(RepeatableQueriesServiceObserver* observer); void AddObserver(RepeatableQueriesServiceObserver* observer);
void RemoveObserver(RepeatableQueriesServiceObserver* observer); void RemoveObserver(RepeatableQueriesServiceObserver* observer);
...@@ -98,21 +109,39 @@ class RepeatableQueriesService : public KeyedService { ...@@ -98,21 +109,39 @@ class RepeatableQueriesService : public KeyedService {
// Called when the signin status changes. // Called when the signin status changes.
void SigninStatusChanged(); void SigninStatusChanged();
// Returns the server destination URL for |query|.
GURL GetQueryDestinationURL(const base::string16& query);
// Returns the resolved deletion URL for the given relative deletion URL.
GURL GetQueryDeletionURL(const std::string& deletion_url);
// Returns the server request URL. // Returns the server request URL.
GURL GetRequestURL(); GURL GetRequestURL();
private: private:
// Requests repeatable queries from the server. Called for signed-in users. // Requests repeatable queries from the server. Called for signed-in users.
void GetRepeatableQueriesFromServer(); void GetRepeatableQueriesFromServer();
void RepeatableQueriesResponseLoaded(std::unique_ptr<std::string> response); void RepeatableQueriesResponseLoaded(network::SimpleURLLoader* loader,
std::unique_ptr<std::string> response);
void RepeatableQueriesParsed(data_decoder::DataDecoder::ValueOrError result); void RepeatableQueriesParsed(data_decoder::DataDecoder::ValueOrError result);
// Queries the in-memory URLDatabase for the repeatable queries submitted // Queries the in-memory URLDatabase for the repeatable queries submitted
// to the default search provider. Called for unauthenticated users. // to the default search provider. Called for unauthenticated users.
void GetRepeatableQueriesFromURLDatabase(); void GetRepeatableQueriesFromURLDatabase();
// Deletes |query| from the in-memory URLDatabase.
void DeleteRepeatableQueryFromURLDatabase(const base::string16& query);
// Deletes the query with |deletion_url| from the server.
void DeleteRepeatableQueryFromServer(const std::string& deletion_url);
void DeletionResponseLoaded(network::SimpleURLLoader* loader,
std::unique_ptr<std::string> response);
void NotifyObservers(); void NotifyObservers();
bool IsQueryDeleted(const base::string16& query);
void MarkQueryAsDeleted(const base::string16& query);
history::HistoryService* history_service_; history::HistoryService* history_service_;
TemplateURLService* template_url_service_; TemplateURLService* template_url_service_;
...@@ -129,7 +158,12 @@ class RepeatableQueriesService : public KeyedService { ...@@ -129,7 +158,12 @@ class RepeatableQueriesService : public KeyedService {
std::vector<RepeatableQuery> repeatable_queries_; std::vector<RepeatableQuery> repeatable_queries_;
std::unique_ptr<network::SimpleURLLoader> simple_loader_; // Used to ensure the deleted repeatable queries won't be suggested again.
// This does not need to be persisted across sessions as the queries do get
// deleted on the server as well as on the device, whichever is applicable.
std::set<base::string16> deleted_repeatable_queries_;
std::vector<std::unique_ptr<network::SimpleURLLoader>> loaders_;
base::WeakPtrFactory<RepeatableQueriesService> weak_ptr_factory_{this}; base::WeakPtrFactory<RepeatableQueriesService> weak_ptr_factory_{this};
}; };
......
...@@ -277,6 +277,7 @@ Refer to README.md for content description and update process. ...@@ -277,6 +277,7 @@ Refer to README.md for content description and update process.
<item id="remoting_telemetry_log_writer" added_in_milestone="86" hash_code="107268760" type="0" content_hash_code="81741595" os_list="linux,windows" file_path="remoting/base/telemetry_log_writer.cc"/> <item id="remoting_telemetry_log_writer" added_in_milestone="86" hash_code="107268760" type="0" content_hash_code="81741595" os_list="linux,windows" file_path="remoting/base/telemetry_log_writer.cc"/>
<item id="render_view_context_menu" added_in_milestone="62" hash_code="25844439" type="0" content_hash_code="69471170" os_list="linux,windows" file_path="chrome/browser/renderer_context_menu/render_view_context_menu.cc"/> <item id="render_view_context_menu" added_in_milestone="62" hash_code="25844439" type="0" content_hash_code="69471170" os_list="linux,windows" file_path="chrome/browser/renderer_context_menu/render_view_context_menu.cc"/>
<item id="renderer_initiated_download" added_in_milestone="62" hash_code="116443055" type="0" content_hash_code="37846436" os_list="linux,windows" file_path="content/browser/renderer_host/render_frame_host_impl.cc"/> <item id="renderer_initiated_download" added_in_milestone="62" hash_code="116443055" type="0" content_hash_code="37846436" os_list="linux,windows" file_path="content/browser/renderer_host/render_frame_host_impl.cc"/>
<item id="repeatable_queries_deletion" added_in_milestone="88" hash_code="59980744" type="0" content_hash_code="9022058" os_list="linux,windows" file_path="components/search/repeatable_queries/repeatable_queries_service.cc"/>
<item id="repeatable_queries_service" added_in_milestone="88" hash_code="5394442" type="0" content_hash_code="115294794" os_list="linux,windows" file_path="components/search/repeatable_queries/repeatable_queries_service.cc"/> <item id="repeatable_queries_service" added_in_milestone="88" hash_code="5394442" type="0" content_hash_code="115294794" os_list="linux,windows" file_path="components/search/repeatable_queries/repeatable_queries_service.cc"/>
<item id="reporting" added_in_milestone="62" hash_code="109891200" type="0" content_hash_code="125758928" os_list="linux,windows" file_path="net/reporting/reporting_uploader.cc"/> <item id="reporting" added_in_milestone="62" hash_code="109891200" type="0" content_hash_code="125758928" os_list="linux,windows" file_path="net/reporting/reporting_uploader.cc"/>
<item id="resource_dispatcher_host" added_in_milestone="62" hash_code="81157007" type="0" deprecated="2019-07-30" content_hash_code="35725167" file_path=""/> <item id="resource_dispatcher_host" added_in_milestone="62" hash_code="81157007" type="0" deprecated="2019-07-30" content_hash_code="35725167" file_path=""/>
......
...@@ -393,6 +393,7 @@ hidden="true" so that these annotations don't show up in the document. ...@@ -393,6 +393,7 @@ hidden="true" so that these annotations don't show up in the document.
<traffic_annotation unique_id="popular_sites_fetch"/> <traffic_annotation unique_id="popular_sites_fetch"/>
<traffic_annotation unique_id="search_suggest_service"/> <traffic_annotation unique_id="search_suggest_service"/>
<traffic_annotation unique_id="remote_suggestions_provider"/> <traffic_annotation unique_id="remote_suggestions_provider"/>
<traffic_annotation unique_id="repeatable_queries_deletion"/>
<traffic_annotation unique_id="repeatable_queries_service"/> <traffic_annotation unique_id="repeatable_queries_service"/>
<traffic_annotation unique_id="promo_service"/> <traffic_annotation unique_id="promo_service"/>
<traffic_annotation unique_id="task_module_service"/> <traffic_annotation unique_id="task_module_service"/>
......
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