summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--chrome/browser/dom_ui/dom_ui_contents.cc2
-rw-r--r--chrome/browser/dom_ui/history_ui.cc26
-rw-r--r--chrome/browser/dom_ui/history_ui.h2
-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
-rw-r--r--chrome/browser/resources/history.html31
11 files changed, 118 insertions, 22 deletions
diff --git a/chrome/browser/dom_ui/dom_ui_contents.cc b/chrome/browser/dom_ui/dom_ui_contents.cc
index cad2dd4..9d80db3 100644
--- a/chrome/browser/dom_ui/dom_ui_contents.cc
+++ b/chrome/browser/dom_ui/dom_ui_contents.cc
@@ -246,7 +246,7 @@ bool DOMUIContents::InitCurrentUI(bool reload) {
if (url.is_empty() || !url.is_valid())
return false;
- if (reload || url != current_url_) {
+ if (reload || url.host() != current_url_.host()) {
// Shut down our existing DOMUI.
delete current_ui_;
current_ui_ = NULL;
diff --git a/chrome/browser/dom_ui/history_ui.cc b/chrome/browser/dom_ui/history_ui.cc
index 6e09592..8bc2013 100644
--- a/chrome/browser/dom_ui/history_ui.cc
+++ b/chrome/browser/dom_ui/history_ui.cc
@@ -76,6 +76,10 @@ void HistoryUIHTMLSource::StartDataRequest(const std::string& path,
localized_strings.SetString(L"deletedaywarning",
l10n_util::GetString(IDS_HISTORY_DELETE_PRIOR_VISITS_WARNING));
+ localized_strings.SetString(L"textdirection",
+ (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ?
+ L"rtl" : L"ltr");
+
static const StringPiece history_html(
ResourceBundle::GetSharedInstance().GetRawDataResource(
IDR_HISTORY_HTML));
@@ -101,9 +105,9 @@ BrowsingHistoryHandler::BrowsingHistoryHandler(DOMUI* dom_ui)
dom_ui_->RegisterMessageCallback("getHistory",
NewCallback(this, &BrowsingHistoryHandler::HandleGetHistory));
dom_ui_->RegisterMessageCallback("searchHistory",
- NewCallback(this, &BrowsingHistoryHandler::HandleSearchHistory));
+ NewCallback(this, &BrowsingHistoryHandler::HandleSearchHistory));
dom_ui_->RegisterMessageCallback("deleteDay",
- NewCallback(this, &BrowsingHistoryHandler::HandleDeleteDay));
+ NewCallback(this, &BrowsingHistoryHandler::HandleDeleteDay));
// Create our favicon data source.
g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
@@ -143,6 +147,9 @@ void BrowsingHistoryHandler::HandleGetHistory(const Value* value) {
options.end_time = Time::Now().LocalMidnight();
options.end_time -= TimeDelta::FromDays(day - 1);
+ // As we're querying per-day, we can turn entry repeats off.
+ options.most_recent_visit_only = true;
+
// Need to remember the query string for our results.
search_text_ = std::wstring();
@@ -259,8 +266,11 @@ void BrowsingHistoryHandler::QueryComplete(
results_value.Append(page_value);
}
- StringValue temp(search_text_);
- dom_ui_->CallJavascriptFunction(L"historyResult", temp, results_value);
+ DictionaryValue info_value;
+ info_value.SetString(L"term", search_text_);
+ info_value.SetBoolean(L"finished", results->reached_beginning());
+
+ dom_ui_->CallJavascriptFunction(L"historyResult", info_value, results_value);
}
void BrowsingHistoryHandler::ExtractSearchHistoryArguments(const Value* value,
@@ -342,8 +352,8 @@ void BrowsingHistoryHandler::Observe(NotificationType type,
return;
}
- // Some URLs were deleted from history. Reload the most visited list.
- HandleGetHistory(NULL);
+ // Some URLs were deleted from history. Reload the list.
+ dom_ui_->CallJavascriptFunction(L"historyDeleted");
}
////////////////////////////////////////////////////////////////////////////////
@@ -377,7 +387,7 @@ GURL HistoryUI::GetBaseURL() {
// static
const GURL HistoryUI::GetHistoryURLWithSearchText(
- const std::wstring& text) {
- return GURL(GetBaseURL().spec() + "#q=" +
+ const std::wstring& text) {
+ return GURL(GetBaseURL().spec() + "#q=" +
EscapeQueryParamValue(WideToUTF8(text)));
}
diff --git a/chrome/browser/dom_ui/history_ui.h b/chrome/browser/dom_ui/history_ui.h
index 38ccc3a..3bc550e 100644
--- a/chrome/browser/dom_ui/history_ui.h
+++ b/chrome/browser/dom_ui/history_ui.h
@@ -74,7 +74,7 @@ class BrowsingHistoryHandler : public DOMMessageHandler,
scoped_ptr<BrowsingDataRemover> remover_;
// Our consumer for the history service.
- CancelableRequestConsumerTSimple<PageUsageData*> cancelable_consumer_;
+ CancelableRequestConsumerT<int, 0> cancelable_consumer_;
DISALLOW_COPY_AND_ASSIGN(BrowsingHistoryHandler);
};
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
diff --git a/chrome/browser/resources/history.html b/chrome/browser/resources/history.html
index 0b1e9b6..cf88429 100644
--- a/chrome/browser/resources/history.html
+++ b/chrome/browser/resources/history.html
@@ -1,5 +1,5 @@
<!DOCTYPE HTML>
-<html id="t">
+<html id="t" jsvalues="dir:textdirection;">
<head>
<meta charset="utf-8">
<title jscontent="title"></title>
@@ -259,7 +259,7 @@ HistoryModel.prototype.getSearchText = function() {
HistoryModel.prototype.requestPage = function(page) {
this.requestedPage_ = page;
this.changed = true;
- this.updateSearch_();
+ this.updateSearch_(false);
}
/**
@@ -267,9 +267,9 @@ HistoryModel.prototype.requestPage = function(page) {
* @param {String} term The search term that the results are for.
* @param {Array} results A list of results
*/
-HistoryModel.prototype.addResults = function(term, results) {
+HistoryModel.prototype.addResults = function(info, results) {
this.inFlight_ = false;
- if (term != this.searchText_) {
+ if (info.term != this.searchText_) {
// If our results aren't for our current search term, they're rubbish.
return;
}
@@ -302,7 +302,7 @@ HistoryModel.prototype.addResults = function(term, results) {
if (results.length)
this.changed = true;
- this.updateSearch_();
+ this.updateSearch_(info.finished);
}
/**
@@ -354,8 +354,9 @@ HistoryModel.prototype.clearModel_ = function() {
* page. If we think we can fill the page, call the view and let it know
* we're ready to show something.
*/
-HistoryModel.prototype.updateSearch_ = function() {
- if (this.searchText_ && this.searchDepth_ >= MAX_SEARCH_DEPTH_MONTHS) {
+HistoryModel.prototype.updateSearch_ = function(finished) {
+ if ((this.searchText_ && this.searchDepth_ >= MAX_SEARCH_DEPTH_MONTHS) ||
+ finished) {
// We have maxed out. There will be no more data.
this.complete_ = true;
this.view_.onModelReady();
@@ -761,15 +762,15 @@ function deleteNextInQueue() {
/**
* Our history system calls this function with results from searches.
*/
-function historyResult(term, results) {
- historyModel.addResults(term, results);
+function historyResult(info, results) {
+ historyModel.addResults(info, results);
}
/**
* Our history system calls this function when a deletion has finished.
*/
function deleteComplete() {
- historyView.reload();
+ window.console.log("Delete complete");
deleteInFlight = false;
if (deleteQueue.length > 1) {
deleteQueue = deleteQueue.slice(1, deleteQueue.length);
@@ -782,10 +783,20 @@ function deleteComplete() {
* another delete is in-progress).
*/
function deleteFailed() {
+ window.console.log("Delete failed");
// The deletion failed - try again later.
deleteInFlight = false;
setTimeout(deleteNextInQueue, 500);
}
+
+/**
+ * We're called when something is deleted (either by us or by someone
+ * else).
+ */
+function historyDeleted() {
+ window.console.log("History deleted");
+ historyView.reload();
+}
</script>
<style type="text/css">
body {