Chromium Code Reviews| 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/history/history_backend.h" | 5 #include "chrome/browser/history/history_backend.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <list> | 9 #include <list> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 1096 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1107 return db_->GetAllTypedUrls(urls); | 1107 return db_->GetAllTypedUrls(urls); |
| 1108 return false; | 1108 return false; |
| 1109 } | 1109 } |
| 1110 | 1110 |
| 1111 bool HistoryBackend::GetVisitsForURL(URLID id, VisitVector* visits) { | 1111 bool HistoryBackend::GetVisitsForURL(URLID id, VisitVector* visits) { |
| 1112 if (db_) | 1112 if (db_) |
| 1113 return db_->GetVisitsForURL(id, visits); | 1113 return db_->GetVisitsForURL(id, visits); |
| 1114 return false; | 1114 return false; |
| 1115 } | 1115 } |
| 1116 | 1116 |
| 1117 bool HistoryBackend::GetVisitsForURLWithOptions(URLID id, | |
|
brettw
2013/06/18 23:26:28
I don't get why this is a function since it looks
rmcilroy
2013/06/19 10:30:14
I was following the pattern of the functions above
| |
| 1118 const QueryOptions& options, | |
| 1119 VisitVector* visits) { | |
| 1120 if (db_) | |
| 1121 return db_->GetVisitsForURLWithOptions(id, options, visits); | |
| 1122 return false; | |
| 1123 } | |
| 1124 | |
| 1117 bool HistoryBackend::GetMostRecentVisitsForURL(URLID id, | 1125 bool HistoryBackend::GetMostRecentVisitsForURL(URLID id, |
| 1118 int max_visits, | 1126 int max_visits, |
| 1119 VisitVector* visits) { | 1127 VisitVector* visits) { |
| 1120 if (db_) | 1128 if (db_) |
| 1121 return db_->GetMostRecentVisitsForURL(id, max_visits, visits); | 1129 return db_->GetMostRecentVisitsForURL(id, max_visits, visits); |
| 1122 return false; | 1130 return false; |
| 1123 } | 1131 } |
| 1124 | 1132 |
| 1125 bool HistoryBackend::UpdateURL(URLID id, const history::URLRow& url) { | 1133 bool HistoryBackend::UpdateURL(URLID id, const history::URLRow& url) { |
| 1126 if (db_) | 1134 if (db_) |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1395 QueryHistoryBasic(db_.get(), db_.get(), options, &request->value); | 1403 QueryHistoryBasic(db_.get(), db_.get(), options, &request->value); |
| 1396 | 1404 |
| 1397 // Now query the archived database. This is a bit tricky because we don't | 1405 // Now query the archived database. This is a bit tricky because we don't |
| 1398 // want to query it if the queried time range isn't going to find anything | 1406 // want to query it if the queried time range isn't going to find anything |
| 1399 // in it. | 1407 // in it. |
| 1400 // TODO(brettw) bug 1171036: do blimpie querying for the archived database | 1408 // TODO(brettw) bug 1171036: do blimpie querying for the archived database |
| 1401 // as well. | 1409 // as well. |
| 1402 // if (archived_db_.get() && | 1410 // if (archived_db_.get() && |
| 1403 // expirer_.GetCurrentArchiveTime() - TimeDelta::FromDays(7)) { | 1411 // expirer_.GetCurrentArchiveTime() - TimeDelta::FromDays(7)) { |
| 1404 } else { | 1412 } else { |
| 1405 // Full text history query. | 1413 // Text history query. |
| 1406 QueryHistoryFTS(text_query, options, &request->value); | 1414 QueryHistoryText(db_.get(), db_.get(), text_query, options, |
| 1415 &request->value); | |
| 1416 if (archived_db_.get() && | |
| 1417 expirer_.GetCurrentArchiveTime() >= options.begin_time) { | |
| 1418 QueryHistoryText(archived_db_.get(), archived_db_.get(), text_query, | |
| 1419 options, &request->value); | |
| 1420 } | |
| 1407 } | 1421 } |
| 1408 } | 1422 } |
| 1409 | 1423 |
| 1410 request->ForwardResult(request->handle(), &request->value); | 1424 request->ForwardResult(request->handle(), &request->value); |
| 1411 | 1425 |
| 1412 UMA_HISTOGRAM_TIMES("History.QueryHistory", | 1426 UMA_HISTOGRAM_TIMES("History.QueryHistory", |
| 1413 TimeTicks::Now() - beginning_time); | 1427 TimeTicks::Now() - beginning_time); |
| 1414 } | 1428 } |
| 1415 | 1429 |
| 1416 // Basic time-based querying of history. | 1430 // Basic time-based querying of history. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1461 | 1475 |
| 1462 // We don't set any of the query-specific parts of the URLResult, since | 1476 // We don't set any of the query-specific parts of the URLResult, since |
| 1463 // snippets and stuff don't apply to basic querying. | 1477 // snippets and stuff don't apply to basic querying. |
| 1464 result->AppendURLBySwapping(&url_result); | 1478 result->AppendURLBySwapping(&url_result); |
| 1465 } | 1479 } |
| 1466 | 1480 |
| 1467 if (!has_more_results && options.begin_time <= first_recorded_time_) | 1481 if (!has_more_results && options.begin_time <= first_recorded_time_) |
| 1468 result->set_reached_beginning(true); | 1482 result->set_reached_beginning(true); |
| 1469 } | 1483 } |
| 1470 | 1484 |
| 1485 // Text-based querying of history. | |
| 1486 void HistoryBackend::QueryHistoryText(URLDatabase* url_db, | |
| 1487 VisitDatabase* visit_db, | |
| 1488 const string16& text_query, | |
| 1489 const QueryOptions& options, | |
| 1490 QueryResults* result) { | |
| 1491 URLRows text_matches; | |
| 1492 url_db->GetTextMatches(text_query, &text_matches); | |
| 1493 | |
| 1494 std::vector<URLResult> matching_visits; | |
| 1495 VisitVector visits; // Declare outside loop to prevent re-construction. | |
| 1496 for (size_t i = 0; i < text_matches.size(); i++) { | |
| 1497 // Get all visits for given URL match. | |
| 1498 GetVisitsForURLWithOptions(text_matches[i].id(), options, &visits); | |
| 1499 | |
| 1500 for (size_t j = 0; j < visits.size(); j++) { | |
| 1501 URLResult url_result(text_matches[i]); | |
| 1502 url_result.set_visit_time(visits[j].visit_time); | |
| 1503 matching_visits.push_back(url_result); | |
| 1504 } | |
| 1505 } | |
| 1506 | |
| 1507 std::sort(matching_visits.begin(), matching_visits.end(), | |
| 1508 URLResult::CompareVisitTime); | |
| 1509 | |
| 1510 size_t max_results = options.max_count == 0 ? | |
| 1511 std::numeric_limits<size_t>::max() : static_cast<int>(options.max_count); | |
| 1512 for (std::vector<URLResult>::iterator it = matching_visits.begin(); | |
| 1513 it != matching_visits.end() && result->size() < max_results; ++it) { | |
| 1514 result->AppendURLBySwapping(&(*it)); | |
| 1515 } | |
| 1516 | |
| 1517 if (matching_visits.size() == result->size() && | |
| 1518 options.begin_time <= first_recorded_time_) | |
| 1519 result->set_reached_beginning(true); | |
| 1520 } | |
| 1521 | |
| 1471 void HistoryBackend::QueryHistoryFTS(const string16& text_query, | 1522 void HistoryBackend::QueryHistoryFTS(const string16& text_query, |
| 1472 const QueryOptions& options, | 1523 const QueryOptions& options, |
| 1473 QueryResults* result) { | 1524 QueryResults* result) { |
| 1474 if (!text_database_) | 1525 if (!text_database_) |
| 1475 return; | 1526 return; |
| 1476 | 1527 |
| 1477 // Full text query, first get all the FTS results in the time range. | 1528 // Full text query, first get all the FTS results in the time range. |
| 1478 std::vector<TextDatabase::Match> fts_matches; | 1529 std::vector<TextDatabase::Match> fts_matches; |
| 1479 Time first_time_searched; | 1530 Time first_time_searched; |
| 1480 text_database_->GetTextMatches(text_query, options, | 1531 text_database_->GetTextMatches(text_query, options, |
| (...skipping 1617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3098 info.url_id = visit.url_id; | 3149 info.url_id = visit.url_id; |
| 3099 info.time = visit.visit_time; | 3150 info.time = visit.visit_time; |
| 3100 info.transition = visit.transition; | 3151 info.transition = visit.transition; |
| 3101 // If we don't have a delegate yet during setup or shutdown, we will drop | 3152 // If we don't have a delegate yet during setup or shutdown, we will drop |
| 3102 // these notifications. | 3153 // these notifications. |
| 3103 if (delegate_) | 3154 if (delegate_) |
| 3104 delegate_->NotifyVisitDBObserversOnAddVisit(info); | 3155 delegate_->NotifyVisitDBObserversOnAddVisit(info); |
| 3105 } | 3156 } |
| 3106 | 3157 |
| 3107 } // namespace history | 3158 } // namespace history |
| OLD | NEW |