Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3025)

Unified Diff: chrome/browser/notifications/sync_notifier/image_holder.cc

Issue 193773003: Turn on and use the AppInfo data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Turn on app info: Refactoring the image holders Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/notifications/sync_notifier/image_holder.cc
diff --git a/chrome/browser/notifications/sync_notifier/image_holder.cc b/chrome/browser/notifications/sync_notifier/image_holder.cc
new file mode 100644
index 0000000000000000000000000000000000000000..35abb5ebfbac5ec8d78142999441a628c3404214
--- /dev/null
+++ b/chrome/browser/notifications/sync_notifier/image_holder.cc
@@ -0,0 +1,89 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This class holds the URL to an image and the bitmap for the fetched image,
+// and has code to fetch the bitmap from the URL.
+
+#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),
+ delegate_(delegate),
+ profile_(profile) {
+
+ // Create a featcher for each URL that is set.
+ if (!low_dpi_url_.is_empty()) {
+ CreateBitmapFetcher(low_dpi_url_);
+ }
+ if (!high_dpi_url_.is_empty()) {
+ CreateBitmapFetcher(high_dpi_url_);
+ }
+}
+
+ImageHolder::~ImageHolder() {}
+
+// This will let us know if we have tried to fetch once and the try completed.
+// Currently there is no logic for retries.
+bool ImageHolder::IsFetchingDone() const {
+ return ( (low_dpi_url_.is_empty() || low_dpi_fetched_) &&
+ (high_dpi_url_.is_empty() || high_dpi_fetched_) );
+}
+
+// If this bitmap has a valid GURL, create a fetcher for it.
+void ImageHolder::CreateBitmapFetcher(const GURL& url) {
+ // Check for dups, ignore any request for a dup.
+ 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() {
+ // Now that we have queued them all, start the fetching.
+ ScopedVector<chrome::BitmapFetcher>::iterator iter;
+ for (iter = fetchers_.begin(); iter != fetchers_.end(); ++iter) {
+ (*iter)->Start(profile_);
+ }
+}
+
+// Method inherited from BitmapFetcher delegate.
+void ImageHolder::OnFetchComplete(const GURL url,
+ const SkBitmap* bitmap) {
+ // TODO(petewil): Should I retry if a fetch fails?
+
+ // TODO(petewil):
+ // Use the ImageSkia functions instead and use 2.0 as scale for the hi dpi
+ // versions, then combine into one gfx::Image, which I pass to the
+ // Notification Center.
+
+ // Match the bitmap to the URL to put it into the right variable.
+ if (url == low_dpi_url_) {
+ low_dpi_fetched_ = true;
+ if (bitmap != NULL)
+ low_dpi_image_ = gfx::Image::CreateFrom1xBitmap(*bitmap);
+ } else if (url == high_dpi_url_) {
+ high_dpi_fetched_ = true;
+ if (bitmap != NULL)
+ high_dpi_image_ = gfx::Image::CreateFrom1xBitmap(*bitmap);
+ } else {
+ DVLOG(2) << __FUNCTION__ << "Unmatched bitmap arrived " << url;
+ }
+
+ // Notify callback of bitmap arrival.
+ delegate_->OnFetchComplete();
+}
+
+} // namespace notifier.

Powered by Google App Engine
This is Rietveld 408576698