| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/bookmarks/browser/typed_count_sorter.h" | 5 #include "components/bookmarks/browser/typed_count_sorter.h" |
| 6 | 6 |
| 7 #include "components/bookmarks/browser/bookmark_client.h" | 7 #include "components/bookmarks/browser/bookmark_client.h" |
| 8 | 8 |
| 9 namespace bookmarks { | 9 namespace bookmarks { |
| 10 | 10 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 } | 49 } |
| 50 | 50 |
| 51 TypedCountSorter::~TypedCountSorter() {} | 51 TypedCountSorter::~TypedCountSorter() {} |
| 52 | 52 |
| 53 void TypedCountSorter::SortMatches(const TitledUrlNodeSet& matches, | 53 void TypedCountSorter::SortMatches(const TitledUrlNodeSet& matches, |
| 54 TitledUrlNodes* sorted_nodes) const { | 54 TitledUrlNodes* sorted_nodes) const { |
| 55 sorted_nodes->reserve(matches.size()); | 55 sorted_nodes->reserve(matches.size()); |
| 56 if (client_->SupportsTypedCountForUrls()) { | 56 if (client_->SupportsTypedCountForUrls()) { |
| 57 UrlNodeMap url_node_map; | 57 UrlNodeMap url_node_map; |
| 58 UrlTypedCountMap url_typed_count_map; | 58 UrlTypedCountMap url_typed_count_map; |
| 59 for (auto node : matches) { | 59 for (auto* node : matches) { |
| 60 const GURL& url = node->GetTitledUrlNodeUrl(); | 60 const GURL& url = node->GetTitledUrlNodeUrl(); |
| 61 url_node_map.insert(std::make_pair(&url, node)); | 61 url_node_map.insert(std::make_pair(&url, node)); |
| 62 url_typed_count_map.insert(std::make_pair(&url, 0)); | 62 url_typed_count_map.insert(std::make_pair(&url, 0)); |
| 63 } | 63 } |
| 64 | 64 |
| 65 client_->GetTypedCountForUrls(&url_typed_count_map); | 65 client_->GetTypedCountForUrls(&url_typed_count_map); |
| 66 | 66 |
| 67 UrlTypedCountPairs url_typed_counts; | 67 UrlTypedCountPairs url_typed_counts; |
| 68 std::copy(url_typed_count_map.begin(), | 68 std::copy(url_typed_count_map.begin(), |
| 69 url_typed_count_map.end(), | 69 url_typed_count_map.end(), |
| 70 std::back_inserter(url_typed_counts)); | 70 std::back_inserter(url_typed_counts)); |
| 71 std::sort(url_typed_counts.begin(), | 71 std::sort(url_typed_counts.begin(), |
| 72 url_typed_counts.end(), | 72 url_typed_counts.end(), |
| 73 UrlTypedCountPairSortFunctor()); | 73 UrlTypedCountPairSortFunctor()); |
| 74 std::transform(url_typed_counts.begin(), | 74 std::transform(url_typed_counts.begin(), |
| 75 url_typed_counts.end(), | 75 url_typed_counts.end(), |
| 76 std::back_inserter(*sorted_nodes), | 76 std::back_inserter(*sorted_nodes), |
| 77 UrlTypedCountPairNodeLookupFunctor(url_node_map)); | 77 UrlTypedCountPairNodeLookupFunctor(url_node_map)); |
| 78 } else { | 78 } else { |
| 79 sorted_nodes->insert(sorted_nodes->end(), matches.begin(), matches.end()); | 79 sorted_nodes->insert(sorted_nodes->end(), matches.begin(), matches.end()); |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 | 82 |
| 83 } // namespace bookmarks | 83 } // namespace bookmarks |
| OLD | NEW |