Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(488)

Side by Side Diff: components/omnibox/browser/url_index_private_data.cc

Issue 2776793002: Make flat containers stable, allow constructing from vector. (Closed)
Patch Set: Put back media log change lost in merge Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/omnibox/browser/in_memory_url_index_types.cc ('k') | media/base/media_log.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 // construct a flat_set than to insert elements one by one. 592 // construct a flat_set than to insert elements one by one.
593 HistoryIDVector buffer; 593 HistoryIDVector buffer;
594 for (WordID word_id : word_id_set) { 594 for (WordID word_id : word_id_set) {
595 WordIDHistoryMap::iterator word_iter = word_id_history_map_.find(word_id); 595 WordIDHistoryMap::iterator word_iter = word_id_history_map_.find(word_id);
596 if (word_iter != word_id_history_map_.end()) { 596 if (word_iter != word_id_history_map_.end()) {
597 HistoryIDSet& word_history_id_set(word_iter->second); 597 HistoryIDSet& word_history_id_set(word_iter->second);
598 buffer.insert(buffer.end(), word_history_id_set.begin(), 598 buffer.insert(buffer.end(), word_history_id_set.begin(),
599 word_history_id_set.end()); 599 word_history_id_set.end());
600 } 600 }
601 } 601 }
602 HistoryIDSet history_id_set(buffer.begin(), buffer.end()); 602 HistoryIDSet history_id_set(buffer.begin(), buffer.end(),
603 base::KEEP_FIRST_OF_DUPES);
603 604
604 // Record a new cache entry for this word if the term is longer than 605 // Record a new cache entry for this word if the term is longer than
605 // a single character. 606 // a single character.
606 if (term_length > 1) 607 if (term_length > 1)
607 search_term_cache_[term] = SearchTermCacheItem(word_id_set, history_id_set); 608 search_term_cache_[term] = SearchTermCacheItem(word_id_set, history_id_set);
608 609
609 return history_id_set; 610 return history_id_set;
610 } 611 }
611 612
612 WordIDSet URLIndexPrivateData::WordIDSetForTermChars( 613 WordIDSet URLIndexPrivateData::WordIDSetForTermChars(
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 if (actual_item_count == 0 || actual_item_count != expected_item_count) 1083 if (actual_item_count == 0 || actual_item_count != expected_item_count)
1083 return false; 1084 return false;
1084 1085
1085 for (const auto& entry : list_item.char_word_map_entry()) { 1086 for (const auto& entry : list_item.char_word_map_entry()) {
1086 expected_item_count = entry.item_count(); 1087 expected_item_count = entry.item_count();
1087 actual_item_count = entry.word_id_size(); 1088 actual_item_count = entry.word_id_size();
1088 if (actual_item_count == 0 || actual_item_count != expected_item_count) 1089 if (actual_item_count == 0 || actual_item_count != expected_item_count)
1089 return false; 1090 return false;
1090 base::char16 uni_char = static_cast<base::char16>(entry.char_16()); 1091 base::char16 uni_char = static_cast<base::char16>(entry.char_16());
1091 const RepeatedField<int32_t>& word_ids = entry.word_id(); 1092 const RepeatedField<int32_t>& word_ids = entry.word_id();
1092 char_word_map_[uni_char] = {word_ids.begin(), word_ids.end()}; 1093 char_word_map_[uni_char] =
1094 WordIDSet(word_ids.begin(), word_ids.end(), base::KEEP_FIRST_OF_DUPES);
1093 } 1095 }
1094 return true; 1096 return true;
1095 } 1097 }
1096 1098
1097 bool URLIndexPrivateData::RestoreWordIDHistoryMap( 1099 bool URLIndexPrivateData::RestoreWordIDHistoryMap(
1098 const InMemoryURLIndexCacheItem& cache) { 1100 const InMemoryURLIndexCacheItem& cache) {
1099 if (!cache.has_word_id_history_map()) 1101 if (!cache.has_word_id_history_map())
1100 return false; 1102 return false;
1101 const WordIDHistoryMapItem& list_item(cache.word_id_history_map()); 1103 const WordIDHistoryMapItem& list_item(cache.word_id_history_map());
1102 uint32_t expected_item_count = list_item.item_count(); 1104 uint32_t expected_item_count = list_item.item_count();
1103 uint32_t actual_item_count = list_item.word_id_history_map_entry_size(); 1105 uint32_t actual_item_count = list_item.word_id_history_map_entry_size();
1104 if (actual_item_count == 0 || actual_item_count != expected_item_count) 1106 if (actual_item_count == 0 || actual_item_count != expected_item_count)
1105 return false; 1107 return false;
1106 for (const auto& entry : list_item.word_id_history_map_entry()) { 1108 for (const auto& entry : list_item.word_id_history_map_entry()) {
1107 expected_item_count = entry.item_count(); 1109 expected_item_count = entry.item_count();
1108 actual_item_count = entry.history_id_size(); 1110 actual_item_count = entry.history_id_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 WordID word_id = entry.word_id(); 1113 WordID word_id = entry.word_id();
1112 const RepeatedField<int64_t>& history_ids = entry.history_id(); 1114 const RepeatedField<int64_t>& history_ids = entry.history_id();
1113 word_id_history_map_[word_id] = {history_ids.begin(), history_ids.end()}; 1115 word_id_history_map_[word_id] = HistoryIDSet(
1116 history_ids.begin(), history_ids.end(), base::KEEP_FIRST_OF_DUPES);
1114 for (HistoryID history_id : history_ids) 1117 for (HistoryID history_id : history_ids)
1115 history_id_word_map_[history_id].insert(word_id); 1118 history_id_word_map_[history_id].insert(word_id);
1116 } 1119 }
1117 return true; 1120 return true;
1118 } 1121 }
1119 1122
1120 bool URLIndexPrivateData::RestoreHistoryInfoMap( 1123 bool URLIndexPrivateData::RestoreHistoryInfoMap(
1121 const InMemoryURLIndexCacheItem& cache) { 1124 const InMemoryURLIndexCacheItem& cache) {
1122 if (!cache.has_history_info_map()) 1125 if (!cache.has_history_info_map())
1123 return false; 1126 return false;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1263 // First cut: typed count, visit count, recency. 1266 // First cut: typed count, visit count, recency.
1264 // TODO(mrossetti): This is too simplistic. Consider an approach which ranks 1267 // TODO(mrossetti): This is too simplistic. Consider an approach which ranks
1265 // recently visited (within the last 12/24 hours) as highly important. Get 1268 // recently visited (within the last 12/24 hours) as highly important. Get
1266 // input from mpearson. 1269 // input from mpearson.
1267 if (r1.typed_count() != r2.typed_count()) 1270 if (r1.typed_count() != r2.typed_count())
1268 return (r1.typed_count() > r2.typed_count()); 1271 return (r1.typed_count() > r2.typed_count());
1269 if (r1.visit_count() != r2.visit_count()) 1272 if (r1.visit_count() != r2.visit_count())
1270 return (r1.visit_count() > r2.visit_count()); 1273 return (r1.visit_count() > r2.visit_count());
1271 return (r1.last_visit() > r2.last_visit()); 1274 return (r1.last_visit() > r2.last_visit());
1272 } 1275 }
OLDNEW
« no previous file with comments | « components/omnibox/browser/in_memory_url_index_types.cc ('k') | media/base/media_log.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698