summaryrefslogtreecommitdiffstats
path: root/chrome/browser/dom_ui
diff options
context:
space:
mode:
authorglen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-19 22:26:06 +0000
committerglen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-19 22:26:06 +0000
commitfbf644e73feb4e48db8739344f3c62cdccec0832 (patch)
treed9b2eafafb3c7185d6dffb1a276990eb50cb413c /chrome/browser/dom_ui
parent12e14fcf977c5a4be6dd8e2778ac13382e2bf08a (diff)
downloadchromium_src-fbf644e73feb4e48db8739344f3c62cdccec0832.zip
chromium_src-fbf644e73feb4e48db8739344f3c62cdccec0832.tar.gz
chromium_src-fbf644e73feb4e48db8739344f3c62cdccec0832.tar.bz2
* Add day deletion to history
* Speed up history viewing by swapping the search depth to day rather than month - it's now orders of magnitude faster for people who visit more than 30 pages a day, and very slightly slower for people who visit less than 10 pages a day. Review URL: http://codereview.chromium.org/21182 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10051 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r--chrome/browser/dom_ui/history_ui.cc97
-rw-r--r--chrome/browser/dom_ui/history_ui.h31
2 files changed, 102 insertions, 26 deletions
diff --git a/chrome/browser/dom_ui/history_ui.cc b/chrome/browser/dom_ui/history_ui.cc
index ed6f3b2..0062cf0 100644
--- a/chrome/browser/dom_ui/history_ui.cc
+++ b/chrome/browser/dom_ui/history_ui.cc
@@ -25,6 +25,7 @@
#include "generated_resources.h"
using base::Time;
+using base::TimeDelta;
// HistoryUI is accessible from chrome-ui://history.
static const char kHistoryHost[] = "history";
@@ -68,8 +69,10 @@ void HistoryUIHTMLSource::StartDataRequest(const std::string& path,
l10n_util::GetString(IDS_HISTORY_NO_RESULTS));
localized_strings.SetString(L"noitems",
l10n_util::GetString(IDS_HISTORY_NO_ITEMS));
- localized_strings.SetString(L"delete",
- l10n_util::GetString(IDS_HISTORY_DELETE));
+ localized_strings.SetString(L"deleteday",
+ l10n_util::GetString(IDS_HISTORY_DELETE_PRIOR_VISITS_LINK));
+ localized_strings.SetString(L"deletedaywarning",
+ l10n_util::GetString(IDS_HISTORY_DELETE_PRIOR_VISITS_WARNING));
static const StringPiece history_html(
ResourceBundle::GetSharedInstance().GetRawDataResource(
@@ -91,9 +94,14 @@ void HistoryUIHTMLSource::StartDataRequest(const std::string& path,
////////////////////////////////////////////////////////////////////////////////
BrowsingHistoryHandler::BrowsingHistoryHandler(DOMUI* dom_ui)
: DOMMessageHandler(dom_ui),
+ remover_(NULL),
search_text_() {
dom_ui_->RegisterMessageCallback("getHistory",
NewCallback(this, &BrowsingHistoryHandler::HandleGetHistory));
+ dom_ui_->RegisterMessageCallback("searchHistory",
+ NewCallback(this, &BrowsingHistoryHandler::HandleSearchHistory));
+ dom_ui_->RegisterMessageCallback("deleteDay",
+ NewCallback(this, &BrowsingHistoryHandler::HandleDeleteDay));
// Create our favicon data source.
g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
@@ -111,6 +119,9 @@ BrowsingHistoryHandler::~BrowsingHistoryHandler() {
NotificationService* service = NotificationService::current();
service->RemoveObserver(this, NotificationType::HISTORY_URLS_DELETED,
Source<Profile>(dom_ui_->get_profile()));
+
+ if (remover_)
+ remover_->RemoveObserver(this);
}
void BrowsingHistoryHandler::HandleGetHistory(const Value* value) {
@@ -118,23 +129,82 @@ void BrowsingHistoryHandler::HandleGetHistory(const Value* value) {
cancelable_consumer_.CancelAllRequests();
// Get arguments (if any).
- int month;
- std::wstring query;
- ExtractGetHistoryArguments(value, &month, &query);
+ int day = 0;
+ ExtractIntegerValue(value, &day);
// Set our query options.
- history::QueryOptions options = CreateQueryOptions(month, query);
+ history::QueryOptions options;
+ options.begin_time = Time::Now().LocalMidnight();
+ options.begin_time -= TimeDelta::FromDays(day);
+ options.end_time = Time::Now().LocalMidnight();
+ options.end_time -= TimeDelta::FromDays(day - 1);
+
+ // Need to remember the query string for our results.
+ search_text_ = std::wstring();
+
+ HistoryService* hs =
+ dom_ui_->get_profile()->GetHistoryService(Profile::EXPLICIT_ACCESS);
+ hs->QueryHistory(search_text_,
+ options,
+ &cancelable_consumer_,
+ NewCallback(this, &BrowsingHistoryHandler::QueryComplete));
+}
+
+void BrowsingHistoryHandler::HandleSearchHistory(const Value* value) {
+ // Anything in-flight is invalid.
+ cancelable_consumer_.CancelAllRequests();
+
+ // Get arguments (if any).
+ int month = 0;
+ std::wstring query;
+ ExtractSearchHistoryArguments(value, &month, &query);
+
+ // Set the query ranges for the given month.
+ history::QueryOptions options = CreateMonthQueryOptions(month);
+
+ // When searching, limit the number of results returned and only show the
+ // most recent matches.
+ options.max_count = kMaxSearchResults;
+ options.most_recent_visit_only = true;
// Need to remember the query string for our results.
search_text_ = query;
HistoryService* hs =
- dom_ui_->get_profile()->GetHistoryService(Profile::EXPLICIT_ACCESS);
+ dom_ui_->get_profile()->GetHistoryService(Profile::EXPLICIT_ACCESS);
hs->QueryHistory(search_text_,
options,
&cancelable_consumer_,
NewCallback(this, &BrowsingHistoryHandler::QueryComplete));
}
+void BrowsingHistoryHandler::HandleDeleteDay(const Value* value) {
+ // Anything in-flight is invalid.
+ cancelable_consumer_.CancelAllRequests();
+
+ // Get time.
+ Time time;
+ bool success = Time::FromString(ExtractStringValue(value).c_str(), &time);
+ DCHECK(success);
+
+ Time begin_time = time.LocalMidnight();
+ Time end_time = begin_time + TimeDelta::FromDays(1);
+
+ if (!remover_) {
+ remover_ = new BrowsingDataRemover(dom_ui_->get_profile(),
+ begin_time,
+ end_time);
+ remover_->AddObserver(this);
+ }
+
+ remover_->Remove(BrowsingDataRemover::REMOVE_HISTORY |
+ BrowsingDataRemover::REMOVE_COOKIES |
+ BrowsingDataRemover::REMOVE_CACHE);
+}
+
+void BrowsingHistoryHandler::OnBrowsingDataRemoverDone() {
+ dom_ui_->CallJavascriptFunction(L"deleteComplete");
+}
+
void BrowsingHistoryHandler::QueryComplete(
HistoryService::Handle request_handle,
history::QueryResults* results) {
@@ -184,7 +254,7 @@ void BrowsingHistoryHandler::QueryComplete(
StringValue(search_text_), results_value);
}
-void BrowsingHistoryHandler::ExtractGetHistoryArguments(const Value* value,
+void BrowsingHistoryHandler::ExtractSearchHistoryArguments(const Value* value,
int* month, std::wstring* query) {
*month = 0;
@@ -212,8 +282,8 @@ void BrowsingHistoryHandler::ExtractGetHistoryArguments(const Value* value,
}
}
-history::QueryOptions BrowsingHistoryHandler::CreateQueryOptions(int month,
- const std::wstring& query) {
+history::QueryOptions BrowsingHistoryHandler::CreateMonthQueryOptions(
+ int month) {
history::QueryOptions options;
// Configure the begin point of the search to the start of the
@@ -252,13 +322,6 @@ history::QueryOptions BrowsingHistoryHandler::CreateQueryOptions(int month,
options.begin_time = Time::FromLocalExploded(exploded);
}
- // If searching, only show the most recent entry and limit the number of
- // results returned.
- if (!query.empty()) {
- options.max_count = kMaxSearchResults;
- options.most_recent_visit_only = true;
- }
-
return options;
}
diff --git a/chrome/browser/dom_ui/history_ui.h b/chrome/browser/dom_ui/history_ui.h
index 742cf81..96efd3e 100644
--- a/chrome/browser/dom_ui/history_ui.h
+++ b/chrome/browser/dom_ui/history_ui.h
@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_DOM_UI_HISTORY_UI_H__
#define CHROME_BROWSER_DOM_UI_HISTORY_UI_H__
+#include "chrome/browser/browsing_data_remover.h"
#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
#include "chrome/browser/dom_ui/dom_ui.h"
#include "chrome/browser/dom_ui/dom_ui_contents.h"
@@ -28,7 +29,8 @@ class HistoryUIHTMLSource : public ChromeURLDataManager::DataSource {
// The handler for Javascript messages related to the "history" view.
class BrowsingHistoryHandler : public DOMMessageHandler,
- public NotificationObserver {
+ public NotificationObserver,
+ public BrowsingDataRemover::Observer {
public:
explicit BrowsingHistoryHandler(DOMUI* dom_ui_);
virtual ~BrowsingHistoryHandler();
@@ -36,28 +38,39 @@ class BrowsingHistoryHandler : public DOMMessageHandler,
// Callback for the "getHistory" message.
void HandleGetHistory(const Value* value);
+ // Callback for the "searchHistory" message.
+ void HandleSearchHistory(const Value* value);
+
+ // Callback for the "deleteDay" message.
+ void HandleDeleteDay(const Value* value);
+
// NotificationObserver implementation.
virtual void Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details);
+ // BrowsingDataRemover observer implementation.
+ void OnBrowsingDataRemoverDone();
+
private:
- // Callback from the history system when the most visited list is available.
+ // Callback from the history system when the history list is available.
void QueryComplete(HistoryService::Handle request_handle,
history::QueryResults* results);
- // Extract the arguments from the call to HandleGetHistory.
- void ExtractGetHistoryArguments(const Value* value,
- int* month,
- std::wstring* query);
+ // Extract the arguments from the call to HandleSearchHistory.
+ void ExtractSearchHistoryArguments(const Value* value,
+ int* month,
+ std::wstring* query);
- // Get the query options for a given month and query.
- history::QueryOptions CreateQueryOptions(int month,
- const std::wstring& query);
+ // Figure out the query options for a month-wide query.
+ history::QueryOptions CreateMonthQueryOptions(int month);
// Current search text.
std::wstring search_text_;
+ // Browsing history remover
+ BrowsingDataRemover* remover_;
+
// Our consumer for the history service.
CancelableRequestConsumerT<PageUsageData*, NULL> cancelable_consumer_;