summaryrefslogtreecommitdiffstats
path: root/chrome/browser/dom_ui
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/dom_ui
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/dom_ui')
-rw-r--r--chrome/browser/dom_ui/dom_ui_thumbnail_source.cc41
-rw-r--r--chrome/browser/dom_ui/dom_ui_thumbnail_source.h14
2 files changed, 49 insertions, 6 deletions
diff --git a/chrome/browser/dom_ui/dom_ui_thumbnail_source.cc b/chrome/browser/dom_ui/dom_ui_thumbnail_source.cc
index 9f3d175..c3d51a1 100644
--- a/chrome/browser/dom_ui/dom_ui_thumbnail_source.cc
+++ b/chrome/browser/dom_ui/dom_ui_thumbnail_source.cc
@@ -17,27 +17,40 @@
DOMUIThumbnailSource::DOMUIThumbnailSource(Profile* profile)
: DataSource(chrome::kChromeUIThumbnailPath, MessageLoop::current()),
- profile_(profile) {
+ profile_(profile),
+ store_(profile->GetThumbnailStore()) {
+}
+
+DOMUIThumbnailSource::~DOMUIThumbnailSource() {
+ store_->CancelPendingRequests(pending_requests_);
}
void DOMUIThumbnailSource::StartDataRequest(const std::string& path,
int request_id) {
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kThumbnailStore)) {
- ThumbnailStore* store = profile_->GetThumbnailStore();
RefCountedBytes* data = NULL;
- if (!store->GetPageThumbnail(GURL(path), &data)) {
+ ThumbnailStore::GetStatus res = store_->GetPageThumbnail(GURL(path), &data);
+ if (res == ThumbnailStore::SUCCESS) {
+ // Got the thumbnail.
+ SendResponse(request_id, data);
+ } else if (res == ThumbnailStore::FAIL) {
+ // Don't have the thumbnail so return the default thumbnail.
if (!default_thumbnail_.get()) {
default_thumbnail_ = new RefCountedBytes;
ResourceBundle::GetSharedInstance().LoadImageResourceBytes(
IDR_DEFAULT_THUMBNAIL, &default_thumbnail_->data);
}
SendResponse(request_id, default_thumbnail_);
- return;
+ } else if (res == ThumbnailStore::ASYNC) {
+ // Getting the redirect list for the url. Will return thumbnail later.
+ ThumbnailStore::ThumbnailDataCallback* cb =
+ NewCallback(this, &DOMUIThumbnailSource::ReturnData);
+ pending_requests_.insert(request_id);
+ store_->GetPageThumbnailAsync(GURL(path), request_id, cb);
}
- SendResponse(request_id, data);
return;
- }
+ } // end --thumbnail-store switch
HistoryService* hs = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
if (hs) {
@@ -53,6 +66,22 @@ void DOMUIThumbnailSource::StartDataRequest(const std::string& path,
}
}
+void DOMUIThumbnailSource::ReturnData(int request_id,
+ scoped_refptr<RefCountedBytes> data) {
+ pending_requests_.erase(request_id);
+ if (data.get() && !data->data.empty()) {
+ SendResponse(request_id, data);
+ } else {
+ if (!default_thumbnail_.get()) {
+ default_thumbnail_ = new RefCountedBytes;
+ ResourceBundle::GetSharedInstance().LoadImageResourceBytes(
+ IDR_DEFAULT_THUMBNAIL, &default_thumbnail_->data);
+ }
+
+ SendResponse(request_id, default_thumbnail_);
+ }
+}
+
void DOMUIThumbnailSource::OnThumbnailDataAvailable(
HistoryService::Handle request_handle,
scoped_refptr<RefCountedBytes> data) {
diff --git a/chrome/browser/dom_ui/dom_ui_thumbnail_source.h b/chrome/browser/dom_ui/dom_ui_thumbnail_source.h
index 6b9be7e..b694466 100644
--- a/chrome/browser/dom_ui/dom_ui_thumbnail_source.h
+++ b/chrome/browser/dom_ui/dom_ui_thumbnail_source.h
@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_DOM_UI_DOM_UI_THUMBNAIL_SOURCE_H_
#define CHROME_BROWSER_DOM_UI_DOM_UI_THUMBNAIL_SOURCE_H_
+#include <set>
#include <string>
#include "base/basictypes.h"
@@ -13,17 +14,24 @@
#include "chrome/browser/history/history.h"
class Profile;
+class ThumbnailStore;
// ThumbnailSource is the gateway between network-level chrome:
// requests for thumbnails and the history backend that serves these.
class DOMUIThumbnailSource : public ChromeURLDataManager::DataSource {
public:
explicit DOMUIThumbnailSource(Profile* profile);
+ virtual ~DOMUIThumbnailSource();
// Called when the network layer has requested a resource underneath
// the path we registered.
virtual void StartDataRequest(const std::string& path, int request_id);
+ // Used only when chromium is invoked with the --thumbnail-store switch.
+ // If StartDataRequest does not return thumbnail data synchronously, this
+ // method will be invoked when the thumbnail data becomes available.
+ virtual void ReturnData(int request_id, scoped_refptr<RefCountedBytes> data);
+
virtual std::string GetMimeType(const std::string&) const {
// We need to explicitly return a mime type, otherwise if the user tries to
// drag the image they get no extension.
@@ -38,6 +46,12 @@ class DOMUIThumbnailSource : public ChromeURLDataManager::DataSource {
Profile* profile_;
CancelableRequestConsumerT<int, 0> cancelable_consumer_;
+ // A set of outstanding request_id's. These are canceled on destruction.
+ std::set<int> pending_requests_;
+
+ // The ThumbnailStore from which thumbnails are requested.
+ scoped_refptr<ThumbnailStore> store_;
+
// Raw PNG representation of the thumbnail to show when the thumbnail
// database doesn't have a thumbnail for a webpage.
scoped_refptr<RefCountedBytes> default_thumbnail_;