summaryrefslogtreecommitdiffstats
path: root/chrome/browser/thumbnail_store.h
diff options
context:
space:
mode:
authormeelapshah@chromium.org <meelapshah@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-24 22:38:58 +0000
committermeelapshah@chromium.org <meelapshah@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-24 22:38:58 +0000
commitf2458dc291eb8c593e5d9e56c293bb0c9507a2ae (patch)
tree158c04d0cb5ccb40eca5783dd8a1cdd81f57fb7f /chrome/browser/thumbnail_store.h
parentc3ee6f79c78d6fcb470262afc140aad614b8624c (diff)
downloadchromium_src-f2458dc291eb8c593e5d9e56c293bb0c9507a2ae.zip
chromium_src-f2458dc291eb8c593e5d9e56c293bb0c9507a2ae.tar.gz
chromium_src-f2458dc291eb8c593e5d9e56c293bb0c9507a2ae.tar.bz2
Add looking up/caching of redirect lists to find the best thumbnail.
Added timer to clean unpopular thumbnails from the cache/disk every hour. Still need to implement removal of blacklisted urls. Review URL: http://codereview.chromium.org/126237 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19189 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/thumbnail_store.h')
-rw-r--r--chrome/browser/thumbnail_store.h123
1 files changed, 115 insertions, 8 deletions
diff --git a/chrome/browser/thumbnail_store.h b/chrome/browser/thumbnail_store.h
index 486f99c..40e6033 100644
--- a/chrome/browser/thumbnail_store.h
+++ b/chrome/browser/thumbnail_store.h
@@ -6,16 +6,26 @@
#define CHROME_BROWSER_THUMBNAIL_STORE_H_
#include <map>
+#include <set>
+#include <string>
#include <vector>
#include "base/file_path.h"
#include "base/message_loop.h"
#include "base/ref_counted.h"
+#include "base/timer.h"
+#include "chrome/browser/cancelable_request.h"
+#include "chrome/browser/history/history.h"
+#include "chrome/common/pref_names.h"
#include "chrome/common/ref_counted_util.h"
#include "testing/gtest/include/gtest/gtest_prod.h"
+class DictionaryValue;
class GURL;
+class HistoryService;
+class PageUsageData;
class Pickle;
+class Profile;
class SkBitmap;
struct ThumbnailScore;
namespace base {
@@ -26,13 +36,16 @@ class Time;
// by the new_tab_ui.
class ThumbnailStore : public base::RefCountedThreadSafe<ThumbnailStore> {
public:
+ typedef Callback2<int, scoped_refptr<RefCountedBytes> >::Type
+ ThumbnailDataCallback;
+
ThumbnailStore();
~ThumbnailStore();
// Must be called after creation but before other methods are called.
// file_path is a directory where a new database should be created
// or the location of an existing databse.
- void Init(const FilePath& file_path);
+ void Init(const FilePath& file_path, Profile* profile);
// Stores the given thumbnail and score with the associated url in the cache.
// If write_to_disk is true, the thumbnail data is written to disk on the
@@ -43,20 +56,48 @@ class ThumbnailStore : public base::RefCountedThreadSafe<ThumbnailStore> {
bool write_to_disk);
// Sets *data to point to the thumbnail for the given url.
- // Returns false if there is not data for the given url or some other
- // error occurred.
- bool GetPageThumbnail(const GURL& url, RefCountedBytes** data);
+ // A return value of ASYNC means you should call GetPageThumbnailAsync.
+ // On a return value of SUCCESS, the refcount of the out parameter data
+ // is incremented for the caller who takes ownership of that reference.
+ enum GetStatus { SUCCESS, FAIL, ASYNC };
+ ThumbnailStore::GetStatus GetPageThumbnail(const GURL& url,
+ RefCountedBytes** data);
+
+ // Retrieves the redirects list for the given url asynchronously.
+ // Calls the callback with the request_id and thumbnail data if found.
+ void GetPageThumbnailAsync(const GURL& url,
+ int request_id,
+ ThumbnailStore::ThumbnailDataCallback* cb);
+
+ // Cancels the given set of request_id's which were issued from
+ // GetPageThumbnailAsync.
+ // This method is called from ~DOMUIThumbnailSource. If a
+ // DOMUIThumbnailSource requests a thumbnail but is destroyed before the
+ // data is sent back, this method will cancel the request and delete the
+ // callback.
+ void CancelPendingRequests(const std::set<int>& pending_requests);
private:
FRIEND_TEST(ThumbnailStoreTest, RetrieveFromCache);
FRIEND_TEST(ThumbnailStoreTest, RetrieveFromDisk);
+ FRIEND_TEST(ThumbnailStoreTest, UpdateThumbnail);
+ FRIEND_TEST(ThumbnailStoreTest, FollowRedirects);
// Data structure used to store thumbnail data in memory.
typedef std::map<GURL, std::pair<scoped_refptr<RefCountedBytes>,
- ThumbnailScore> > Cache;
+ ThumbnailScore> > Cache;
- // The location of the thumbnail store.
- FilePath file_path_;
+ // Data structure used to cache the redirect lists for urls.
+ typedef std::map<GURL, scoped_refptr<RefCountedVector<GURL> > > RedirectMap;
+
+ // Data structure used to store request_id's and callbacks for
+ // GetPageThumbnailAsync.
+ typedef std::map<int, std::pair<ThumbnailStore::ThumbnailDataCallback*,
+ HistoryService::Handle> > RequestMap;
+
+ // Deletes thumbnail data from disk for the given list of urls.
+ void DeleteThumbnails(
+ scoped_refptr<RefCountedVector<GURL> > thumbnail_urls) const;
// Read all thumbnail data from the specified FilePath into a Cache object.
// Done on the file_thread and returns to OnDiskDataAvailable on the thread
@@ -83,13 +124,79 @@ class ThumbnailStore : public base::RefCountedThreadSafe<ThumbnailStore> {
// Unpack a ThumbnailScore from a given Pickle and associated iterator.
// Returns false is a ThumbnailScore could not be unpacked.
- bool UnpackScore(ThumbnailScore* score, const Pickle& packed,
+ bool UnpackScore(ThumbnailScore* score,
+ const Pickle& packed,
void*& iter) const;
+ bool ShouldStoreThumbnailForURL(const GURL& url) const;
+
+ bool IsURLBlacklisted(const GURL& url) const;
+
+ std::wstring GetDictionaryKeyForURL(const std::string& url) const;
+
+ // Returns true if url is in most_visited_urls_.
+ bool IsPopular(const GURL& url) const;
+
+ // The callback for GetPageThumbnailAsync. Caches the redirect list
+ // and calls the callback for the request asssociated with the url.
+ void OnRedirectQueryComplete(HistoryService::Handle request_handle,
+ GURL url,
+ bool success,
+ HistoryService::RedirectList* redirects);
+
+ // Called on a timer initiated in Init(). Calls the HistoryService to
+ // update the list of most visited URLs. The callback is
+ // OnMostVisitedURLsAvailable.
+ void UpdateMostVisited();
+
+ // Updates the list of most visited URLs. Then calls CleanCacheData.
+ void OnMostVisitedURLsAvailable(CancelableRequestProvider::Handle handle,
+ std::vector<PageUsageData*>* data);
+
+ // Remove entries from the in memory thumbnail cache and redirect lists
+ // cache that have been blacklisted or are not in the top kMaxCacheSize
+ // visited sites.
+ void CleanCacheData();
+
// The Cache maintained by the object.
scoped_ptr<ThumbnailStore::Cache> cache_;
bool cache_initialized_;
+ // The location of the thumbnail store.
+ FilePath file_path_;
+
+ scoped_refptr<HistoryService> hs_;
+
+ // A list of the most_visited_urls_ refreshed every 30mins from the
+ // HistoryService.
+ std::vector<GURL> most_visited_urls_;
+
+ // A pointer to the persistent URL blacklist for this profile.
+ const DictionaryValue* url_blacklist_;
+
+ // A map pairing the URL that a user typed to a list of URLs it was
+ // redirected to. Ex:
+ // google.com => { http://www.google.com/ }
+ ThumbnailStore::RedirectMap redirect_urls_;
+
+ // When GetPageThumbnailAsync is called, this map records the request_id
+ // and callback associated with the request. When the thumbnail becomes
+ // available, the callback is taken from this map and the thumbnail data
+ // is returned to it.
+ ThumbnailStore::RequestMap redirect_requests_;
+
+ // Timer on which UpdateMostVisited runs.
+ base::RepeatingTimer<ThumbnailStore> timer_;
+
+ // Consumer for getting redirect lists from the history service.
+ CancelableRequestConsumerT<int, -1> hs_consumer_;
+
+ // Consumer for getting the list of most visited urls.
+ CancelableRequestConsumerTSimple<PageUsageData*> cancelable_consumer_;
+
+ static const int kMostVisitedScope = 90;
+ static const unsigned int kMaxCacheSize = 45;
+
DISALLOW_COPY_AND_ASSIGN(ThumbnailStore);
};