This source file includes following definitions.
- profile_
- IsFetchingDone
- CreateBitmapFetcher
- StartFetch
- OnFetchComplete
#include "chrome/browser/notifications/sync_notifier/image_holder.h"
namespace notifier {
ImageHolder::ImageHolder(const GURL& low_dpi_url,
const GURL& high_dpi_url,
Profile* profile,
ImageHolderDelegate* delegate)
: low_dpi_url_(low_dpi_url),
high_dpi_url_(high_dpi_url),
low_dpi_fetched_(false),
high_dpi_fetched_(false),
delegate_(delegate),
profile_(profile) {
if (!low_dpi_url_.is_valid()) {
low_dpi_url_ = GURL();
}
if (!high_dpi_url_.is_valid()) {
high_dpi_url_ = GURL();
}
if (!low_dpi_url_.is_empty()) {
CreateBitmapFetcher(low_dpi_url_);
}
if (!high_dpi_url_.is_empty()) {
CreateBitmapFetcher(high_dpi_url_);
}
}
ImageHolder::~ImageHolder() {}
bool ImageHolder::IsFetchingDone() const {
return ((low_dpi_url_.is_empty() || low_dpi_fetched_) &&
(high_dpi_url_.is_empty() || high_dpi_fetched_));
}
void ImageHolder::CreateBitmapFetcher(const GURL& url) {
ScopedVector<chrome::BitmapFetcher>::iterator iter;
for (iter = fetchers_.begin(); iter != fetchers_.end(); ++iter) {
if ((*iter)->url() == url)
return;
}
if (url.is_valid()) {
fetchers_.push_back(new chrome::BitmapFetcher(url, this));
DVLOG(2) << __FUNCTION__ << "Pushing bitmap " << url;
}
}
void ImageHolder::StartFetch() {
ScopedVector<chrome::BitmapFetcher>::iterator iter;
for (iter = fetchers_.begin(); iter != fetchers_.end(); ++iter) {
(*iter)->Start(profile_);
}
}
void ImageHolder::OnFetchComplete(const GURL url, const SkBitmap* bitmap) {
if (url == low_dpi_url_) {
low_dpi_fetched_ = true;
if (bitmap != NULL)
image_.AddRepresentation(gfx::ImageSkiaRep(*bitmap, 1.0));
} else if (url == high_dpi_url_) {
high_dpi_fetched_ = true;
if (bitmap != NULL)
image_.AddRepresentation(gfx::ImageSkiaRep(*bitmap, 2.0));
} else {
DVLOG(2) << __FUNCTION__ << "Unmatched bitmap arrived " << url;
}
delegate_->OnFetchComplete();
}
}