Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1464)

Unified Diff: components/omnibox/browser/zero_suggest_provider.cc

Issue 2724303002: Omnibox - Zero Suggest - Log When/Whether Contextual Search is Possible (Closed)
Patch Set: correct part of histograms.xml description Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/omnibox/browser/zero_suggest_provider.cc
diff --git a/components/omnibox/browser/zero_suggest_provider.cc b/components/omnibox/browser/zero_suggest_provider.cc
index 1a5d022917791cebdb92f6881df8209ef52197c7..eb6e0c42d4d0d8eececcb9037ab8c41bc97078cc 100644
--- a/components/omnibox/browser/zero_suggest_provider.cc
+++ b/components/omnibox/browser/zero_suggest_provider.cc
@@ -19,6 +19,7 @@
#include "components/data_use_measurement/core/data_use_user_data.h"
#include "components/history/core/browser/history_types.h"
#include "components/history/core/browser/top_sites.h"
+#include "components/metrics/proto/omnibox_event.pb.h"
#include "components/metrics/proto/omnibox_input_type.pb.h"
#include "components/omnibox/browser/autocomplete_classifier.h"
#include "components/omnibox/browser/autocomplete_input.h"
@@ -43,19 +44,28 @@
namespace {
+// Represents if, on focus, ZeroSuggestProvider is allowed to display
+// contextual suggestions and, if not, why not.
+// These values are written to logs. New enum values can be added, but existing
+// enums must never be renumbered or deleted and reused.
+enum ZeroSuggestEligibleOnFocus {
+ ZERO_SUGGEST_ELIGIBLE = 0,
+ ZERO_SUGGEST_GENERALLY_ELIGIBLE_BUT_NOT_THIS_URL = 1,
+ ZERO_SUGGEST_GENERALLY_INELIGIBLE = 2,
+ ZERO_SUGGEST_ELIGIBLE_MAX_VALUE
+};
+
// TODO(hfung): The histogram code was copied and modified from
// search_provider.cc. Refactor and consolidate the code.
// We keep track in a histogram how many suggest requests we send, how
// many suggest requests we invalidate (e.g., due to a user typing
// another character), and how many replies we receive.
-// *** ADD NEW ENUMS AFTER ALL PREVIOUSLY DEFINED ONES! ***
-// (excluding the end-of-list enum value)
-// We do not want values of existing enums to change or else it screws
-// up the statistics.
+// These values are written to logs. New enum values can be added, but existing
+// enums must never be renumbered or deleted and reused.
enum ZeroSuggestRequestsHistogramValue {
ZERO_SUGGEST_REQUEST_SENT = 1,
- ZERO_SUGGEST_REQUEST_INVALIDATED,
- ZERO_SUGGEST_REPLY_RECEIVED,
+ ZERO_SUGGEST_REQUEST_INVALIDATED = 2,
+ ZERO_SUGGEST_REPLY_RECEIVED = 3,
ZERO_SUGGEST_MAX_REQUEST_HISTOGRAM_VALUE
};
@@ -68,6 +78,9 @@ void LogOmniboxZeroSuggestRequest(
// Relevance value to use if it was not set explicitly by the server.
const int kDefaultZeroSuggestRelevance = 100;
+// Used for testing whether zero suggest is ever available.
+std::string kArbitraryInsecureUrlString = "http://www.google.com/";
+
} // namespace
// static
@@ -101,32 +114,36 @@ void ZeroSuggestProvider::Start(const AutocompleteInput& input,
current_query_ = input.current_url().spec();
current_page_classification_ = input.current_page_classification();
current_url_match_ = MatchForCurrentURL();
- TemplateURLService* template_url_service = client()->GetTemplateURLService();
-
- const TemplateURL* default_provider =
- template_url_service->GetDefaultSearchProvider();
- if (default_provider == NULL)
- return;
- base::string16 prefix;
- TemplateURLRef::SearchTermsArgs search_term_args(prefix);
- std::string url_string;
- if (OmniboxFieldTrial::InZeroSuggestRedirectToChromeFieldTrial()) {
- url_string = OmniboxFieldTrial::ZeroSuggestRedirectToChromeServerAddress();
- } else {
- url_string = default_provider->suggestions_url_ref().ReplaceSearchTerms(
- search_term_args, template_url_service->search_terms_data());
- }
+ std::string url_string(GetContextualSuggestionsUrl());
GURL suggest_url(url_string);
-
if (!suggest_url.is_valid())
return;
// No need to send the current page URL in personalized suggest or
// most visited field trials.
- if (CanSendURL(input.current_url(), suggest_url, default_provider,
+ const TemplateURLService* template_url_service =
+ client()->GetTemplateURLService();
+ const TemplateURL* default_provider =
+ template_url_service->GetDefaultSearchProvider();
+ const bool can_send_current_url =
+ CanSendURL(input.current_url(), suggest_url, default_provider,
current_page_classification_,
- template_url_service->search_terms_data(), client()) &&
+ template_url_service->search_terms_data(), client());
+ GURL arbitrary_insecure_url(kArbitraryInsecureUrlString);
+ const bool can_send_ordinary_url =
+ CanSendURL(arbitrary_insecure_url, suggest_url, default_provider,
+ current_page_classification_,
+ template_url_service->search_terms_data(), client());
+ const ZeroSuggestEligibleOnFocus eligibility =
+ can_send_current_url
+ ? ZERO_SUGGEST_ELIGIBLE
+ : (can_send_ordinary_url
+ ? ZERO_SUGGEST_GENERALLY_ELIGIBLE_BUT_NOT_THIS_URL
+ : ZERO_SUGGEST_GENERALLY_INELIGIBLE);
+ UMA_HISTOGRAM_ENUMERATION("Omnibox.ZeroSuggest.Eligible.OnFocus", eligibility,
+ ZERO_SUGGEST_ELIGIBLE_MAX_VALUE);
+ if (can_send_current_url &&
!OmniboxFieldTrial::InZeroSuggestPersonalizedFieldTrial() &&
!OmniboxFieldTrial::InZeroSuggestMostVisitedFieldTrial()) {
// Update suggest_url to include the current_page_url.
@@ -136,6 +153,8 @@ void ZeroSuggestProvider::Start(const AutocompleteInput& input,
OmniboxFieldTrial::ZeroSuggestRedirectToChromeAdditionalFields();
suggest_url = GURL(url_string);
} else {
+ base::string16 prefix;
+ TemplateURLRef::SearchTermsArgs search_term_args(prefix);
search_term_args.current_page_url = current_query_;
suggest_url =
GURL(default_provider->suggestions_url_ref().ReplaceSearchTerms(
@@ -209,6 +228,23 @@ ZeroSuggestProvider::ZeroSuggestProvider(
results_from_cache_(false),
waiting_for_most_visited_urls_request_(false),
weak_ptr_factory_(this) {
+ // Record whether contextual zero suggest is possible for this user / profile.
+ // To check whether this is allowed, use an arbitrary insecure (http) URL
+ // as the URL we'd want suggestions for. The value of OTHER as the current
+ // page classification is to correspond with that URL.
+ const TemplateURLService* template_url_service =
+ client->GetTemplateURLService();
+ // Template URL service can be null in tests.
+ if (template_url_service != nullptr) {
+ GURL suggest_url(GetContextualSuggestionsUrl());
+ UMA_HISTOGRAM_BOOLEAN(
+ "Omnibox.ZeroSuggest.Eligible.OnProfileOpen",
+ suggest_url.is_valid() &&
+ CanSendURL(GURL(kArbitraryInsecureUrlString), suggest_url,
+ template_url_service->GetDefaultSearchProvider(),
+ metrics::OmniboxEventProto::OTHER,
+ template_url_service->search_terms_data(), client));
+ }
}
ZeroSuggestProvider::~ZeroSuggestProvider() {
@@ -479,6 +515,25 @@ bool ZeroSuggestProvider::ShouldShowNonContextualZeroSuggest(
return true;
}
+std::string ZeroSuggestProvider::GetContextualSuggestionsUrl() const {
+ // Without a default search provider, refuse to do anything (even if the user
+ // in the redirect-to-chrome field trial).
+ const TemplateURLService* template_url_service =
+ client()->GetTemplateURLService();
+ const TemplateURL* default_provider =
+ template_url_service->GetDefaultSearchProvider();
+ if (default_provider == nullptr)
+ return "";
+
+ if (OmniboxFieldTrial::InZeroSuggestRedirectToChromeFieldTrial()) {
+ return OmniboxFieldTrial::ZeroSuggestRedirectToChromeServerAddress();
+ }
+ base::string16 prefix;
+ TemplateURLRef::SearchTermsArgs search_term_args(prefix);
+ return default_provider->suggestions_url_ref().ReplaceSearchTerms(
+ search_term_args, template_url_service->search_terms_data());
+}
+
void ZeroSuggestProvider::MaybeUseCachedSuggestions() {
if (!OmniboxFieldTrial::InZeroSuggestPersonalizedFieldTrial())
return;

Powered by Google App Engine
This is Rietveld 408576698