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

Side by Side Diff: chrome/browser/history/url_index_private_data.cc

Issue 285233012: Abstract history dependencies on bookmarks through HistoryClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addresss comments & rebase Created 6 years, 6 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
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 "chrome/browser/history/url_index_private_data.h" 5 #include "chrome/browser/history/url_index_private_data.h"
6 6
7 #include <functional> 7 #include <functional>
8 #include <iterator> 8 #include <iterator>
9 #include <limits> 9 #include <limits>
10 #include <numeric> 10 #include <numeric>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/basictypes.h" 14 #include "base/basictypes.h"
15 #include "base/file_util.h" 15 #include "base/file_util.h"
16 #include "base/i18n/break_iterator.h" 16 #include "base/i18n/break_iterator.h"
17 #include "base/i18n/case_conversion.h" 17 #include "base/i18n/case_conversion.h"
18 #include "base/metrics/histogram.h" 18 #include "base/metrics/histogram.h"
19 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
20 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
21 #include "base/time/time.h" 21 #include "base/time/time.h"
22 #include "chrome/browser/history/history_database.h" 22 #include "chrome/browser/history/history_database.h"
23 #include "chrome/browser/history/history_db_task.h" 23 #include "chrome/browser/history/history_db_task.h"
24 #include "chrome/browser/history/history_service.h" 24 #include "chrome/browser/history/history_service.h"
25 #include "chrome/browser/history/in_memory_url_index.h" 25 #include "chrome/browser/history/in_memory_url_index.h"
26 #include "components/bookmarks/browser/bookmark_service.h"
27 #include "components/bookmarks/browser/bookmark_utils.h" 26 #include "components/bookmarks/browser/bookmark_utils.h"
27 #include "components/history/core/browser/history_client.h"
28 #include "net/base/net_util.h" 28 #include "net/base/net_util.h"
29 29
30 #if defined(USE_SYSTEM_PROTOBUF) 30 #if defined(USE_SYSTEM_PROTOBUF)
31 #include <google/protobuf/repeated_field.h> 31 #include <google/protobuf/repeated_field.h>
32 #else 32 #else
33 #include "third_party/protobuf/src/google/protobuf/repeated_field.h" 33 #include "third_party/protobuf/src/google/protobuf/repeated_field.h"
34 #endif 34 #endif
35 35
36 using google::protobuf::RepeatedField; 36 using google::protobuf::RepeatedField;
37 using google::protobuf::RepeatedPtrField; 37 using google::protobuf::RepeatedPtrField;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 pre_filter_item_count_(0), 144 pre_filter_item_count_(0),
145 post_filter_item_count_(0), 145 post_filter_item_count_(0),
146 post_scoring_item_count_(0) { 146 post_scoring_item_count_(0) {
147 } 147 }
148 148
149 ScoredHistoryMatches URLIndexPrivateData::HistoryItemsForTerms( 149 ScoredHistoryMatches URLIndexPrivateData::HistoryItemsForTerms(
150 base::string16 search_string, 150 base::string16 search_string,
151 size_t cursor_position, 151 size_t cursor_position,
152 size_t max_matches, 152 size_t max_matches,
153 const std::string& languages, 153 const std::string& languages,
154 BookmarkService* bookmark_service) { 154 HistoryClient* history_client) {
155 // If cursor position is set and useful (not at either end of the 155 // If cursor position is set and useful (not at either end of the
156 // string), allow the search string to be broken at cursor position. 156 // string), allow the search string to be broken at cursor position.
157 // We do this by pretending there's a space where the cursor is. 157 // We do this by pretending there's a space where the cursor is.
158 if ((cursor_position != base::string16::npos) && 158 if ((cursor_position != base::string16::npos) &&
159 (cursor_position < search_string.length()) && 159 (cursor_position < search_string.length()) &&
160 (cursor_position > 0)) { 160 (cursor_position > 0)) {
161 search_string.insert(cursor_position, base::ASCIIToUTF16(" ")); 161 search_string.insert(cursor_position, base::ASCIIToUTF16(" "));
162 } 162 }
163 pre_filter_item_count_ = 0; 163 pre_filter_item_count_ = 0;
164 post_filter_item_count_ = 0; 164 post_filter_item_count_ = 0;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 // Don't score matches when there are no terms to score against. (It's 236 // Don't score matches when there are no terms to score against. (It's
237 // possible that the word break iterater that extracts words to search 237 // possible that the word break iterater that extracts words to search
238 // for in the database allows some whitespace "words" whereas Tokenize 238 // for in the database allows some whitespace "words" whereas Tokenize
239 // excludes a long list of whitespace.) One could write a scoring 239 // excludes a long list of whitespace.) One could write a scoring
240 // function that gives a reasonable order to matches when there 240 // function that gives a reasonable order to matches when there
241 // are no terms (i.e., all the words are some form of whitespace), 241 // are no terms (i.e., all the words are some form of whitespace),
242 // but this is such a rare edge case that it's not worth the time. 242 // but this is such a rare edge case that it's not worth the time.
243 return scored_items; 243 return scored_items;
244 } 244 }
245 scored_items = std::for_each(history_id_set.begin(), history_id_set.end(), 245 scored_items = std::for_each(history_id_set.begin(), history_id_set.end(),
246 AddHistoryMatch(*this, languages, bookmark_service, lower_raw_string, 246 AddHistoryMatch(*this, languages, history_client, lower_raw_string,
247 lower_raw_terms, base::Time::Now())).ScoredMatches(); 247 lower_raw_terms, base::Time::Now())).ScoredMatches();
248 248
249 // Select and sort only the top |max_matches| results. 249 // Select and sort only the top |max_matches| results.
250 if (scored_items.size() > max_matches) { 250 if (scored_items.size() > max_matches) {
251 std::partial_sort(scored_items.begin(), 251 std::partial_sort(scored_items.begin(),
252 scored_items.begin() + 252 scored_items.begin() +
253 max_matches, 253 max_matches,
254 scored_items.end(), 254 scored_items.end(),
255 ScoredHistoryMatch::MatchScoreGreater); 255 ScoredHistoryMatch::MatchScoreGreater);
256 scored_items.resize(max_matches); 256 scored_items.resize(max_matches);
(...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 : used_(true) {} 1256 : used_(true) {}
1257 1257
1258 URLIndexPrivateData::SearchTermCacheItem::~SearchTermCacheItem() {} 1258 URLIndexPrivateData::SearchTermCacheItem::~SearchTermCacheItem() {}
1259 1259
1260 1260
1261 // URLIndexPrivateData::AddHistoryMatch ---------------------------------------- 1261 // URLIndexPrivateData::AddHistoryMatch ----------------------------------------
1262 1262
1263 URLIndexPrivateData::AddHistoryMatch::AddHistoryMatch( 1263 URLIndexPrivateData::AddHistoryMatch::AddHistoryMatch(
1264 const URLIndexPrivateData& private_data, 1264 const URLIndexPrivateData& private_data,
1265 const std::string& languages, 1265 const std::string& languages,
1266 BookmarkService* bookmark_service, 1266 HistoryClient* history_client,
1267 const base::string16& lower_string, 1267 const base::string16& lower_string,
1268 const String16Vector& lower_terms, 1268 const String16Vector& lower_terms,
1269 const base::Time now) 1269 const base::Time now)
1270 : private_data_(private_data), 1270 : private_data_(private_data),
1271 languages_(languages), 1271 languages_(languages),
1272 bookmark_service_(bookmark_service), 1272 history_client_(history_client),
1273 lower_string_(lower_string), 1273 lower_string_(lower_string),
1274 lower_terms_(lower_terms), 1274 lower_terms_(lower_terms),
1275 now_(now) { 1275 now_(now) {
1276 // Calculate offsets for each term. For instance, the offset for 1276 // Calculate offsets for each term. For instance, the offset for
1277 // ".net" should be 1, indicating that the actual word-part of the term 1277 // ".net" should be 1, indicating that the actual word-part of the term
1278 // starts at offset 1. 1278 // starts at offset 1.
1279 lower_terms_to_word_starts_offsets_.resize(lower_terms_.size(), 0u); 1279 lower_terms_to_word_starts_offsets_.resize(lower_terms_.size(), 0u);
1280 for (size_t i = 0; i < lower_terms_.size(); ++i) { 1280 for (size_t i = 0; i < lower_terms_.size(); ++i) {
1281 base::i18n::BreakIterator iter(lower_terms_[i], 1281 base::i18n::BreakIterator iter(lower_terms_[i],
1282 base::i18n::BreakIterator::BREAK_WORD); 1282 base::i18n::BreakIterator::BREAK_WORD);
1283 // If the iterator doesn't work, assume an offset of 0. 1283 // If the iterator doesn't work, assume an offset of 0.
1284 if (!iter.Init()) 1284 if (!iter.Init())
1285 continue; 1285 continue;
(...skipping 12 matching lines...) Expand all
1298 HistoryInfoMap::const_iterator hist_pos = 1298 HistoryInfoMap::const_iterator hist_pos =
1299 private_data_.history_info_map_.find(history_id); 1299 private_data_.history_info_map_.find(history_id);
1300 if (hist_pos != private_data_.history_info_map_.end()) { 1300 if (hist_pos != private_data_.history_info_map_.end()) {
1301 const URLRow& hist_item = hist_pos->second.url_row; 1301 const URLRow& hist_item = hist_pos->second.url_row;
1302 const VisitInfoVector& visits = hist_pos->second.visits; 1302 const VisitInfoVector& visits = hist_pos->second.visits;
1303 WordStartsMap::const_iterator starts_pos = 1303 WordStartsMap::const_iterator starts_pos =
1304 private_data_.word_starts_map_.find(history_id); 1304 private_data_.word_starts_map_.find(history_id);
1305 DCHECK(starts_pos != private_data_.word_starts_map_.end()); 1305 DCHECK(starts_pos != private_data_.word_starts_map_.end());
1306 ScoredHistoryMatch match(hist_item, visits, languages_, lower_string_, 1306 ScoredHistoryMatch match(hist_item, visits, languages_, lower_string_,
1307 lower_terms_, lower_terms_to_word_starts_offsets_, 1307 lower_terms_, lower_terms_to_word_starts_offsets_,
1308 starts_pos->second, now_, bookmark_service_); 1308 starts_pos->second, now_, history_client_);
1309 if (match.raw_score() > 0) 1309 if (match.raw_score() > 0)
1310 scored_matches_.push_back(match); 1310 scored_matches_.push_back(match);
1311 } 1311 }
1312 } 1312 }
1313 1313
1314 1314
1315 // URLIndexPrivateData::HistoryItemFactorGreater ------------------------------- 1315 // URLIndexPrivateData::HistoryItemFactorGreater -------------------------------
1316 1316
1317 URLIndexPrivateData::HistoryItemFactorGreater::HistoryItemFactorGreater( 1317 URLIndexPrivateData::HistoryItemFactorGreater::HistoryItemFactorGreater(
1318 const HistoryInfoMap& history_info_map) 1318 const HistoryInfoMap& history_info_map)
(...skipping 18 matching lines...) Expand all
1337 // recently visited (within the last 12/24 hours) as highly important. Get 1337 // recently visited (within the last 12/24 hours) as highly important. Get
1338 // input from mpearson. 1338 // input from mpearson.
1339 if (r1.typed_count() != r2.typed_count()) 1339 if (r1.typed_count() != r2.typed_count())
1340 return (r1.typed_count() > r2.typed_count()); 1340 return (r1.typed_count() > r2.typed_count());
1341 if (r1.visit_count() != r2.visit_count()) 1341 if (r1.visit_count() != r2.visit_count())
1342 return (r1.visit_count() > r2.visit_count()); 1342 return (r1.visit_count() > r2.visit_count());
1343 return (r1.last_visit() > r2.last_visit()); 1343 return (r1.last_visit() > r2.last_visit());
1344 } 1344 }
1345 1345
1346 } // namespace history 1346 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698