summaryrefslogtreecommitdiffstats
path: root/chrome/browser/history
diff options
context:
space:
mode:
authormeelapshah@chromium.org <meelapshah@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-01 17:27:37 +0000
committermeelapshah@chromium.org <meelapshah@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-01 17:27:37 +0000
commita003b3c269dbca5e2ca7bccf541319e11869e545 (patch)
tree4693a02e65e0456c1911496f9d91f6db48e91d08 /chrome/browser/history
parente6f546c3ab626d39d375376890b7f4bfef92f48e (diff)
downloadchromium_src-a003b3c269dbca5e2ca7bccf541319e11869e545.zip
chromium_src-a003b3c269dbca5e2ca7bccf541319e11869e545.tar.gz
chromium_src-a003b3c269dbca5e2ca7bccf541319e11869e545.tar.bz2
Add a function to the History to return a list of the top n visited URLs where and the list of most recent redirects for each of those URLs.
Review URL: http://codereview.chromium.org/151057 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19743 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/history')
-rw-r--r--chrome/browser/history/history.cc9
-rw-r--r--chrome/browser/history/history.h14
-rw-r--r--chrome/browser/history/history_backend.cc30
-rw-r--r--chrome/browser/history/history_backend.h5
-rw-r--r--chrome/browser/history/history_marshaling.h5
-rw-r--r--chrome/browser/history/history_types.h5
6 files changed, 68 insertions, 0 deletions
diff --git a/chrome/browser/history/history.cc b/chrome/browser/history/history.cc
index 49b76c6..b6c1d0a 100644
--- a/chrome/browser/history/history.cc
+++ b/chrome/browser/history/history.cc
@@ -536,6 +536,15 @@ HistoryService::Handle HistoryService::GetVisitCountToHost(
new history::GetVisitCountToHostRequest(callback), url);
}
+HistoryService::Handle HistoryService::QueryTopURLsAndRedirects(
+ int result_count,
+ CancelableRequestConsumerBase* consumer,
+ QueryTopURLsAndRedirectsCallback* callback) {
+ return Schedule(PRIORITY_NORMAL, &HistoryBackend::QueryTopURLsAndRedirects,
+ consumer, new history::QueryTopURLsAndRedirectsRequest(callback),
+ result_count);
+}
+
void HistoryService::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
diff --git a/chrome/browser/history/history.h b/chrome/browser/history/history.h
index fcea84f..200e19c 100644
--- a/chrome/browser/history/history.h
+++ b/chrome/browser/history/history.h
@@ -305,6 +305,20 @@ class HistoryService : public CancelableRequestProvider,
CancelableRequestConsumerBase* consumer,
GetVisitCountToHostCallback* callback);
+ // Called when QueryTopURLsAndRedirects completes. The vector contains a list
+ // of the top |result_count| URLs. For each of these URLs, there is an entry
+ // in the map containing redirects from the URL. For example, if we have the
+ // redirect chain A -> B -> C and A is a top visited URL, then A will be in
+ // the vector and "A => {B -> C}" will be in the map.
+ typedef Callback2<std::vector<GURL>*, history::RedirectMap*>::Type
+ QueryTopURLsAndRedirectsCallback;
+
+ // Request the top |result_count| most visited URLs and the chain of redirects
+ // leading to each of these URLs.
+ Handle QueryTopURLsAndRedirects(int result_count,
+ CancelableRequestConsumerBase* consumer,
+ QueryTopURLsAndRedirectsCallback* callback);
+
// Thumbnails ----------------------------------------------------------------
// Implemented by consumers to get thumbnail data. Called when a request for
diff --git a/chrome/browser/history/history_backend.cc b/chrome/browser/history/history_backend.cc
index 7060c45..622932b 100644
--- a/chrome/browser/history/history_backend.cc
+++ b/chrome/browser/history/history_backend.cc
@@ -1152,6 +1152,36 @@ void HistoryBackend::GetVisitCountToHost(
request->handle(), success, count, first_visit));
}
+void HistoryBackend::QueryTopURLsAndRedirects(
+ scoped_refptr<QueryTopURLsAndRedirectsRequest> request,
+ int result_count) {
+ if (request->canceled())
+ return;
+
+ if (!db_.get()) {
+ request->ForwardResult(QueryTopURLsAndRedirectsRequest::TupleType(
+ NULL, NULL));
+ return;
+ }
+
+ std::vector<GURL>* top_urls = &request->value.a;
+ history::RedirectMap* redirects = &request->value.b;
+
+ std::vector<PageUsageData*> data;
+ db_->QuerySegmentUsage(base::Time::Now() - base::TimeDelta::FromDays(90),
+ result_count, &data);
+
+ for (size_t i = 0; i < data.size(); ++i) {
+ top_urls->push_back(data[i]->GetURL());
+ HistoryService::RedirectList list;
+ GetMostRecentRedirectsFrom(top_urls->back(), &list);
+ (*redirects)[top_urls->back()] = new RefCountedVector<GURL>(list);
+ }
+
+ request->ForwardResult(QueryTopURLsAndRedirectsRequest::TupleType(
+ top_urls, redirects));
+}
+
void HistoryBackend::GetRedirectsFromSpecificVisit(
VisitID cur_visit, HistoryService::RedirectList* redirects) {
// Follow any redirects from the given visit and add them to the list.
diff --git a/chrome/browser/history/history_backend.h b/chrome/browser/history/history_backend.h
index 421e0a0..4870589 100644
--- a/chrome/browser/history/history_backend.h
+++ b/chrome/browser/history/history_backend.h
@@ -147,6 +147,11 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>,
void GetVisitCountToHost(scoped_refptr<GetVisitCountToHostRequest> request,
const GURL& url);
+
+ void QueryTopURLsAndRedirects(
+ scoped_refptr<QueryTopURLsAndRedirectsRequest> request,
+ int result_count);
+
// 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
diff --git a/chrome/browser/history/history_marshaling.h b/chrome/browser/history/history_marshaling.h
index a6f449c..e2ed5ca 100644
--- a/chrome/browser/history/history_marshaling.h
+++ b/chrome/browser/history/history_marshaling.h
@@ -70,6 +70,11 @@ typedef CancelableRequest1<HistoryService::QueryRedirectsCallback,
typedef CancelableRequest<HistoryService::GetVisitCountToHostCallback>
GetVisitCountToHostRequest;
+typedef CancelableRequest1<HistoryService::QueryTopURLsAndRedirectsCallback,
+ Tuple2<std::vector<GURL>,
+ history::RedirectMap> >
+ QueryTopURLsAndRedirectsRequest;
+
// Thumbnails -----------------------------------------------------------------
typedef CancelableRequest<HistoryService::ThumbnailDataCallback>
diff --git a/chrome/browser/history/history_types.h b/chrome/browser/history/history_types.h
index 7a973ba..8c92d64 100644
--- a/chrome/browser/history/history_types.h
+++ b/chrome/browser/history/history_types.h
@@ -17,6 +17,7 @@
#include "base/time.h"
#include "chrome/browser/history/snippet.h"
#include "chrome/common/page_transition_types.h"
+#include "chrome/common/ref_counted_util.h"
#include "googleurl/src/gurl.h"
namespace history {
@@ -25,6 +26,10 @@ namespace history {
class HistoryBackend;
class URLDatabase;
+// Structure to hold redirect lists for URLs. For a redirect chain
+// A -> B -> C, and entry in the map would look like "A => {B -> C}".
+typedef std::map<GURL, scoped_refptr<RefCountedVector<GURL> > > RedirectMap;
+
typedef int64 StarID; // Unique identifier for star entries.
typedef int64 UIStarID; // Identifier for star entries that come from the UI.
typedef int64 DownloadID; // Identifier for a download.