summaryrefslogtreecommitdiffstats
path: root/chrome/browser/history
diff options
context:
space:
mode:
authorglen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-11 01:24:08 +0000
committerglen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-11 01:24:08 +0000
commit153c6986284b7fc39fe5a875e0df5c8f29120957 (patch)
tree6f891ff5bbf3f2029d8c8a011d8916de6f2bfe1f /chrome/browser/history
parent193e1cdbcaac17d0fac6093f9bd63cd5477e4325 (diff)
downloadchromium_src-153c6986284b7fc39fe5a875e0df5c8f29120957.zip
chromium_src-153c6986284b7fc39fe5a875e0df5c8f29120957.tar.gz
chromium_src-153c6986284b7fc39fe5a875e0df5c8f29120957.tar.bz2
Stop history search going on beyond the start of history.
Stop losing first-searches on history page due to BUG=8438,8456 Review URL: http://codereview.chromium.org/43054 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11411 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/history')
-rw-r--r--chrome/browser/history/history_backend.cc22
-rw-r--r--chrome/browser/history/history_backend.h4
-rw-r--r--chrome/browser/history/history_querying_unittest.cc26
-rw-r--r--chrome/browser/history/history_types.cc6
-rw-r--r--chrome/browser/history/history_types.h6
-rw-r--r--chrome/browser/history/visit_database.cc12
-rw-r--r--chrome/browser/history/visit_database.h3
7 files changed, 77 insertions, 2 deletions
diff --git a/chrome/browser/history/history_backend.cc b/chrome/browser/history/history_backend.cc
index 94c309a..861aed5 100644
--- a/chrome/browser/history/history_backend.cc
+++ b/chrome/browser/history/history_backend.cc
@@ -350,6 +350,11 @@ void HistoryBackend::AddPage(scoped_refptr<HistoryAddPageArgs> request) {
last_recorded_time_ = last_requested_time_;
}
+ // If the user is adding older history, we need to make sure our times
+ // are correct.
+ if (request->time < first_recorded_time_)
+ first_recorded_time_ = request->time;
+
if (request->redirects.size() <= 1) {
// The single entry is both a chain start and end.
PageTransition::Type t = request->transition |
@@ -565,6 +570,9 @@ void HistoryBackend::InitImpl() {
if (text_database_.get())
text_database_->BeginTransaction();
+ // Get the first item in our database.
+ db_->GetStartDate(&first_recorded_time_);
+
// Start expiring old stuff.
expirer_.StartArchivingOldStuff(TimeDelta::FromDays(kArchiveDaysThreshold));
@@ -1042,6 +1050,9 @@ void HistoryBackend::QueryHistoryBasic(URLDatabase* url_db,
// snippets and stuff don't apply to basic querying.
result->AppendURLBySwapping(&url_result);
}
+
+ if (options.begin_time <= first_recorded_time_)
+ result->set_reached_beginning(true);
}
void HistoryBackend::QueryHistoryFTS(const std::wstring& text_query,
@@ -1092,6 +1103,9 @@ void HistoryBackend::QueryHistoryFTS(const std::wstring& text_query,
// result of the swap.
result->AppendURLBySwapping(&url_result);
}
+
+ if (options.begin_time <= first_recorded_time_)
+ result->set_reached_beginning(true);
}
// Frontend to GetMostRecentRedirectsFrom from the history thread.
@@ -1581,6 +1595,7 @@ void HistoryBackend::ReleaseDBTasks() {
void HistoryBackend::DeleteURL(const GURL& url) {
expirer_.DeleteURL(url);
+ db_->GetStartDate(&first_recorded_time_);
// Force a commit, if the user is deleting something for privacy reasons, we
// want to get it on disk ASAP.
Commit();
@@ -1608,6 +1623,9 @@ void HistoryBackend::ExpireHistoryBetween(
}
}
+ if (begin_time <= first_recorded_time_)
+ db_->GetStartDate(&first_recorded_time_);
+
request->ForwardResult(ExpireHistoryRequest::TupleType());
if (history_publisher_.get())
@@ -1729,6 +1747,8 @@ void HistoryBackend::DeleteAllHistory() {
}
}
+ db_->GetStartDate(&first_recorded_time_);
+
// Send out the notfication that history is cleared. The in-memory datdabase
// will pick this up and clear itself.
URLsDeletedDetails* details = new URLsDeletedDetails;
@@ -1822,6 +1842,8 @@ bool HistoryBackend::ClearAllMainHistory(
db_->CommitTransaction();
db_->Vacuum();
db_->BeginTransaction();
+ db_->GetStartDate(&first_recorded_time_);
+
return true;
}
diff --git a/chrome/browser/history/history_backend.h b/chrome/browser/history/history_backend.h
index 1dfa16e..5c23991 100644
--- a/chrome/browser/history/history_backend.h
+++ b/chrome/browser/history/history_backend.h
@@ -144,7 +144,6 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>,
void GetVisitCountToHost(scoped_refptr<GetVisitCountToHostRequest> request,
const GURL& url);
-
// Computes the most recent URL(s) that the given canonical URL has
// redirected to and returns true on success. There may be more than one
// redirect in a row, so this function will fill the given array with the
@@ -461,6 +460,9 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>,
// This keeps track of that higher-resolution timestamp.
base::Time last_recorded_time_;
+ // Timestamp of the first entry in our database.
+ base::Time first_recorded_time_;
+
// When non-NULL, this is the task that should be invoked on
MessageLoop* backend_destroy_message_loop_;
Task* backend_destroy_task_;
diff --git a/chrome/browser/history/history_querying_unittest.cc b/chrome/browser/history/history_querying_unittest.cc
index 488fd97..fe9a819 100644
--- a/chrome/browser/history/history_querying_unittest.cc
+++ b/chrome/browser/history/history_querying_unittest.cc
@@ -199,6 +199,32 @@ TEST_F(HistoryQueryTest, BasicDupes) {
EXPECT_TRUE(NthResultIs(results, 3, 1));
}
+TEST_F(HistoryQueryTest, ReachedBeginning) {
+ ASSERT_TRUE(history_.get());
+
+ QueryOptions options;
+ QueryResults results;
+
+ QueryHistory(std::wstring(), options, &results);
+ EXPECT_TRUE(results.reached_beginning());
+
+ options.begin_time = test_entries[1].time;
+ QueryHistory(std::wstring(), options, &results);
+ EXPECT_FALSE(results.reached_beginning());
+
+ options.begin_time = test_entries[0].time + TimeDelta::FromMicroseconds(1);
+ QueryHistory(std::wstring(), options, &results);
+ EXPECT_FALSE(results.reached_beginning());
+
+ options.begin_time = test_entries[0].time;
+ QueryHistory(std::wstring(), options, &results);
+ EXPECT_TRUE(results.reached_beginning());
+
+ options.begin_time = test_entries[0].time - TimeDelta::FromMicroseconds(1);
+ QueryHistory(std::wstring(), options, &results);
+ EXPECT_TRUE(results.reached_beginning());
+}
+
// This does most of the same tests above, but searches for a FTS string that
// will match the pages in question. This will trigger a different code path.
TEST_F(HistoryQueryTest, FTS) {
diff --git a/chrome/browser/history/history_types.cc b/chrome/browser/history/history_types.cc
index e44636f..4d42d60 100644
--- a/chrome/browser/history/history_types.cc
+++ b/chrome/browser/history/history_types.cc
@@ -92,7 +92,7 @@ void URLResult::Swap(URLResult* other) {
// QueryResults ----------------------------------------------------------------
-QueryResults::QueryResults() {
+QueryResults::QueryResults() : reached_beginning_(false) {
}
QueryResults::~QueryResults() {
@@ -119,6 +119,7 @@ const size_t* QueryResults::MatchesForURL(const GURL& url,
void QueryResults::Swap(QueryResults* other) {
std::swap(first_time_searched_, other->first_time_searched_);
+ std::swap(reached_beginning_, other->reached_beginning_);
results_.swap(other->results_);
url_to_results_.swap(other->url_to_results_);
}
@@ -142,6 +143,9 @@ void QueryResults::AppendResultsBySwapping(QueryResults* other,
if (first_time_searched_ > other->first_time_searched_)
std::swap(first_time_searched_, other->first_time_searched_);
+ if (reached_beginning_ != other->reached_beginning_)
+ std::swap(reached_beginning_, other->reached_beginning_);
+
for (size_t i = 0; i < other->results_.size(); i++) {
// Just transfer pointer ownership.
results_.push_back(other->results_[i]);
diff --git a/chrome/browser/history/history_types.h b/chrome/browser/history/history_types.h
index cc64a45..ecd39f6 100644
--- a/chrome/browser/history/history_types.h
+++ b/chrome/browser/history/history_types.h
@@ -377,6 +377,9 @@ class QueryResults {
void set_first_time_searched(base::Time t) { first_time_searched_ = t; }
// Note: If you need end_time_searched, it can be added.
+ void set_reached_beginning(bool reached) { reached_beginning_ = reached; }
+ bool reached_beginning() { return reached_beginning_; }
+
size_t size() const { return results_.size(); }
URLResult& operator[](size_t i) { return *results_[i]; }
@@ -431,6 +434,9 @@ class QueryResults {
base::Time first_time_searched_;
+ // Whether the query reaches the beginning of the database.
+ bool reached_beginning_;
+
// The ordered list of results. The pointers inside this are owned by this
// QueryResults object.
URLResultVector results_;
diff --git a/chrome/browser/history/visit_database.cc b/chrome/browser/history/visit_database.cc
index 6a7497d..4e796de 100644
--- a/chrome/browser/history/visit_database.cc
+++ b/chrome/browser/history/visit_database.cc
@@ -368,4 +368,16 @@ bool VisitDatabase::GetVisitCountToHost(const GURL& url,
return true;
}
+bool VisitDatabase::GetStartDate(Time* first_visit) {
+ SQLITE_UNIQUE_STATEMENT(statement, GetStatementCache(),
+ "SELECT MIN(visit_time) FROM visits WHERE visit_time != 0");
+ if (!statement.is_valid() || statement->step() != SQLITE_ROW ||
+ statement->column_int64(0) == 0) {
+ *first_visit = Time::Now();
+ return false;
+ }
+ *first_visit = Time::FromInternalValue(statement->column_int64(0));
+ return true;
+}
+
} // namespace history
diff --git a/chrome/browser/history/visit_database.h b/chrome/browser/history/visit_database.h
index 137fdc0..0b2549e 100644
--- a/chrome/browser/history/visit_database.h
+++ b/chrome/browser/history/visit_database.h
@@ -119,6 +119,9 @@ class VisitDatabase {
bool GetVisitCountToHost(const GURL& url, int* count,
base::Time* first_visit);
+ // Get the time of the first item in our database.
+ bool GetStartDate(base::Time* first_visit);
+
protected:
// Returns the database and statement cache for the functions in this
// interface. The decendent of this class implements these functions to