| Index: components/omnibox/browser/physical_web_provider.cc
|
| diff --git a/components/omnibox/browser/physical_web_provider.cc b/components/omnibox/browser/physical_web_provider.cc
|
| index 15ba262ab3d8c5e8acbdcc15a9a85de3dc69ab47..c177310b252c740a995398ae1708f87aa93c9963 100644
|
| --- a/components/omnibox/browser/physical_web_provider.cc
|
| +++ b/components/omnibox/browser/physical_web_provider.cc
|
| @@ -56,14 +56,18 @@ void PhysicalWebProvider::Start(const AutocompleteInput& input,
|
| done_ = false;
|
| matches_.clear();
|
|
|
| + const bool input_from_focus = input.from_omnibox_focus();
|
| +
|
| had_physical_web_suggestions_ = false;
|
| - if (input.from_omnibox_focus())
|
| - had_physical_web_suggestions_at_focus_or_later_ = false;
|
| + if (input_from_focus) {
|
| + BeginOmniboxSession();
|
| + }
|
|
|
| // Don't provide suggestions in incognito mode.
|
| if (client_->IsOffTheRecord()) {
|
| done_ = true;
|
| nearby_url_count_ = 0;
|
| + nearby_url_count_at_focus_ = 0;
|
| return;
|
| }
|
|
|
| @@ -72,14 +76,20 @@ void PhysicalWebProvider::Start(const AutocompleteInput& input,
|
| if (!data_source) {
|
| done_ = true;
|
| nearby_url_count_ = 0;
|
| + nearby_url_count_at_focus_ = 0;
|
| return;
|
| }
|
|
|
| - const bool input_from_focus = input.from_omnibox_focus();
|
| + auto metadata_list = data_source->GetMetadataList();
|
| + nearby_url_count_ = metadata_list->size();
|
| + if (input_from_focus) {
|
| + nearby_url_count_at_focus_ = nearby_url_count_;
|
| + }
|
| +
|
| const bool empty_input_from_user = !input_from_focus && input.text().empty();
|
|
|
| if (input_from_focus || empty_input_from_user) {
|
| - ConstructZeroSuggestMatches(data_source->GetMetadataList());
|
| + ConstructZeroSuggestMatches(std::move(metadata_list));
|
|
|
| if (!matches_.empty()) {
|
| had_physical_web_suggestions_ = true;
|
| @@ -105,7 +115,7 @@ void PhysicalWebProvider::Start(const AutocompleteInput& input,
|
| client_, input, input.current_url(), history_url_provider_, -1));
|
| }
|
| } else {
|
| - ConstructQuerySuggestMatches(data_source->GetMetadataList(), input);
|
| + ConstructQuerySuggestMatches(std::move(metadata_list), input);
|
|
|
| if (!matches_.empty()) {
|
| had_physical_web_suggestions_ = true;
|
| @@ -150,6 +160,11 @@ void PhysicalWebProvider::AddProviderInfo(ProvidersInfo* provider_info) const {
|
| // nearby Physical Web URLs at the time the provider last constructed matches.
|
| UMA_HISTOGRAM_EXACT_LINEAR("Omnibox.SuggestionUsed.NearbyURLCount",
|
| nearby_url_count_, 50);
|
| +
|
| + // When the user accepts an autocomplete suggestion, record the number of
|
| + // nearby Physical Web URLs at the time the omnibox input was last focused.
|
| + UMA_HISTOGRAM_EXACT_LINEAR("Omnibox.SuggestionUsed.NearbyURLCount.AtFocus",
|
| + nearby_url_count_at_focus_, 50);
|
| }
|
|
|
| PhysicalWebProvider::PhysicalWebProvider(
|
| @@ -158,6 +173,8 @@ PhysicalWebProvider::PhysicalWebProvider(
|
| : AutocompleteProvider(AutocompleteProvider::TYPE_PHYSICAL_WEB),
|
| client_(client),
|
| history_url_provider_(history_url_provider),
|
| + nearby_url_count_(0),
|
| + nearby_url_count_at_focus_(0),
|
| zero_suggest_enabled_(
|
| OmniboxFieldTrial::InPhysicalWebZeroSuggestFieldTrial()),
|
| after_typing_enabled_(
|
| @@ -165,17 +182,26 @@ PhysicalWebProvider::PhysicalWebProvider(
|
| zero_suggest_base_relevance_(
|
| OmniboxFieldTrial::GetPhysicalWebZeroSuggestBaseRelevance()),
|
| after_typing_base_relevance_(
|
| - OmniboxFieldTrial::GetPhysicalWebAfterTypingBaseRelevance()) {}
|
| + OmniboxFieldTrial::GetPhysicalWebAfterTypingBaseRelevance()),
|
| + had_physical_web_suggestions_(false),
|
| + had_physical_web_suggestions_at_focus_or_later_(false) {}
|
|
|
| PhysicalWebProvider::~PhysicalWebProvider() {
|
| }
|
|
|
| +void PhysicalWebProvider::BeginOmniboxSession() {
|
| + // Some metrics are tracked per-session and must be reset each time a new
|
| + // session begins. Per-session metrics are recorded in AddProviderInfo.
|
| + nearby_url_count_at_focus_ = 0;
|
| + had_physical_web_suggestions_at_focus_or_later_ = false;
|
| +}
|
| +
|
| void PhysicalWebProvider::ConstructZeroSuggestMatches(
|
| std::unique_ptr<physical_web::MetadataList> metadata_list) {
|
| - nearby_url_count_ = metadata_list->size();
|
| + size_t nearby_url_count = metadata_list->size();
|
| size_t used_slots = 0;
|
|
|
| - for (size_t i = 0; i < nearby_url_count_; ++i) {
|
| + for (size_t i = 0; i < nearby_url_count; ++i) {
|
| const auto& metadata_item = (*metadata_list)[i];
|
| std::string url_string = metadata_item.resolved_url.spec();
|
| std::string title_string = metadata_item.title;
|
| @@ -189,7 +215,7 @@ void PhysicalWebProvider::ConstructZeroSuggestMatches(
|
| // Append an overflow item if creating a match for each metadata item would
|
| // exceed the match limit.
|
| const size_t remaining_slots = kPhysicalWebMaxMatches - used_slots;
|
| - const size_t remaining_metadata = nearby_url_count_ - i;
|
| + const size_t remaining_metadata = nearby_url_count - i;
|
| if ((remaining_slots == 1) && (remaining_metadata > remaining_slots)) {
|
| AppendOverflowItem(remaining_metadata, relevance, title);
|
| break;
|
|
|