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

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

Issue 2266083002: Avoid DCHECK failure for chrome:// URLs in autocomplete suggestions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add missing default match check Created 4 years, 4 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/physical_web_provider.cc
diff --git a/components/omnibox/browser/physical_web_provider.cc b/components/omnibox/browser/physical_web_provider.cc
index 1161fe2079667b1d4723dafd8fea7b5678aa8c63..be64a23ebf4aa055e60a9c36cf753dbea5d25193 100644
--- a/components/omnibox/browser/physical_web_provider.cc
+++ b/components/omnibox/browser/physical_web_provider.cc
@@ -7,7 +7,9 @@
#include "base/values.h"
#include "components/omnibox/browser/autocomplete_provider_client.h"
#include "components/omnibox/browser/autocomplete_provider_listener.h"
+#include "components/omnibox/browser/history_url_provider.h"
#include "components/omnibox/browser/physical_web_provider.h"
+#include "components/omnibox/browser/verbatim_match.h"
#include "components/physical_web/data_source/physical_web_data_source.h"
#include "components/url_formatter/url_formatter.h"
#include "grit/components_strings.h"
@@ -38,8 +40,9 @@ static const int kPhysicalWebUrlBaseRelevance = 700;
// static
PhysicalWebProvider* PhysicalWebProvider::Create(
- AutocompleteProviderClient* client) {
- return new PhysicalWebProvider(client);
+ AutocompleteProviderClient* client,
+ HistoryURLProvider* history_url_provider) {
+ return new PhysicalWebProvider(client, history_url_provider);
}
void PhysicalWebProvider::Start(const AutocompleteInput& input,
@@ -65,6 +68,14 @@ void PhysicalWebProvider::Start(const AutocompleteInput& input,
ConstructMatches(data_source->GetMetadata().get());
+ // If the omnibox is not empty, add a default verbatim match.
Mark P 2016/08/31 22:39:33 Perhaps revise the first sentence to something lik
+ // This match will be opened when the user presses "Enter".
+ if (!matches_.empty() && !input.text().empty()) {
mattreynolds 2016/08/31 22:06:48 bugfix: we should only add the verbatim match if w
Mark P 2016/08/31 22:39:33 Acknowledged. Good catch.
+ AutocompleteMatch verbatim_match = VerbatimMatchForURL(
+ client_, input, input.current_url(), history_url_provider_, -1);
+ matches_.push_back(verbatim_match);
+ }
+
done_ = true;
}
@@ -73,9 +84,12 @@ void PhysicalWebProvider::Stop(bool clear_cached_results,
done_ = true;
}
-PhysicalWebProvider::PhysicalWebProvider(AutocompleteProviderClient* client)
+PhysicalWebProvider::PhysicalWebProvider(
+ AutocompleteProviderClient* client,
+ HistoryURLProvider* history_url_provider)
: AutocompleteProvider(AutocompleteProvider::TYPE_PHYSICAL_WEB),
- client_(client) {
+ client_(client),
+ history_url_provider_(history_url_provider) {
}
PhysicalWebProvider::~PhysicalWebProvider() {
@@ -83,6 +97,7 @@ PhysicalWebProvider::~PhysicalWebProvider() {
void PhysicalWebProvider::ConstructMatches(base::ListValue* metadata_list) {
const size_t metadata_count = metadata_list->GetSize();
+ size_t used_slots = 0;
for (size_t i = 0; i < metadata_count; ++i) {
base::DictionaryValue* metadata_item = NULL;
@@ -99,11 +114,11 @@ void PhysicalWebProvider::ConstructMatches(base::ListValue* metadata_list) {
// Add match items with decreasing relevance to preserve the ordering in
// the metadata list.
- int relevance = kPhysicalWebUrlBaseRelevance - matches_.size();
+ int relevance = kPhysicalWebUrlBaseRelevance - used_slots;
// Append an overflow item if creating a match for each metadata item would
// exceed the match limit.
- const size_t remaining_slots = kPhysicalWebMaxMatches - matches_.size();
+ const size_t remaining_slots = kPhysicalWebMaxMatches - used_slots;
const size_t remaining_metadata = metadata_count - i;
if ((remaining_slots == 1) && (remaining_metadata > remaining_slots)) {
AppendOverflowItem(remaining_metadata, relevance);
@@ -133,9 +148,8 @@ void PhysicalWebProvider::ConstructMatches(base::ListValue* metadata_list) {
match.description_class.push_back(
ACMatchClassification(0, ACMatchClassification::NONE));
- match.allowed_to_be_default_match = matches_.empty();
-
matches_.push_back(match);
+ ++used_slots;
}
}
@@ -164,7 +178,5 @@ void PhysicalWebProvider::AppendOverflowItem(int additional_url_count,
match.description_class.push_back(
ACMatchClassification(0, ACMatchClassification::NONE));
- match.allowed_to_be_default_match = matches_.empty();
-
matches_.push_back(match);
}

Powered by Google App Engine
This is Rietveld 408576698