[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
blundell | 2102f7c | 2015-07-09 10:00:53 | [diff] [blame] | 5 | #include "components/omnibox/browser/zero_suggest_provider.h" |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 6 | |
avi | f57136c1 | 2015-12-25 23:27:45 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 9 | #include "base/callback.h" |
gcomanici | 8cabc77f | 2017-04-27 20:04:54 | [diff] [blame] | 10 | #include "base/feature_list.h" |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 11 | #include "base/i18n/case_conversion.h" |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 12 | #include "base/json/json_string_value_serializer.h" |
asvitkine | 3033081 | 2016-08-30 04:01:08 | [diff] [blame] | 13 | #include "base/metrics/histogram_macros.h" |
[email protected] | f7f41c0e | 2014-08-11 04:22:23 | [diff] [blame] | 14 | #include "base/metrics/user_metrics.h" |
[email protected] | 98570e1 | 2013-06-10 19:54:22 | [diff] [blame] | 15 | #include "base/strings/string16.h" |
| 16 | #include "base/strings/string_util.h" |
[email protected] | 135cb80 | 2013-06-09 16:44:20 | [diff] [blame] | 17 | #include "base/strings/utf_string_conversions.h" |
[email protected] | 4dcb797 | 2013-06-28 15:15:41 | [diff] [blame] | 18 | #include "base/time/time.h" |
a-v-y | dd768d5 | 2016-03-25 21:07:46 | [diff] [blame] | 19 | #include "base/trace_event/trace_event.h" |
amohammadkhan | f76ae11 | 2015-09-14 17:34:43 | [diff] [blame] | 20 | #include "components/data_use_measurement/core/data_use_user_data.h" |
sdefresne | bc766ef | 2014-09-25 09:28:13 | [diff] [blame] | 21 | #include "components/history/core/browser/history_types.h" |
sdefresne | 0da3bc0 | 2015-01-29 18:26:35 | [diff] [blame] | 22 | #include "components/history/core/browser/top_sites.h" |
blundell | 2102f7c | 2015-07-09 10:00:53 | [diff] [blame] | 23 | #include "components/omnibox/browser/autocomplete_classifier.h" |
| 24 | #include "components/omnibox/browser/autocomplete_input.h" |
| 25 | #include "components/omnibox/browser/autocomplete_match.h" |
| 26 | #include "components/omnibox/browser/autocomplete_provider_listener.h" |
Daniel Kenji Toyama | f1e4b57 | 2017-08-03 16:31:11 | [diff] [blame] | 27 | #include "components/omnibox/browser/contextual_suggestions_service.h" |
blundell | 2102f7c | 2015-07-09 10:00:53 | [diff] [blame] | 28 | #include "components/omnibox/browser/history_url_provider.h" |
| 29 | #include "components/omnibox/browser/omnibox_field_trial.h" |
| 30 | #include "components/omnibox/browser/omnibox_pref_names.h" |
| 31 | #include "components/omnibox/browser/search_provider.h" |
sdefresne | 70948d6 | 2015-08-11 10:46:35 | [diff] [blame] | 32 | #include "components/omnibox/browser/verbatim_match.h" |
[email protected] | f0c8c499 | 2014-05-15 17:37:26 | [diff] [blame] | 33 | #include "components/pref_registry/pref_registry_syncable.h" |
brettw | f00b9b4 | 2016-02-01 22:11:38 | [diff] [blame] | 34 | #include "components/prefs/pref_service.h" |
[email protected] | bf5c532d | 2014-07-05 00:29:53 | [diff] [blame] | 35 | #include "components/search_engines/template_url_service.h" |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 36 | #include "components/url_formatter/url_formatter.h" |
asvitkine | 9a27983 | 2015-12-18 02:35:50 | [diff] [blame] | 37 | #include "components/variations/net/variations_http_headers.h" |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 38 | #include "net/base/escape.h" |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 39 | #include "net/url_request/url_fetcher.h" |
| 40 | #include "net/url_request/url_request_status.h" |
Steven Holte | f9d5ed6 | 2017-10-21 02:02:30 | [diff] [blame] | 41 | #include "third_party/metrics_proto/omnibox_event.pb.h" |
| 42 | #include "third_party/metrics_proto/omnibox_input_type.pb.h" |
[email protected] | 761fa470 | 2013-07-02 15:25:15 | [diff] [blame] | 43 | #include "url/gurl.h" |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 44 | |
| 45 | namespace { |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 46 | |
mpearson | 3d89cdc | 2017-03-03 21:15:45 | [diff] [blame] | 47 | // Represents whether ZeroSuggestProvider is allowed to display contextual |
| 48 | // suggestions on focus, and if not, why not. |
| 49 | // These values are written to logs. New enum values can be added, but existing |
| 50 | // enums must never be renumbered or deleted and reused. |
| 51 | enum class ZeroSuggestEligibility { |
| 52 | ELIGIBLE = 0, |
| 53 | // URL_INELIGIBLE would be ELIGIBLE except some property of the current URL |
| 54 | // itself prevents ZeroSuggest from triggering. |
| 55 | URL_INELIGIBLE = 1, |
| 56 | GENERALLY_INELIGIBLE = 2, |
| 57 | ELIGIBLE_MAX_VALUE |
| 58 | }; |
| 59 | |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 60 | // TODO(hfung): The histogram code was copied and modified from |
| 61 | // search_provider.cc. Refactor and consolidate the code. |
| 62 | // We keep track in a histogram how many suggest requests we send, how |
| 63 | // many suggest requests we invalidate (e.g., due to a user typing |
| 64 | // another character), and how many replies we receive. |
mpearson | 3d89cdc | 2017-03-03 21:15:45 | [diff] [blame] | 65 | // These values are written to logs. New enum values can be added, but existing |
| 66 | // enums must never be renumbered or deleted and reused. |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 67 | enum ZeroSuggestRequestsHistogramValue { |
| 68 | ZERO_SUGGEST_REQUEST_SENT = 1, |
mpearson | 3d89cdc | 2017-03-03 21:15:45 | [diff] [blame] | 69 | ZERO_SUGGEST_REQUEST_INVALIDATED = 2, |
| 70 | ZERO_SUGGEST_REPLY_RECEIVED = 3, |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 71 | ZERO_SUGGEST_MAX_REQUEST_HISTOGRAM_VALUE |
| 72 | }; |
| 73 | |
| 74 | void LogOmniboxZeroSuggestRequest( |
| 75 | ZeroSuggestRequestsHistogramValue request_value) { |
| 76 | UMA_HISTOGRAM_ENUMERATION("Omnibox.ZeroSuggestRequests", request_value, |
| 77 | ZERO_SUGGEST_MAX_REQUEST_HISTOGRAM_VALUE); |
| 78 | } |
| 79 | |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 80 | // Relevance value to use if it was not set explicitly by the server. |
| 81 | const int kDefaultZeroSuggestRelevance = 100; |
| 82 | |
mpearson | 3d89cdc | 2017-03-03 21:15:45 | [diff] [blame] | 83 | // Used for testing whether zero suggest is ever available. |
mpearson | c90c24b | 2017-03-04 00:11:26 | [diff] [blame] | 84 | constexpr char kArbitraryInsecureUrlString[] = "http://www.google.com/"; |
mpearson | 3d89cdc | 2017-03-03 21:15:45 | [diff] [blame] | 85 | |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 86 | } // namespace |
| 87 | |
[email protected] | a00008d4 | 2012-09-15 05:07:58 | [diff] [blame] | 88 | // static |
| 89 | ZeroSuggestProvider* ZeroSuggestProvider::Create( |
blundell | 55e35e8 | 2015-06-16 08:46:18 | [diff] [blame] | 90 | AutocompleteProviderClient* client, |
mpearson | 931028c | 2016-07-01 18:55:11 | [diff] [blame] | 91 | HistoryURLProvider* history_url_provider, |
blundell | d130d59 | 2015-06-21 19:29:13 | [diff] [blame] | 92 | AutocompleteProviderListener* listener) { |
mpearson | 931028c | 2016-07-01 18:55:11 | [diff] [blame] | 93 | return new ZeroSuggestProvider(client, history_url_provider, listener); |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 94 | } |
| 95 | |
[email protected] | 855ebff | 2014-05-09 07:14:38 | [diff] [blame] | 96 | // static |
| 97 | void ZeroSuggestProvider::RegisterProfilePrefs( |
| 98 | user_prefs::PrefRegistrySyncable* registry) { |
blundell | d130d59 | 2015-06-21 19:29:13 | [diff] [blame] | 99 | registry->RegisterStringPref(omnibox::kZeroSuggestCachedResults, |
| 100 | std::string()); |
[email protected] | 855ebff | 2014-05-09 07:14:38 | [diff] [blame] | 101 | } |
| 102 | |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 103 | void ZeroSuggestProvider::Start(const AutocompleteInput& input, |
jif | cf322cd | 2015-06-17 11:01:18 | [diff] [blame] | 104 | bool minimal_changes) { |
a-v-y | dd768d5 | 2016-03-25 21:07:46 | [diff] [blame] | 105 | TRACE_EVENT0("omnibox", "ZeroSuggestProvider::Start"); |
[email protected] | f030c4d | 2014-03-25 01:05:54 | [diff] [blame] | 106 | matches_.clear(); |
mpearson | 6eaf7fc | 2017-04-11 04:09:57 | [diff] [blame] | 107 | if (!input.from_omnibox_focus() || client()->IsOffTheRecord() || |
mariakhomenko | 3ef531d7 | 2015-01-10 00:03:43 | [diff] [blame] | 108 | input.type() == metrics::OmniboxInputType::INVALID) |
[email protected] | f030c4d | 2014-03-25 01:05:54 | [diff] [blame] | 109 | return; |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 110 | |
mpearson | 8a37c38 | 2015-03-07 05:58:57 | [diff] [blame] | 111 | Stop(true, false); |
blundell | d130d59 | 2015-06-21 19:29:13 | [diff] [blame] | 112 | set_field_trial_triggered(false); |
| 113 | set_field_trial_triggered_in_session(false); |
[email protected] | 855ebff | 2014-05-09 07:14:38 | [diff] [blame] | 114 | results_from_cache_ = false; |
[email protected] | f030c4d | 2014-03-25 01:05:54 | [diff] [blame] | 115 | permanent_text_ = input.text(); |
| 116 | current_query_ = input.current_url().spec(); |
gcomanici | 8cabc77f | 2017-04-27 20:04:54 | [diff] [blame] | 117 | current_title_ = input.current_title(); |
[email protected] | f030c4d | 2014-03-25 01:05:54 | [diff] [blame] | 118 | current_page_classification_ = input.current_page_classification(); |
[email protected] | 9b9fa67 | 2013-11-07 06:04:52 | [diff] [blame] | 119 | current_url_match_ = MatchForCurrentURL(); |
| 120 | |
Daniel Kenji Toyama | f1e4b57 | 2017-08-03 16:31:11 | [diff] [blame] | 121 | GURL suggest_url = ContextualSuggestionsService::ContextualSuggestionsUrl( |
| 122 | /*current_url=*/"", client()->GetTemplateURLService()); |
[email protected] | 162c8d9fa | 2014-03-18 20:25:41 | [diff] [blame] | 123 | if (!suggest_url.is_valid()) |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 124 | return; |
[email protected] | 162c8d9fa | 2014-03-18 20:25:41 | [diff] [blame] | 125 | |
mariakhomenko | bfc3a2a | 2014-10-24 00:48:22 | [diff] [blame] | 126 | // No need to send the current page URL in personalized suggest or |
| 127 | // most visited field trials. |
mpearson | 3d89cdc | 2017-03-03 21:15:45 | [diff] [blame] | 128 | const TemplateURLService* template_url_service = |
| 129 | client()->GetTemplateURLService(); |
| 130 | const TemplateURL* default_provider = |
| 131 | template_url_service->GetDefaultSearchProvider(); |
| 132 | const bool can_send_current_url = |
| 133 | CanSendURL(input.current_url(), suggest_url, default_provider, |
[email protected] | e6477f1 | 2014-08-05 07:59:54 | [diff] [blame] | 134 | current_page_classification_, |
mpearson | 3d89cdc | 2017-03-03 21:15:45 | [diff] [blame] | 135 | template_url_service->search_terms_data(), client()); |
| 136 | GURL arbitrary_insecure_url(kArbitraryInsecureUrlString); |
| 137 | ZeroSuggestEligibility eligibility = ZeroSuggestEligibility::ELIGIBLE; |
| 138 | if (!can_send_current_url) { |
| 139 | const bool can_send_ordinary_url = |
| 140 | CanSendURL(arbitrary_insecure_url, suggest_url, default_provider, |
| 141 | current_page_classification_, |
| 142 | template_url_service->search_terms_data(), client()); |
| 143 | eligibility = can_send_ordinary_url |
| 144 | ? ZeroSuggestEligibility::URL_INELIGIBLE |
| 145 | : ZeroSuggestEligibility::GENERALLY_INELIGIBLE; |
| 146 | } |
| 147 | UMA_HISTOGRAM_ENUMERATION( |
| 148 | "Omnibox.ZeroSuggest.Eligible.OnFocus", static_cast<int>(eligibility), |
| 149 | static_cast<int>(ZeroSuggestEligibility::ELIGIBLE_MAX_VALUE)); |
Daniel Kenji Toyama | f1e4b57 | 2017-08-03 16:31:11 | [diff] [blame] | 150 | |
| 151 | bool can_attach_current_url = |
| 152 | can_send_current_url && |
Theresa Wellington | dd71c5c | 2017-10-02 15:50:38 | [diff] [blame] | 153 | !OmniboxFieldTrial::InZeroSuggestPersonalizedFieldTrial( |
| 154 | client()->GetPrefs()) && |
| 155 | !OmniboxFieldTrial::InZeroSuggestMostVisitedFieldTrial( |
| 156 | client()->GetPrefs()); |
Daniel Kenji Toyama | f1e4b57 | 2017-08-03 16:31:11 | [diff] [blame] | 157 | |
| 158 | if (!can_attach_current_url && |
| 159 | !ShouldShowNonContextualZeroSuggest(input.current_url())) { |
[email protected] | 162c8d9fa | 2014-03-18 20:25:41 | [diff] [blame] | 160 | return; |
| 161 | } |
| 162 | |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 163 | done_ = false; |
Daniel Kenji Toyama | f1e4b57 | 2017-08-03 16:31:11 | [diff] [blame] | 164 | |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 165 | // TODO(jered): Consider adding locally-sourced zero-suggestions here too. |
| 166 | // These may be useful on the NTP or more relevant to the user than server |
| 167 | // suggestions, if based on local browsing history. |
[email protected] | 855ebff | 2014-05-09 07:14:38 | [diff] [blame] | 168 | MaybeUseCachedSuggestions(); |
Daniel Kenji Toyama | f1e4b57 | 2017-08-03 16:31:11 | [diff] [blame] | 169 | |
Theresa Wellington | dd71c5c | 2017-10-02 15:50:38 | [diff] [blame] | 170 | if (OmniboxFieldTrial::InZeroSuggestMostVisitedFieldTrial( |
| 171 | client()->GetPrefs())) { |
Daniel Kenji Toyama | f1e4b57 | 2017-08-03 16:31:11 | [diff] [blame] | 172 | most_visited_urls_.clear(); |
| 173 | scoped_refptr<history::TopSites> ts = client()->GetTopSites(); |
| 174 | if (ts) { |
| 175 | waiting_for_most_visited_urls_request_ = true; |
| 176 | ts->GetMostVisitedURLs( |
| 177 | base::Bind(&ZeroSuggestProvider::OnMostVisitedUrlsAvailable, |
| 178 | weak_ptr_factory_.GetWeakPtr()), |
| 179 | false); |
| 180 | } |
| 181 | return; |
| 182 | } |
| 183 | |
| 184 | // Create a request for suggestions with |this| as the fetcher delegate. |
| 185 | client() |
Gheorghe Comanici | 86bbdf6 | 2017-08-28 17:20:33 | [diff] [blame] | 186 | ->GetContextualSuggestionsService(/*create_if_necessary=*/true) |
Daniel Kenji Toyama | f1e4b57 | 2017-08-03 16:31:11 | [diff] [blame] | 187 | ->CreateContextualSuggestionsRequest( |
| 188 | can_attach_current_url ? current_query_ : std::string(), |
| 189 | client()->GetTemplateURLService(), |
| 190 | /*fetcher_delegate=*/this, |
| 191 | base::BindOnce( |
| 192 | &ZeroSuggestProvider::OnContextualSuggestionsFetcherAvailable, |
| 193 | weak_ptr_factory_.GetWeakPtr())); |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 194 | } |
| 195 | |
mpearson | 8a37c38 | 2015-03-07 05:58:57 | [diff] [blame] | 196 | void ZeroSuggestProvider::Stop(bool clear_cached_results, |
| 197 | bool due_to_user_inactivity) { |
[email protected] | ec3f679b | 2014-08-18 07:45:13 | [diff] [blame] | 198 | if (fetcher_) |
| 199 | LogOmniboxZeroSuggestRequest(ZERO_SUGGEST_REQUEST_INVALIDATED); |
| 200 | fetcher_.reset(); |
mariakhomenko | bfc3a2a | 2014-10-24 00:48:22 | [diff] [blame] | 201 | waiting_for_most_visited_urls_request_ = false; |
Gheorghe Comanici | 86bbdf6 | 2017-08-28 17:20:33 | [diff] [blame] | 202 | auto* contextual_suggestions_service = |
| 203 | client()->GetContextualSuggestionsService(/*create_if_necessary=*/false); |
| 204 | // contextual_suggestions_service can be null if in incognito mode. |
| 205 | if (contextual_suggestions_service != nullptr) { |
| 206 | contextual_suggestions_service->StopCreatingContextualSuggestionsRequest(); |
| 207 | } |
[email protected] | ec3f679b | 2014-08-18 07:45:13 | [diff] [blame] | 208 | done_ = true; |
| 209 | |
| 210 | if (clear_cached_results) { |
| 211 | // We do not call Clear() on |results_| to retain |verbatim_relevance| |
| 212 | // value in the |results_| object. |verbatim_relevance| is used at the |
jif | cf322cd | 2015-06-17 11:01:18 | [diff] [blame] | 213 | // beginning of the next call to Start() to determine the current url |
| 214 | // match relevance. |
[email protected] | ec3f679b | 2014-08-18 07:45:13 | [diff] [blame] | 215 | results_.suggest_results.clear(); |
| 216 | results_.navigation_results.clear(); |
| 217 | current_query_.clear(); |
gcomanici | 8cabc77f | 2017-04-27 20:04:54 | [diff] [blame] | 218 | current_title_.clear(); |
mariakhomenko | 1535e6a | 2015-03-20 07:48:45 | [diff] [blame] | 219 | most_visited_urls_.clear(); |
[email protected] | ec3f679b | 2014-08-18 07:45:13 | [diff] [blame] | 220 | } |
| 221 | } |
| 222 | |
[email protected] | 855ebff | 2014-05-09 07:14:38 | [diff] [blame] | 223 | void ZeroSuggestProvider::DeleteMatch(const AutocompleteMatch& match) { |
Theresa Wellington | dd71c5c | 2017-10-02 15:50:38 | [diff] [blame] | 224 | if (OmniboxFieldTrial::InZeroSuggestPersonalizedFieldTrial( |
| 225 | client()->GetPrefs())) { |
[email protected] | 855ebff | 2014-05-09 07:14:38 | [diff] [blame] | 226 | // Remove the deleted match from the cache, so it is not shown to the user |
| 227 | // again. Since we cannot remove just one result, blow away the cache. |
blundell | d130d59 | 2015-06-21 19:29:13 | [diff] [blame] | 228 | client()->GetPrefs()->SetString(omnibox::kZeroSuggestCachedResults, |
[email protected] | 855ebff | 2014-05-09 07:14:38 | [diff] [blame] | 229 | std::string()); |
| 230 | } |
| 231 | BaseSearchProvider::DeleteMatch(match); |
| 232 | } |
| 233 | |
[email protected] | ec3f679b | 2014-08-18 07:45:13 | [diff] [blame] | 234 | void ZeroSuggestProvider::AddProviderInfo(ProvidersInfo* provider_info) const { |
| 235 | BaseSearchProvider::AddProviderInfo(provider_info); |
mariakhomenko | 1535e6a | 2015-03-20 07:48:45 | [diff] [blame] | 236 | if (!results_.suggest_results.empty() || |
| 237 | !results_.navigation_results.empty() || |
| 238 | !most_visited_urls_.empty()) |
[email protected] | ec3f679b | 2014-08-18 07:45:13 | [diff] [blame] | 239 | provider_info->back().set_times_returned_results_in_session(1); |
| 240 | } |
| 241 | |
[email protected] | f030c4d | 2014-03-25 01:05:54 | [diff] [blame] | 242 | void ZeroSuggestProvider::ResetSession() { |
| 243 | // The user has started editing in the omnibox, so leave |
blundell | d130d59 | 2015-06-21 19:29:13 | [diff] [blame] | 244 | // |field_trial_triggered_in_session| unchanged and set |
| 245 | // |field_trial_triggered| to false since zero suggest is inactive now. |
| 246 | set_field_trial_triggered(false); |
[email protected] | f030c4d | 2014-03-25 01:05:54 | [diff] [blame] | 247 | } |
| 248 | |
mpearson | 931028c | 2016-07-01 18:55:11 | [diff] [blame] | 249 | ZeroSuggestProvider::ZeroSuggestProvider( |
| 250 | AutocompleteProviderClient* client, |
| 251 | HistoryURLProvider* history_url_provider, |
| 252 | AutocompleteProviderListener* listener) |
blundell | d130d59 | 2015-06-21 19:29:13 | [diff] [blame] | 253 | : BaseSearchProvider(AutocompleteProvider::TYPE_ZERO_SUGGEST, client), |
mpearson | 931028c | 2016-07-01 18:55:11 | [diff] [blame] | 254 | history_url_provider_(history_url_provider), |
[email protected] | 776ee590 | 2014-08-11 09:15:19 | [diff] [blame] | 255 | listener_(listener), |
[email protected] | 855ebff | 2014-05-09 07:14:38 | [diff] [blame] | 256 | results_from_cache_(false), |
mariakhomenko | bfc3a2a | 2014-10-24 00:48:22 | [diff] [blame] | 257 | waiting_for_most_visited_urls_request_(false), |
[email protected] | 8f064e5 | 2013-09-18 01:17:14 | [diff] [blame] | 258 | weak_ptr_factory_(this) { |
mpearson | 3d89cdc | 2017-03-03 21:15:45 | [diff] [blame] | 259 | // Record whether contextual zero suggest is possible for this user / profile. |
| 260 | const TemplateURLService* template_url_service = |
| 261 | client->GetTemplateURLService(); |
| 262 | // Template URL service can be null in tests. |
| 263 | if (template_url_service != nullptr) { |
Daniel Kenji Toyama | f1e4b57 | 2017-08-03 16:31:11 | [diff] [blame] | 264 | GURL suggest_url = ContextualSuggestionsService::ContextualSuggestionsUrl( |
| 265 | /*current_url=*/"", template_url_service); |
mpearson | 3d89cdc | 2017-03-03 21:15:45 | [diff] [blame] | 266 | // To check whether this is allowed, use an arbitrary insecure (http) URL |
| 267 | // as the URL we'd want suggestions for. The value of OTHER as the current |
| 268 | // page classification is to correspond with that URL. |
| 269 | UMA_HISTOGRAM_BOOLEAN( |
| 270 | "Omnibox.ZeroSuggest.Eligible.OnProfileOpen", |
| 271 | suggest_url.is_valid() && |
| 272 | CanSendURL(GURL(kArbitraryInsecureUrlString), suggest_url, |
| 273 | template_url_service->GetDefaultSearchProvider(), |
| 274 | metrics::OmniboxEventProto::OTHER, |
| 275 | template_url_service->search_terms_data(), client)); |
| 276 | } |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | ZeroSuggestProvider::~ZeroSuggestProvider() { |
| 280 | } |
| 281 | |
[email protected] | 776ee590 | 2014-08-11 09:15:19 | [diff] [blame] | 282 | const TemplateURL* ZeroSuggestProvider::GetTemplateURL(bool is_keyword) const { |
| 283 | // Zero suggest provider should not receive keyword results. |
| 284 | DCHECK(!is_keyword); |
blundell | d130d59 | 2015-06-21 19:29:13 | [diff] [blame] | 285 | return client()->GetTemplateURLService()->GetDefaultSearchProvider(); |
[email protected] | 776ee590 | 2014-08-11 09:15:19 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | const AutocompleteInput ZeroSuggestProvider::GetInput(bool is_keyword) const { |
jif | cf322cd | 2015-06-17 11:01:18 | [diff] [blame] | 289 | // The callers of this method won't look at the AutocompleteInput's |
| 290 | // |from_omnibox_focus| member, so we can set its value to false. |
Kevin Bailey | bcc319e | 2017-10-01 21:53:02 | [diff] [blame] | 291 | AutocompleteInput input(base::string16(), current_page_classification_, |
| 292 | client()->GetSchemeClassifier()); |
| 293 | input.set_current_url(GURL(current_query_)); |
| 294 | input.set_current_title(current_title_); |
| 295 | input.set_prevent_inline_autocomplete(true); |
| 296 | input.set_allow_exact_keyword_match(false); |
| 297 | return input; |
[email protected] | 776ee590 | 2014-08-11 09:15:19 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | bool ZeroSuggestProvider::ShouldAppendExtraParams( |
| 301 | const SearchSuggestionParser::SuggestResult& result) const { |
| 302 | // We always use the default provider for search, so append the params. |
| 303 | return true; |
| 304 | } |
| 305 | |
[email protected] | 776ee590 | 2014-08-11 09:15:19 | [diff] [blame] | 306 | void ZeroSuggestProvider::RecordDeletionResult(bool success) { |
| 307 | if (success) { |
| 308 | base::RecordAction( |
| 309 | base::UserMetricsAction("Omnibox.ZeroSuggestDelete.Success")); |
| 310 | } else { |
| 311 | base::RecordAction( |
| 312 | base::UserMetricsAction("Omnibox.ZeroSuggestDelete.Failure")); |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | void ZeroSuggestProvider::OnURLFetchComplete(const net::URLFetcher* source) { |
| 317 | DCHECK(!done_); |
| 318 | DCHECK_EQ(fetcher_.get(), source); |
| 319 | |
| 320 | LogOmniboxZeroSuggestRequest(ZERO_SUGGEST_REPLY_RECEIVED); |
| 321 | |
| 322 | bool results_updated = false; |
| 323 | if (source->GetStatus().is_success() && source->GetResponseCode() == 200) { |
| 324 | std::string json_data = SearchSuggestionParser::ExtractJsonData(source); |
dcheng | 259570c | 2016-04-22 00:45:57 | [diff] [blame] | 325 | std::unique_ptr<base::Value> data( |
[email protected] | 776ee590 | 2014-08-11 09:15:19 | [diff] [blame] | 326 | SearchSuggestionParser::DeserializeJsonData(json_data)); |
| 327 | if (data) { |
| 328 | if (StoreSuggestionResponse(json_data, *data)) |
| 329 | return; |
| 330 | results_updated = ParseSuggestResults( |
| 331 | *data, kDefaultZeroSuggestRelevance, false, &results_); |
| 332 | } |
| 333 | } |
| 334 | fetcher_.reset(); |
| 335 | done_ = true; |
| 336 | ConvertResultsToAutocompleteMatches(); |
| 337 | listener_->OnProviderUpdate(results_updated); |
| 338 | } |
| 339 | |
[email protected] | 855ebff | 2014-05-09 07:14:38 | [diff] [blame] | 340 | bool ZeroSuggestProvider::StoreSuggestionResponse( |
| 341 | const std::string& json_data, |
| 342 | const base::Value& parsed_data) { |
Theresa Wellington | dd71c5c | 2017-10-02 15:50:38 | [diff] [blame] | 343 | if (!OmniboxFieldTrial::InZeroSuggestPersonalizedFieldTrial( |
| 344 | client()->GetPrefs()) || |
[email protected] | 855ebff | 2014-05-09 07:14:38 | [diff] [blame] | 345 | json_data.empty()) |
| 346 | return false; |
blundell | d130d59 | 2015-06-21 19:29:13 | [diff] [blame] | 347 | client()->GetPrefs()->SetString(omnibox::kZeroSuggestCachedResults, |
| 348 | json_data); |
[email protected] | 855ebff | 2014-05-09 07:14:38 | [diff] [blame] | 349 | |
| 350 | // If we received an empty result list, we should update the display, as it |
| 351 | // may be showing cached results that should not be shown. |
Ivan Kotenkov | 75b1c3a | 2017-10-24 14:47:24 | [diff] [blame^] | 352 | const base::ListValue* root_list = nullptr; |
| 353 | const base::ListValue* results_list = nullptr; |
[email protected] | 855ebff | 2014-05-09 07:14:38 | [diff] [blame] | 354 | if (parsed_data.GetAsList(&root_list) && |
| 355 | root_list->GetList(1, &results_list) && |
| 356 | results_list->empty()) |
| 357 | return false; |
| 358 | |
| 359 | // We are finished with the request and want to bail early. |
| 360 | if (results_from_cache_) |
| 361 | done_ = true; |
| 362 | |
| 363 | return results_from_cache_; |
| 364 | } |
| 365 | |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 366 | void ZeroSuggestProvider::AddSuggestResultsToMap( |
[email protected] | 0b9575f | 2014-07-30 11:58:37 | [diff] [blame] | 367 | const SearchSuggestionParser::SuggestResults& results, |
[email protected] | 0234620 | 2014-02-05 05:18:30 | [diff] [blame] | 368 | MatchMap* map) { |
[email protected] | d4a94b9 | 2014-03-04 01:35:22 | [diff] [blame] | 369 | for (size_t i = 0; i < results.size(); ++i) |
[email protected] | 7bc5e16 | 2014-08-15 19:41:11 | [diff] [blame] | 370 | AddMatchToMap(results[i], std::string(), i, false, false, map); |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 371 | } |
| 372 | |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 373 | AutocompleteMatch ZeroSuggestProvider::NavigationToMatch( |
[email protected] | 0b9575f | 2014-07-30 11:58:37 | [diff] [blame] | 374 | const SearchSuggestionParser::NavigationResult& navigation) { |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 375 | AutocompleteMatch match(this, navigation.relevance(), false, |
[email protected] | 78981d8c | 2014-05-09 15:05:47 | [diff] [blame] | 376 | navigation.type()); |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 377 | match.destination_url = navigation.url(); |
| 378 | |
[email protected] | 23db649 | 2014-01-16 02:35:30 | [diff] [blame] | 379 | // Zero suggest results should always omit protocols and never appear bold. |
Tommy C. Li | a46e638 | 2017-08-01 23:26:27 | [diff] [blame] | 380 | auto format_types = AutocompleteMatch::GetFormatTypes(false, false, false); |
tommycli | 72014f6 | 2017-06-29 21:42:16 | [diff] [blame] | 381 | match.contents = url_formatter::FormatUrl(navigation.url(), format_types, |
| 382 | net::UnescapeRule::SPACES, nullptr, |
| 383 | nullptr, nullptr); |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 384 | match.fill_into_edit += |
blundell | d130d59 | 2015-06-21 19:29:13 | [diff] [blame] | 385 | AutocompleteInput::FormattedStringWithEquivalentMeaning( |
Tommy C. Li | 0beb815 | 2017-08-25 18:30:26 | [diff] [blame] | 386 | navigation.url(), url_formatter::FormatUrl(navigation.url()), |
| 387 | client()->GetSchemeClassifier()); |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 388 | |
[email protected] | b959d7d4 | 2013-12-13 17:26:37 | [diff] [blame] | 389 | AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 390 | match.contents.length(), ACMatchClassification::URL, |
| 391 | &match.contents_class); |
[email protected] | 9c97f89c | 2013-06-25 03:12:16 | [diff] [blame] | 392 | |
| 393 | match.description = |
| 394 | AutocompleteMatch::SanitizeString(navigation.description()); |
[email protected] | b959d7d4 | 2013-12-13 17:26:37 | [diff] [blame] | 395 | AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, |
[email protected] | 9c97f89c | 2013-06-25 03:12:16 | [diff] [blame] | 396 | match.description.length(), ACMatchClassification::NONE, |
| 397 | &match.description_class); |
gcomanici | 67d53ac | 2017-04-01 17:07:19 | [diff] [blame] | 398 | match.subtype_identifier = navigation.subtype_identifier(); |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 399 | return match; |
| 400 | } |
| 401 | |
[email protected] | 8f064e5 | 2013-09-18 01:17:14 | [diff] [blame] | 402 | void ZeroSuggestProvider::OnMostVisitedUrlsAvailable( |
| 403 | const history::MostVisitedURLList& urls) { |
mariakhomenko | bfc3a2a | 2014-10-24 00:48:22 | [diff] [blame] | 404 | if (!waiting_for_most_visited_urls_request_) return; |
[email protected] | 8f064e5 | 2013-09-18 01:17:14 | [diff] [blame] | 405 | most_visited_urls_ = urls; |
mariakhomenko | bfc3a2a | 2014-10-24 00:48:22 | [diff] [blame] | 406 | waiting_for_most_visited_urls_request_ = false; |
| 407 | done_ = true; |
| 408 | ConvertResultsToAutocompleteMatches(); |
| 409 | listener_->OnProviderUpdate(true); |
[email protected] | 8f064e5 | 2013-09-18 01:17:14 | [diff] [blame] | 410 | } |
| 411 | |
Daniel Kenji Toyama | f1e4b57 | 2017-08-03 16:31:11 | [diff] [blame] | 412 | void ZeroSuggestProvider::OnContextualSuggestionsFetcherAvailable( |
| 413 | std::unique_ptr<net::URLFetcher> fetcher) { |
| 414 | fetcher_ = std::move(fetcher); |
| 415 | fetcher_->Start(); |
| 416 | LogOmniboxZeroSuggestRequest(ZERO_SUGGEST_REQUEST_SENT); |
| 417 | } |
| 418 | |
[email protected] | 9c97f89c | 2013-06-25 03:12:16 | [diff] [blame] | 419 | void ZeroSuggestProvider::ConvertResultsToAutocompleteMatches() { |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 420 | matches_.clear(); |
| 421 | |
blundell | d130d59 | 2015-06-21 19:29:13 | [diff] [blame] | 422 | TemplateURLService* template_url_service = client()->GetTemplateURLService(); |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 423 | const TemplateURL* default_provider = |
blundell | d130d59 | 2015-06-21 19:29:13 | [diff] [blame] | 424 | template_url_service->GetDefaultSearchProvider(); |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 425 | // Fail if we can't set the clickthrough URL for query suggestions. |
Ivan Kotenkov | 75b1c3a | 2017-10-24 14:47:24 | [diff] [blame^] | 426 | if (default_provider == nullptr || |
blundell | d130d59 | 2015-06-21 19:29:13 | [diff] [blame] | 427 | !default_provider->SupportsReplacement( |
| 428 | template_url_service->search_terms_data())) |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 429 | return; |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 430 | |
[email protected] | 0040474 | 2014-02-20 13:09:05 | [diff] [blame] | 431 | MatchMap map; |
| 432 | AddSuggestResultsToMap(results_.suggest_results, &map); |
| 433 | |
| 434 | const int num_query_results = map.size(); |
| 435 | const int num_nav_results = results_.navigation_results.size(); |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 436 | const int num_results = num_query_results + num_nav_results; |
[email protected] | 9c97f89c | 2013-06-25 03:12:16 | [diff] [blame] | 437 | UMA_HISTOGRAM_COUNTS("ZeroSuggest.QueryResults", num_query_results); |
[email protected] | 78981d8c | 2014-05-09 15:05:47 | [diff] [blame] | 438 | UMA_HISTOGRAM_COUNTS("ZeroSuggest.URLResults", num_nav_results); |
[email protected] | 9c97f89c | 2013-06-25 03:12:16 | [diff] [blame] | 439 | UMA_HISTOGRAM_COUNTS("ZeroSuggest.AllResults", num_results); |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 440 | |
[email protected] | 8f064e5 | 2013-09-18 01:17:14 | [diff] [blame] | 441 | // Show Most Visited results after ZeroSuggest response is received. |
Theresa Wellington | dd71c5c | 2017-10-02 15:50:38 | [diff] [blame] | 442 | if (OmniboxFieldTrial::InZeroSuggestMostVisitedFieldTrial( |
| 443 | client()->GetPrefs())) { |
[email protected] | 3feb8b00 | 2013-10-14 23:50:13 | [diff] [blame] | 444 | if (!current_url_match_.destination_url.is_valid()) |
| 445 | return; |
[email protected] | 8f064e5 | 2013-09-18 01:17:14 | [diff] [blame] | 446 | matches_.push_back(current_url_match_); |
| 447 | int relevance = 600; |
| 448 | if (num_results > 0) { |
| 449 | UMA_HISTOGRAM_COUNTS( |
| 450 | "Omnibox.ZeroSuggest.MostVisitedResultsCounterfactual", |
| 451 | most_visited_urls_.size()); |
| 452 | } |
[email protected] | 23db649 | 2014-01-16 02:35:30 | [diff] [blame] | 453 | const base::string16 current_query_string16( |
| 454 | base::ASCIIToUTF16(current_query_)); |
[email protected] | 8f064e5 | 2013-09-18 01:17:14 | [diff] [blame] | 455 | for (size_t i = 0; i < most_visited_urls_.size(); i++) { |
| 456 | const history::MostVisitedURL& url = most_visited_urls_[i]; |
[email protected] | 0b9575f | 2014-07-30 11:58:37 | [diff] [blame] | 457 | SearchSuggestionParser::NavigationResult nav( |
blundell | d130d59 | 2015-06-21 19:29:13 | [diff] [blame] | 458 | client()->GetSchemeClassifier(), url.url, |
gcomanici | 67d53ac | 2017-04-01 17:07:19 | [diff] [blame] | 459 | AutocompleteMatchType::NAVSUGGEST, 0, url.title, std::string(), false, |
jshin | 1fb7646 | 2016-04-05 22:13:03 | [diff] [blame] | 460 | relevance, true, current_query_string16); |
[email protected] | 8f064e5 | 2013-09-18 01:17:14 | [diff] [blame] | 461 | matches_.push_back(NavigationToMatch(nav)); |
| 462 | --relevance; |
| 463 | } |
| 464 | return; |
| 465 | } |
| 466 | |
[email protected] | 9c97f89c | 2013-06-25 03:12:16 | [diff] [blame] | 467 | if (num_results == 0) |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 468 | return; |
| 469 | |
| 470 | // TODO(jered): Rip this out once the first match is decoupled from the |
| 471 | // current typing in the omnibox. |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 472 | matches_.push_back(current_url_match_); |
| 473 | |
[email protected] | 0040474 | 2014-02-20 13:09:05 | [diff] [blame] | 474 | for (MatchMap::const_iterator it(map.begin()); it != map.end(); ++it) |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 475 | matches_.push_back(it->second); |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 476 | |
[email protected] | 0b9575f | 2014-07-30 11:58:37 | [diff] [blame] | 477 | const SearchSuggestionParser::NavigationResults& nav_results( |
| 478 | results_.navigation_results); |
| 479 | for (SearchSuggestionParser::NavigationResults::const_iterator it( |
gcomanici | 67d53ac | 2017-04-01 17:07:19 | [diff] [blame] | 480 | nav_results.begin()); |
| 481 | it != nav_results.end(); ++it) { |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 482 | matches_.push_back(NavigationToMatch(*it)); |
gcomanici | 67d53ac | 2017-04-01 17:07:19 | [diff] [blame] | 483 | } |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 484 | } |
| 485 | |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 486 | AutocompleteMatch ZeroSuggestProvider::MatchForCurrentURL() { |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 487 | // The placeholder suggestion for the current URL has high relevance so |
| 488 | // that it is in the first suggestion slot and inline autocompleted. It |
| 489 | // gets dropped as soon as the user types something. |
mpearson | 931028c | 2016-07-01 18:55:11 | [diff] [blame] | 490 | AutocompleteInput tmp(GetInput(false)); |
| 491 | tmp.UpdateText(permanent_text_, base::string16::npos, tmp.parts()); |
gcomanici | 8cabc77f | 2017-04-27 20:04:54 | [diff] [blame] | 492 | const base::string16 description = |
| 493 | (base::FeatureList::IsEnabled(omnibox::kDisplayTitleForCurrentUrl)) |
| 494 | ? current_title_ |
| 495 | : base::string16(); |
| 496 | return VerbatimMatchForURL(client(), tmp, GURL(current_query_), description, |
mpearson | 931028c | 2016-07-01 18:55:11 | [diff] [blame] | 497 | history_url_provider_, |
sdefresne | 70948d6 | 2015-08-11 10:46:35 | [diff] [blame] | 498 | results_.verbatim_relevance); |
[email protected] | 0040474 | 2014-02-20 13:09:05 | [diff] [blame] | 499 | } |
[email protected] | 162c8d9fa | 2014-03-18 20:25:41 | [diff] [blame] | 500 | |
mariakhomenko | bfc3a2a | 2014-10-24 00:48:22 | [diff] [blame] | 501 | bool ZeroSuggestProvider::ShouldShowNonContextualZeroSuggest( |
[email protected] | 162c8d9fa | 2014-03-18 20:25:41 | [diff] [blame] | 502 | const GURL& current_page_url) const { |
gcomanici | de29a436 | 2017-06-02 15:44:08 | [diff] [blame] | 503 | if (!ZeroSuggestEnabled(current_page_classification_, client())) |
[email protected] | 162c8d9fa | 2014-03-18 20:25:41 | [diff] [blame] | 504 | return false; |
| 505 | |
| 506 | // If we cannot send URLs, then only the MostVisited and Personalized |
| 507 | // variations can be shown. |
Theresa Wellington | dd71c5c | 2017-10-02 15:50:38 | [diff] [blame] | 508 | // The const-cast allows the non-const AutocompleteProviderClient::GetPrefs() |
| 509 | // function to be called. OmniboxFieldTrial does not modify prefs, so the |
| 510 | // cast is safe in this application. |
| 511 | if (!OmniboxFieldTrial::InZeroSuggestMostVisitedFieldTrial( |
| 512 | const_cast<AutocompleteProviderClient*>(client())->GetPrefs()) && |
| 513 | !OmniboxFieldTrial::InZeroSuggestPersonalizedFieldTrial( |
| 514 | const_cast<AutocompleteProviderClient*>(client())->GetPrefs())) |
[email protected] | 162c8d9fa | 2014-03-18 20:25:41 | [diff] [blame] | 515 | return false; |
| 516 | |
| 517 | // Only show zero suggest for HTTP[S] pages. |
| 518 | // TODO(mariakhomenko): We may be able to expand this set to include pages |
| 519 | // with other schemes (e.g. chrome://). That may require improvements to |
| 520 | // the formatting of the verbatim result returned by MatchForCurrentURL(). |
| 521 | if (!current_page_url.is_valid() || |
[email protected] | e8ca69c | 2014-05-07 15:31:19 | [diff] [blame] | 522 | ((current_page_url.scheme() != url::kHttpScheme) && |
| 523 | (current_page_url.scheme() != url::kHttpsScheme))) |
[email protected] | 162c8d9fa | 2014-03-18 20:25:41 | [diff] [blame] | 524 | return false; |
| 525 | |
Theresa Wellington | dd71c5c | 2017-10-02 15:50:38 | [diff] [blame] | 526 | if (OmniboxFieldTrial::InZeroSuggestMostVisitedWithoutSerpFieldTrial( |
| 527 | const_cast<AutocompleteProviderClient*>(client())->GetPrefs()) && |
blundell | d130d59 | 2015-06-21 19:29:13 | [diff] [blame] | 528 | client() |
| 529 | ->GetTemplateURLService() |
| 530 | ->IsSearchResultsPageFromDefaultSearchProvider(current_page_url)) |
mariakhomenko | bfc3a2a | 2014-10-24 00:48:22 | [diff] [blame] | 531 | return false; |
| 532 | |
[email protected] | 162c8d9fa | 2014-03-18 20:25:41 | [diff] [blame] | 533 | return true; |
| 534 | } |
[email protected] | 855ebff | 2014-05-09 07:14:38 | [diff] [blame] | 535 | |
| 536 | void ZeroSuggestProvider::MaybeUseCachedSuggestions() { |
Theresa Wellington | dd71c5c | 2017-10-02 15:50:38 | [diff] [blame] | 537 | if (!OmniboxFieldTrial::InZeroSuggestPersonalizedFieldTrial( |
| 538 | client()->GetPrefs())) |
[email protected] | 855ebff | 2014-05-09 07:14:38 | [diff] [blame] | 539 | return; |
| 540 | |
blundell | d130d59 | 2015-06-21 19:29:13 | [diff] [blame] | 541 | std::string json_data = |
| 542 | client()->GetPrefs()->GetString(omnibox::kZeroSuggestCachedResults); |
[email protected] | 855ebff | 2014-05-09 07:14:38 | [diff] [blame] | 543 | if (!json_data.empty()) { |
dcheng | 259570c | 2016-04-22 00:45:57 | [diff] [blame] | 544 | std::unique_ptr<base::Value> data( |
[email protected] | 2c802d1 | 2014-07-31 12:57:14 | [diff] [blame] | 545 | SearchSuggestionParser::DeserializeJsonData(json_data)); |
[email protected] | 776ee590 | 2014-08-11 09:15:19 | [diff] [blame] | 546 | if (data && ParseSuggestResults( |
| 547 | *data, kDefaultZeroSuggestRelevance, false, &results_)) { |
[email protected] | 855ebff | 2014-05-09 07:14:38 | [diff] [blame] | 548 | ConvertResultsToAutocompleteMatches(); |
| 549 | results_from_cache_ = !matches_.empty(); |
| 550 | } |
| 551 | } |
| 552 | } |