| 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 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 if (visit_id) { | 751 if (visit_id) { |
| 752 if (typed_url_syncable_service_.get()) | 752 if (typed_url_syncable_service_.get()) |
| 753 typed_url_syncable_service_->OnUrlVisited(transition, &url_info); | 753 typed_url_syncable_service_->OnUrlVisited(transition, &url_info); |
| 754 | 754 |
| 755 scoped_ptr<URLVisitedDetails> details(new URLVisitedDetails); | 755 scoped_ptr<URLVisitedDetails> details(new URLVisitedDetails); |
| 756 details->transition = transition; | 756 details->transition = transition; |
| 757 details->row = url_info; | 757 details->row = url_info; |
| 758 details->visit_time = time; | 758 details->visit_time = time; |
| 759 // TODO(meelapshah) Disabled due to potential PageCycler regression. | 759 // TODO(meelapshah) Disabled due to potential PageCycler regression. |
| 760 // Re-enable this. | 760 // Re-enable this. |
| 761 // GetMostRecentRedirectsTo(url, &details->redirects); | 761 // QueryRedirectsTo(url, &details->redirects); |
| 762 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URL_VISITED, | 762 BroadcastNotifications(chrome::NOTIFICATION_HISTORY_URL_VISITED, |
| 763 details.PassAs<HistoryDetails>()); | 763 details.PassAs<HistoryDetails>()); |
| 764 } else { | 764 } else { |
| 765 VLOG(0) << "Failed to build visit insert statement: " | 765 VLOG(0) << "Failed to build visit insert statement: " |
| 766 << "url_id = " << url_id; | 766 << "url_id = " << url_id; |
| 767 } | 767 } |
| 768 | 768 |
| 769 return std::make_pair(url_id, visit_id); | 769 return std::make_pair(url_id, visit_id); |
| 770 } | 770 } |
| 771 | 771 |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1284 for (std::vector<URLResult>::iterator it = matching_visits.begin(); | 1284 for (std::vector<URLResult>::iterator it = matching_visits.begin(); |
| 1285 it != matching_visits.end() && result->size() < max_results; ++it) { | 1285 it != matching_visits.end() && result->size() < max_results; ++it) { |
| 1286 result->AppendURLBySwapping(&(*it)); | 1286 result->AppendURLBySwapping(&(*it)); |
| 1287 } | 1287 } |
| 1288 | 1288 |
| 1289 if (matching_visits.size() == result->size() && | 1289 if (matching_visits.size() == result->size() && |
| 1290 options.begin_time <= first_recorded_time_) | 1290 options.begin_time <= first_recorded_time_) |
| 1291 result->set_reached_beginning(true); | 1291 result->set_reached_beginning(true); |
| 1292 } | 1292 } |
| 1293 | 1293 |
| 1294 // Frontend to GetMostRecentRedirectsFrom from the history thread. | 1294 void HistoryBackend::QueryRedirectsFrom(const GURL& from_url, |
| 1295 void HistoryBackend::QueryRedirectsFrom( | 1295 RedirectList* redirects) { |
| 1296 scoped_refptr<QueryRedirectsRequest> request, | 1296 redirects->clear(); |
| 1297 const GURL& url) { | 1297 if (!db_) |
| 1298 if (request->canceled()) | |
| 1299 return; | 1298 return; |
| 1300 bool success = GetMostRecentRedirectsFrom(url, &request->value); | 1299 |
| 1301 request->ForwardResult(request->handle(), url, success, &request->value); | 1300 URLID from_url_id = db_->GetRowForURL(from_url, NULL); |
| 1301 VisitID cur_visit = db_->GetMostRecentVisitForURL(from_url_id, NULL); |
| 1302 if (!cur_visit) |
| 1303 return; // No visits for URL. |
| 1304 |
| 1305 GetRedirectsFromSpecificVisit(cur_visit, redirects); |
| 1302 } | 1306 } |
| 1303 | 1307 |
| 1304 void HistoryBackend::QueryRedirectsTo( | 1308 void HistoryBackend::QueryRedirectsTo(const GURL& to_url, |
| 1305 scoped_refptr<QueryRedirectsRequest> request, | 1309 RedirectList* redirects) { |
| 1306 const GURL& url) { | 1310 redirects->clear(); |
| 1307 if (request->canceled()) | 1311 if (!db_) |
| 1308 return; | 1312 return; |
| 1309 bool success = GetMostRecentRedirectsTo(url, &request->value); | 1313 |
| 1310 request->ForwardResult(request->handle(), url, success, &request->value); | 1314 URLID to_url_id = db_->GetRowForURL(to_url, NULL); |
| 1315 VisitID cur_visit = db_->GetMostRecentVisitForURL(to_url_id, NULL); |
| 1316 if (!cur_visit) |
| 1317 return; // No visits for URL. |
| 1318 |
| 1319 GetRedirectsToSpecificVisit(cur_visit, redirects); |
| 1311 } | 1320 } |
| 1312 | 1321 |
| 1313 void HistoryBackend::GetVisibleVisitCountToHost( | 1322 void HistoryBackend::GetVisibleVisitCountToHost( |
| 1314 scoped_refptr<GetVisibleVisitCountToHostRequest> request, | 1323 scoped_refptr<GetVisibleVisitCountToHostRequest> request, |
| 1315 const GURL& url) { | 1324 const GURL& url) { |
| 1316 if (request->canceled()) | 1325 if (request->canceled()) |
| 1317 return; | 1326 return; |
| 1318 int count = 0; | 1327 int count = 0; |
| 1319 Time first_visit; | 1328 Time first_visit; |
| 1320 const bool success = db_.get() && | 1329 const bool success = db_.get() && |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1336 std::vector<GURL>* top_urls = &request->value.a; | 1345 std::vector<GURL>* top_urls = &request->value.a; |
| 1337 history::RedirectMap* redirects = &request->value.b; | 1346 history::RedirectMap* redirects = &request->value.b; |
| 1338 | 1347 |
| 1339 ScopedVector<PageUsageData> data; | 1348 ScopedVector<PageUsageData> data; |
| 1340 db_->QuerySegmentUsage(base::Time::Now() - base::TimeDelta::FromDays(90), | 1349 db_->QuerySegmentUsage(base::Time::Now() - base::TimeDelta::FromDays(90), |
| 1341 result_count, &data.get()); | 1350 result_count, &data.get()); |
| 1342 | 1351 |
| 1343 for (size_t i = 0; i < data.size(); ++i) { | 1352 for (size_t i = 0; i < data.size(); ++i) { |
| 1344 top_urls->push_back(data[i]->GetURL()); | 1353 top_urls->push_back(data[i]->GetURL()); |
| 1345 RefCountedVector<GURL>* list = new RefCountedVector<GURL>; | 1354 RefCountedVector<GURL>* list = new RefCountedVector<GURL>; |
| 1346 GetMostRecentRedirectsFrom(top_urls->back(), &list->data); | 1355 QueryRedirectsFrom(top_urls->back(), &list->data); |
| 1347 (*redirects)[top_urls->back()] = list; | 1356 (*redirects)[top_urls->back()] = list; |
| 1348 } | 1357 } |
| 1349 | 1358 |
| 1350 request->ForwardResult(request->handle(), true, top_urls, redirects); | 1359 request->ForwardResult(request->handle(), true, top_urls, redirects); |
| 1351 } | 1360 } |
| 1352 | 1361 |
| 1353 // Will replace QueryTopURLsAndRedirectsRequest. | 1362 // Will replace QueryTopURLsAndRedirectsRequest. |
| 1354 void HistoryBackend::QueryMostVisitedURLs( | 1363 void HistoryBackend::QueryMostVisitedURLs( |
| 1355 scoped_refptr<QueryMostVisitedURLsRequest> request, | 1364 scoped_refptr<QueryMostVisitedURLsRequest> request, |
| 1356 int result_count, | 1365 int result_count, |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1459 return; | 1468 return; |
| 1460 | 1469 |
| 1461 ScopedVector<PageUsageData> data; | 1470 ScopedVector<PageUsageData> data; |
| 1462 db_->QuerySegmentUsage(base::Time::Now() - | 1471 db_->QuerySegmentUsage(base::Time::Now() - |
| 1463 base::TimeDelta::FromDays(days_back), | 1472 base::TimeDelta::FromDays(days_back), |
| 1464 result_count, &data.get()); | 1473 result_count, &data.get()); |
| 1465 | 1474 |
| 1466 for (size_t i = 0; i < data.size(); ++i) { | 1475 for (size_t i = 0; i < data.size(); ++i) { |
| 1467 PageUsageData* current_data = data[i]; | 1476 PageUsageData* current_data = data[i]; |
| 1468 RedirectList redirects; | 1477 RedirectList redirects; |
| 1469 GetMostRecentRedirectsFrom(current_data->GetURL(), &redirects); | 1478 QueryRedirectsFrom(current_data->GetURL(), &redirects); |
| 1470 MostVisitedURL url = MakeMostVisitedURL(*current_data, redirects); | 1479 MostVisitedURL url = MakeMostVisitedURL(*current_data, redirects); |
| 1471 result->push_back(url); | 1480 result->push_back(url); |
| 1472 } | 1481 } |
| 1473 } | 1482 } |
| 1474 | 1483 |
| 1475 void HistoryBackend::GetRedirectsFromSpecificVisit( | 1484 void HistoryBackend::GetRedirectsFromSpecificVisit( |
| 1476 VisitID cur_visit, history::RedirectList* redirects) { | 1485 VisitID cur_visit, history::RedirectList* redirects) { |
| 1477 // Follow any redirects from the given visit and add them to the list. | 1486 // Follow any redirects from the given visit and add them to the list. |
| 1478 // It *should* be impossible to get a circular chain here, but we check | 1487 // It *should* be impossible to get a circular chain here, but we check |
| 1479 // just in case to avoid infinite loops. | 1488 // just in case to avoid infinite loops. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1505 while (db_->GetRedirectToVisit(cur_visit, &cur_visit, &cur_url)) { | 1514 while (db_->GetRedirectToVisit(cur_visit, &cur_visit, &cur_url)) { |
| 1506 if (visit_set.find(cur_visit) != visit_set.end()) { | 1515 if (visit_set.find(cur_visit) != visit_set.end()) { |
| 1507 NOTREACHED() << "Loop in visit chain, giving up"; | 1516 NOTREACHED() << "Loop in visit chain, giving up"; |
| 1508 return; | 1517 return; |
| 1509 } | 1518 } |
| 1510 visit_set.insert(cur_visit); | 1519 visit_set.insert(cur_visit); |
| 1511 redirects->push_back(cur_url); | 1520 redirects->push_back(cur_url); |
| 1512 } | 1521 } |
| 1513 } | 1522 } |
| 1514 | 1523 |
| 1515 bool HistoryBackend::GetMostRecentRedirectsFrom( | |
| 1516 const GURL& from_url, | |
| 1517 history::RedirectList* redirects) { | |
| 1518 redirects->clear(); | |
| 1519 if (!db_) | |
| 1520 return false; | |
| 1521 | |
| 1522 URLID from_url_id = db_->GetRowForURL(from_url, NULL); | |
| 1523 VisitID cur_visit = db_->GetMostRecentVisitForURL(from_url_id, NULL); | |
| 1524 if (!cur_visit) | |
| 1525 return false; // No visits for URL. | |
| 1526 | |
| 1527 GetRedirectsFromSpecificVisit(cur_visit, redirects); | |
| 1528 return true; | |
| 1529 } | |
| 1530 | |
| 1531 bool HistoryBackend::GetMostRecentRedirectsTo( | |
| 1532 const GURL& to_url, | |
| 1533 history::RedirectList* redirects) { | |
| 1534 redirects->clear(); | |
| 1535 if (!db_) | |
| 1536 return false; | |
| 1537 | |
| 1538 URLID to_url_id = db_->GetRowForURL(to_url, NULL); | |
| 1539 VisitID cur_visit = db_->GetMostRecentVisitForURL(to_url_id, NULL); | |
| 1540 if (!cur_visit) | |
| 1541 return false; // No visits for URL. | |
| 1542 | |
| 1543 GetRedirectsToSpecificVisit(cur_visit, redirects); | |
| 1544 return true; | |
| 1545 } | |
| 1546 | |
| 1547 void HistoryBackend::ScheduleAutocomplete(HistoryURLProvider* provider, | 1524 void HistoryBackend::ScheduleAutocomplete(HistoryURLProvider* provider, |
| 1548 HistoryURLProviderParams* params) { | 1525 HistoryURLProviderParams* params) { |
| 1549 // ExecuteWithDB should handle the NULL database case. | 1526 // ExecuteWithDB should handle the NULL database case. |
| 1550 provider->ExecuteWithDB(this, db_.get(), params); | 1527 provider->ExecuteWithDB(this, db_.get(), params); |
| 1551 } | 1528 } |
| 1552 | 1529 |
| 1553 void HistoryBackend::DeleteFTSIndexDatabases() { | 1530 void HistoryBackend::DeleteFTSIndexDatabases() { |
| 1554 // Find files on disk matching the text databases file pattern so we can | 1531 // Find files on disk matching the text databases file pattern so we can |
| 1555 // quickly test for and delete them. | 1532 // quickly test for and delete them. |
| 1556 base::FilePath::StringType filepattern = | 1533 base::FilePath::StringType filepattern = |
| (...skipping 1278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2835 int rank = kPageVisitStatsMaxTopSites; | 2812 int rank = kPageVisitStatsMaxTopSites; |
| 2836 std::map<GURL, int>::const_iterator it = most_visited_urls_map_.find(url); | 2813 std::map<GURL, int>::const_iterator it = most_visited_urls_map_.find(url); |
| 2837 if (it != most_visited_urls_map_.end()) | 2814 if (it != most_visited_urls_map_.end()) |
| 2838 rank = (*it).second; | 2815 rank = (*it).second; |
| 2839 UMA_HISTOGRAM_ENUMERATION("History.TopSitesVisitsByRank", | 2816 UMA_HISTOGRAM_ENUMERATION("History.TopSitesVisitsByRank", |
| 2840 rank, kPageVisitStatsMaxTopSites + 1); | 2817 rank, kPageVisitStatsMaxTopSites + 1); |
| 2841 } | 2818 } |
| 2842 #endif | 2819 #endif |
| 2843 | 2820 |
| 2844 } // namespace history | 2821 } // namespace history |
| OLD | NEW |