Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // 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.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/omnibox/browser/shortcut_match.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 | |
| 9 #include "components/omnibox/browser/match_compare.h" | |
| 10 | |
| 11 ShortcutMatch::ShortcutMatch(int relevance, | |
| 12 const GURL& stripped_destination_url, | |
| 13 const ShortcutsDatabase::Shortcut* shortcut) : | |
| 14 relevance(relevance), | |
| 15 stripped_destination_url(stripped_destination_url), | |
| 16 shortcut(shortcut), | |
| 17 contents(shortcut->match_core.contents), | |
| 18 type(static_cast<AutocompleteMatch::Type>(shortcut->match_core.type)) {} | |
| 19 | |
| 20 // static | |
| 21 bool ShortcutMatch::DestinationsEqual(const ShortcutMatch& elem1, | |
| 22 const ShortcutMatch& elem2) { | |
| 23 if (elem1.stripped_destination_url.is_empty() && | |
| 24 elem2.stripped_destination_url.is_empty()) | |
| 25 return false; | |
| 26 return elem1.stripped_destination_url == elem2.stripped_destination_url; | |
| 27 } | |
| 28 | |
| 29 // static | |
| 30 void ShortcutMatch::DedupShortcutMatchesByDestination( | |
| 31 OmniboxEventProto::PageClassification page_classification, | |
| 32 std::vector<ShortcutMatch>* matches) { | |
| 33 DestinationSort<ShortcutMatch> destination_sort(page_classification); | |
| 34 // Sort matches such that duplicate matches are consecutive. | |
| 35 std::sort(matches->begin(), matches->end(), destination_sort); | |
| 36 | |
| 37 // Erase duplicate matches. | |
| 38 matches->erase( | |
| 39 std::unique(matches->begin(), | |
| 40 matches->end(), | |
| 41 &ShortcutMatch::DestinationsEqual), | |
| 42 matches->end()); | |
| 43 } | |
| OLD | NEW |