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

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

Issue 1877833002: Optimize shortcuts provider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added new files Created 4 years, 8 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/shortcut_match.cc
diff --git a/components/omnibox/browser/shortcut_match.cc b/components/omnibox/browser/shortcut_match.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4115e512cfc56f7c20190186ff3d3f132feb2f06
--- /dev/null
+++ b/components/omnibox/browser/shortcut_match.cc
@@ -0,0 +1,43 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
Peter Kasting 2016/04/12 00:55:08 Nit: Wrong copyright header (no (c))
Alexander Yashkin 2016/04/12 09:09:20 Done.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/omnibox/browser/shortcut_match.h"
+
+#include <algorithm>
+
+#include "components/omnibox/browser/match_compare.h"
+
+ShortcutMatch::ShortcutMatch(int relevance,
+ const GURL& stripped_destination_url,
+ const ShortcutsDatabase::Shortcut* shortcut) :
+ relevance(relevance),
+ stripped_destination_url(stripped_destination_url),
+ shortcut(shortcut),
+ contents(shortcut->match_core.contents),
+ type(static_cast<AutocompleteMatch::Type>(shortcut->match_core.type)) {}
+
+// static
+bool ShortcutMatch::DestinationsEqual(const ShortcutMatch& elem1,
+ const ShortcutMatch& elem2) {
+ if (elem1.stripped_destination_url.is_empty() &&
+ elem2.stripped_destination_url.is_empty())
+ return false;
+ return elem1.stripped_destination_url == elem2.stripped_destination_url;
+}
+
+// static
+void ShortcutMatch::DedupShortcutMatchesByDestination(
+ OmniboxEventProto::PageClassification page_classification,
+ std::vector<ShortcutMatch>* matches) {
+ DestinationSort<ShortcutMatch> destination_sort(page_classification);
+ // Sort matches such that duplicate matches are consecutive.
+ std::sort(matches->begin(), matches->end(), destination_sort);
+
+ // Erase duplicate matches.
+ matches->erase(
+ std::unique(matches->begin(),
+ matches->end(),
+ &ShortcutMatch::DestinationsEqual),
+ matches->end());
+}

Powered by Google App Engine
This is Rietveld 408576698