OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_NOTIFICATION_BITMAP_FETCHER_H _ | 5 #ifndef CHROME_BROWSER_BITMAP_FETCHER_H_ |
6 #define CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_NOTIFICATION_BITMAP_FETCHER_H _ | 6 #define CHROME_BROWSER_BITMAP_FETCHER_H_ |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "chrome/browser/image_decoder.h" | 9 #include "chrome/browser/image_decoder.h" |
10 #include "net/url_request/url_fetcher_delegate.h" | 10 #include "net/url_request/url_fetcher_delegate.h" |
11 #include "third_party/skia/include/core/SkBitmap.h" | 11 #include "third_party/skia/include/core/SkBitmap.h" |
12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
13 | 13 |
14 namespace net { | 14 namespace net { |
15 class URLFetcher; | 15 class URLFetcher; |
16 } // namespace net | 16 } // namespace net |
17 | 17 |
18 class Profile; | 18 class Profile; |
19 | 19 |
20 namespace notifier { | 20 // A delegate interface for users of BitmapFetcher. |
Pete Williamson
2014/02/11 03:41:11
Should this be in a namespace somewhere?
gone
2014/02/11 05:32:07
Put it into the chrome namespace.
| |
21 | 21 class BitmapFetcherDelegate { |
22 // A delegate interface for users of NotificationBitmapFetcher. | |
23 class NotificationBitmapFetcherDelegate { | |
24 public: | 22 public: |
25 // This will be called when the bitmap has been requested, whether or not the | 23 // This will be called when the bitmap has been requested, whether or not the |
26 // request succeeds. |url| is the URL that was originally fetched so we can | 24 // request succeeds. |url| is the URL that was originally fetched so we can |
27 // match up the bitmap with a specific request. | 25 // match up the bitmap with a specific request. |
28 virtual void OnFetchComplete(const GURL url, const SkBitmap* bitmap) = 0; | 26 virtual void OnFetchComplete(const GURL url, const SkBitmap* bitmap) = 0; |
29 | 27 |
30 protected: | 28 protected: |
31 virtual ~NotificationBitmapFetcherDelegate() {} | 29 virtual ~BitmapFetcherDelegate() {} |
32 }; | 30 }; |
33 | 31 |
34 class NotificationBitmapFetcher | 32 class BitmapFetcher : public net::URLFetcherDelegate, |
35 : public net::URLFetcherDelegate, | 33 public ImageDecoder::Delegate { |
36 public ImageDecoder::Delegate { | |
37 public: | 34 public: |
38 NotificationBitmapFetcher( | 35 BitmapFetcher(const GURL& url, BitmapFetcherDelegate* delegate); |
39 const GURL& url, | 36 virtual ~BitmapFetcher(); |
40 NotificationBitmapFetcherDelegate* delegate); | |
41 virtual ~NotificationBitmapFetcher(); | |
42 | 37 |
43 GURL url() const { return url_; } | 38 GURL url() const { return url_; } |
44 | 39 |
45 // Start fetching the URL with the fetcher. The operation will be continued | 40 // Start fetching the URL with the fetcher. The operation will be continued |
46 // in the OnURLFetchComplete callback. | 41 // in the OnURLFetchComplete callback. |
47 void Start(Profile* profile); | 42 void Start(Profile* profile); |
48 | 43 |
49 // Methods inherited from URLFetcherDelegate | 44 // Methods inherited from URLFetcherDelegate |
50 | 45 |
51 // This will be called when the URL has been fetched, successfully or not. | 46 // This will be called when the URL has been fetched, successfully or not. |
52 // Use accessor methods on |source| to get the results. | 47 // Use accessor methods on |source| to get the results. |
53 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 48 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
54 | 49 |
55 // This will be called when some part of the response is read. |current| | 50 // This will be called when some part of the response is read. |current| |
56 // denotes the number of bytes received up to the call, and |total| is the | 51 // denotes the number of bytes received up to the call, and |total| is the |
57 // expected total size of the response (or -1 if not determined). | 52 // expected total size of the response (or -1 if not determined). |
58 virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source, | 53 virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source, |
59 int64 current, int64 total) OVERRIDE; | 54 int64 current, |
55 int64 total) OVERRIDE; | |
60 | 56 |
61 // Methods inherited from ImageDecoder::Delegate | 57 // Methods inherited from ImageDecoder::Delegate |
62 | 58 |
63 // Called when image is decoded. |decoder| is used to identify the image in | 59 // Called when image is decoded. |decoder| is used to identify the image in |
64 // case of decoding several images simultaneously. This will not be called | 60 // case of decoding several images simultaneously. This will not be called |
65 // on the UI thread. | 61 // on the UI thread. |
66 virtual void OnImageDecoded(const ImageDecoder* decoder, | 62 virtual void OnImageDecoded(const ImageDecoder* decoder, |
67 const SkBitmap& decoded_image) OVERRIDE; | 63 const SkBitmap& decoded_image) OVERRIDE; |
68 | 64 |
69 // Called when decoding image failed. | 65 // Called when decoding image failed. |
70 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; | 66 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; |
71 | 67 |
72 private: | 68 private: |
73 scoped_ptr<net::URLFetcher> url_fetcher_; | 69 scoped_ptr<net::URLFetcher> url_fetcher_; |
74 scoped_refptr<ImageDecoder> image_decoder_; | 70 scoped_refptr<ImageDecoder> image_decoder_; |
75 const GURL url_; | 71 const GURL url_; |
76 scoped_ptr<SkBitmap> bitmap_; | 72 scoped_ptr<SkBitmap> bitmap_; |
77 NotificationBitmapFetcherDelegate* const delegate_; | 73 BitmapFetcherDelegate* const delegate_; |
78 | 74 |
79 DISALLOW_COPY_AND_ASSIGN(NotificationBitmapFetcher); | 75 DISALLOW_COPY_AND_ASSIGN(BitmapFetcher); |
80 }; | 76 }; |
81 | 77 |
82 } // namespace notifier | 78 #endif // CHROME_BROWSER_BITMAP_FETCHER_H_ |
83 | |
84 #endif // CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_NOTIFICATION_BITMAP_FETCHE R_H_ | |
OLD | NEW |