summaryrefslogtreecommitdiffstats
path: root/chrome/browser/dom_ui
diff options
context:
space:
mode:
authormeelapshah@chromium.org <meelapshah@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-28 01:22:25 +0000
committermeelapshah@chromium.org <meelapshah@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-28 01:22:25 +0000
commitdaa82dc7442d26d9a50e342c0d9dcee43f287df8 (patch)
treebe3c211a383852579223f57be9c1ee13b84c1f6d /chrome/browser/dom_ui
parentabaa71c990b2d9dd514e9f2eefb1d2cf7b720562 (diff)
downloadchromium_src-daa82dc7442d26d9a50e342c0d9dcee43f287df8.zip
chromium_src-daa82dc7442d26d9a50e342c0d9dcee43f287df8.tar.gz
chromium_src-daa82dc7442d26d9a50e342c0d9dcee43f287df8.tar.bz2
Make ThumbnailStore broadcast a notification when it has finished reading thumbnails from disk.
Make DOMUIThumbnailSource wait for this notification if ThumbnailStore isn't ready yet. Also clean up some of the code. Review URL: http://codereview.chromium.org/155911 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21785 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/dom_ui')
-rw-r--r--chrome/browser/dom_ui/dom_ui_thumbnail_source.cc56
-rw-r--r--chrome/browser/dom_ui/dom_ui_thumbnail_source.h21
2 files changed, 64 insertions, 13 deletions
diff --git a/chrome/browser/dom_ui/dom_ui_thumbnail_source.cc b/chrome/browser/dom_ui/dom_ui_thumbnail_source.cc
index 5a10c7c..230389b 100644
--- a/chrome/browser/dom_ui/dom_ui_thumbnail_source.cc
+++ b/chrome/browser/dom_ui/dom_ui_thumbnail_source.cc
@@ -10,6 +10,7 @@
#include "chrome/browser/profile.h"
#include "chrome/browser/thumbnail_store.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/notification_service.h"
#include "chrome/common/url_constants.h"
#include "googleurl/src/gurl.h"
#include "grit/theme_resources.h"
@@ -23,20 +24,18 @@ DOMUIThumbnailSource::DOMUIThumbnailSource(Profile* profile)
void DOMUIThumbnailSource::StartDataRequest(const std::string& path,
int request_id) {
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kThumbnailStore)) {
- RefCountedBytes* data = NULL;
scoped_refptr<ThumbnailStore> store_ = profile_->GetThumbnailStore();
- if (store_->GetPageThumbnail(GURL(path), &data)) {
- // Got the thumbnail.
- SendResponse(request_id, data);
- } else {
- // 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);
+ if (!store_->IsReady()) {
+ // Register to be notified when the ThumbnailStore is ready.
+ if (registrar_.IsEmpty()) {
+ registrar_.Add(this, NotificationType::THUMBNAIL_STORE_READY,
+ Source<ThumbnailStore>(store_.get()));
}
- SendResponse(request_id, default_thumbnail_);
+ // Insert into pending_requests.
+ pending_requests_.push_back(std::make_pair(path, request_id));
+ } else {
+ DoDataRequest(path, request_id);
}
return;
} // end --thumbnail-store switch
@@ -55,6 +54,24 @@ void DOMUIThumbnailSource::StartDataRequest(const std::string& path,
}
}
+void DOMUIThumbnailSource::DoDataRequest(const std::string& path,
+ int request_id) {
+ RefCountedBytes* data = NULL;
+ scoped_refptr<ThumbnailStore> store_ = profile_->GetThumbnailStore();
+ if (store_->GetPageThumbnail(GURL(path), &data)) {
+ // Got the thumbnail.
+ SendResponse(request_id, data);
+ } else {
+ // 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_);
+ }
+}
+
void DOMUIThumbnailSource::OnThumbnailDataAvailable(
HistoryService::Handle request_handle,
scoped_refptr<RefCountedBytes> data) {
@@ -74,3 +91,20 @@ void DOMUIThumbnailSource::OnThumbnailDataAvailable(
SendResponse(request_id, default_thumbnail_);
}
}
+
+void DOMUIThumbnailSource::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ if (type.value != NotificationType::THUMBNAIL_STORE_READY) {
+ NOTREACHED();
+ return;
+ }
+
+ // This notification is sent only once.
+ registrar_.RemoveAll();
+
+ for (size_t i = 0; i < pending_requests_.size(); ++i)
+ DoDataRequest(pending_requests_[i].first, pending_requests_[i].second);
+
+ pending_requests_.clear();
+}
diff --git a/chrome/browser/dom_ui/dom_ui_thumbnail_source.h b/chrome/browser/dom_ui/dom_ui_thumbnail_source.h
index c94967b..4e1555d 100644
--- a/chrome/browser/dom_ui/dom_ui_thumbnail_source.h
+++ b/chrome/browser/dom_ui/dom_ui_thumbnail_source.h
@@ -5,20 +5,22 @@
#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 <vector>
#include "base/basictypes.h"
#include "base/scoped_ptr.h"
#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
#include "chrome/browser/history/history.h"
+#include "chrome/common/notification_registrar.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 {
+class DOMUIThumbnailSource : public ChromeURLDataManager::DataSource,
+ public NotificationObserver {
public:
explicit DOMUIThumbnailSource(Profile* profile);
@@ -37,6 +39,14 @@ class DOMUIThumbnailSource : public ChromeURLDataManager::DataSource {
scoped_refptr<RefCountedBytes> data);
private:
+ // NotificationObserver implementation
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
+ // Fetch the specified resource.
+ void DoDataRequest(const std::string& path, int request_id);
+
Profile* profile_;
CancelableRequestConsumerT<int, 0> cancelable_consumer_;
@@ -44,6 +54,13 @@ class DOMUIThumbnailSource : public ChromeURLDataManager::DataSource {
// database doesn't have a thumbnail for a webpage.
scoped_refptr<RefCountedBytes> default_thumbnail_;
+ // Store requests when the ThumbnailStore isn't ready. When a notification is
+ // received that it is ready, then serve these requests.
+ std::vector<std::pair<std::string, int> > pending_requests_;
+
+ // To register to be notified when the ThumbnailStore is ready.
+ NotificationRegistrar registrar_;
+
DISALLOW_COPY_AND_ASSIGN(DOMUIThumbnailSource);
};