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 "components/omnibox/browser/url_index_private_data.h" | 5 #include "components/omnibox/browser/url_index_private_data.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <functional> | 9 #include <functional> |
10 #include <iterator> | 10 #include <iterator> |
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 // construct a flat_set than to insert elements one by one. | 597 // construct a flat_set than to insert elements one by one. |
598 HistoryIDVector buffer; | 598 HistoryIDVector buffer; |
599 for (WordID word_id : word_id_set) { | 599 for (WordID word_id : word_id_set) { |
600 WordIDHistoryMap::iterator word_iter = word_id_history_map_.find(word_id); | 600 WordIDHistoryMap::iterator word_iter = word_id_history_map_.find(word_id); |
601 if (word_iter != word_id_history_map_.end()) { | 601 if (word_iter != word_id_history_map_.end()) { |
602 HistoryIDSet& word_history_id_set(word_iter->second); | 602 HistoryIDSet& word_history_id_set(word_iter->second); |
603 buffer.insert(buffer.end(), word_history_id_set.begin(), | 603 buffer.insert(buffer.end(), word_history_id_set.begin(), |
604 word_history_id_set.end()); | 604 word_history_id_set.end()); |
605 } | 605 } |
606 } | 606 } |
607 HistoryIDSet history_id_set(buffer.begin(), buffer.end()); | 607 HistoryIDSet history_id_set(buffer.begin(), buffer.end(), |
| 608 base::KEEP_FIRST_OF_DUPES); |
608 | 609 |
609 // Record a new cache entry for this word if the term is longer than | 610 // Record a new cache entry for this word if the term is longer than |
610 // a single character. | 611 // a single character. |
611 if (term_length > 1) | 612 if (term_length > 1) |
612 search_term_cache_[term] = SearchTermCacheItem(word_id_set, history_id_set); | 613 search_term_cache_[term] = SearchTermCacheItem(word_id_set, history_id_set); |
613 | 614 |
614 return history_id_set; | 615 return history_id_set; |
615 } | 616 } |
616 | 617 |
617 WordIDSet URLIndexPrivateData::WordIDSetForTermChars( | 618 WordIDSet URLIndexPrivateData::WordIDSetForTermChars( |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1087 if (actual_item_count == 0 || actual_item_count != expected_item_count) | 1088 if (actual_item_count == 0 || actual_item_count != expected_item_count) |
1088 return false; | 1089 return false; |
1089 | 1090 |
1090 for (const auto& entry : list_item.char_word_map_entry()) { | 1091 for (const auto& entry : list_item.char_word_map_entry()) { |
1091 expected_item_count = entry.item_count(); | 1092 expected_item_count = entry.item_count(); |
1092 actual_item_count = entry.word_id_size(); | 1093 actual_item_count = entry.word_id_size(); |
1093 if (actual_item_count == 0 || actual_item_count != expected_item_count) | 1094 if (actual_item_count == 0 || actual_item_count != expected_item_count) |
1094 return false; | 1095 return false; |
1095 base::char16 uni_char = static_cast<base::char16>(entry.char_16()); | 1096 base::char16 uni_char = static_cast<base::char16>(entry.char_16()); |
1096 const RepeatedField<int32_t>& word_ids = entry.word_id(); | 1097 const RepeatedField<int32_t>& word_ids = entry.word_id(); |
1097 char_word_map_[uni_char] = {word_ids.begin(), word_ids.end()}; | 1098 char_word_map_[uni_char] = |
| 1099 WordIDSet(word_ids.begin(), word_ids.end(), base::KEEP_FIRST_OF_DUPES); |
1098 } | 1100 } |
1099 return true; | 1101 return true; |
1100 } | 1102 } |
1101 | 1103 |
1102 bool URLIndexPrivateData::RestoreWordIDHistoryMap( | 1104 bool URLIndexPrivateData::RestoreWordIDHistoryMap( |
1103 const InMemoryURLIndexCacheItem& cache) { | 1105 const InMemoryURLIndexCacheItem& cache) { |
1104 if (!cache.has_word_id_history_map()) | 1106 if (!cache.has_word_id_history_map()) |
1105 return false; | 1107 return false; |
1106 const WordIDHistoryMapItem& list_item(cache.word_id_history_map()); | 1108 const WordIDHistoryMapItem& list_item(cache.word_id_history_map()); |
1107 uint32_t expected_item_count = list_item.item_count(); | 1109 uint32_t expected_item_count = list_item.item_count(); |
1108 uint32_t actual_item_count = list_item.word_id_history_map_entry_size(); | 1110 uint32_t actual_item_count = list_item.word_id_history_map_entry_size(); |
1109 if (actual_item_count == 0 || actual_item_count != expected_item_count) | 1111 if (actual_item_count == 0 || actual_item_count != expected_item_count) |
1110 return false; | 1112 return false; |
1111 for (const auto& entry : list_item.word_id_history_map_entry()) { | 1113 for (const auto& entry : list_item.word_id_history_map_entry()) { |
1112 expected_item_count = entry.item_count(); | 1114 expected_item_count = entry.item_count(); |
1113 actual_item_count = entry.history_id_size(); | 1115 actual_item_count = entry.history_id_size(); |
1114 if (actual_item_count == 0 || actual_item_count != expected_item_count) | 1116 if (actual_item_count == 0 || actual_item_count != expected_item_count) |
1115 return false; | 1117 return false; |
1116 WordID word_id = entry.word_id(); | 1118 WordID word_id = entry.word_id(); |
1117 const RepeatedField<int64_t>& history_ids = entry.history_id(); | 1119 const RepeatedField<int64_t>& history_ids = entry.history_id(); |
1118 word_id_history_map_[word_id] = {history_ids.begin(), history_ids.end()}; | 1120 word_id_history_map_[word_id] = HistoryIDSet( |
| 1121 history_ids.begin(), history_ids.end(), base::KEEP_FIRST_OF_DUPES); |
1119 for (HistoryID history_id : history_ids) | 1122 for (HistoryID history_id : history_ids) |
1120 history_id_word_map_[history_id].insert(word_id); | 1123 history_id_word_map_[history_id].insert(word_id); |
1121 } | 1124 } |
1122 return true; | 1125 return true; |
1123 } | 1126 } |
1124 | 1127 |
1125 bool URLIndexPrivateData::RestoreHistoryInfoMap( | 1128 bool URLIndexPrivateData::RestoreHistoryInfoMap( |
1126 const InMemoryURLIndexCacheItem& cache) { | 1129 const InMemoryURLIndexCacheItem& cache) { |
1127 if (!cache.has_history_info_map()) | 1130 if (!cache.has_history_info_map()) |
1128 return false; | 1131 return false; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1268 // First cut: typed count, visit count, recency. | 1271 // First cut: typed count, visit count, recency. |
1269 // TODO(mrossetti): This is too simplistic. Consider an approach which ranks | 1272 // TODO(mrossetti): This is too simplistic. Consider an approach which ranks |
1270 // recently visited (within the last 12/24 hours) as highly important. Get | 1273 // recently visited (within the last 12/24 hours) as highly important. Get |
1271 // input from mpearson. | 1274 // input from mpearson. |
1272 if (r1.typed_count() != r2.typed_count()) | 1275 if (r1.typed_count() != r2.typed_count()) |
1273 return (r1.typed_count() > r2.typed_count()); | 1276 return (r1.typed_count() > r2.typed_count()); |
1274 if (r1.visit_count() != r2.visit_count()) | 1277 if (r1.visit_count() != r2.visit_count()) |
1275 return (r1.visit_count() > r2.visit_count()); | 1278 return (r1.visit_count() > r2.visit_count()); |
1276 return (r1.last_visit() > r2.last_visit()); | 1279 return (r1.last_visit() > r2.last_visit()); |
1277 } | 1280 } |
OLD | NEW |