OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/bookmarks/bookmark_index.h" | 5 #include "chrome/browser/bookmarks/bookmark_index.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 #include <list> | 9 #include <list> |
10 | 10 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 Profile::EXPLICIT_ACCESS) : NULL; | 116 Profile::EXPLICIT_ACCESS) : NULL; |
117 | 117 |
118 history::URLDatabase* url_db = history_service ? | 118 history::URLDatabase* url_db = history_service ? |
119 history_service->InMemoryDatabase() : NULL; | 119 history_service->InMemoryDatabase() : NULL; |
120 | 120 |
121 for (Matches::const_iterator i = matches.begin(); i != matches.end(); ++i) | 121 for (Matches::const_iterator i = matches.begin(); i != matches.end(); ++i) |
122 ExtractBookmarkNodePairs(url_db, *i, node_typed_counts); | 122 ExtractBookmarkNodePairs(url_db, *i, node_typed_counts); |
123 | 123 |
124 std::sort(node_typed_counts->begin(), node_typed_counts->end(), | 124 std::sort(node_typed_counts->begin(), node_typed_counts->end(), |
125 &NodeTypedCountPairSortFunc); | 125 &NodeTypedCountPairSortFunc); |
| 126 // Eliminate duplicates. |
| 127 node_typed_counts->erase(std::unique(node_typed_counts->begin(), |
| 128 node_typed_counts->end()), |
| 129 node_typed_counts->end()); |
126 } | 130 } |
127 | 131 |
128 void BookmarkIndex::ExtractBookmarkNodePairs( | 132 void BookmarkIndex::ExtractBookmarkNodePairs( |
129 history::URLDatabase* url_db, | 133 history::URLDatabase* url_db, |
130 const Match& match, | 134 const Match& match, |
131 NodeTypedCountPairs* node_typed_counts) const { | 135 NodeTypedCountPairs* node_typed_counts) const { |
132 | 136 |
133 for (NodeSet::const_iterator i = match.nodes_begin(); | 137 for (NodeSet::const_iterator i = match.nodes_begin(); |
134 i != match.nodes_end(); ++i) { | 138 i != match.nodes_end(); ++i) { |
135 history::URLRow url; | 139 history::URLRow url; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 Index::iterator i = index_.find(term); | 270 Index::iterator i = index_.find(term); |
267 if (i == index_.end()) { | 271 if (i == index_.end()) { |
268 // We can get here if the node has the same term more than once. For | 272 // We can get here if the node has the same term more than once. For |
269 // example, a bookmark with the title 'foo foo' would end up here. | 273 // example, a bookmark with the title 'foo foo' would end up here. |
270 return; | 274 return; |
271 } | 275 } |
272 i->second.erase(node); | 276 i->second.erase(node); |
273 if (i->second.empty()) | 277 if (i->second.empty()) |
274 index_.erase(i); | 278 index_.erase(i); |
275 } | 279 } |
OLD | NEW |