Commit 74d8ada0 authored by Travis Skare's avatar Travis Skare Committed by Commit Bot

[Omnibox] DocumentSuggest: Add counterfactual study support.

Bug: 889697
Change-Id: I6771c03f5448f83b385dc17a8526ab958378f5bf
Reviewed-on: https://chromium-review.googlesource.com/c/1247524
Commit-Queue: Travis Skare <skare@chromium.org>
Reviewed-by: default avatarJustin Donnelly <jdonnelly@chromium.org>
Reviewed-by: default avatarMark Pearson <mpearson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#625757}
parent 051153e8
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include <vector>
#include "base/callback.h" #include "base/callback.h"
#include "base/feature_list.h" #include "base/feature_list.h"
...@@ -177,6 +178,7 @@ void DocumentProvider::Start(const AutocompleteInput& input, ...@@ -177,6 +178,7 @@ void DocumentProvider::Start(const AutocompleteInput& input,
bool minimal_changes) { bool minimal_changes) {
TRACE_EVENT0("omnibox", "DocumentProvider::Start"); TRACE_EVENT0("omnibox", "DocumentProvider::Start");
matches_.clear(); matches_.clear();
field_trial_triggered_ = false;
// Perform various checks - feature is enabled, user is allowed to use the // Perform various checks - feature is enabled, user is allowed to use the
// feature, we're not under backoff, etc. // feature, we're not under backoff, etc.
...@@ -247,14 +249,35 @@ void DocumentProvider::DeleteMatch(const AutocompleteMatch& match) { ...@@ -247,14 +249,35 @@ void DocumentProvider::DeleteMatch(const AutocompleteMatch& match) {
} }
void DocumentProvider::AddProviderInfo(ProvidersInfo* provider_info) const { void DocumentProvider::AddProviderInfo(ProvidersInfo* provider_info) const {
// TODO(skare): Verify that we don't lose metrics based on what provider_info->push_back(metrics::OmniboxEventProto_ProviderInfo());
// zero_suggest_provider and BaseSearchProvider add. metrics::OmniboxEventProto_ProviderInfo& new_entry = provider_info->back();
return; new_entry.set_provider(metrics::OmniboxEventProto::DOCUMENT);
new_entry.set_provider_done(done_);
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 DocumentProvider::ResetSession() {
field_trial_triggered_in_session_ = false;
field_trial_triggered_ = false;
} }
DocumentProvider::DocumentProvider(AutocompleteProviderClient* client, DocumentProvider::DocumentProvider(AutocompleteProviderClient* client,
AutocompleteProviderListener* listener) AutocompleteProviderListener* listener)
: AutocompleteProvider(AutocompleteProvider::TYPE_DOCUMENT), : AutocompleteProvider(AutocompleteProvider::TYPE_DOCUMENT),
field_trial_triggered_(false),
field_trial_triggered_in_session_(false),
backoff_for_session_(false), backoff_for_session_(false),
client_(client), client_(client),
listener_(listener), listener_(listener),
...@@ -372,6 +395,11 @@ bool DocumentProvider::ParseDocumentSearchResults(const base::Value& root_val, ...@@ -372,6 +395,11 @@ bool DocumentProvider::ParseDocumentSearchResults(const base::Value& root_val,
int score2 = base::GetFieldTrialParamByFeatureAsInt( int score2 = base::GetFieldTrialParamByFeatureAsInt(
omnibox::kDocumentProvider, "DocumentScoreResult3", 300); omnibox::kDocumentProvider, "DocumentScoreResult3", 300);
// Some users may be in a counterfactual study arm in which we perform all
// necessary work but do not forward the autocomplete matches.
bool in_counterfactual_group = base::GetFieldTrialParamByFeatureAsBool(
omnibox::kDocumentProvider, "DocumentProviderCounterfactualArm", false);
// Clear the previous results now that new results are available. // Clear the previous results now that new results are available.
matches->clear(); matches->clear();
for (size_t i = 0; i < num_results; i++) { for (size_t i = 0; i < num_results; i++) {
...@@ -450,7 +478,11 @@ bool DocumentProvider::ParseDocumentSearchResults(const base::Value& root_val, ...@@ -450,7 +478,11 @@ bool DocumentProvider::ParseDocumentSearchResults(const base::Value& root_val,
&match.description_class, 0, ACMatchClassification::NONE); &match.description_class, 0, ACMatchClassification::NONE);
} }
match.transition = ui::PAGE_TRANSITION_GENERATED; match.transition = ui::PAGE_TRANSITION_GENERATED;
if (!in_counterfactual_group) {
matches->push_back(match); matches->push_back(match);
} }
field_trial_triggered_ = true;
field_trial_triggered_in_session_ = true;
}
return true; return true;
} }
...@@ -49,6 +49,7 @@ class DocumentProvider : public AutocompleteProvider { ...@@ -49,6 +49,7 @@ class DocumentProvider : public AutocompleteProvider {
void Stop(bool clear_cached_results, bool due_to_user_inactivity) override; void Stop(bool clear_cached_results, bool due_to_user_inactivity) override;
void DeleteMatch(const AutocompleteMatch& match) override; void DeleteMatch(const AutocompleteMatch& match) override;
void AddProviderInfo(ProvidersInfo* provider_info) const override; void AddProviderInfo(ProvidersInfo* provider_info) const override;
void ResetSession() override;
// Registers a client-side preference to enable document suggestions. // Registers a client-side preference to enable document suggestions.
static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
...@@ -112,6 +113,12 @@ class DocumentProvider : public AutocompleteProvider { ...@@ -112,6 +113,12 @@ class DocumentProvider : public AutocompleteProvider {
const std::string& modified_timestamp_string, const std::string& modified_timestamp_string,
base::Time now); base::Time now);
// Whether a field trial has triggered for this query and this session,
// respectively. Works similarly to BaseSearchProvider, though this class does
// not inherit from it.
bool field_trial_triggered_;
bool field_trial_triggered_in_session_;
// Whether the server has instructed us to backoff for this session (in // Whether the server has instructed us to backoff for this session (in
// cases where the corpus is uninteresting). // cases where the corpus is uninteresting).
bool backoff_for_session_; bool backoff_for_session_;
......
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