Index: chrome/browser/notifications/sync_notifier/image_holder.h |
diff --git a/chrome/browser/notifications/sync_notifier/image_holder.h b/chrome/browser/notifications/sync_notifier/image_holder.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..78a8771bc11b96e8e489d92b4684464143b52a5a |
--- /dev/null |
+++ b/chrome/browser/notifications/sync_notifier/image_holder.h |
@@ -0,0 +1,81 @@ |
+// 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. |
+ |
+#ifndef CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_IMAGE_HOLDER_H_ |
+#define CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_IMAGE_HOLDER_H_ |
+ |
+#include "base/memory/scoped_vector.h" |
+#include "chrome/browser/bitmap_fetcher.h" |
+#include "ui/gfx/image/image.h" |
+#include "url/gurl.h" |
+ |
+class Profile; |
+ |
+namespace notifier { |
+ |
+// This provides a callback so the ImageHolder can inform its parent when a |
+// bitmap arrives. |
+class ImageHolderDelegate { |
+ public: |
+ virtual void OnFetchComplete() = 0; |
+}; |
+ |
+// This class encapsulates the action of fetching a bitmap, reporting when it is |
+// fetched, and holding onto the bitmap until no longer needed. |
+class ImageHolder : public chrome::BitmapFetcherDelegate { |
+ public: |
+ ImageHolder(const GURL& low_dpi_url, |
dewittj
2014/03/24 17:35:50
I would prefer something similar to ImageSkia wher
Pete Williamson
2014/03/25 00:08:37
I'd rather that the ImageHolder was able to hold b
|
+ const GURL& high_dpi_url, |
+ Profile* profile, |
+ ImageHolderDelegate* delegate); |
+ virtual ~ImageHolder(); |
+ |
+ // Begin fetching of the URLs we have. |
+ void StartFetch(); |
+ |
+ // Check whether we have a response from the server for these resources, |
+ // even if the response is a failed fetch. |
+ bool IsFetchingDone() const; |
+ |
+ // Inherited from BitmapFetcherDelegate |
+ virtual void OnFetchComplete(const GURL url, const SkBitmap* bitmap) OVERRIDE; |
+ |
+ // Accessors: |
+ GURL low_dpi_url() const { return low_dpi_url_; } |
+ void set_low_dpi_url(const GURL& low_dpi_url) { |
+ low_dpi_url_ = low_dpi_url; |
+ } |
+ GURL high_dpi_url() const { return high_dpi_url_; } |
+ void set_high_dpi_url(const GURL& high_dpi_url) { |
+ high_dpi_url_ = high_dpi_url; |
+ } |
+ gfx::Image low_dpi_image() { return low_dpi_image_; } |
+ gfx::Image high_dpi_image() { return high_dpi_image_; } |
+ |
+ private: |
+ void CreateBitmapFetcher(const GURL& url); |
+ |
+ GURL low_dpi_url_; |
+ GURL high_dpi_url_; |
+ bool low_dpi_fetched_; |
+ bool high_dpi_fetched_; |
+ gfx::Image low_dpi_image_; |
+ gfx::Image high_dpi_image_; |
+ ImageHolderDelegate* delegate_; |
+ ScopedVector<chrome::BitmapFetcher> fetchers_; |
+ Profile* profile_; |
+ |
+ FRIEND_TEST_ALL_PREFIXES(ImageHolderTest, CreateBitmapFetcherTest); |
+ FRIEND_TEST_ALL_PREFIXES(ImageHolderTest, OnFetchCompleteTest); |
+ FRIEND_TEST_ALL_PREFIXES(ImageHolderTest, IsFetchingDoneTest); |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ImageHolder); |
+}; |
+ |
+} // namespace notifier. |
+ |
+#endif // CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_IMAGE_HOLDER_H_ |