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. | |
dewittj
2014/03/25 22:31:14
I think that this comment and the one on line 28 s
Pete Williamson
2014/03/26 18:12:55
I just removed the comment.
| |
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 "ui/gfx/image/image_skia.h" | |
15 #include "url/gurl.h" | |
16 | |
17 class Profile; | |
18 | |
19 namespace notifier { | |
20 | |
21 // This provides a callback so the ImageHolder can inform its parent when a | |
22 // bitmap arrives. | |
23 class ImageHolderDelegate { | |
24 public: | |
25 virtual void OnFetchComplete() = 0; | |
26 }; | |
27 | |
28 // This class encapsulates the action of fetching a bitmap, reporting when it is | |
29 // fetched, and holding onto the bitmap until no longer needed. | |
30 class ImageHolder : public chrome::BitmapFetcherDelegate { | |
31 public: | |
32 ImageHolder(const GURL& low_dpi_url, | |
33 const GURL& high_dpi_url, | |
34 Profile* profile, | |
35 ImageHolderDelegate* delegate); | |
36 virtual ~ImageHolder(); | |
37 | |
38 // Begin fetching of the URLs we have. | |
39 void StartFetch(); | |
40 | |
41 // Check whether we have a response from the server for these resources, | |
42 // even if the response is a failed fetch. | |
43 bool IsFetchingDone() const; | |
44 | |
45 // Inherited from BitmapFetcherDelegate | |
46 virtual void OnFetchComplete(const GURL url, const SkBitmap* bitmap) OVERRIDE; | |
47 | |
48 // Accessors: | |
49 GURL low_dpi_url() const { return low_dpi_url_; } | |
50 void set_low_dpi_url(const GURL& low_dpi_url) { | |
dewittj
2014/03/25 22:31:14
nit: unused, remove.
Pete Williamson
2014/03/26 18:12:55
I'd really like to leave these in. They form an i
dewittj
2014/03/26 18:38:39
Can you explain how an unused function is integral
Pete Williamson
2014/03/26 21:03:50
Done.
| |
51 low_dpi_url_ = low_dpi_url; | |
52 } | |
53 GURL high_dpi_url() const { return high_dpi_url_; } | |
54 void set_high_dpi_url(const GURL& high_dpi_url) { | |
dewittj
2014/03/25 22:31:14
nit: unused, remove.
| |
55 high_dpi_url_ = high_dpi_url; | |
56 } | |
57 gfx::Image low_dpi_image() { return gfx::Image(image_); } | |
58 gfx::Image high_dpi_image() { return gfx::Image(image_); } | |
dewittj
2014/03/25 22:31:14
nit: remove high_dpi_image() since it's not used,
| |
59 | |
60 private: | |
61 // Helper function to create a bitmap fetcher (but not start the fetch). | |
62 void CreateBitmapFetcher(const GURL& url); | |
63 | |
64 GURL low_dpi_url_; | |
65 GURL high_dpi_url_; | |
66 bool low_dpi_fetched_; | |
67 bool high_dpi_fetched_; | |
68 gfx::ImageSkia image_; | |
69 ImageHolderDelegate* delegate_; | |
70 ScopedVector<chrome::BitmapFetcher> fetchers_; | |
71 Profile* profile_; | |
72 | |
73 FRIEND_TEST_ALL_PREFIXES(ImageHolderTest, CreateBitmapFetcherTest); | |
74 FRIEND_TEST_ALL_PREFIXES(ImageHolderTest, OnFetchCompleteTest); | |
75 FRIEND_TEST_ALL_PREFIXES(ImageHolderTest, IsFetchingDoneTest); | |
76 | |
77 DISALLOW_COPY_AND_ASSIGN(ImageHolder); | |
78 }; | |
79 | |
80 } // namespace notifier. | |
81 | |
82 #endif // CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_IMAGE_HOLDER_H_ | |
OLD | NEW |