summaryrefslogtreecommitdiffstats
path: root/chrome/browser/history
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-19 16:03:42 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-19 16:03:42 +0000
commit523623c62f291467769fbb3c0e7fd5c1709b4da1 (patch)
treef7ffe236605e0d56d89bd7c6c5e8785662be166d /chrome/browser/history
parentd0cc0f3d2c1216d2c2168690f64dc448d3ac9ca8 (diff)
downloadchromium_src-523623c62f291467769fbb3c0e7fd5c1709b4da1.zip
chromium_src-523623c62f291467769fbb3c0e7fd5c1709b4da1.tar.gz
chromium_src-523623c62f291467769fbb3c0e7fd5c1709b4da1.tar.bz2
Add command line flag --top-sites to replace the thumbnail store flag.
Use the flag for querying for thumbnails. Add timer to update TopSites (every second for now). BUG=None TEST='chrome --top-sites' git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47671 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/history')
-rw-r--r--chrome/browser/history/top_sites.cc19
-rw-r--r--chrome/browser/history/top_sites.h14
2 files changed, 27 insertions, 6 deletions
diff --git a/chrome/browser/history/top_sites.cc b/chrome/browser/history/top_sites.cc
index 90399b1..fd23865 100644
--- a/chrome/browser/history/top_sites.cc
+++ b/chrome/browser/history/top_sites.cc
@@ -15,6 +15,8 @@ namespace history {
// How many top sites to store in the cache.
static const int kTopSitesNumber = 20;
static const int kDaysOfHistory = 90;
+static const int64 kUpdateIntervalSecs = 15; // TODO(Nik): come up
+ // with an algorithm for timing.
TopSites::TopSites(Profile* profile) : profile_(profile),
mock_history_service_(NULL) {
@@ -23,9 +25,12 @@ TopSites::TopSites(Profile* profile) : profile_(profile),
TopSites::~TopSites() {
}
-bool TopSites::Init() {
+void TopSites::Init() {
// TODO(brettw) read the database here.
- return true;
+
+ // Start the one-shot timer.
+ timer_.Start(base::TimeDelta::FromSeconds(kUpdateIntervalSecs), this,
+ &TopSites::StartQueryForMostVisited);
}
bool TopSites::SetPageThumbnail(const GURL& url,
@@ -70,6 +75,16 @@ MostVisitedURLList TopSites::GetMostVisitedURLs() {
return top_sites_;
}
+bool TopSites::GetPageThumbnail(const GURL& url, RefCountedBytes** data) const {
+ std::map<GURL, Images>::const_iterator found = top_images_.find(url);
+ if (found == top_images_.end())
+ return false; // No thumbnail for this URL.
+
+ Images image = found->second;
+ *data = image.thumbnail.get();
+ return true;
+}
+
void TopSites::StoreMostVisited(MostVisitedURLList* most_visited) {
lock_.AssertAcquired();
// TODO(brettw) filter for blacklist!
diff --git a/chrome/browser/history/top_sites.h b/chrome/browser/history/top_sites.h
index 6a85ef6..ff98b7a 100644
--- a/chrome/browser/history/top_sites.h
+++ b/chrome/browser/history/top_sites.h
@@ -12,6 +12,7 @@
#include "base/basictypes.h"
#include "base/lock.h"
+#include "base/timer.h"
#include "base/ref_counted.h"
#include "base/ref_counted_memory.h"
#include "chrome/browser/cancelable_request.h"
@@ -55,8 +56,8 @@ class TopSites : public base::RefCountedThreadSafe<TopSites> {
virtual ~MockHistoryService() {}
};
- // Initializes this component, returning true on success.
- bool Init();
+ // Initializes TopSites.
+ void Init();
// Sets the given thumbnail for the given URL. Returns true if the thumbnail
// was updated. False means either the URL wasn't known to us, or we felt
@@ -65,10 +66,12 @@ class TopSites : public base::RefCountedThreadSafe<TopSites> {
const SkBitmap& thumbnail,
const ThumbnailScore& score);
+ // Returns a list of most visited URLs or an empty list if it's not
+ // cached yet.
MostVisitedURLList GetMostVisitedURLs();
- // TODO(brettw): write this.
- // bool GetPageThumbnail(const GURL& url, RefCountedBytes** data) const;
+ // Get a thumbnail for a given page. Returns true iff we have the thumbnail.
+ bool GetPageThumbnail(const GURL& url, RefCountedBytes** data) const;
private:
friend class base::RefCountedThreadSafe<TopSites>;
@@ -152,6 +155,9 @@ class TopSites : public base::RefCountedThreadSafe<TopSites> {
// maps the redirects to the index into top_sites_ that contains it.
std::map<GURL, size_t> canonical_urls_;
+ // Timer for updating TopSites data.
+ base::OneShotTimer<TopSites> timer_;
+
// TODO(brettw): use the blacklist.
// std::set<GURL> blacklist_;