Commit 508d4fdc authored by Angela Yoeurng's avatar Angela Yoeurng Committed by Commit Bot

[omnibox] Add support for pedals counterfactual logging

Bug: 893183
Change-Id: Ib8eea4c29e68ec0483c1f97522ac516e6d18fb44
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2360416
Commit-Queue: Angela Yoeurng <yoangela@chromium.org>
Reviewed-by: default avatarJustin Donnelly <jdonnelly@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#800173}
parent c9b77625
...@@ -38,6 +38,8 @@ ...@@ -38,6 +38,8 @@
#include "components/omnibox/browser/history_url_provider.h" #include "components/omnibox/browser/history_url_provider.h"
#include "components/omnibox/browser/keyword_provider.h" #include "components/omnibox/browser/keyword_provider.h"
#include "components/omnibox/browser/local_history_zero_suggest_provider.h" #include "components/omnibox/browser/local_history_zero_suggest_provider.h"
#include "components/omnibox/browser/omnibox_field_trial.h"
#include "components/omnibox/browser/omnibox_pedal_provider.h"
#include "components/omnibox/browser/on_device_head_provider.h" #include "components/omnibox/browser/on_device_head_provider.h"
#include "components/omnibox/browser/query_tile_provider.h" #include "components/omnibox/browser/query_tile_provider.h"
#include "components/omnibox/browser/search_provider.h" #include "components/omnibox/browser/search_provider.h"
...@@ -552,14 +554,28 @@ void AutocompleteController::AddProvidersInfo( ...@@ -552,14 +554,28 @@ void AutocompleteController::AddProvidersInfo(
// This is also a good place to put code to add info that you want to // This is also a good place to put code to add info that you want to
// add for every provider. // add for every provider.
} }
if (OmniboxFieldTrial::IsPedalSuggestionsEnabled()) {
// OmniboxPedalProvider is not a "true" AutocompleteProvider and isn't
// included in the list of providers, though needs to report information for
// its field trial. Manually call AddProviderInfo for pedals.
provider_client_->GetPedalProvider()->AddProviderInfo(provider_info);
}
} }
void AutocompleteController::ResetSession() { void AutocompleteController::ResetSession() {
search_service_worker_signal_sent_ = false; search_service_worker_signal_sent_ = false;
for (Providers::const_iterator i(providers_.begin()); i != providers_.end(); for (Providers::const_iterator i(providers_.begin()); i != providers_.end();
++i) ++i) {
(*i)->ResetSession(); (*i)->ResetSession();
}
if (OmniboxFieldTrial::IsPedalSuggestionsEnabled()) {
// OmniboxPedalProvider is not included in the list of providers as it's not
// a "true" AutocompleteProvider. Manually call ResetSession() for pedals.
provider_client_->GetPedalProvider()->ResetSession();
}
} }
void AutocompleteController::UpdateMatchDestinationURLWithQueryFormulationTime( void AutocompleteController::UpdateMatchDestinationURLWithQueryFormulationTime(
......
...@@ -393,23 +393,16 @@ void AutocompleteResult::DemoteOnDeviceSearchSuggestions() { ...@@ -393,23 +393,16 @@ void AutocompleteResult::DemoteOnDeviceSearchSuggestions() {
void AutocompleteResult::ConvertInSuggestionPedalMatches( void AutocompleteResult::ConvertInSuggestionPedalMatches(
AutocompleteProviderClient* client) { AutocompleteProviderClient* client) {
const OmniboxPedalProvider* provider = client->GetPedalProvider(); OmniboxPedalProvider* provider = client->GetPedalProvider();
// Used to ensure we keep only one Pedal of each kind. // Used to ensure we keep only one Pedal of each kind.
std::unordered_set<OmniboxPedal*> pedals_found; std::unordered_set<OmniboxPedal*> pedals_found;
provider->set_field_trial_triggered(false);
for (auto& match : matches_) { for (auto& match : matches_) {
if (OmniboxFieldTrial::IsSuggestionButtonRowEnabled()) { // Skip matches that have already detected their pedal.
// Skip only matches that have already detected their pedal. With the if (match.pedal)
// button row enabled, a pedal may attach along with tab switch and continue;
// associated keyword buttons.
if (match.pedal)
continue;
} else {
// Skip matches that will not show Pedal because they already
// have a tab match or associated keyword. Also skip matches
// that have already detected their Pedal.
if (match.has_tab_match || match.associated_keyword || match.pedal)
continue;
}
OmniboxPedal* const pedal = provider->FindPedalMatch(match.contents); OmniboxPedal* const pedal = provider->FindPedalMatch(match.contents);
if (pedal) { if (pedal) {
......
...@@ -7,12 +7,15 @@ ...@@ -7,12 +7,15 @@
#include "base/i18n/case_conversion.h" #include "base/i18n/case_conversion.h"
#include "base/i18n/char_iterator.h" #include "base/i18n/char_iterator.h"
#include "base/json/json_reader.h" #include "base/json/json_reader.h"
#include "base/metrics/field_trial_params.h"
#include "base/strings/string_tokenizer.h" #include "base/strings/string_tokenizer.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "components/omnibox/browser/autocomplete_provider_client.h" #include "components/omnibox/browser/autocomplete_provider_client.h"
#include "components/omnibox/browser/omnibox_field_trial.h"
#include "components/omnibox/browser/omnibox_pedal.h" #include "components/omnibox/browser/omnibox_pedal.h"
#include "components/omnibox/browser/omnibox_pedal_implementations.h" #include "components/omnibox/browser/omnibox_pedal_implementations.h"
#include "components/omnibox/common/omnibox_features.h"
#include "components/omnibox/resources/grit/omnibox_resources.h" #include "components/omnibox/resources/grit/omnibox_resources.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
...@@ -31,16 +34,49 @@ OmniboxPedalProvider::OmniboxPedalProvider(AutocompleteProviderClient& client) ...@@ -31,16 +34,49 @@ OmniboxPedalProvider::OmniboxPedalProvider(AutocompleteProviderClient& client)
OmniboxPedalProvider::~OmniboxPedalProvider() {} OmniboxPedalProvider::~OmniboxPedalProvider() {}
void OmniboxPedalProvider::AddProviderInfo(ProvidersInfo* provider_info) const {
provider_info->push_back(metrics::OmniboxEventProto_ProviderInfo());
metrics::OmniboxEventProto_ProviderInfo& new_entry = provider_info->back();
new_entry.set_provider(metrics::OmniboxEventProto::SEARCH);
new_entry.set_provider_done(true);
if (field_trial_triggered_ || field_trial_triggered_in_session_) {
std::vector<uint32_t> field_trial_hashes;
OmniboxFieldTrial::GetActiveSuggestFieldTrialHashes(&field_trial_hashes);
for (uint32_t trial : field_trial_hashes) {
if (field_trial_triggered_)
new_entry.mutable_field_trial_triggered()->Add(trial);
if (field_trial_triggered_in_session_)
new_entry.mutable_field_trial_triggered_in_session()->Add(trial);
}
}
}
void OmniboxPedalProvider::ResetSession() {
field_trial_triggered_in_session_ = false;
field_trial_triggered_ = false;
}
OmniboxPedal* OmniboxPedalProvider::FindPedalMatch( OmniboxPedal* OmniboxPedalProvider::FindPedalMatch(
const base::string16& match_text) const { const base::string16& match_text) {
OmniboxPedal::Tokens match_tokens = Tokenize(match_text); OmniboxPedal::Tokens match_tokens = Tokenize(match_text);
if (match_tokens.empty()) { if (match_tokens.empty()) {
return nullptr; return nullptr;
} }
// Some users may be in a counterfactual study arm in which the pedal button
// is not attached to the suggestion.
bool in_pedal_counterfactual_group = base::GetFieldTrialParamByFeatureAsBool(
omnibox::kOmniboxPedalSuggestions, "PedalSuggestionsCounterfactualArm",
false);
for (const auto& pedal : pedals_) { for (const auto& pedal : pedals_) {
if (pedal.second->IsTriggerMatch(match_tokens) && if (pedal.second->IsTriggerMatch(match_tokens) &&
pedal.second->IsReadyToTrigger(client_)) { pedal.second->IsReadyToTrigger(client_)) {
return pedal.second.get(); field_trial_triggered_ = true;
field_trial_triggered_in_session_ = true;
return in_pedal_counterfactual_group ? nullptr : pedal.second.get();
} }
} }
return nullptr; return nullptr;
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/strings/utf_offset_string_conversions.h" #include "base/strings/utf_offset_string_conversions.h"
#include "base/values.h" #include "base/values.h"
#include "components/omnibox/browser/autocomplete_provider.h"
#include "components/omnibox/browser/omnibox_pedal.h" #include "components/omnibox/browser/omnibox_pedal.h"
#include "components/omnibox/browser/omnibox_pedal_implementations.h" #include "components/omnibox/browser/omnibox_pedal_implementations.h"
...@@ -26,7 +27,20 @@ class OmniboxPedalProvider { ...@@ -26,7 +27,20 @@ class OmniboxPedalProvider {
// Returns the Pedal triggered by given |match_text| or nullptr if none // Returns the Pedal triggered by given |match_text| or nullptr if none
// trigger. // trigger.
OmniboxPedal* FindPedalMatch(const base::string16& match_text) const; OmniboxPedal* FindPedalMatch(const base::string16& match_text);
// "Fake" implementation of AutocompleteProvider AddProviderInfo, though this
// class is not a true subclass of AutocompleteProvider. This is used
// for logging and reporting for our field trial.
void AddProviderInfo(ProvidersInfo* provider_info) const;
// "Fake" implementation of AutocompleteProvider::ResetSession. Resets the
// field trial flags.
void ResetSession();
void set_field_trial_triggered(bool triggered) {
field_trial_triggered_ = triggered;
}
protected: protected:
FRIEND_TEST_ALL_PREFIXES(OmniboxPedalImplementationsTest, FRIEND_TEST_ALL_PREFIXES(OmniboxPedalImplementationsTest,
...@@ -69,6 +83,10 @@ class OmniboxPedalProvider { ...@@ -69,6 +83,10 @@ class OmniboxPedalProvider {
// This serves as an upper bound on the number of tokens we will accept from // This serves as an upper bound on the number of tokens we will accept from
// text before giving up and treating it as non-match for all Pedals. // text before giving up and treating it as non-match for all Pedals.
size_t max_tokens_ = 0; size_t max_tokens_ = 0;
// Whether a field trial has triggered for this query and this session
bool field_trial_triggered_ = false;
bool field_trial_triggered_in_session_ = false;
}; };
#endif // COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_PEDAL_PROVIDER_H_ #endif // COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_PEDAL_PROVIDER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment