OLD | NEW |
---|---|
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <set> | 7 #include <set> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
343 // added in order. However, we don't want to disallow pages from recording | 343 // added in order. However, we don't want to disallow pages from recording |
344 // times earlier than our last_recorded_time_, because someone might set | 344 // times earlier than our last_recorded_time_, because someone might set |
345 // their machine's clock back. | 345 // their machine's clock back. |
346 if (last_requested_time_ == request->time) { | 346 if (last_requested_time_ == request->time) { |
347 last_recorded_time_ = last_recorded_time_ + TimeDelta::FromMicroseconds(1); | 347 last_recorded_time_ = last_recorded_time_ + TimeDelta::FromMicroseconds(1); |
348 } else { | 348 } else { |
349 last_requested_time_ = request->time; | 349 last_requested_time_ = request->time; |
350 last_recorded_time_ = last_requested_time_; | 350 last_recorded_time_ = last_requested_time_; |
351 } | 351 } |
352 | 352 |
353 // If the user is adding older history, we need to make sure our times | |
354 // are correct. | |
355 if (request->time < first_recorded_time_) | |
356 first_recorded_time_ = request->time; | |
357 | |
353 if (request->redirects.size() <= 1) { | 358 if (request->redirects.size() <= 1) { |
354 // The single entry is both a chain start and end. | 359 // The single entry is both a chain start and end. |
355 PageTransition::Type t = request->transition | | 360 PageTransition::Type t = request->transition | |
356 PageTransition::CHAIN_START | PageTransition::CHAIN_END; | 361 PageTransition::CHAIN_START | PageTransition::CHAIN_END; |
357 | 362 |
358 // No redirect case (one element means just the page itself). | 363 // No redirect case (one element means just the page itself). |
359 last_ids = AddPageVisit(request->url, last_recorded_time_, | 364 last_ids = AddPageVisit(request->url, last_recorded_time_, |
360 last_ids.second, t); | 365 last_ids.second, t); |
361 | 366 |
362 // Update the segment for this visit. | 367 // Update the segment for this visit. |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
558 | 563 |
559 // Open the long-running transaction. | 564 // Open the long-running transaction. |
560 db_->BeginTransaction(); | 565 db_->BeginTransaction(); |
561 if (thumbnail_db_.get()) | 566 if (thumbnail_db_.get()) |
562 thumbnail_db_->BeginTransaction(); | 567 thumbnail_db_->BeginTransaction(); |
563 if (archived_db_.get()) | 568 if (archived_db_.get()) |
564 archived_db_->BeginTransaction(); | 569 archived_db_->BeginTransaction(); |
565 if (text_database_.get()) | 570 if (text_database_.get()) |
566 text_database_->BeginTransaction(); | 571 text_database_->BeginTransaction(); |
567 | 572 |
573 // Get the first item in our database. | |
574 db_->GetStartDate(&first_recorded_time_); | |
575 | |
568 // Start expiring old stuff. | 576 // Start expiring old stuff. |
569 expirer_.StartArchivingOldStuff(TimeDelta::FromDays(kArchiveDaysThreshold)); | 577 expirer_.StartArchivingOldStuff(TimeDelta::FromDays(kArchiveDaysThreshold)); |
570 | 578 |
571 HISTOGRAM_TIMES("History.InitTime", | 579 HISTOGRAM_TIMES("History.InitTime", |
572 TimeTicks::Now() - beginning_time); | 580 TimeTicks::Now() - beginning_time); |
573 } | 581 } |
574 | 582 |
575 std::pair<URLID, VisitID> HistoryBackend::AddPageVisit( | 583 std::pair<URLID, VisitID> HistoryBackend::AddPageVisit( |
576 const GURL& url, | 584 const GURL& url, |
577 Time time, | 585 Time time, |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1035 // main DB, and do nothing otherwise. | 1043 // main DB, and do nothing otherwise. |
1036 db_->GetRowForURL(url_result.url(), &url_result); | 1044 db_->GetRowForURL(url_result.url(), &url_result); |
1037 } | 1045 } |
1038 | 1046 |
1039 url_result.set_visit_time(visit.visit_time); | 1047 url_result.set_visit_time(visit.visit_time); |
1040 | 1048 |
1041 // We don't set any of the query-specific parts of the URLResult, since | 1049 // We don't set any of the query-specific parts of the URLResult, since |
1042 // snippets and stuff don't apply to basic querying. | 1050 // snippets and stuff don't apply to basic querying. |
1043 result->AppendURLBySwapping(&url_result); | 1051 result->AppendURLBySwapping(&url_result); |
1044 } | 1052 } |
1053 | |
1054 if (options.begin_time <= first_recorded_time_) | |
1055 result->set_reached_beginning(true); | |
1045 } | 1056 } |
1046 | 1057 |
1047 void HistoryBackend::QueryHistoryFTS(const std::wstring& text_query, | 1058 void HistoryBackend::QueryHistoryFTS(const std::wstring& text_query, |
1048 const QueryOptions& options, | 1059 const QueryOptions& options, |
1049 QueryResults* result) { | 1060 QueryResults* result) { |
1050 if (!text_database_.get()) | 1061 if (!text_database_.get()) |
1051 return; | 1062 return; |
1052 | 1063 |
1053 // Full text query, first get all the FTS results in the time range. | 1064 // Full text query, first get all the FTS results in the time range. |
1054 std::vector<TextDatabase::Match> fts_matches; | 1065 std::vector<TextDatabase::Match> fts_matches; |
(...skipping 30 matching lines...) Expand all Loading... | |
1085 url_result.snippet_.Swap(&fts_matches[i].snippet); | 1096 url_result.snippet_.Swap(&fts_matches[i].snippet); |
1086 | 1097 |
1087 // The visit time also comes from the full text search database. Since it | 1098 // The visit time also comes from the full text search database. Since it |
1088 // has the time, we can avoid an extra query of the visits table. | 1099 // has the time, we can avoid an extra query of the visits table. |
1089 url_result.set_visit_time(fts_matches[i].time); | 1100 url_result.set_visit_time(fts_matches[i].time); |
1090 | 1101 |
1091 // Add it to the vector, this will clear our |url_row| object as a | 1102 // Add it to the vector, this will clear our |url_row| object as a |
1092 // result of the swap. | 1103 // result of the swap. |
1093 result->AppendURLBySwapping(&url_result); | 1104 result->AppendURLBySwapping(&url_result); |
1094 } | 1105 } |
1106 | |
1107 if (options.begin_time <= first_recorded_time_) | |
1108 result->set_reached_beginning(true); | |
1095 } | 1109 } |
1096 | 1110 |
1097 // Frontend to GetMostRecentRedirectsFrom from the history thread. | 1111 // Frontend to GetMostRecentRedirectsFrom from the history thread. |
1098 void HistoryBackend::QueryRedirectsFrom( | 1112 void HistoryBackend::QueryRedirectsFrom( |
1099 scoped_refptr<QueryRedirectsRequest> request, | 1113 scoped_refptr<QueryRedirectsRequest> request, |
1100 const GURL& url) { | 1114 const GURL& url) { |
1101 if (request->canceled()) | 1115 if (request->canceled()) |
1102 return; | 1116 return; |
1103 bool success = GetMostRecentRedirectsFrom(url, &request->value); | 1117 bool success = GetMostRecentRedirectsFrom(url, &request->value); |
1104 request->ForwardResult(QueryRedirectsRequest::TupleType( | 1118 request->ForwardResult(QueryRedirectsRequest::TupleType( |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1574 | 1588 |
1575 //////////////////////////////////////////////////////////////////////////////// | 1589 //////////////////////////////////////////////////////////////////////////////// |
1576 // | 1590 // |
1577 // Generic operations | 1591 // Generic operations |
1578 // | 1592 // |
1579 //////////////////////////////////////////////////////////////////////////////// | 1593 //////////////////////////////////////////////////////////////////////////////// |
1580 | 1594 |
1581 void HistoryBackend::DeleteURL(const GURL& url) { | 1595 void HistoryBackend::DeleteURL(const GURL& url) { |
1582 expirer_.DeleteURL(url); | 1596 expirer_.DeleteURL(url); |
1583 | 1597 |
1598 db_->GetStartDate(&first_recorded_time_); | |
1584 // Force a commit, if the user is deleting something for privacy reasons, we | 1599 // Force a commit, if the user is deleting something for privacy reasons, we |
1585 // want to get it on disk ASAP. | 1600 // want to get it on disk ASAP. |
1586 Commit(); | 1601 Commit(); |
1587 } | 1602 } |
1588 | 1603 |
1589 void HistoryBackend::ExpireHistoryBetween( | 1604 void HistoryBackend::ExpireHistoryBetween( |
1590 scoped_refptr<ExpireHistoryRequest> request, | 1605 scoped_refptr<ExpireHistoryRequest> request, |
1591 Time begin_time, | 1606 Time begin_time, |
1592 Time end_time) { | 1607 Time end_time) { |
1593 if (request->canceled()) | 1608 if (request->canceled()) |
1594 return; | 1609 return; |
1595 | 1610 |
1596 if (db_.get()) { | 1611 if (db_.get()) { |
1597 if (begin_time.is_null() && end_time.is_null()) { | 1612 if (begin_time.is_null() && end_time.is_null()) { |
1598 // Special case deleting all history so it can be faster and to reduce the | 1613 // Special case deleting all history so it can be faster and to reduce the |
1599 // possibility of an information leak. | 1614 // possibility of an information leak. |
1600 DeleteAllHistory(); | 1615 DeleteAllHistory(); |
1601 } else { | 1616 } else { |
1602 // Clearing parts of history, have the expirer do the depend | 1617 // Clearing parts of history, have the expirer do the depend |
1603 expirer_.ExpireHistoryBetween(begin_time, end_time); | 1618 expirer_.ExpireHistoryBetween(begin_time, end_time); |
1604 | 1619 |
1605 // Force a commit, if the user is deleting something for privacy reasons, | 1620 // Force a commit, if the user is deleting something for privacy reasons, |
1606 // we want to get it on disk ASAP. | 1621 // we want to get it on disk ASAP. |
1607 Commit(); | 1622 Commit(); |
1608 } | 1623 } |
1609 } | 1624 } |
1610 | 1625 |
1626 if (begin_time <= first_recorded_time_) | |
1627 db_->GetStartDate(&first_recorded_time_); | |
1628 | |
1611 request->ForwardResult(ExpireHistoryRequest::TupleType()); | 1629 request->ForwardResult(ExpireHistoryRequest::TupleType()); |
1612 | 1630 |
1613 if (history_publisher_.get()) | 1631 if (history_publisher_.get()) |
1614 history_publisher_->DeleteUserHistoryBetween(begin_time, end_time); | 1632 history_publisher_->DeleteUserHistoryBetween(begin_time, end_time); |
1615 } | 1633 } |
1616 | 1634 |
1617 void HistoryBackend::URLsNoLongerBookmarked(const std::set<GURL>& urls) { | 1635 void HistoryBackend::URLsNoLongerBookmarked(const std::set<GURL>& urls) { |
1618 if (!db_.get()) | 1636 if (!db_.get()) |
1619 return; | 1637 return; |
1620 | 1638 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1722 archived_db_.reset(new ArchivedDatabase()); | 1740 archived_db_.reset(new ArchivedDatabase()); |
1723 if (!archived_db_->Init(archived_file_name)) { | 1741 if (!archived_db_->Init(archived_file_name)) { |
1724 LOG(WARNING) << "Could not initialize the archived database."; | 1742 LOG(WARNING) << "Could not initialize the archived database."; |
1725 archived_db_.reset(); | 1743 archived_db_.reset(); |
1726 } else { | 1744 } else { |
1727 // Open our long-running transaction on this database. | 1745 // Open our long-running transaction on this database. |
1728 archived_db_->BeginTransaction(); | 1746 archived_db_->BeginTransaction(); |
1729 } | 1747 } |
1730 } | 1748 } |
1731 | 1749 |
1750 db_->GetStartDate(&first_recorded_time_); | |
1751 | |
1732 // Send out the notfication that history is cleared. The in-memory datdabase | 1752 // Send out the notfication that history is cleared. The in-memory datdabase |
1733 // will pick this up and clear itself. | 1753 // will pick this up and clear itself. |
1734 URLsDeletedDetails* details = new URLsDeletedDetails; | 1754 URLsDeletedDetails* details = new URLsDeletedDetails; |
1735 details->all_history = true; | 1755 details->all_history = true; |
1736 BroadcastNotifications(NotificationType::HISTORY_URLS_DELETED, details); | 1756 BroadcastNotifications(NotificationType::HISTORY_URLS_DELETED, details); |
1737 } | 1757 } |
1738 | 1758 |
1739 bool HistoryBackend::ClearAllThumbnailHistory( | 1759 bool HistoryBackend::ClearAllThumbnailHistory( |
1740 std::vector<URLRow>* kept_urls) { | 1760 std::vector<URLRow>* kept_urls) { |
1741 if (!thumbnail_db_.get()) { | 1761 if (!thumbnail_db_.get()) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1815 | 1835 |
1816 // Delete the old tables and recreate them empty. | 1836 // Delete the old tables and recreate them empty. |
1817 db_->RecreateAllTablesButURL(); | 1837 db_->RecreateAllTablesButURL(); |
1818 | 1838 |
1819 // Vacuum to reclaim the space from the dropped tables. This must be done | 1839 // Vacuum to reclaim the space from the dropped tables. This must be done |
1820 // when there is no transaction open, and we assume that our long-running | 1840 // when there is no transaction open, and we assume that our long-running |
1821 // transaction is currently open. | 1841 // transaction is currently open. |
1822 db_->CommitTransaction(); | 1842 db_->CommitTransaction(); |
1823 db_->Vacuum(); | 1843 db_->Vacuum(); |
1824 db_->BeginTransaction(); | 1844 db_->BeginTransaction(); |
1845 db_->GetStartDate(&first_recorded_time_); | |
1846 | |
1847 first_recorded_time_ = Time::Now(); | |
sky
2009/03/11 01:11:31
nuke this.
| |
1848 | |
1825 return true; | 1849 return true; |
1826 } | 1850 } |
1827 | 1851 |
1828 BookmarkService* HistoryBackend::GetBookmarkService() { | 1852 BookmarkService* HistoryBackend::GetBookmarkService() { |
1829 if (bookmark_service_) | 1853 if (bookmark_service_) |
1830 bookmark_service_->BlockTillLoaded(); | 1854 bookmark_service_->BlockTillLoaded(); |
1831 return bookmark_service_; | 1855 return bookmark_service_; |
1832 } | 1856 } |
1833 | 1857 |
1834 } // namespace history | 1858 } // namespace history |
OLD | NEW |