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 namespace chrome { |
21 | 21 |
22 // A delegate interface for users of NotificationBitmapFetcher. | 22 // A delegate interface for users of BitmapFetcher. |
23 class NotificationBitmapFetcherDelegate { | 23 class BitmapFetcherDelegate { |
sky
2014/02/13 18:55:05
nit: move into its own file.
gone
2014/02/13 23:39:38
Done.
| |
24 public: | 24 public: |
25 // This will be called when the bitmap has been requested, whether or not the | 25 // 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 | 26 // request succeeds. |url| is the URL that was originally fetched so we can |
27 // match up the bitmap with a specific request. | 27 // match up the bitmap with a specific request. |
sky
2014/02/13 18:55:05
Document that bitmap may be NULL for either failur
gone
2014/02/13 23:39:38
Done.
| |
28 virtual void OnFetchComplete(const GURL url, const SkBitmap* bitmap) = 0; | 28 virtual void OnFetchComplete(const GURL url, const SkBitmap* bitmap) = 0; |
29 | 29 |
30 protected: | 30 protected: |
31 virtual ~NotificationBitmapFetcherDelegate() {} | 31 virtual ~BitmapFetcherDelegate() {} |
32 }; | 32 }; |
33 | 33 |
34 class NotificationBitmapFetcher | 34 class BitmapFetcher : public net::URLFetcherDelegate, |
sky
2014/02/13 18:55:05
Description?
gone
2014/02/13 23:39:38
Done.
| |
35 : public net::URLFetcherDelegate, | 35 public ImageDecoder::Delegate { |
36 public ImageDecoder::Delegate { | |
37 public: | 36 public: |
38 NotificationBitmapFetcher( | 37 BitmapFetcher(const GURL& url, BitmapFetcherDelegate* delegate); |
39 const GURL& url, | 38 virtual ~BitmapFetcher(); |
40 NotificationBitmapFetcherDelegate* delegate); | |
41 virtual ~NotificationBitmapFetcher(); | |
42 | 39 |
43 GURL url() const { return url_; } | 40 GURL url() const { return url_; } |
sky
2014/02/13 18:55:05
const GURL&
gone
2014/02/13 23:39:38
Done.
| |
44 | 41 |
45 // Start fetching the URL with the fetcher. The operation will be continued | 42 // Start fetching the URL with the fetcher. The operation will be continued |
sky
2014/02/13 18:55:05
Will be continued?
Pete Williamson
2014/02/13 21:30:31
The idea here in the original code this came from
sky
2014/02/13 23:12:30
My comment was more that particular sentence is co
Pete Williamson
2014/02/13 23:27:06
OK, I agree that the new wording would be good.
gone
2014/02/13 23:39:38
Done.
| |
46 // in the OnURLFetchComplete callback. | 43 // in the OnURLFetchComplete callback. |
47 void Start(Profile* profile); | 44 void Start(Profile* profile); |
48 | 45 |
49 // Methods inherited from URLFetcherDelegate | 46 // Methods inherited from URLFetcherDelegate |
50 | 47 |
51 // This will be called when the URL has been fetched, successfully or not. | 48 // This will be called when the URL has been fetched, successfully or not. |
52 // Use accessor methods on |source| to get the results. | 49 // Use accessor methods on |source| to get the results. |
53 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 50 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
54 | 51 |
55 // This will be called when some part of the response is read. |current| | 52 // 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 | 53 // 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). | 54 // expected total size of the response (or -1 if not determined). |
58 virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source, | 55 virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source, |
59 int64 current, int64 total) OVERRIDE; | 56 int64 current, |
57 int64 total) OVERRIDE; | |
60 | 58 |
61 // Methods inherited from ImageDecoder::Delegate | 59 // Methods inherited from ImageDecoder::Delegate |
62 | 60 |
63 // Called when image is decoded. |decoder| is used to identify the image in | 61 // 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 | 62 // case of decoding several images simultaneously. This will not be called |
65 // on the UI thread. | 63 // on the UI thread. |
66 virtual void OnImageDecoded(const ImageDecoder* decoder, | 64 virtual void OnImageDecoded(const ImageDecoder* decoder, |
67 const SkBitmap& decoded_image) OVERRIDE; | 65 const SkBitmap& decoded_image) OVERRIDE; |
68 | 66 |
69 // Called when decoding image failed. | 67 // Called when decoding image failed. |
70 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; | 68 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; |
71 | 69 |
72 private: | 70 private: |
73 scoped_ptr<net::URLFetcher> url_fetcher_; | 71 scoped_ptr<net::URLFetcher> url_fetcher_; |
74 scoped_refptr<ImageDecoder> image_decoder_; | 72 scoped_refptr<ImageDecoder> image_decoder_; |
75 const GURL url_; | 73 const GURL url_; |
76 scoped_ptr<SkBitmap> bitmap_; | 74 scoped_ptr<SkBitmap> bitmap_; |
sky
2014/02/13 18:55:05
Why do we need this as a member? Why not declare i
Pete Williamson
2014/02/13 21:30:31
The intent was to use this object to both fetch an
sky
2014/02/13 23:12:30
When you are not even exposing the bitmap publicly
Pete Williamson
2014/02/13 23:27:06
My bad, I think I was remembering another part of
gone
2014/02/13 23:39:38
Done.
| |
77 NotificationBitmapFetcherDelegate* const delegate_; | 75 BitmapFetcherDelegate* const delegate_; |
78 | 76 |
79 DISALLOW_COPY_AND_ASSIGN(NotificationBitmapFetcher); | 77 DISALLOW_COPY_AND_ASSIGN(BitmapFetcher); |
80 }; | 78 }; |
81 | 79 |
82 } // namespace notifier | 80 } // namespace chrome |
83 | 81 |
84 #endif // CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_NOTIFICATION_BITMAP_FETCHE R_H_ | 82 #endif // CHROME_BROWSER_BITMAP_FETCHER_H_ |
OLD | NEW |