OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 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 #ifndef CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_NOTIFICATION_BITMAP_FETCHER_H
_ |
| 6 #define CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_NOTIFICATION_BITMAP_FETCHER_H
_ |
| 7 |
| 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "chrome/browser/image_decoder.h" |
| 10 #include "googleurl/src/gurl.h" |
| 11 #include "net/url_request/url_fetcher_delegate.h" |
| 12 #include "third_party/skia/include/core/SkBitmap.h" |
| 13 |
| 14 namespace net { |
| 15 class URLFetcher; |
| 16 } // namespace net |
| 17 |
| 18 namespace notifier { |
| 19 |
| 20 // A delegate interface for users of NotificationBitmapFetcher. |
| 21 class NotificationBitmapFetcherDelegate { |
| 22 public: |
| 23 // This will be called when the bitmap has been fetched, successfully or not. |
| 24 virtual void OnFetchComplete(const SkBitmap* bitmap) = 0; |
| 25 |
| 26 protected: |
| 27 virtual ~NotificationBitmapFetcherDelegate() {} |
| 28 }; |
| 29 |
| 30 class NotificationBitmapFetcher |
| 31 : public net::URLFetcherDelegate, |
| 32 public ImageDecoder::Delegate { |
| 33 public: |
| 34 NotificationBitmapFetcher( |
| 35 const GURL& url, |
| 36 NotificationBitmapFetcherDelegate* delegate); |
| 37 virtual ~NotificationBitmapFetcher(); |
| 38 |
| 39 // Start fetching the URL with the fetcher. The operation will be continued |
| 40 // in the OnURLFetchComplete callback. |
| 41 void Start(); |
| 42 |
| 43 // Methods inherited from URLFetcherDelegate |
| 44 |
| 45 // This will be called when the URL has been fetched, successfully or not. |
| 46 // Use accessor methods on |source| to get the results. |
| 47 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 48 |
| 49 // This will be called when some part of the response is read. |current| |
| 50 // denotes the number of bytes received up to the call, and |total| is the |
| 51 // expected total size of the response (or -1 if not determined). |
| 52 virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source, |
| 53 int64 current, int64 total) OVERRIDE; |
| 54 |
| 55 // Methods inherited from ImageDecoder::Delegate |
| 56 |
| 57 // Called when image is decoded. |decoder| is used to identify the image in |
| 58 // case of decoding several images simultaneously. This will not be called |
| 59 // on the UI thread. |
| 60 virtual void OnImageDecoded(const ImageDecoder* decoder, |
| 61 const SkBitmap& decoded_image) OVERRIDE; |
| 62 |
| 63 // Called when decoding image failed. |
| 64 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; |
| 65 |
| 66 // Used to pass in a fetcher for dependency injection in tests. |
| 67 void SetURLFetcherForTest(scoped_ptr<net::URLFetcher> url_fetcher); |
| 68 |
| 69 private: |
| 70 scoped_ptr<net::URLFetcher> url_fetcher_; |
| 71 scoped_refptr<ImageDecoder> image_decoder_; |
| 72 const GURL url_; |
| 73 scoped_ptr<SkBitmap> bitmap_; |
| 74 NotificationBitmapFetcherDelegate* const delegate_; |
| 75 |
| 76 DISALLOW_COPY_AND_ASSIGN(NotificationBitmapFetcher); |
| 77 }; |
| 78 |
| 79 } // namespace notifier |
| 80 |
| 81 #endif // CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_NOTIFICATION_BITMAP_FETCHE
R_H_ |
OLD | NEW |