From 523623c62f291467769fbb3c0e7fd5c1709b4da1 Mon Sep 17 00:00:00 2001 From: "brettw@chromium.org" Date: Wed, 19 May 2010 16:03:42 +0000 Subject: 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 --- chrome/browser/history/top_sites.cc | 19 +++++++++++++++++-- chrome/browser/history/top_sites.h | 14 ++++++++++---- 2 files changed, 27 insertions(+), 6 deletions(-) (limited to 'chrome/browser/history') 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::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 { 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 { 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; @@ -152,6 +155,9 @@ class TopSites : public base::RefCountedThreadSafe { // maps the redirects to the index into top_sites_ that contains it. std::map canonical_urls_; + // Timer for updating TopSites data. + base::OneShotTimer timer_; + // TODO(brettw): use the blacklist. // std::set blacklist_; -- cgit v1.1