OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // This class holds the URL to an image and the bitmap for the fetched image, | |
6 // and has code to fetch the bitmap from the URL. | |
7 | |
8 #ifndef CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_IMAGE_HOLDER_H_ | |
9 #define CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_IMAGE_HOLDER_H_ | |
10 | |
11 #include "base/memory/scoped_vector.h" | |
12 #include "chrome/browser/bitmap_fetcher.h" | |
13 #include "ui/gfx/image/image.h" | |
14 #include "url/gurl.h" | |
15 | |
16 class Profile; | |
17 | |
18 namespace notifier { | |
19 | |
20 // This provides a callback so the ImageHolder can inform its parent when a | |
21 // bitmap arrives. | |
22 class ImageHolderDelegate { | |
23 public: | |
24 virtual void OnFetchComplete() = 0; | |
25 }; | |
26 | |
27 // This class encapsulates the action of fetching a bitmap, reporting when it is | |
28 // fetched, and holding onto the bitmap until no longer needed. | |
29 class ImageHolder : public chrome::BitmapFetcherDelegate { | |
30 public: | |
31 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
| |
32 const GURL& high_dpi_url, | |
33 Profile* profile, | |
34 ImageHolderDelegate* delegate); | |
35 virtual ~ImageHolder(); | |
36 | |
37 // Begin fetching of the URLs we have. | |
38 void StartFetch(); | |
39 | |
40 // Check whether we have a response from the server for these resources, | |
41 // even if the response is a failed fetch. | |
42 bool IsFetchingDone() const; | |
43 | |
44 // Inherited from BitmapFetcherDelegate | |
45 virtual void OnFetchComplete(const GURL url, const SkBitmap* bitmap) OVERRIDE; | |
46 | |
47 // Accessors: | |
48 GURL low_dpi_url() const { return low_dpi_url_; } | |
49 void set_low_dpi_url(const GURL& low_dpi_url) { | |
50 low_dpi_url_ = low_dpi_url; | |
51 } | |
52 GURL high_dpi_url() const { return high_dpi_url_; } | |
53 void set_high_dpi_url(const GURL& high_dpi_url) { | |
54 high_dpi_url_ = high_dpi_url; | |
55 } | |
56 gfx::Image low_dpi_image() { return low_dpi_image_; } | |
57 gfx::Image high_dpi_image() { return high_dpi_image_; } | |
58 | |
59 private: | |
60 void CreateBitmapFetcher(const GURL& url); | |
61 | |
62 GURL low_dpi_url_; | |
63 GURL high_dpi_url_; | |
64 bool low_dpi_fetched_; | |
65 bool high_dpi_fetched_; | |
66 gfx::Image low_dpi_image_; | |
67 gfx::Image high_dpi_image_; | |
68 ImageHolderDelegate* delegate_; | |
69 ScopedVector<chrome::BitmapFetcher> fetchers_; | |
70 Profile* profile_; | |
71 | |
72 FRIEND_TEST_ALL_PREFIXES(ImageHolderTest, CreateBitmapFetcherTest); | |
73 FRIEND_TEST_ALL_PREFIXES(ImageHolderTest, OnFetchCompleteTest); | |
74 FRIEND_TEST_ALL_PREFIXES(ImageHolderTest, IsFetchingDoneTest); | |
75 | |
76 DISALLOW_COPY_AND_ASSIGN(ImageHolder); | |
77 }; | |
78 | |
79 } // namespace notifier. | |
80 | |
81 #endif // CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_IMAGE_HOLDER_H_ | |
OLD | NEW |