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 1340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1351 QueryHistoryBasic(db_.get(), db_.get(), options, &request->value); | 1351 QueryHistoryBasic(db_.get(), db_.get(), options, &request->value); |
1352 | 1352 |
1353 // Now query the archived database. This is a bit tricky because we don't | 1353 // Now query the archived database. This is a bit tricky because we don't |
1354 // want to query it if the queried time range isn't going to find anything | 1354 // want to query it if the queried time range isn't going to find anything |
1355 // in it. | 1355 // in it. |
1356 // TODO(brettw) bug 1171036: do blimpie querying for the archived database | 1356 // TODO(brettw) bug 1171036: do blimpie querying for the archived database |
1357 // as well. | 1357 // as well. |
1358 // if (archived_db_.get() && | 1358 // if (archived_db_.get() && |
1359 // expirer_.GetCurrentArchiveTime() - TimeDelta::FromDays(7)) { | 1359 // expirer_.GetCurrentArchiveTime() - TimeDelta::FromDays(7)) { |
1360 } else { | 1360 } else { |
1361 // Full text history query. | 1361 // Text history query. |
1362 QueryHistoryFTS(text_query, options, &request->value); | 1362 QueryHistoryText(db_.get(), db_.get(), text_query, options, |
1363 &request->value); | |
1364 if (archived_db_.get() && | |
1365 expirer_.GetCurrentArchiveTime() >= options.begin_time) { | |
1366 QueryHistoryText(archived_db_.get(), archived_db_.get(), text_query, | |
1367 options, &request->value); | |
1368 } | |
1363 } | 1369 } |
1364 } | 1370 } |
1365 | 1371 |
1366 request->ForwardResult(request->handle(), &request->value); | 1372 request->ForwardResult(request->handle(), &request->value); |
1367 | 1373 |
1368 UMA_HISTOGRAM_TIMES("History.QueryHistory", | 1374 UMA_HISTOGRAM_TIMES("History.QueryHistory", |
1369 TimeTicks::Now() - beginning_time); | 1375 TimeTicks::Now() - beginning_time); |
1370 } | 1376 } |
1371 | 1377 |
1372 // Basic time-based querying of history. | 1378 // Basic time-based querying of history. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1417 | 1423 |
1418 // We don't set any of the query-specific parts of the URLResult, since | 1424 // We don't set any of the query-specific parts of the URLResult, since |
1419 // snippets and stuff don't apply to basic querying. | 1425 // snippets and stuff don't apply to basic querying. |
1420 result->AppendURLBySwapping(&url_result); | 1426 result->AppendURLBySwapping(&url_result); |
1421 } | 1427 } |
1422 | 1428 |
1423 if (!has_more_results && options.begin_time <= first_recorded_time_) | 1429 if (!has_more_results && options.begin_time <= first_recorded_time_) |
1424 result->set_reached_beginning(true); | 1430 result->set_reached_beginning(true); |
1425 } | 1431 } |
1426 | 1432 |
1433 // Text-based querying of history. | |
1434 void HistoryBackend::QueryHistoryText(URLDatabase* url_db, | |
1435 VisitDatabase* visit_db, | |
1436 const string16& text_query, | |
1437 const QueryOptions& options, | |
1438 QueryResults* result) { | |
Scott Hess - ex-Googler
2013/06/20 19:50:22
Do you think there would be any value to histogram
rmcilroy
2013/06/20 21:48:08
There is already a timing histogram for the caller
Scott Hess - ex-Googler
2013/06/20 22:18:31
Sounds good.
| |
1439 URLRows text_matches; | |
1440 url_db->GetTextMatches(text_query, &text_matches); | |
1441 | |
1442 std::vector<URLResult> matching_visits; | |
1443 VisitVector visits; // Declare outside loop to prevent re-construction. | |
1444 for (size_t i = 0; i < text_matches.size(); i++) { | |
1445 const URLRow& text_match = text_matches[i]; | |
1446 // Get all visits for given URL match. | |
1447 visit_db->GetVisitsForURLWithOptions(text_match.id(), options, &visits); | |
1448 for (size_t j = 0; j < visits.size(); j++) { | |
1449 URLResult url_result(text_match); | |
1450 url_result.set_visit_time(visits[j].visit_time); | |
1451 matching_visits.push_back(url_result); | |
1452 } | |
1453 } | |
1454 | |
1455 std::sort(matching_visits.begin(), matching_visits.end(), | |
1456 URLResult::CompareVisitTime); | |
1457 | |
1458 size_t max_results = options.max_count == 0 ? | |
1459 std::numeric_limits<size_t>::max() : static_cast<int>(options.max_count); | |
1460 for (std::vector<URLResult>::iterator it = matching_visits.begin(); | |
1461 it != matching_visits.end() && result->size() < max_results; ++it) { | |
1462 result->AppendURLBySwapping(&(*it)); | |
1463 } | |
1464 | |
1465 if (matching_visits.size() == result->size() && | |
1466 options.begin_time <= first_recorded_time_) | |
1467 result->set_reached_beginning(true); | |
1468 } | |
1469 | |
1427 void HistoryBackend::QueryHistoryFTS(const string16& text_query, | 1470 void HistoryBackend::QueryHistoryFTS(const string16& text_query, |
1428 const QueryOptions& options, | 1471 const QueryOptions& options, |
1429 QueryResults* result) { | 1472 QueryResults* result) { |
1430 if (!text_database_) | 1473 if (!text_database_) |
1431 return; | 1474 return; |
1432 | 1475 |
1433 // Full text query, first get all the FTS results in the time range. | 1476 // Full text query, first get all the FTS results in the time range. |
1434 std::vector<TextDatabase::Match> fts_matches; | 1477 std::vector<TextDatabase::Match> fts_matches; |
1435 Time first_time_searched; | 1478 Time first_time_searched; |
1436 text_database_->GetTextMatches(text_query, options, | 1479 text_database_->GetTextMatches(text_query, options, |
(...skipping 1631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3068 info.url_id = visit.url_id; | 3111 info.url_id = visit.url_id; |
3069 info.time = visit.visit_time; | 3112 info.time = visit.visit_time; |
3070 info.transition = visit.transition; | 3113 info.transition = visit.transition; |
3071 // If we don't have a delegate yet during setup or shutdown, we will drop | 3114 // If we don't have a delegate yet during setup or shutdown, we will drop |
3072 // these notifications. | 3115 // these notifications. |
3073 if (delegate_) | 3116 if (delegate_) |
3074 delegate_->NotifyVisitDBObserversOnAddVisit(info); | 3117 delegate_->NotifyVisitDBObserversOnAddVisit(info); |
3075 } | 3118 } |
3076 | 3119 |
3077 } // namespace history | 3120 } // namespace history |
OLD | NEW |