[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 | |
Kevin Bailey | 1e2a90e | 2017-10-27 21:02:05 | [diff] [blame] | 9 | #include <string> |
| 10 | #include <utility> |
| 11 | |
Sebastien Marchand | 53801a3 | 2019-01-25 16:26:11 | [diff] [blame] | 12 | #include "base/bind.h" |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 13 | #include "base/callback.h" |
gcomanici | 8cabc77f | 2017-04-27 20:04:54 | [diff] [blame] | 14 | #include "base/feature_list.h" |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 15 | #include "base/i18n/case_conversion.h" |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 16 | #include "base/json/json_string_value_serializer.h" |
asvitkine | 3033081 | 2016-08-30 04:01:08 | [diff] [blame] | 17 | #include "base/metrics/histogram_macros.h" |
[email protected] | f7f41c0e | 2014-08-11 04:22:23 | [diff] [blame] | 18 | #include "base/metrics/user_metrics.h" |
Moe Ahmadi | 0993aec | 2019-09-19 21:42:30 | [diff] [blame] | 19 | #include "base/stl_util.h" |
[email protected] | 98570e1 | 2013-06-10 19:54:22 | [diff] [blame] | 20 | #include "base/strings/string16.h" |
| 21 | #include "base/strings/string_util.h" |
[email protected] | 135cb80 | 2013-06-09 16:44:20 | [diff] [blame] | 22 | #include "base/strings/utf_string_conversions.h" |
[email protected] | 4dcb797 | 2013-06-28 15:15:41 | [diff] [blame] | 23 | #include "base/time/time.h" |
a-v-y | dd768d5 | 2016-03-25 21:07:46 | [diff] [blame] | 24 | #include "base/trace_event/trace_event.h" |
Tommy C. Li | 0af0956 | 2019-06-11 23:58:51 | [diff] [blame] | 25 | #include "build/build_config.h" |
sdefresne | bc766ef | 2014-09-25 09:28:13 | [diff] [blame] | 26 | #include "components/history/core/browser/history_types.h" |
sdefresne | 0da3bc0 | 2015-01-29 18:26:35 | [diff] [blame] | 27 | #include "components/history/core/browser/top_sites.h" |
blundell | 2102f7c | 2015-07-09 10:00:53 | [diff] [blame] | 28 | #include "components/omnibox/browser/autocomplete_classifier.h" |
| 29 | #include "components/omnibox/browser/autocomplete_input.h" |
| 30 | #include "components/omnibox/browser/autocomplete_match.h" |
manuk | 3972b2f | 2019-04-19 14:22:56 | [diff] [blame] | 31 | #include "components/omnibox/browser/autocomplete_match_classification.h" |
Tommy Li | ec99def | 2019-10-14 22:37:23 | [diff] [blame] | 32 | #include "components/omnibox/browser/autocomplete_provider_client.h" |
blundell | 2102f7c | 2015-07-09 10:00:53 | [diff] [blame] | 33 | #include "components/omnibox/browser/autocomplete_provider_listener.h" |
Tommy Li | ec99def | 2019-10-14 22:37:23 | [diff] [blame] | 34 | #include "components/omnibox/browser/omnibox_field_trial.h" |
Moe Ahmadi | 1266de8 | 2020-04-10 17:19:53 | [diff] [blame] | 35 | #include "components/omnibox/browser/omnibox_prefs.h" |
Tommy C. Li | 06ec26a | 2019-06-10 18:01:42 | [diff] [blame] | 36 | #include "components/omnibox/browser/remote_suggestions_service.h" |
blundell | 2102f7c | 2015-07-09 10:00:53 | [diff] [blame] | 37 | #include "components/omnibox/browser/search_provider.h" |
Tommy Li | 823509e | 2019-12-06 22:42:47 | [diff] [blame] | 38 | #include "components/omnibox/browser/search_suggestion_parser.h" |
sdefresne | 70948d6 | 2015-08-11 10:46:35 | [diff] [blame] | 39 | #include "components/omnibox/browser/verbatim_match.h" |
Tomasz Wiszkowski | d938a111 | 2019-03-06 18:01:57 | [diff] [blame] | 40 | #include "components/omnibox/common/omnibox_features.h" |
[email protected] | f0c8c499 | 2014-05-15 17:37:26 | [diff] [blame] | 41 | #include "components/pref_registry/pref_registry_syncable.h" |
brettw | f00b9b4 | 2016-02-01 22:11:38 | [diff] [blame] | 42 | #include "components/prefs/pref_service.h" |
Tommy C. Li | 17b5ba11 | 2020-08-11 02:29:21 | [diff] [blame] | 43 | #include "components/search_engines/omnibox_focus_type.h" |
Gheorghe Comanici | 864725b | 2017-11-28 21:48:01 | [diff] [blame] | 44 | #include "components/search_engines/search_engine_type.h" |
[email protected] | bf5c532d | 2014-07-05 00:29:53 | [diff] [blame] | 45 | #include "components/search_engines/template_url_service.h" |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 46 | #include "components/url_formatter/url_formatter.h" |
asvitkine | 9a27983 | 2015-12-18 02:35:50 | [diff] [blame] | 47 | #include "components/variations/net/variations_http_headers.h" |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 48 | #include "net/base/escape.h" |
Maks Orlovich | 1b20851 | 2018-06-13 21:08:17 | [diff] [blame] | 49 | #include "services/network/public/cpp/shared_url_loader_factory.h" |
| 50 | #include "services/network/public/cpp/simple_url_loader.h" |
Steven Holte | f9d5ed6 | 2017-10-21 02:02:30 | [diff] [blame] | 51 | #include "third_party/metrics_proto/omnibox_event.pb.h" |
| 52 | #include "third_party/metrics_proto/omnibox_input_type.pb.h" |
[email protected] | 761fa470 | 2013-07-02 15:25:15 | [diff] [blame] | 53 | #include "url/gurl.h" |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 54 | |
Tommy C. Li | 0af0956 | 2019-06-11 23:58:51 | [diff] [blame] | 55 | using metrics::OmniboxEventProto; |
| 56 | |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 57 | namespace { |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 58 | |
mpearson | 3d89cdc | 2017-03-03 21:15:45 | [diff] [blame] | 59 | // Represents whether ZeroSuggestProvider is allowed to display contextual |
| 60 | // suggestions on focus, and if not, why not. |
| 61 | // These values are written to logs. New enum values can be added, but existing |
| 62 | // enums must never be renumbered or deleted and reused. |
| 63 | enum class ZeroSuggestEligibility { |
| 64 | ELIGIBLE = 0, |
| 65 | // URL_INELIGIBLE would be ELIGIBLE except some property of the current URL |
| 66 | // itself prevents ZeroSuggest from triggering. |
| 67 | URL_INELIGIBLE = 1, |
| 68 | GENERALLY_INELIGIBLE = 2, |
| 69 | ELIGIBLE_MAX_VALUE |
| 70 | }; |
| 71 | |
Tomasz Wiszkowski | fd790c0 | 2019-08-29 17:31:29 | [diff] [blame] | 72 | // Histogram values describing client eligibility to receive RemoteNoURL |
| 73 | // suggestions on NTP. |
| 74 | // These values are persisted to logs. New values can be added, but existing |
| 75 | // enums must never be renumbered or deleted and reused. |
| 76 | enum class ZeroSuggestEligibilityForRemoteNoURL { |
| 77 | kEligible = 0, |
| 78 | kIneligibleUserOffTheRecord = 1, |
| 79 | kIneligibleSuggestionsDisabled = 2, |
| 80 | kIneligibleUserNotAuthenticated = 3, |
| 81 | // Used to report users ineligible for RemoteNoURL suggestions when the |
| 82 | // search and suggest server of their choice cannot be used to offer the |
| 83 | // RemoteNoURL suggestions. |
| 84 | kIneligibleWithUserSelectedServer = 4, |
| 85 | kIneligibleUserNotParticipating = 5, |
| 86 | |
| 87 | kMaxValue = kIneligibleUserNotParticipating |
| 88 | }; |
| 89 | |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 90 | // TODO(hfung): The histogram code was copied and modified from |
| 91 | // search_provider.cc. Refactor and consolidate the code. |
| 92 | // We keep track in a histogram how many suggest requests we send, how |
| 93 | // many suggest requests we invalidate (e.g., due to a user typing |
| 94 | // another character), and how many replies we receive. |
mpearson | 3d89cdc | 2017-03-03 21:15:45 | [diff] [blame] | 95 | // These values are written to logs. New enum values can be added, but existing |
| 96 | // enums must never be renumbered or deleted and reused. |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 97 | enum ZeroSuggestRequestsHistogramValue { |
| 98 | ZERO_SUGGEST_REQUEST_SENT = 1, |
mpearson | 3d89cdc | 2017-03-03 21:15:45 | [diff] [blame] | 99 | ZERO_SUGGEST_REQUEST_INVALIDATED = 2, |
| 100 | ZERO_SUGGEST_REPLY_RECEIVED = 3, |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 101 | ZERO_SUGGEST_MAX_REQUEST_HISTOGRAM_VALUE |
| 102 | }; |
| 103 | |
| 104 | void LogOmniboxZeroSuggestRequest( |
| 105 | ZeroSuggestRequestsHistogramValue request_value) { |
| 106 | UMA_HISTOGRAM_ENUMERATION("Omnibox.ZeroSuggestRequests", request_value, |
| 107 | ZERO_SUGGEST_MAX_REQUEST_HISTOGRAM_VALUE); |
| 108 | } |
| 109 | |
Tomasz Wiszkowski | fd790c0 | 2019-08-29 17:31:29 | [diff] [blame] | 110 | // Record user eligibility for RemoteNoUrl suggestions for supplied page class. |
| 111 | // The |histogram_variant| is used to specify particular variant of the |
| 112 | // Omnibox.ZeroSuggest.Eligible.RemoteNoUrl histogram that should be updated. |
| 113 | void LogOmniboxRemoteNoUrlEligibilityOnNTP( |
| 114 | OmniboxEventProto::PageClassification page_class, |
| 115 | bool log_for_profile_open, |
| 116 | AutocompleteProviderClient* client) { |
| 117 | ZeroSuggestEligibilityForRemoteNoURL value = |
| 118 | ZeroSuggestEligibilityForRemoteNoURL::kEligible; |
| 119 | |
| 120 | auto* service = client->GetTemplateURLService(); |
| 121 | auto* provider = service ? service->GetDefaultSearchProvider() : nullptr; |
| 122 | auto engine = provider ? provider->GetEngineType(service->search_terms_data()) |
| 123 | : SEARCH_ENGINE_UNKNOWN; |
Moe Ahmadi | 0993aec | 2019-09-19 21:42:30 | [diff] [blame] | 124 | const auto variants = OmniboxFieldTrial::GetZeroSuggestVariants(page_class); |
Tomasz Wiszkowski | fd790c0 | 2019-08-29 17:31:29 | [diff] [blame] | 125 | |
Moe Ahmadi | 0993aec | 2019-09-19 21:42:30 | [diff] [blame] | 126 | if (!base::Contains(variants, ZeroSuggestProvider::kRemoteNoUrlVariant)) { |
Tomasz Wiszkowski | fd790c0 | 2019-08-29 17:31:29 | [diff] [blame] | 127 | value = |
| 128 | ZeroSuggestEligibilityForRemoteNoURL::kIneligibleUserNotParticipating; |
| 129 | } else if (client->IsOffTheRecord()) { |
| 130 | value = ZeroSuggestEligibilityForRemoteNoURL::kIneligibleUserOffTheRecord; |
| 131 | } else if (!client->SearchSuggestEnabled()) { |
| 132 | value = |
| 133 | ZeroSuggestEligibilityForRemoteNoURL::kIneligibleSuggestionsDisabled; |
| 134 | } else if (!client->IsAuthenticated()) { |
| 135 | value = |
| 136 | ZeroSuggestEligibilityForRemoteNoURL::kIneligibleUserNotAuthenticated; |
| 137 | } else if (service == nullptr || provider == nullptr || |
| 138 | engine != SEARCH_ENGINE_GOOGLE) { |
| 139 | value = |
| 140 | ZeroSuggestEligibilityForRemoteNoURL::kIneligibleWithUserSelectedServer; |
| 141 | } |
| 142 | |
| 143 | if (log_for_profile_open) { |
| 144 | UMA_HISTOGRAM_ENUMERATION( |
| 145 | "Omnibox.ZeroSuggest.Eligible.RemoteNoUrl.OnNTP.OnProfileOpen", value); |
| 146 | } else { |
| 147 | UMA_HISTOGRAM_ENUMERATION( |
| 148 | "Omnibox.ZeroSuggest.Eligible.RemoteNoUrl.OnNTP.OnFocus", value); |
| 149 | } |
| 150 | } |
| 151 | |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 152 | // Relevance value to use if it was not set explicitly by the server. |
| 153 | const int kDefaultZeroSuggestRelevance = 100; |
| 154 | |
mpearson | 3d89cdc | 2017-03-03 21:15:45 | [diff] [blame] | 155 | // Used for testing whether zero suggest is ever available. |
mpearson | c90c24b | 2017-03-04 00:11:26 | [diff] [blame] | 156 | constexpr char kArbitraryInsecureUrlString[] = "http://www.google.com/"; |
mpearson | 3d89cdc | 2017-03-03 21:15:45 | [diff] [blame] | 157 | |
Tomasz Wiszkowski | 57492ab | 2019-05-29 21:28:27 | [diff] [blame] | 158 | // Metric name tracking the omnibox suggestion eligibility. |
| 159 | constexpr char kOmniboxZeroSuggestEligibleHistogramName[] = |
| 160 | "Omnibox.ZeroSuggest.Eligible.OnFocusV2"; |
| 161 | |
Moe Ahmadi | 85bf7086 | 2019-10-11 00:03:32 | [diff] [blame] | 162 | // Remote suggestions are allowed only if the user is signed-in and has Google |
| 163 | // set up as their default search engine. This only applies to |
| 164 | // kRemoteNoUrlVariant since most of these checks are done in |
| 165 | // BaseSearchProvider::CanSendURL (with the exception of the authentication |
| 166 | // state) which applies to kRemoteSendUrlVariant. |
| 167 | bool RemoteNoUrlSuggestionsAreAllowed( |
Tomasz Wiszkowski | 5abea20 | 2019-06-06 22:51:14 | [diff] [blame] | 168 | AutocompleteProviderClient* client, |
Gheorghe Comanici | 864725b | 2017-11-28 21:48:01 | [diff] [blame] | 169 | const TemplateURLService* template_url_service) { |
Tomasz Wiszkowski | 5abea20 | 2019-06-06 22:51:14 | [diff] [blame] | 170 | if (!client->SearchSuggestEnabled()) |
Moe Ahmadi | 85bf7086 | 2019-10-11 00:03:32 | [diff] [blame] | 171 | return false; |
Tomasz Wiszkowski | 5abea20 | 2019-06-06 22:51:14 | [diff] [blame] | 172 | |
| 173 | if (!client->IsAuthenticated()) |
Moe Ahmadi | 85bf7086 | 2019-10-11 00:03:32 | [diff] [blame] | 174 | return false; |
Gheorghe Comanici | 864725b | 2017-11-28 21:48:01 | [diff] [blame] | 175 | |
Gheorghe Comanici | 9a364f57 | 2018-01-24 17:22:00 | [diff] [blame] | 176 | if (template_url_service == nullptr) |
| 177 | return false; |
Gheorghe Comanici | 68250410 | 2017-11-30 17:47:25 | [diff] [blame] | 178 | |
Gheorghe Comanici | 9a364f57 | 2018-01-24 17:22:00 | [diff] [blame] | 179 | const TemplateURL* default_provider = |
| 180 | template_url_service->GetDefaultSearchProvider(); |
Moe Ahmadi | 85bf7086 | 2019-10-11 00:03:32 | [diff] [blame] | 181 | return default_provider && |
Gheorghe Comanici | 9a364f57 | 2018-01-24 17:22:00 | [diff] [blame] | 182 | default_provider->GetEngineType( |
Moe Ahmadi | 85bf7086 | 2019-10-11 00:03:32 | [diff] [blame] | 183 | template_url_service->search_terms_data()) == SEARCH_ENGINE_GOOGLE; |
Gheorghe Comanici | 864725b | 2017-11-28 21:48:01 | [diff] [blame] | 184 | } |
| 185 | |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 186 | } // namespace |
| 187 | |
[email protected] | a00008d4 | 2012-09-15 05:07:58 | [diff] [blame] | 188 | // static |
Tommy C. Li | 0af0956 | 2019-06-11 23:58:51 | [diff] [blame] | 189 | const char ZeroSuggestProvider::kNoneVariant[] = "None"; |
| 190 | const char ZeroSuggestProvider::kRemoteNoUrlVariant[] = "RemoteNoUrl"; |
| 191 | const char ZeroSuggestProvider::kRemoteSendUrlVariant[] = "RemoteSendUrl"; |
| 192 | const char ZeroSuggestProvider::kMostVisitedVariant[] = "MostVisited"; |
| 193 | |
| 194 | // static |
[email protected] | a00008d4 | 2012-09-15 05:07:58 | [diff] [blame] | 195 | ZeroSuggestProvider* ZeroSuggestProvider::Create( |
blundell | 55e35e8 | 2015-06-16 08:46:18 | [diff] [blame] | 196 | AutocompleteProviderClient* client, |
blundell | d130d59 | 2015-06-21 19:29:13 | [diff] [blame] | 197 | AutocompleteProviderListener* listener) { |
Tommy Li | ec99def | 2019-10-14 22:37:23 | [diff] [blame] | 198 | return new ZeroSuggestProvider(client, listener); |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 199 | } |
| 200 | |
[email protected] | 855ebff | 2014-05-09 07:14:38 | [diff] [blame] | 201 | // static |
Moe Ahmadi | 1266de8 | 2020-04-10 17:19:53 | [diff] [blame] | 202 | void ZeroSuggestProvider::RegisterProfilePrefs(PrefRegistrySimple* registry) { |
blundell | d130d59 | 2015-06-21 19:29:13 | [diff] [blame] | 203 | registry->RegisterStringPref(omnibox::kZeroSuggestCachedResults, |
| 204 | std::string()); |
[email protected] | 855ebff | 2014-05-09 07:14:38 | [diff] [blame] | 205 | } |
| 206 | |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 207 | void ZeroSuggestProvider::Start(const AutocompleteInput& input, |
jif | cf322cd | 2015-06-17 11:01:18 | [diff] [blame] | 208 | bool minimal_changes) { |
a-v-y | dd768d5 | 2016-03-25 21:07:46 | [diff] [blame] | 209 | TRACE_EVENT0("omnibox", "ZeroSuggestProvider::Start"); |
[email protected] | f030c4d | 2014-03-25 01:05:54 | [diff] [blame] | 210 | matches_.clear(); |
Kevin Bailey | 8642e61 | 2018-04-23 20:27:54 | [diff] [blame] | 211 | Stop(true, false); |
Jenny Zhang | 5bc2e3d | 2018-09-10 18:50:55 | [diff] [blame] | 212 | |
Tomasz Wiszkowski | fd790c0 | 2019-08-29 17:31:29 | [diff] [blame] | 213 | current_page_classification_ = input.current_page_classification(); |
| 214 | |
Tommy C. Li | 17b5ba11 | 2020-08-11 02:29:21 | [diff] [blame] | 215 | if (input.focus_type() != OmniboxFocusType::DEFAULT && |
| 216 | IsNTPPage(current_page_classification_)) { |
Tomasz Wiszkowski | fd790c0 | 2019-08-29 17:31:29 | [diff] [blame] | 217 | LogOmniboxRemoteNoUrlEligibilityOnNTP(current_page_classification_, false, |
| 218 | client()); |
| 219 | } |
| 220 | |
Tomasz Wiszkowski | 57492ab | 2019-05-29 21:28:27 | [diff] [blame] | 221 | if (!AllowZeroSuggestSuggestions(input)) { |
| 222 | UMA_HISTOGRAM_ENUMERATION(kOmniboxZeroSuggestEligibleHistogramName, |
| 223 | ZeroSuggestEligibility::GENERALLY_INELIGIBLE, |
| 224 | ZeroSuggestEligibility::ELIGIBLE_MAX_VALUE); |
[email protected] | f030c4d | 2014-03-25 01:05:54 | [diff] [blame] | 225 | return; |
Tomasz Wiszkowski | 57492ab | 2019-05-29 21:28:27 | [diff] [blame] | 226 | } |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 227 | |
Kevin Bailey | 5fea432 | 2018-03-21 22:36:05 | [diff] [blame] | 228 | result_type_running_ = NONE; |
blundell | d130d59 | 2015-06-21 19:29:13 | [diff] [blame] | 229 | set_field_trial_triggered(false); |
| 230 | set_field_trial_triggered_in_session(false); |
[email protected] | f030c4d | 2014-03-25 01:05:54 | [diff] [blame] | 231 | permanent_text_ = input.text(); |
| 232 | current_query_ = input.current_url().spec(); |
gcomanici | 8cabc77f | 2017-04-27 20:04:54 | [diff] [blame] | 233 | current_title_ = input.current_title(); |
Tommy Li | ec99def | 2019-10-14 22:37:23 | [diff] [blame] | 234 | current_text_match_ = MatchForCurrentText(); |
[email protected] | 9b9fa67 | 2013-11-07 06:04:52 | [diff] [blame] | 235 | |
Tommy C. Li | 6aee62d5 | 2019-06-27 20:25:00 | [diff] [blame] | 236 | TemplateURLRef::SearchTermsArgs search_terms_args; |
| 237 | search_terms_args.page_classification = current_page_classification_; |
Tommy Li | 5e88351 | 2020-08-07 19:32:04 | [diff] [blame] | 238 | // TODO(tommycli): Once AutocompleteInput supports tracking OmniboxFocusType, |
| 239 | // copy the value from there. |
| 240 | search_terms_args.focus_type = OmniboxFocusType::ON_FOCUS; |
Tommy C. Li | 06ec26a | 2019-06-10 18:01:42 | [diff] [blame] | 241 | GURL suggest_url = RemoteSuggestionsService::EndpointUrl( |
Tommy C. Li | 6aee62d5 | 2019-06-27 20:25:00 | [diff] [blame] | 242 | search_terms_args, client()->GetTemplateURLService()); |
[email protected] | 162c8d9fa | 2014-03-18 20:25:41 | [diff] [blame] | 243 | if (!suggest_url.is_valid()) |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 244 | return; |
[email protected] | 162c8d9fa | 2014-03-18 20:25:41 | [diff] [blame] | 245 | |
Gheorghe Comanici | 9a364f57 | 2018-01-24 17:22:00 | [diff] [blame] | 246 | result_type_running_ = TypeOfResultToRun(input.current_url(), suggest_url); |
Kevin Bailey | 5fea432 | 2018-03-21 22:36:05 | [diff] [blame] | 247 | if (result_type_running_ == NONE) |
[email protected] | 162c8d9fa | 2014-03-18 20:25:41 | [diff] [blame] | 248 | return; |
[email protected] | 162c8d9fa | 2014-03-18 20:25:41 | [diff] [blame] | 249 | |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 250 | done_ = false; |
Daniel Kenji Toyama | f1e4b57 | 2017-08-03 16:31:11 | [diff] [blame] | 251 | |
[email protected] | 855ebff | 2014-05-09 07:14:38 | [diff] [blame] | 252 | MaybeUseCachedSuggestions(); |
Daniel Kenji Toyama | f1e4b57 | 2017-08-03 16:31:11 | [diff] [blame] | 253 | |
Kevin Bailey | 5fea432 | 2018-03-21 22:36:05 | [diff] [blame] | 254 | if (result_type_running_ == MOST_VISITED) { |
Daniel Kenji Toyama | f1e4b57 | 2017-08-03 16:31:11 | [diff] [blame] | 255 | most_visited_urls_.clear(); |
| 256 | scoped_refptr<history::TopSites> ts = client()->GetTopSites(); |
Gheorghe Comanici | 9a364f57 | 2018-01-24 17:22:00 | [diff] [blame] | 257 | if (!ts) { |
| 258 | done_ = true; |
Kevin Bailey | 5fea432 | 2018-03-21 22:36:05 | [diff] [blame] | 259 | result_type_running_ = NONE; |
Gheorghe Comanici | 9a364f57 | 2018-01-24 17:22:00 | [diff] [blame] | 260 | return; |
Daniel Kenji Toyama | f1e4b57 | 2017-08-03 16:31:11 | [diff] [blame] | 261 | } |
Gheorghe Comanici | 9a364f57 | 2018-01-24 17:22:00 | [diff] [blame] | 262 | |
Kevin Bailey | 40bb0ac5 | 2019-04-02 00:43:32 | [diff] [blame] | 263 | ts->GetMostVisitedURLs(base::BindRepeating( |
| 264 | &ZeroSuggestProvider::OnMostVisitedUrlsAvailable, |
| 265 | weak_ptr_factory_.GetWeakPtr(), most_visited_request_num_)); |
Daniel Kenji Toyama | f1e4b57 | 2017-08-03 16:31:11 | [diff] [blame] | 266 | return; |
| 267 | } |
| 268 | |
Tommy C. Li | 6aee62d5 | 2019-06-27 20:25:00 | [diff] [blame] | 269 | search_terms_args.current_page_url = |
Tommy C. Li | d77691a | 2019-06-05 02:07:46 | [diff] [blame] | 270 | result_type_running_ == REMOTE_SEND_URL ? current_query_ : std::string(); |
Maks Orlovich | 1b20851 | 2018-06-13 21:08:17 | [diff] [blame] | 271 | // Create a request for suggestions, routing completion to |
Tommy C. Li | 06ec26a | 2019-06-10 18:01:42 | [diff] [blame] | 272 | // OnRemoteSuggestionsLoaderAvailable. |
Daniel Kenji Toyama | f1e4b57 | 2017-08-03 16:31:11 | [diff] [blame] | 273 | client() |
Tommy C. Li | 06ec26a | 2019-06-10 18:01:42 | [diff] [blame] | 274 | ->GetRemoteSuggestionsService(/*create_if_necessary=*/true) |
| 275 | ->CreateSuggestionsRequest( |
Tommy Li | 3fe8391 | 2019-08-23 17:33:11 | [diff] [blame] | 276 | search_terms_args, client()->GetTemplateURLService(), |
Daniel Kenji Toyama | f1e4b57 | 2017-08-03 16:31:11 | [diff] [blame] | 277 | base::BindOnce( |
Tommy C. Li | 06ec26a | 2019-06-10 18:01:42 | [diff] [blame] | 278 | &ZeroSuggestProvider::OnRemoteSuggestionsLoaderAvailable, |
Maks Orlovich | 1b20851 | 2018-06-13 21:08:17 | [diff] [blame] | 279 | weak_ptr_factory_.GetWeakPtr()), |
| 280 | base::BindOnce( |
| 281 | &ZeroSuggestProvider::OnURLLoadComplete, |
| 282 | base::Unretained(this) /* this owns SimpleURLLoader */)); |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 283 | } |
| 284 | |
mpearson | 8a37c38 | 2015-03-07 05:58:57 | [diff] [blame] | 285 | void ZeroSuggestProvider::Stop(bool clear_cached_results, |
| 286 | bool due_to_user_inactivity) { |
Maks Orlovich | 1b20851 | 2018-06-13 21:08:17 | [diff] [blame] | 287 | if (loader_) |
[email protected] | ec3f679b | 2014-08-18 07:45:13 | [diff] [blame] | 288 | LogOmniboxZeroSuggestRequest(ZERO_SUGGEST_REQUEST_INVALIDATED); |
Maks Orlovich | 1b20851 | 2018-06-13 21:08:17 | [diff] [blame] | 289 | loader_.reset(); |
Tommy Li | 3fe8391 | 2019-08-23 17:33:11 | [diff] [blame] | 290 | |
Kevin Bailey | 5fea432 | 2018-03-21 22:36:05 | [diff] [blame] | 291 | // TODO(krb): It would allow us to remove some guards if we could also cancel |
| 292 | // the TopSites::GetMostVisitedURLs request. |
[email protected] | ec3f679b | 2014-08-18 07:45:13 | [diff] [blame] | 293 | done_ = true; |
Kevin Bailey | 5fea432 | 2018-03-21 22:36:05 | [diff] [blame] | 294 | result_type_running_ = NONE; |
| 295 | ++most_visited_request_num_; |
[email protected] | ec3f679b | 2014-08-18 07:45:13 | [diff] [blame] | 296 | |
| 297 | if (clear_cached_results) { |
| 298 | // We do not call Clear() on |results_| to retain |verbatim_relevance| |
| 299 | // value in the |results_| object. |verbatim_relevance| is used at the |
jif | cf322cd | 2015-06-17 11:01:18 | [diff] [blame] | 300 | // beginning of the next call to Start() to determine the current url |
| 301 | // match relevance. |
[email protected] | ec3f679b | 2014-08-18 07:45:13 | [diff] [blame] | 302 | results_.suggest_results.clear(); |
| 303 | results_.navigation_results.clear(); |
Moe Ahmadi | b8a1daf | 2020-02-14 22:23:25 | [diff] [blame] | 304 | results_.experiment_stats.clear(); |
Moe Ahmadi | d2704a7a | 2020-03-31 22:04:26 | [diff] [blame] | 305 | results_.headers_map.clear(); |
[email protected] | ec3f679b | 2014-08-18 07:45:13 | [diff] [blame] | 306 | current_query_.clear(); |
gcomanici | 8cabc77f | 2017-04-27 20:04:54 | [diff] [blame] | 307 | current_title_.clear(); |
mariakhomenko | 1535e6a | 2015-03-20 07:48:45 | [diff] [blame] | 308 | most_visited_urls_.clear(); |
[email protected] | ec3f679b | 2014-08-18 07:45:13 | [diff] [blame] | 309 | } |
| 310 | } |
| 311 | |
[email protected] | 855ebff | 2014-05-09 07:14:38 | [diff] [blame] | 312 | void ZeroSuggestProvider::DeleteMatch(const AutocompleteMatch& match) { |
Moe Ahmadi | 0993aec | 2019-09-19 21:42:30 | [diff] [blame] | 313 | if (base::Contains(OmniboxFieldTrial::GetZeroSuggestVariants( |
| 314 | current_page_classification_), |
| 315 | kRemoteNoUrlVariant)) { |
[email protected] | 855ebff | 2014-05-09 07:14:38 | [diff] [blame] | 316 | // Remove the deleted match from the cache, so it is not shown to the user |
| 317 | // again. Since we cannot remove just one result, blow away the cache. |
blundell | d130d59 | 2015-06-21 19:29:13 | [diff] [blame] | 318 | client()->GetPrefs()->SetString(omnibox::kZeroSuggestCachedResults, |
[email protected] | 855ebff | 2014-05-09 07:14:38 | [diff] [blame] | 319 | std::string()); |
| 320 | } |
| 321 | BaseSearchProvider::DeleteMatch(match); |
| 322 | } |
| 323 | |
[email protected] | ec3f679b | 2014-08-18 07:45:13 | [diff] [blame] | 324 | void ZeroSuggestProvider::AddProviderInfo(ProvidersInfo* provider_info) const { |
| 325 | BaseSearchProvider::AddProviderInfo(provider_info); |
mariakhomenko | 1535e6a | 2015-03-20 07:48:45 | [diff] [blame] | 326 | if (!results_.suggest_results.empty() || |
| 327 | !results_.navigation_results.empty() || |
| 328 | !most_visited_urls_.empty()) |
[email protected] | ec3f679b | 2014-08-18 07:45:13 | [diff] [blame] | 329 | provider_info->back().set_times_returned_results_in_session(1); |
| 330 | } |
| 331 | |
[email protected] | f030c4d | 2014-03-25 01:05:54 | [diff] [blame] | 332 | void ZeroSuggestProvider::ResetSession() { |
| 333 | // The user has started editing in the omnibox, so leave |
blundell | d130d59 | 2015-06-21 19:29:13 | [diff] [blame] | 334 | // |field_trial_triggered_in_session| unchanged and set |
| 335 | // |field_trial_triggered| to false since zero suggest is inactive now. |
| 336 | set_field_trial_triggered(false); |
[email protected] | f030c4d | 2014-03-25 01:05:54 | [diff] [blame] | 337 | } |
| 338 | |
mpearson | 931028c | 2016-07-01 18:55:11 | [diff] [blame] | 339 | ZeroSuggestProvider::ZeroSuggestProvider( |
| 340 | AutocompleteProviderClient* client, |
mpearson | 931028c | 2016-07-01 18:55:11 | [diff] [blame] | 341 | AutocompleteProviderListener* listener) |
blundell | d130d59 | 2015-06-21 19:29:13 | [diff] [blame] | 342 | : BaseSearchProvider(AutocompleteProvider::TYPE_ZERO_SUGGEST, client), |
[email protected] | 776ee590 | 2014-08-11 09:15:19 | [diff] [blame] | 343 | listener_(listener), |
Jeremy Roman | 5c341f6d | 2019-07-15 15:56:10 | [diff] [blame] | 344 | result_type_running_(NONE) { |
Tommy C. Li | 06ec26a | 2019-06-10 18:01:42 | [diff] [blame] | 345 | // Record whether remote zero suggest is possible for this user / profile. |
mpearson | 3d89cdc | 2017-03-03 21:15:45 | [diff] [blame] | 346 | const TemplateURLService* template_url_service = |
| 347 | client->GetTemplateURLService(); |
| 348 | // Template URL service can be null in tests. |
| 349 | if (template_url_service != nullptr) { |
Tommy C. Li | 06ec26a | 2019-06-10 18:01:42 | [diff] [blame] | 350 | GURL suggest_url = RemoteSuggestionsService::EndpointUrl( |
Tommy C. Li | 6aee62d5 | 2019-06-27 20:25:00 | [diff] [blame] | 351 | TemplateURLRef::SearchTermsArgs(), template_url_service); |
mpearson | 3d89cdc | 2017-03-03 21:15:45 | [diff] [blame] | 352 | // To check whether this is allowed, use an arbitrary insecure (http) URL |
| 353 | // as the URL we'd want suggestions for. The value of OTHER as the current |
| 354 | // page classification is to correspond with that URL. |
| 355 | UMA_HISTOGRAM_BOOLEAN( |
| 356 | "Omnibox.ZeroSuggest.Eligible.OnProfileOpen", |
| 357 | suggest_url.is_valid() && |
| 358 | CanSendURL(GURL(kArbitraryInsecureUrlString), suggest_url, |
| 359 | template_url_service->GetDefaultSearchProvider(), |
| 360 | metrics::OmniboxEventProto::OTHER, |
Tommy C. Li | 71171ee | 2019-06-20 17:11:47 | [diff] [blame] | 361 | template_url_service->search_terms_data(), client, |
| 362 | false)); |
Tomasz Wiszkowski | fd790c0 | 2019-08-29 17:31:29 | [diff] [blame] | 363 | |
| 364 | LogOmniboxRemoteNoUrlEligibilityOnNTP( |
| 365 | OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS, true, |
| 366 | client); |
mpearson | 3d89cdc | 2017-03-03 21:15:45 | [diff] [blame] | 367 | } |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 368 | } |
| 369 | |
Tomasz Wiszkowski | f2464a8 | 2020-02-18 22:42:25 | [diff] [blame] | 370 | ZeroSuggestProvider::~ZeroSuggestProvider() = default; |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 371 | |
[email protected] | 776ee590 | 2014-08-11 09:15:19 | [diff] [blame] | 372 | const TemplateURL* ZeroSuggestProvider::GetTemplateURL(bool is_keyword) const { |
| 373 | // Zero suggest provider should not receive keyword results. |
| 374 | DCHECK(!is_keyword); |
blundell | d130d59 | 2015-06-21 19:29:13 | [diff] [blame] | 375 | return client()->GetTemplateURLService()->GetDefaultSearchProvider(); |
[email protected] | 776ee590 | 2014-08-11 09:15:19 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | const AutocompleteInput ZeroSuggestProvider::GetInput(bool is_keyword) const { |
jif | cf322cd | 2015-06-17 11:01:18 | [diff] [blame] | 379 | // The callers of this method won't look at the AutocompleteInput's |
| 380 | // |from_omnibox_focus| member, so we can set its value to false. |
Kevin Bailey | bcc319e | 2017-10-01 21:53:02 | [diff] [blame] | 381 | AutocompleteInput input(base::string16(), current_page_classification_, |
| 382 | client()->GetSchemeClassifier()); |
| 383 | input.set_current_url(GURL(current_query_)); |
| 384 | input.set_current_title(current_title_); |
| 385 | input.set_prevent_inline_autocomplete(true); |
| 386 | input.set_allow_exact_keyword_match(false); |
| 387 | return input; |
[email protected] | 776ee590 | 2014-08-11 09:15:19 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | bool ZeroSuggestProvider::ShouldAppendExtraParams( |
| 391 | const SearchSuggestionParser::SuggestResult& result) const { |
| 392 | // We always use the default provider for search, so append the params. |
| 393 | return true; |
| 394 | } |
| 395 | |
[email protected] | 776ee590 | 2014-08-11 09:15:19 | [diff] [blame] | 396 | void ZeroSuggestProvider::RecordDeletionResult(bool success) { |
| 397 | if (success) { |
| 398 | base::RecordAction( |
| 399 | base::UserMetricsAction("Omnibox.ZeroSuggestDelete.Success")); |
| 400 | } else { |
| 401 | base::RecordAction( |
| 402 | base::UserMetricsAction("Omnibox.ZeroSuggestDelete.Failure")); |
| 403 | } |
| 404 | } |
| 405 | |
Maks Orlovich | 1b20851 | 2018-06-13 21:08:17 | [diff] [blame] | 406 | void ZeroSuggestProvider::OnURLLoadComplete( |
| 407 | const network::SimpleURLLoader* source, |
| 408 | std::unique_ptr<std::string> response_body) { |
[email protected] | 776ee590 | 2014-08-11 09:15:19 | [diff] [blame] | 409 | DCHECK(!done_); |
Maks Orlovich | 1b20851 | 2018-06-13 21:08:17 | [diff] [blame] | 410 | DCHECK_EQ(loader_.get(), source); |
[email protected] | 776ee590 | 2014-08-11 09:15:19 | [diff] [blame] | 411 | |
| 412 | LogOmniboxZeroSuggestRequest(ZERO_SUGGEST_REPLY_RECEIVED); |
| 413 | |
Gheorghe Comanici | 9a364f57 | 2018-01-24 17:22:00 | [diff] [blame] | 414 | const bool results_updated = |
Maks Orlovich | 1b20851 | 2018-06-13 21:08:17 | [diff] [blame] | 415 | response_body && source->NetError() == net::OK && |
| 416 | (source->ResponseInfo() && source->ResponseInfo()->headers && |
| 417 | source->ResponseInfo()->headers->response_code() == 200) && |
| 418 | UpdateResults(SearchSuggestionParser::ExtractJsonData( |
| 419 | source, std::move(response_body))); |
| 420 | loader_.reset(); |
[email protected] | 776ee590 | 2014-08-11 09:15:19 | [diff] [blame] | 421 | done_ = true; |
Kevin Bailey | 5fea432 | 2018-03-21 22:36:05 | [diff] [blame] | 422 | result_type_running_ = NONE; |
| 423 | ++most_visited_request_num_; |
[email protected] | 776ee590 | 2014-08-11 09:15:19 | [diff] [blame] | 424 | listener_->OnProviderUpdate(results_updated); |
| 425 | } |
| 426 | |
Gheorghe Comanici | 9a364f57 | 2018-01-24 17:22:00 | [diff] [blame] | 427 | bool ZeroSuggestProvider::UpdateResults(const std::string& json_data) { |
| 428 | std::unique_ptr<base::Value> data( |
| 429 | SearchSuggestionParser::DeserializeJsonData(json_data)); |
| 430 | if (!data) |
[email protected] | 855ebff | 2014-05-09 07:14:38 | [diff] [blame] | 431 | return false; |
| 432 | |
Tommy C. Li | 467c1bcaa | 2019-06-20 20:48:05 | [diff] [blame] | 433 | // When running the REMOTE_NO_URL variant, we want to store suggestion |
Gheorghe Comanici | 9a364f57 | 2018-01-24 17:22:00 | [diff] [blame] | 434 | // responses if non-empty. |
Tommy C. Li | d77691a | 2019-06-05 02:07:46 | [diff] [blame] | 435 | if (result_type_running_ == REMOTE_NO_URL && !json_data.empty()) { |
Gheorghe Comanici | 9a364f57 | 2018-01-24 17:22:00 | [diff] [blame] | 436 | client()->GetPrefs()->SetString(omnibox::kZeroSuggestCachedResults, |
| 437 | json_data); |
[email protected] | 855ebff | 2014-05-09 07:14:38 | [diff] [blame] | 438 | |
Gheorghe Comanici | 9a364f57 | 2018-01-24 17:22:00 | [diff] [blame] | 439 | // If we received an empty result list, we should update the display, as it |
| 440 | // may be showing cached results that should not be shown. |
| 441 | const base::ListValue* root_list = nullptr; |
| 442 | const base::ListValue* results_list = nullptr; |
| 443 | const bool non_empty_parsed_list = data->GetAsList(&root_list) && |
| 444 | root_list->GetList(1, &results_list) && |
| 445 | !results_list->empty(); |
| 446 | const bool non_empty_cache = !results_.suggest_results.empty() || |
| 447 | !results_.navigation_results.empty(); |
| 448 | if (non_empty_parsed_list && non_empty_cache) |
| 449 | return false; |
| 450 | } |
| 451 | const bool results_updated = ParseSuggestResults( |
| 452 | *data, kDefaultZeroSuggestRelevance, false, &results_); |
| 453 | ConvertResultsToAutocompleteMatches(); |
| 454 | return results_updated; |
[email protected] | 855ebff | 2014-05-09 07:14:38 | [diff] [blame] | 455 | } |
| 456 | |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 457 | AutocompleteMatch ZeroSuggestProvider::NavigationToMatch( |
[email protected] | 0b9575f | 2014-07-30 11:58:37 | [diff] [blame] | 458 | const SearchSuggestionParser::NavigationResult& navigation) { |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 459 | AutocompleteMatch match(this, navigation.relevance(), false, |
[email protected] | 78981d8c | 2014-05-09 15:05:47 | [diff] [blame] | 460 | navigation.type()); |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 461 | match.destination_url = navigation.url(); |
| 462 | |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 463 | match.fill_into_edit += |
blundell | d130d59 | 2015-06-21 19:29:13 | [diff] [blame] | 464 | AutocompleteInput::FormattedStringWithEquivalentMeaning( |
Tommy C. Li | 0beb815 | 2017-08-25 18:30:26 | [diff] [blame] | 465 | navigation.url(), url_formatter::FormatUrl(navigation.url()), |
Kevin Bailey | 83e643d | 2018-03-08 16:01:41 | [diff] [blame] | 466 | client()->GetSchemeClassifier(), nullptr); |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 467 | |
manuk | 3972b2f | 2019-04-19 14:22:56 | [diff] [blame] | 468 | // Zero suggest results should always omit protocols and never appear bold. |
| 469 | auto format_types = AutocompleteMatch::GetFormatTypes(false, false); |
| 470 | match.contents = url_formatter::FormatUrl(navigation.url(), format_types, |
| 471 | net::UnescapeRule::SPACES, nullptr, |
| 472 | nullptr, nullptr); |
| 473 | match.contents_class = ClassifyTermMatches({}, match.contents.length(), 0, |
| 474 | ACMatchClassification::URL); |
[email protected] | 9c97f89c | 2013-06-25 03:12:16 | [diff] [blame] | 475 | |
| 476 | match.description = |
| 477 | AutocompleteMatch::SanitizeString(navigation.description()); |
manuk | 3972b2f | 2019-04-19 14:22:56 | [diff] [blame] | 478 | match.description_class = ClassifyTermMatches({}, match.description.length(), |
| 479 | 0, ACMatchClassification::NONE); |
| 480 | |
Tomasz Wiszkowski | afe090f | 2020-07-10 22:45:36 | [diff] [blame] | 481 | match.subtypes = navigation.subtypes(); |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 482 | return match; |
| 483 | } |
| 484 | |
[email protected] | 8f064e5 | 2013-09-18 01:17:14 | [diff] [blame] | 485 | void ZeroSuggestProvider::OnMostVisitedUrlsAvailable( |
Kevin Bailey | 5fea432 | 2018-03-21 22:36:05 | [diff] [blame] | 486 | size_t orig_request_num, |
[email protected] | 8f064e5 | 2013-09-18 01:17:14 | [diff] [blame] | 487 | const history::MostVisitedURLList& urls) { |
Kevin Bailey | 5fea432 | 2018-03-21 22:36:05 | [diff] [blame] | 488 | if (result_type_running_ != MOST_VISITED || |
| 489 | orig_request_num != most_visited_request_num_) { |
Gheorghe Comanici | 9a364f57 | 2018-01-24 17:22:00 | [diff] [blame] | 490 | return; |
Kevin Bailey | 5fea432 | 2018-03-21 22:36:05 | [diff] [blame] | 491 | } |
[email protected] | 8f064e5 | 2013-09-18 01:17:14 | [diff] [blame] | 492 | most_visited_urls_ = urls; |
mariakhomenko | bfc3a2a | 2014-10-24 00:48:22 | [diff] [blame] | 493 | done_ = true; |
| 494 | ConvertResultsToAutocompleteMatches(); |
Kevin Bailey | 5fea432 | 2018-03-21 22:36:05 | [diff] [blame] | 495 | result_type_running_ = NONE; |
| 496 | ++most_visited_request_num_; |
mariakhomenko | bfc3a2a | 2014-10-24 00:48:22 | [diff] [blame] | 497 | listener_->OnProviderUpdate(true); |
[email protected] | 8f064e5 | 2013-09-18 01:17:14 | [diff] [blame] | 498 | } |
| 499 | |
Tommy C. Li | 06ec26a | 2019-06-10 18:01:42 | [diff] [blame] | 500 | void ZeroSuggestProvider::OnRemoteSuggestionsLoaderAvailable( |
Maks Orlovich | 1b20851 | 2018-06-13 21:08:17 | [diff] [blame] | 501 | std::unique_ptr<network::SimpleURLLoader> loader) { |
Tommy C. Li | 06ec26a | 2019-06-10 18:01:42 | [diff] [blame] | 502 | // RemoteSuggestionsService has already started |loader|, so here it's |
Darwin Huang | 663c17d | 2020-02-06 01:10:01 | [diff] [blame] | 503 | // only necessary to grab its ownership until results come in to |
Maks Orlovich | 1b20851 | 2018-06-13 21:08:17 | [diff] [blame] | 504 | // OnURLLoadComplete(). |
| 505 | loader_ = std::move(loader); |
Daniel Kenji Toyama | f1e4b57 | 2017-08-03 16:31:11 | [diff] [blame] | 506 | LogOmniboxZeroSuggestRequest(ZERO_SUGGEST_REQUEST_SENT); |
| 507 | } |
| 508 | |
[email protected] | 9c97f89c | 2013-06-25 03:12:16 | [diff] [blame] | 509 | void ZeroSuggestProvider::ConvertResultsToAutocompleteMatches() { |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 510 | matches_.clear(); |
| 511 | |
blundell | d130d59 | 2015-06-21 19:29:13 | [diff] [blame] | 512 | TemplateURLService* template_url_service = client()->GetTemplateURLService(); |
Kevin Bailey | 9bdd15d | 2018-02-28 04:07:49 | [diff] [blame] | 513 | DCHECK(template_url_service); |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 514 | const TemplateURL* default_provider = |
blundell | d130d59 | 2015-06-21 19:29:13 | [diff] [blame] | 515 | template_url_service->GetDefaultSearchProvider(); |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 516 | // Fail if we can't set the clickthrough URL for query suggestions. |
Ivan Kotenkov | 75b1c3a | 2017-10-24 14:47:24 | [diff] [blame] | 517 | if (default_provider == nullptr || |
blundell | d130d59 | 2015-06-21 19:29:13 | [diff] [blame] | 518 | !default_provider->SupportsReplacement( |
| 519 | template_url_service->search_terms_data())) |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 520 | return; |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 521 | |
[email protected] | 0040474 | 2014-02-20 13:09:05 | [diff] [blame] | 522 | MatchMap map; |
Tommy Li | 823509e | 2019-12-06 22:42:47 | [diff] [blame] | 523 | |
Tommy C. Li | 167a368 | 2020-07-16 19:47:23 | [diff] [blame] | 524 | // Add all the SuggestResults to the map. We display all ZeroSuggest search |
| 525 | // suggestions as unbolded. |
Tommy Li | 823509e | 2019-12-06 22:42:47 | [diff] [blame] | 526 | for (size_t i = 0; i < results_.suggest_results.size(); ++i) { |
Tommy Li | 823509e | 2019-12-06 22:42:47 | [diff] [blame] | 527 | AddMatchToMap(results_.suggest_results[i], std::string(), i, false, false, |
| 528 | &map); |
| 529 | } |
[email protected] | 0040474 | 2014-02-20 13:09:05 | [diff] [blame] | 530 | |
| 531 | const int num_query_results = map.size(); |
| 532 | const int num_nav_results = results_.navigation_results.size(); |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 533 | const int num_results = num_query_results + num_nav_results; |
Steven Holte | 9592222 | 2018-09-14 20:06:23 | [diff] [blame] | 534 | UMA_HISTOGRAM_COUNTS_1M("ZeroSuggest.QueryResults", num_query_results); |
| 535 | UMA_HISTOGRAM_COUNTS_1M("ZeroSuggest.URLResults", num_nav_results); |
| 536 | UMA_HISTOGRAM_COUNTS_1M("ZeroSuggest.AllResults", num_results); |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 537 | |
[email protected] | 8f064e5 | 2013-09-18 01:17:14 | [diff] [blame] | 538 | // Show Most Visited results after ZeroSuggest response is received. |
Kevin Bailey | 5fea432 | 2018-03-21 22:36:05 | [diff] [blame] | 539 | if (result_type_running_ == MOST_VISITED) { |
Tomasz Wiszkowski | 57492ab | 2019-05-29 21:28:27 | [diff] [blame] | 540 | // Ensure we don't show most visited URL suggestions on NTP. |
| 541 | // This allows us to prevent undesired side outcome of presenting |
| 542 | // URL suggestions to users who are not in the personalized field trial for |
| 543 | // zero query suggestions. |
| 544 | if (IsNTPPage(current_page_classification_) || |
Tommy Li | ec99def | 2019-10-14 22:37:23 | [diff] [blame] | 545 | !current_text_match_.destination_url.is_valid()) { |
[email protected] | 3feb8b00 | 2013-10-14 23:50:13 | [diff] [blame] | 546 | return; |
Tomasz Wiszkowski | 57492ab | 2019-05-29 21:28:27 | [diff] [blame] | 547 | } |
Tommy Li | ec99def | 2019-10-14 22:37:23 | [diff] [blame] | 548 | matches_.push_back(current_text_match_); |
[email protected] | 8f064e5 | 2013-09-18 01:17:14 | [diff] [blame] | 549 | int relevance = 600; |
[email protected] | 23db649 | 2014-01-16 02:35:30 | [diff] [blame] | 550 | const base::string16 current_query_string16( |
| 551 | base::ASCIIToUTF16(current_query_)); |
Tomasz Wiszkowski | f2464a8 | 2020-02-18 22:42:25 | [diff] [blame] | 552 | for (const auto& url : most_visited_urls_) { |
[email protected] | 0b9575f | 2014-07-30 11:58:37 | [diff] [blame] | 553 | SearchSuggestionParser::NavigationResult nav( |
blundell | d130d59 | 2015-06-21 19:29:13 | [diff] [blame] | 554 | client()->GetSchemeClassifier(), url.url, |
Tomasz Wiszkowski | afe090f | 2020-07-10 22:45:36 | [diff] [blame] | 555 | AutocompleteMatchType::NAVSUGGEST, {}, url.title, std::string(), |
Tomasz Wiszkowski | 6a38a20b | 2020-07-09 01:36:18 | [diff] [blame] | 556 | false, relevance, true, current_query_string16); |
[email protected] | 8f064e5 | 2013-09-18 01:17:14 | [diff] [blame] | 557 | matches_.push_back(NavigationToMatch(nav)); |
| 558 | --relevance; |
| 559 | } |
| 560 | return; |
| 561 | } |
| 562 | |
[email protected] | 9c97f89c | 2013-06-25 03:12:16 | [diff] [blame] | 563 | if (num_results == 0) |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 564 | return; |
| 565 | |
Tommy Li | 0731aee | 2020-07-22 23:04:32 | [diff] [blame] | 566 | #if defined(OS_ANDROID) || defined(OS_IOS) |
| 567 | // Android needs the verbatim match on non-NTP surfaces to properly present |
| 568 | // the Search Ready Omnibox URL edit widget. Desktop specifically does NOT |
| 569 | // want to show verbatim matches in remotely-fetched ZeroSuggest anymore. |
| 570 | // iOS we are keeping the same as Android for now. No strong reason to change. |
Tomasz Wiszkowski | 57492ab | 2019-05-29 21:28:27 | [diff] [blame] | 571 | if (!IsNTPPage(current_page_classification_) && |
Tommy Li | ec99def | 2019-10-14 22:37:23 | [diff] [blame] | 572 | current_text_match_.destination_url.is_valid()) { |
| 573 | matches_.push_back(current_text_match_); |
Tomasz Wiszkowski | 57492ab | 2019-05-29 21:28:27 | [diff] [blame] | 574 | } |
Tommy Li | 0731aee | 2020-07-22 23:04:32 | [diff] [blame] | 575 | #endif |
Tomasz Wiszkowski | 57492ab | 2019-05-29 21:28:27 | [diff] [blame] | 576 | |
[email protected] | 0040474 | 2014-02-20 13:09:05 | [diff] [blame] | 577 | for (MatchMap::const_iterator it(map.begin()); it != map.end(); ++it) |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 578 | matches_.push_back(it->second); |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 579 | |
[email protected] | 0b9575f | 2014-07-30 11:58:37 | [diff] [blame] | 580 | const SearchSuggestionParser::NavigationResults& nav_results( |
| 581 | results_.navigation_results); |
Tomasz Wiszkowski | f2464a8 | 2020-02-18 22:42:25 | [diff] [blame] | 582 | for (const auto& nav_result : nav_results) { |
| 583 | matches_.push_back(NavigationToMatch(nav_result)); |
gcomanici | 67d53ac | 2017-04-01 17:07:19 | [diff] [blame] | 584 | } |
[email protected] | 6ce7f61 | 2012-09-05 23:53:07 | [diff] [blame] | 585 | } |
| 586 | |
Tommy Li | ec99def | 2019-10-14 22:37:23 | [diff] [blame] | 587 | AutocompleteMatch ZeroSuggestProvider::MatchForCurrentText() { |
[email protected] | bb1fb2b | 2013-05-31 00:21:01 | [diff] [blame] | 588 | // The placeholder suggestion for the current URL has high relevance so |
| 589 | // that it is in the first suggestion slot and inline autocompleted. It |
| 590 | // gets dropped as soon as the user types something. |
mpearson | 931028c | 2016-07-01 18:55:11 | [diff] [blame] | 591 | AutocompleteInput tmp(GetInput(false)); |
| 592 | tmp.UpdateText(permanent_text_, base::string16::npos, tmp.parts()); |
gcomanici | 8cabc77f | 2017-04-27 20:04:54 | [diff] [blame] | 593 | const base::string16 description = |
| 594 | (base::FeatureList::IsEnabled(omnibox::kDisplayTitleForCurrentUrl)) |
| 595 | ? current_title_ |
| 596 | : base::string16(); |
Tommy Li | ec99def | 2019-10-14 22:37:23 | [diff] [blame] | 597 | |
| 598 | // We pass a nullptr as the |history_url_provider| parameter now to force |
| 599 | // VerbatimMatch to do a classification, since the text can be a search query. |
| 600 | // TODO(tommycli): Simplify this - probably just bypass VerbatimMatchForURL. |
| 601 | AutocompleteMatch match = VerbatimMatchForURL( |
| 602 | client(), tmp, GURL(current_query_), description, |
| 603 | /*history_url_provider=*/nullptr, results_.verbatim_relevance); |
| 604 | match.provider = this; |
| 605 | return match; |
[email protected] | 0040474 | 2014-02-20 13:09:05 | [diff] [blame] | 606 | } |
[email protected] | 162c8d9fa | 2014-03-18 20:25:41 | [diff] [blame] | 607 | |
Gheorghe Comanici | 9a364f57 | 2018-01-24 17:22:00 | [diff] [blame] | 608 | bool ZeroSuggestProvider::AllowZeroSuggestSuggestions( |
Tomasz Wiszkowski | 57492ab | 2019-05-29 21:28:27 | [diff] [blame] | 609 | const AutocompleteInput& input) const { |
| 610 | const auto& page_url = input.current_url(); |
| 611 | const auto page_class = input.current_page_classification(); |
| 612 | const auto input_type = input.type(); |
Peter Kasting | fb1a8ea | 2017-11-28 02:26:50 | [diff] [blame] | 613 | |
Tommy Li | e8ecbf8b | 2020-08-13 00:19:05 | [diff] [blame] | 614 | if (client()->IsOffTheRecord()) |
| 615 | return false; |
| 616 | |
Tommy C. Li | 17b5ba11 | 2020-08-11 02:29:21 | [diff] [blame] | 617 | if (input.focus_type() == OmniboxFocusType::DEFAULT) |
Tomasz Wiszkowski | 57492ab | 2019-05-29 21:28:27 | [diff] [blame] | 618 | return false; |
| 619 | |
Tommy Li | e8ecbf8b | 2020-08-13 00:19:05 | [diff] [blame] | 620 | if (input.focus_type() == OmniboxFocusType::ON_FOCUS && |
| 621 | page_class == metrics::OmniboxEventProto::OTHER && |
| 622 | !base::FeatureList::IsEnabled( |
| 623 | omnibox::kFocusGestureTriggersContextualWebZeroSuggest)) { |
[email protected] | 162c8d9fa | 2014-03-18 20:25:41 | [diff] [blame] | 624 | return false; |
Tommy Li | e8ecbf8b | 2020-08-13 00:19:05 | [diff] [blame] | 625 | } |
[email protected] | 162c8d9fa | 2014-03-18 20:25:41 | [diff] [blame] | 626 | |
Tomasz Wiszkowski | a8780ff9 | 2019-07-25 21:46:05 | [diff] [blame] | 627 | // When the omnibox is empty, only allow zero suggest for the ChromeOS |
Tommy Li | 5cd5921 | 2020-08-04 20:01:08 | [diff] [blame] | 628 | // Launcher and NTP, unless the clobber flag is on. |
| 629 | // |
| 630 | // TODO(tommycli): Add more nuance here, likely with an omnibox_focus_type. |
Yue Ru Sun | e31e157 | 2019-07-19 17:09:57 | [diff] [blame] | 631 | if (input_type == metrics::OmniboxInputType::EMPTY && |
Tomasz Wiszkowski | 57492ab | 2019-05-29 21:28:27 | [diff] [blame] | 632 | !(page_class == metrics::OmniboxEventProto::CHROMEOS_APP_LIST || |
Tommy Li | 5cd5921 | 2020-08-04 20:01:08 | [diff] [blame] | 633 | IsNTPPage(page_class) || |
| 634 | base::FeatureList::IsEnabled( |
| 635 | omnibox::kClobberIsZeroSuggestEntrypoint))) { |
[email protected] | 5b899dc | 2018-10-02 09:20:01 | [diff] [blame] | 636 | return false; |
| 637 | } |
| 638 | |
Tomasz Wiszkowski | 57492ab | 2019-05-29 21:28:27 | [diff] [blame] | 639 | // When omnibox contains pre-populated content, only show zero suggest for |
| 640 | // pages with URLs the user will recognize. |
| 641 | // |
Mark Pearson | 3fb0e316 | 2018-08-27 21:53:57 | [diff] [blame] | 642 | // This list intentionally does not include items such as ftp: and file: |
Tommy C. Li | 06ec26a | 2019-06-10 18:01:42 | [diff] [blame] | 643 | // because (a) these do not work on Android and iOS, where most visited |
Mark Pearson | 3fb0e316 | 2018-08-27 21:53:57 | [diff] [blame] | 644 | // zero suggest is launched and (b) on desktop, where contextual zero suggest |
| 645 | // is running, these types of schemes aren't eligible to be sent to the |
| 646 | // server to ask for suggestions (and thus in practice we won't display zero |
| 647 | // suggest for them). |
Yue Ru Sun | e31e157 | 2019-07-19 17:09:57 | [diff] [blame] | 648 | if (input_type != metrics::OmniboxInputType::EMPTY && |
Tomasz Wiszkowski | 57492ab | 2019-05-29 21:28:27 | [diff] [blame] | 649 | !(page_url.is_valid() && |
| 650 | ((page_url.scheme() == url::kHttpScheme) || |
| 651 | (page_url.scheme() == url::kHttpsScheme) || |
| 652 | (page_url.scheme() == url::kAboutScheme) || |
| 653 | (page_url.scheme() == |
| 654 | client()->GetEmbedderRepresentationOfAboutScheme())))) { |
[email protected] | 162c8d9fa | 2014-03-18 20:25:41 | [diff] [blame] | 655 | return false; |
Tomasz Wiszkowski | 57492ab | 2019-05-29 21:28:27 | [diff] [blame] | 656 | } |
[email protected] | 162c8d9fa | 2014-03-18 20:25:41 | [diff] [blame] | 657 | |
| 658 | return true; |
| 659 | } |
[email protected] | 855ebff | 2014-05-09 07:14:38 | [diff] [blame] | 660 | |
| 661 | void ZeroSuggestProvider::MaybeUseCachedSuggestions() { |
Tommy C. Li | d77691a | 2019-06-05 02:07:46 | [diff] [blame] | 662 | if (result_type_running_ != REMOTE_NO_URL) |
[email protected] | 855ebff | 2014-05-09 07:14:38 | [diff] [blame] | 663 | return; |
| 664 | |
blundell | d130d59 | 2015-06-21 19:29:13 | [diff] [blame] | 665 | std::string json_data = |
| 666 | client()->GetPrefs()->GetString(omnibox::kZeroSuggestCachedResults); |
[email protected] | 855ebff | 2014-05-09 07:14:38 | [diff] [blame] | 667 | if (!json_data.empty()) { |
dcheng | 259570c | 2016-04-22 00:45:57 | [diff] [blame] | 668 | std::unique_ptr<base::Value> data( |
[email protected] | 2c802d1 | 2014-07-31 12:57:14 | [diff] [blame] | 669 | SearchSuggestionParser::DeserializeJsonData(json_data)); |
Gheorghe Comanici | 9a364f57 | 2018-01-24 17:22:00 | [diff] [blame] | 670 | if (data && ParseSuggestResults(*data, kDefaultZeroSuggestRelevance, false, |
| 671 | &results_)) |
[email protected] | 855ebff | 2014-05-09 07:14:38 | [diff] [blame] | 672 | ConvertResultsToAutocompleteMatches(); |
[email protected] | 855ebff | 2014-05-09 07:14:38 | [diff] [blame] | 673 | } |
| 674 | } |
Gheorghe Comanici | 9a364f57 | 2018-01-24 17:22:00 | [diff] [blame] | 675 | |
| 676 | ZeroSuggestProvider::ResultType ZeroSuggestProvider::TypeOfResultToRun( |
| 677 | const GURL& current_url, |
| 678 | const GURL& suggest_url) { |
Gheorghe Comanici | 9a364f57 | 2018-01-24 17:22:00 | [diff] [blame] | 679 | // Check if the URL can be sent in any suggest request. |
| 680 | const TemplateURLService* template_url_service = |
| 681 | client()->GetTemplateURLService(); |
Kevin Bailey | 9bdd15d | 2018-02-28 04:07:49 | [diff] [blame] | 682 | DCHECK(template_url_service); |
Gheorghe Comanici | 9a364f57 | 2018-01-24 17:22:00 | [diff] [blame] | 683 | const TemplateURL* default_provider = |
| 684 | template_url_service->GetDefaultSearchProvider(); |
| 685 | const bool can_send_current_url = CanSendURL( |
| 686 | current_url, suggest_url, default_provider, current_page_classification_, |
Tommy C. Li | 71171ee | 2019-06-20 17:11:47 | [diff] [blame] | 687 | template_url_service->search_terms_data(), client(), false); |
Gheorghe Comanici | 9a364f57 | 2018-01-24 17:22:00 | [diff] [blame] | 688 | // Collect metrics on eligibility. |
| 689 | GURL arbitrary_insecure_url(kArbitraryInsecureUrlString); |
| 690 | ZeroSuggestEligibility eligibility = ZeroSuggestEligibility::ELIGIBLE; |
| 691 | if (!can_send_current_url) { |
| 692 | const bool can_send_ordinary_url = |
| 693 | CanSendURL(arbitrary_insecure_url, suggest_url, default_provider, |
| 694 | current_page_classification_, |
Tommy C. Li | 71171ee | 2019-06-20 17:11:47 | [diff] [blame] | 695 | template_url_service->search_terms_data(), client(), false); |
Gheorghe Comanici | 9a364f57 | 2018-01-24 17:22:00 | [diff] [blame] | 696 | eligibility = can_send_ordinary_url |
| 697 | ? ZeroSuggestEligibility::URL_INELIGIBLE |
| 698 | : ZeroSuggestEligibility::GENERALLY_INELIGIBLE; |
| 699 | } |
| 700 | UMA_HISTOGRAM_ENUMERATION( |
Tomasz Wiszkowski | 57492ab | 2019-05-29 21:28:27 | [diff] [blame] | 701 | kOmniboxZeroSuggestEligibleHistogramName, static_cast<int>(eligibility), |
Gheorghe Comanici | 9a364f57 | 2018-01-24 17:22:00 | [diff] [blame] | 702 | static_cast<int>(ZeroSuggestEligibility::ELIGIBLE_MAX_VALUE)); |
| 703 | |
Moe Ahmadi | 0993aec | 2019-09-19 21:42:30 | [diff] [blame] | 704 | const auto field_trial_variants = |
| 705 | OmniboxFieldTrial::GetZeroSuggestVariants(current_page_classification_); |
Tommy C. Li | 0af0956 | 2019-06-11 23:58:51 | [diff] [blame] | 706 | |
Stepan Khapugin | 5187a46 | 2020-01-07 13:16:26 | [diff] [blame] | 707 | if (base::Contains(field_trial_variants, kNoneVariant)) |
Kevin Bailey | 5fea432 | 2018-03-21 22:36:05 | [diff] [blame] | 708 | return NONE; |
Gheorghe Comanici | 9a364f57 | 2018-01-24 17:22:00 | [diff] [blame] | 709 | |
Tommy C. Li | 0af0956 | 2019-06-11 23:58:51 | [diff] [blame] | 710 | if (current_page_classification_ == OmniboxEventProto::CHROMEOS_APP_LIST) |
Tommy C. Li | d77691a | 2019-06-05 02:07:46 | [diff] [blame] | 711 | return REMOTE_NO_URL; |
Jenny Zhang | 5bc2e3d | 2018-09-10 18:50:55 | [diff] [blame] | 712 | |
Tommy Li | e0a3a99 | 2020-05-29 21:32:05 | [diff] [blame] | 713 | // Contextual Open Web - (same client side behavior for multiple variants). |
| 714 | bool contextual_web_suggestions_enabled = |
| 715 | base::FeatureList::IsEnabled(omnibox::kOnFocusSuggestionsContextualWeb) || |
| 716 | base::FeatureList::IsEnabled( |
| 717 | omnibox::kOnFocusSuggestionsContextualWebOnContent); |
Tommy Li | 5578402 | 2020-04-28 20:58:18 | [diff] [blame] | 718 | if (current_page_classification_ == OmniboxEventProto::OTHER && |
Tommy Li | e0a3a99 | 2020-05-29 21:32:05 | [diff] [blame] | 719 | can_send_current_url && contextual_web_suggestions_enabled) { |
Tommy Li | 5578402 | 2020-04-28 20:58:18 | [diff] [blame] | 720 | return REMOTE_SEND_URL; |
| 721 | } |
| 722 | |
Moe Ahmadi | 31147bc | 2020-06-02 19:07:56 | [diff] [blame] | 723 | // Reactive Zero-Prefix Suggestions (rZPS) on NTP cases. |
Tommy Li | b4b3bb5b | 2020-05-01 02:34:56 | [diff] [blame] | 724 | bool remote_no_url_allowed = |
| 725 | RemoteNoUrlSuggestionsAreAllowed(client(), template_url_service); |
| 726 | if (remote_no_url_allowed) { |
| 727 | // NTP Omnibox. |
| 728 | if ((current_page_classification_ == OmniboxEventProto::NTP || |
| 729 | current_page_classification_ == |
| 730 | OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS) && |
| 731 | base::FeatureList::IsEnabled( |
Moe Ahmadi | 31147bc | 2020-06-02 19:07:56 | [diff] [blame] | 732 | omnibox::kReactiveZeroSuggestionsOnNTPOmnibox)) { |
Tommy Li | b4b3bb5b | 2020-05-01 02:34:56 | [diff] [blame] | 733 | return REMOTE_NO_URL; |
| 734 | } |
| 735 | // NTP Realbox. |
| 736 | if (current_page_classification_ == OmniboxEventProto::NTP_REALBOX && |
| 737 | base::FeatureList::IsEnabled( |
Moe Ahmadi | 31147bc | 2020-06-02 19:07:56 | [diff] [blame] | 738 | omnibox::kReactiveZeroSuggestionsOnNTPRealbox)) { |
Tommy Li | b4b3bb5b | 2020-05-01 02:34:56 | [diff] [blame] | 739 | return REMOTE_NO_URL; |
| 740 | } |
| 741 | } |
| 742 | |
Tommy Li | 0801a8b | 2020-05-30 00:28:55 | [diff] [blame] | 743 | if (base::Contains(field_trial_variants, kRemoteNoUrlVariant) && |
| 744 | remote_no_url_allowed) { |
| 745 | return REMOTE_NO_URL; |
Tommy C. Li | 393c1b14 | 2019-05-22 00:28:41 | [diff] [blame] | 746 | } |
Gheorghe Comanici | 9a364f57 | 2018-01-24 17:22:00 | [diff] [blame] | 747 | |
Moe Ahmadi | 0993aec | 2019-09-19 21:42:30 | [diff] [blame] | 748 | if (base::Contains(field_trial_variants, kRemoteSendUrlVariant) && |
| 749 | can_send_current_url) |
Tommy C. Li | 0af0956 | 2019-06-11 23:58:51 | [diff] [blame] | 750 | return REMOTE_SEND_URL; |
Gheorghe Comanici | 9a364f57 | 2018-01-24 17:22:00 | [diff] [blame] | 751 | |
Moe Ahmadi | 0993aec | 2019-09-19 21:42:30 | [diff] [blame] | 752 | if (base::Contains(field_trial_variants, kMostVisitedVariant)) |
Tommy C. Li | 0af0956 | 2019-06-11 23:58:51 | [diff] [blame] | 753 | return MOST_VISITED; |
| 754 | |
Tommy Li | 0801a8b | 2020-05-30 00:28:55 | [diff] [blame] | 755 | #if defined(OS_ANDROID) |
| 756 | // For Android NTP, default to REMOTE_NO_URL, if it's allowed. |
| 757 | if (IsNTPPage(current_page_classification_) && remote_no_url_allowed) |
| 758 | return REMOTE_NO_URL; |
| 759 | #endif |
| 760 | |
Tommy C. Li | 0af0956 | 2019-06-11 23:58:51 | [diff] [blame] | 761 | #if defined(OS_ANDROID) || defined(OS_IOS) |
Tommy Li | 0801a8b | 2020-05-30 00:28:55 | [diff] [blame] | 762 | // Then, for Android and iOS, default to MOST_VISITED except on the SERP. |
| 763 | if (current_page_classification_ != |
Tommy C. Li | 0af0956 | 2019-06-11 23:58:51 | [diff] [blame] | 764 | OmniboxEventProto::SEARCH_RESULT_PAGE_NO_SEARCH_TERM_REPLACEMENT && |
| 765 | current_page_classification_ != |
| 766 | OmniboxEventProto::SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT) { |
Kevin Bailey | 5fea432 | 2018-03-21 22:36:05 | [diff] [blame] | 767 | return MOST_VISITED; |
Tommy C. Li | 393c1b14 | 2019-05-22 00:28:41 | [diff] [blame] | 768 | } |
Tommy C. Li | 0af0956 | 2019-06-11 23:58:51 | [diff] [blame] | 769 | #endif |
Tommy C. Li | c79d39ab | 2019-06-04 16:58:56 | [diff] [blame] | 770 | |
| 771 | return NONE; |
Gheorghe Comanici | 9a364f57 | 2018-01-24 17:22:00 | [diff] [blame] | 772 | } |