Commit 10bcb5dc authored by Ryan Sturm's avatar Ryan Sturm Committed by Commit Bot

Adding a call from ChromeACProvider to Search Prefetch service

This is called when the AC matches change. The result will be used in
the future to check top result, all results gone (i.e., we can cancel
ongoing prefetches).

Bug: 1138631
Change-Id: I7b6bad212888eac36756f41f2f534233df596b04
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2493461
Commit-Queue: Ryan Sturm <ryansturm@chromium.org>
Reviewed-by: default avatarJustin Donnelly <jdonnelly@chromium.org>
Reviewed-by: default avatarRobert Ogden <robertogden@chromium.org>
Cr-Commit-Position: refs/heads/master@{#820409}
parent 0e38f00c
......@@ -25,6 +25,8 @@
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/history/top_sites_factory.h"
#include "chrome/browser/prefetch/search_prefetch/search_prefetch_service.h"
#include "chrome/browser/prefetch/search_prefetch/search_prefetch_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_key.h"
#include "chrome/browser/query_tiles/tile_service_factory.h"
......@@ -461,6 +463,16 @@ bool ChromeAutocompleteProviderClient::IsBrowserUpdateAvailable() const {
#endif
}
void ChromeAutocompleteProviderClient::OnAutocompleteControllerResultReady(
AutocompleteController* controller) {
auto* search_prefetch_service =
SearchPrefetchServiceFactory::GetForProfile(profile_);
// Prefetches result pages that the search provider marked as prefetchable.
if (search_prefetch_service)
search_prefetch_service->OnResultChanged(controller);
}
bool ChromeAutocompleteProviderClient::StrippedURLsAreEqual(
const GURL& url1,
const GURL& url2,
......
......@@ -84,6 +84,8 @@ class ChromeAutocompleteProviderClient : public AutocompleteProviderClient {
bool IsTabOpenWithURL(const GURL& url,
const AutocompleteInput* input) override;
bool IsBrowserUpdateAvailable() const override;
void OnAutocompleteControllerResultReady(
AutocompleteController* controller) override;
// For testing.
void set_storage_partition(content::StoragePartition* storage_partition) {
......
......@@ -11,6 +11,8 @@
#include "chrome/browser/prefetch/search_prefetch/prefetched_response_container.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "components/omnibox/browser/autocomplete_controller.h"
#include "components/omnibox/browser/base_search_provider.h"
#include "components/search_engines/template_url_service.h"
#include "components/variations/net/variations_http_headers.h"
#include "content/public/browser/browser_context.h"
......@@ -247,3 +249,15 @@ void SearchPrefetchService::DeletePrefetch(base::string16 search_terms) {
void SearchPrefetchService::ReportError() {
last_error_time_ticks_ = base::TimeTicks::Now();
}
void SearchPrefetchService::OnResultChanged(
AutocompleteController* controller) {
const auto& result = controller->result();
for (const auto& match : result) {
// TODO(ryansturm): Pass a bool for IsTopResult to limit prefetch to when
// the match is the first item in the omnibox. https://crbug.com/1138649
if (BaseSearchProvider::ShouldPrefetch(match)) {
MaybePrefetchURL(match.destination_url);
}
}
}
......@@ -19,6 +19,8 @@ class Profile;
class GURL;
class PrefetchedResponseContainer;
class AutocompleteController;
enum class SearchPrefetchStatus {
// The request is on the network and may move to any other state.
kInFlight = 1,
......@@ -36,6 +38,9 @@ class SearchPrefetchService : public KeyedService {
SearchPrefetchService(const SearchPrefetchService&) = delete;
SearchPrefetchService& operator=(const SearchPrefetchService&) = delete;
// Called when |controller| has updated information.
void OnResultChanged(AutocompleteController* controller);
// Returns whether the prefetch started or not.
bool MaybePrefetchURL(const GURL& url);
......
......@@ -1003,3 +1003,8 @@ bool AutocompleteController::OnMemoryDump(
base::trace_event::MemoryAllocatorDump::kUnitsBytes, res);
return true;
}
void AutocompleteController::SetStartStopTimerDurationForTesting(
base::TimeDelta duration) {
stop_timer_duration_ = duration;
}
......@@ -172,6 +172,9 @@ class AutocompleteController : public AutocompleteProviderListener,
return last_time_default_match_changed_;
}
// Sets the provider timeout duration for future calls to |Start()|.
void SetStartStopTimerDurationForTesting(base::TimeDelta duration);
private:
friend class AutocompleteProviderTest;
friend class OmniboxSuggestionButtonRowBrowserTest;
......@@ -320,12 +323,11 @@ class AutocompleteController : public AutocompleteProviderListener,
// Timer used to tell the providers to Stop() searching for matches.
base::OneShotTimer stop_timer_;
// Amount of time (in ms) between when the user stops typing and
// when we send Stop() to every provider. This is intended to avoid
// the disruptive effect of belated omnibox updates, updates that
// come after the user has had to time to read the whole dropdown
// and doesn't expect it to change.
const base::TimeDelta stop_timer_duration_;
// Amount of time between when the user stops typing and when we send Stop()
// to every provider. This is intended to avoid the disruptive effect of
// belated omnibox updates, updates that come after the user has had to time
// to read the whole dropdown and doesn't expect it to change.
base::TimeDelta stop_timer_duration_;
// True if a query is not currently running.
bool done_;
......
......@@ -150,8 +150,8 @@ class AutocompleteProviderClient {
virtual void StartServiceWorker(const GURL& destination_url) {}
// Called by |controller| when its results have changed and all providers are
// done processing the autocomplete request. Chrome ignores this. It's only
// used in components unit tests. TODO(blundell): remove it.
// done processing the autocomplete request. Used by chrome to inform the
// prefetch service of updated results.
virtual void OnAutocompleteControllerResultReady(
AutocompleteController* controller) {}
......
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