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, |
| 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); |
1407 } | 1416 } |
1408 } | 1417 } |
1409 | 1418 |
1410 request->ForwardResult(request->handle(), &request->value); | 1419 request->ForwardResult(request->handle(), &request->value); |
1411 | 1420 |
1412 UMA_HISTOGRAM_TIMES("History.QueryHistory", | 1421 UMA_HISTOGRAM_TIMES("History.QueryHistory", |
1413 TimeTicks::Now() - beginning_time); | 1422 TimeTicks::Now() - beginning_time); |
1414 } | 1423 } |
1415 | 1424 |
1416 // Basic time-based querying of history. | 1425 // Basic time-based querying of history. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1461 | 1470 |
1462 // We don't set any of the query-specific parts of the URLResult, since | 1471 // We don't set any of the query-specific parts of the URLResult, since |
1463 // snippets and stuff don't apply to basic querying. | 1472 // snippets and stuff don't apply to basic querying. |
1464 result->AppendURLBySwapping(&url_result); | 1473 result->AppendURLBySwapping(&url_result); |
1465 } | 1474 } |
1466 | 1475 |
1467 if (!has_more_results && options.begin_time <= first_recorded_time_) | 1476 if (!has_more_results && options.begin_time <= first_recorded_time_) |
1468 result->set_reached_beginning(true); | 1477 result->set_reached_beginning(true); |
1469 } | 1478 } |
1470 | 1479 |
| 1480 // Text-based querying of history. |
| 1481 void HistoryBackend::QueryHistoryText(URLDatabase* url_db, |
| 1482 VisitDatabase* visit_db, |
| 1483 const string16& text_query, |
| 1484 const QueryOptions& options, |
| 1485 QueryResults* result) { |
| 1486 URLRows text_matches; |
| 1487 url_db->GetTextMatches(text_query, &text_matches); |
| 1488 |
| 1489 bool too_many = false; |
| 1490 std::vector<URLResult> matching_visits; |
| 1491 VisitVector visits; // Declare outside loop to prevent re-construction. |
| 1492 for (size_t i = 0; (i < text_matches.size()) && !too_many; i++) { |
| 1493 // Get all visits for given URL match. |
| 1494 GetVisitsForURLWithOptions(text_matches[i].id(), options, &visits); |
| 1495 |
| 1496 for (size_t j = 0; j < visits.size(); j++) { |
| 1497 if (options.max_count != 0 && |
| 1498 static_cast<int>(result->size()) >= options.max_count) { |
| 1499 too_many = true; // Got too many items. |
| 1500 break; |
| 1501 } |
| 1502 URLResult url_result(text_matches[i]); |
| 1503 url_result.set_visit_time(visits[j].visit_time); |
| 1504 matching_visits.push_back(url_result); |
| 1505 } |
| 1506 } |
| 1507 |
| 1508 std::sort(matching_visits.begin(), matching_visits.end(), |
| 1509 URLResult::CompareVisitTime); |
| 1510 for (std::vector<URLResult>::iterator it = matching_visits.begin(); |
| 1511 it != matching_visits.end(); ++it) { |
| 1512 result->AppendURLBySwapping(&(*it)); |
| 1513 } |
| 1514 |
| 1515 if (!too_many && options.begin_time <= first_recorded_time_) |
| 1516 result->set_reached_beginning(true); |
| 1517 } |
| 1518 |
1471 void HistoryBackend::QueryHistoryFTS(const string16& text_query, | 1519 void HistoryBackend::QueryHistoryFTS(const string16& text_query, |
1472 const QueryOptions& options, | 1520 const QueryOptions& options, |
1473 QueryResults* result) { | 1521 QueryResults* result) { |
1474 if (!text_database_) | 1522 if (!text_database_) |
1475 return; | 1523 return; |
1476 | 1524 |
1477 // Full text query, first get all the FTS results in the time range. | 1525 // Full text query, first get all the FTS results in the time range. |
1478 std::vector<TextDatabase::Match> fts_matches; | 1526 std::vector<TextDatabase::Match> fts_matches; |
1479 Time first_time_searched; | 1527 Time first_time_searched; |
1480 text_database_->GetTextMatches(text_query, options, | 1528 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; | 3146 info.url_id = visit.url_id; |
3099 info.time = visit.visit_time; | 3147 info.time = visit.visit_time; |
3100 info.transition = visit.transition; | 3148 info.transition = visit.transition; |
3101 // If we don't have a delegate yet during setup or shutdown, we will drop | 3149 // If we don't have a delegate yet during setup or shutdown, we will drop |
3102 // these notifications. | 3150 // these notifications. |
3103 if (delegate_) | 3151 if (delegate_) |
3104 delegate_->NotifyVisitDBObserversOnAddVisit(info); | 3152 delegate_->NotifyVisitDBObserversOnAddVisit(info); |
3105 } | 3153 } |
3106 | 3154 |
3107 } // namespace history | 3155 } // namespace history |
OLD | NEW |