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()); |
+} |