Commit 7975ab47 authored by Dave Schuyler's avatar Dave Schuyler Committed by Commit Bot

[Omnibox] Move bitmap fetcher cancel

This CL moves when the bitmap fetcher request is canceled. This change
is being made to reduce noise in a future CL (where the request_id_ will
be a collection of request IDs rather than just one). Along the way,
several presubmit warnings are addressed.

The overall intention is make a future CL clearer (less noisy).

Bug: None
Change-Id: I8455f7921c85b3bd9824e06355b7c1c068fec5b2
Reviewed-on: https://chromium-review.googlesource.com/1011284Reviewed-by: default avatarJustin Donnelly <jdonnelly@chromium.org>
Commit-Queue: Dave Schuyler <dschuyler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550699}
parent f0a94e7a
...@@ -6,7 +6,9 @@ ...@@ -6,7 +6,9 @@
#include <stddef.h> #include <stddef.h>
#include <algorithm>
#include <memory> #include <memory>
#include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/callback.h" #include "base/callback.h"
...@@ -269,62 +271,62 @@ void ChromeOmniboxClient::OnResultChanged( ...@@ -269,62 +271,62 @@ void ChromeOmniboxClient::OnResultChanged(
const AutocompleteResult& result, const AutocompleteResult& result,
bool default_match_changed, bool default_match_changed,
const BitmapFetchedCallback& on_bitmap_fetched) { const BitmapFetchedCallback& on_bitmap_fetched) {
BitmapFetcherService* image_service =
BitmapFetcherServiceFactory::GetForBrowserContext(profile_);
if (!image_service) {
return;
}
image_service->CancelRequest(request_id_);
const auto match = std::find_if( const auto match = std::find_if(
result.begin(), result.end(), result.begin(), result.end(),
[](const AutocompleteMatch& current) { return !!current.answer; }); [](const AutocompleteMatch& current) { return !!current.answer; });
if (match != result.end()) { if (match != result.end()) {
BitmapFetcherService* image_service = // TODO(jdonnelly, rhalavati): Create a helper function with Callback to
BitmapFetcherServiceFactory::GetForBrowserContext(profile_); // create annotation and pass it to image_service, merging this annotation
if (image_service) { // and the one in
image_service->CancelRequest(request_id_); // chrome/browser/autocomplete/chrome_autocomplete_provider_client.cc
net::NetworkTrafficAnnotationTag traffic_annotation =
// TODO(jdonnelly, rhalavati): Create a helper function with Callback to net::DefineNetworkTrafficAnnotation("omnibox_result_change", R"(
// create annotation and pass it to image_service, merging this annotation semantics {
// and the one in sender: "Omnibox"
// chrome/browser/autocomplete/chrome_autocomplete_provider_client.cc description:
net::NetworkTrafficAnnotationTag traffic_annotation = "Chromium provides answers in the suggestion list for "
net::DefineNetworkTrafficAnnotation("omnibox_result_change", R"( "certain queries that user types in the omnibox. This request "
semantics { "retrieves a small image (for example, an icon illustrating "
sender: "Omnibox" "the current weather conditions) when this can add information "
description: "to an answer."
"Chromium provides answers in the suggestion list for " trigger:
"certain queries that user types in the omnibox. This request " "Change of results for the query typed by the user in the "
"retrieves a small image (for example, an icon illustrating " "omnibox."
"the current weather conditions) when this can add information " data:
"to an answer." "The only data sent is the path to an image. No user data is "
trigger: "included, although some might be inferrable (e.g. whether the "
"Change of results for the query typed by the user in the " "weather is sunny or rainy in the user's current location) "
"omnibox." "from the name of the image in the path."
data: destination: WEBSITE
"The only data sent is the path to an image. No user data is " }
"included, although some might be inferrable (e.g. whether the " policy {
"weather is sunny or rainy in the user's current location) " cookies_allowed: YES
"from the name of the image in the path." cookies_store: "user"
destination: WEBSITE setting:
} "You can enable or disable this feature via 'Use a prediction "
policy { "service to help complete searches and URLs typed in the "
cookies_allowed: YES "address bar.' in Chromium's settings under Advanced. The "
cookies_store: "user" "feature is enabled by default."
setting: chrome_policy {
"You can enable or disable this feature via 'Use a prediction " SearchSuggestEnabled {
"service to help complete searches and URLs typed in the " policy_options {mode: MANDATORY}
"address bar.' in Chromium's settings under Advanced. The " SearchSuggestEnabled: false
"feature is enabled by default."
chrome_policy {
SearchSuggestEnabled {
policy_options {mode: MANDATORY}
SearchSuggestEnabled: false
}
} }
})"); }
})");
request_id_ = image_service->RequestImage(
match->answer->second_line().image_url(), request_id_ = image_service->RequestImage(
new AnswerImageObserver( match->answer->second_line().image_url(),
base::Bind(&ChromeOmniboxClient::OnBitmapFetched, new AnswerImageObserver(
base::Unretained(this), on_bitmap_fetched)), base::BindRepeating(&ChromeOmniboxClient::OnBitmapFetched,
traffic_annotation); base::Unretained(this), on_bitmap_fetched)),
} traffic_annotation);
} }
} }
...@@ -414,7 +416,7 @@ void ChromeOmniboxClient::OnURLOpenedFromOmnibox(OmniboxLog* log) { ...@@ -414,7 +416,7 @@ void ChromeOmniboxClient::OnURLOpenedFromOmnibox(OmniboxLog* log) {
} }
void ChromeOmniboxClient::OnBookmarkLaunched() { void ChromeOmniboxClient::OnBookmarkLaunched() {
RecordBookmarkLaunch(NULL, BOOKMARK_LAUNCH_LOCATION_OMNIBOX); RecordBookmarkLaunch(nullptr, BOOKMARK_LAUNCH_LOCATION_OMNIBOX);
} }
void ChromeOmniboxClient::DiscardNonCommittedNavigations() { void ChromeOmniboxClient::DiscardNonCommittedNavigations() {
......
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