Chromium Code Reviews| 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/gtest_prod_util.h" | |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/message_loop/message_loop_proxy.h" | |
| 11 #include "chrome/browser/image_decoder.h" | |
| 12 #include "googleurl/src/gurl.h" | |
| 13 #include "net/url_request/url_fetcher_delegate.h" | |
| 14 #include "third_party/skia/include/core/SKBitmap.h" | |
| 15 | |
| 16 namespace net { | |
| 17 class URLFetcher; | |
| 18 } // namespace net | |
| 19 | |
| 20 class NotificationBitmapFetcherTest; | |
| 21 class NotificationBitmapFetcherBrowserTest; | |
| 22 | |
| 23 namespace notifier { | |
| 24 | |
| 25 class NotificationBitmapFetcher | |
| 26 : public net::URLFetcherDelegate, | |
| 27 public ImageDecoder::Delegate, | |
| 28 public base::RefCountedThreadSafe<NotificationBitmapFetcher> { | |
| 29 public: | |
| 30 explicit NotificationBitmapFetcher(GURL& url); | |
|
dcheng
2013/05/23 19:32:25
Style: Chromium does not allow mutable references.
Pete Williamson
2013/05/24 22:18:06
Done.
| |
| 31 ~NotificationBitmapFetcher(); | |
| 32 | |
| 33 bool image_ready(); | |
|
dcheng
2013/05/23 19:32:25
Style: Simple getters should be inlined into the h
Pete Williamson
2013/05/24 22:18:06
removed.
| |
| 34 | |
| 35 bool image_failed(); | |
| 36 | |
| 37 // Returns an unowned pointer to the fetched and decoded bitmap. | |
| 38 SkBitmap* bitmap(); | |
|
dcheng
2013/05/23 19:32:25
Prefer returning const pointers/references. Note t
Pete Williamson
2013/05/24 22:18:06
Removed.
| |
| 39 | |
| 40 // Start fetching the URL with the fetcher. The operation will be continued | |
| 41 // in the OnURLFetchComplete callback. | |
| 42 void StartImageFetch(); | |
| 43 | |
| 44 // Copy the output bitmap. This takes ownership of the bitmap. It is called | |
| 45 // on the UI thread. This also notifies observers. | |
| 46 void HandleImageDecoded(scoped_ptr<SkBitmap> bitmap); | |
| 47 | |
| 48 // If a bitmap image decode fails, notify observers of the failure. | |
| 49 void HandleImageFailed(); | |
| 50 | |
| 51 // Methods inherited from URLFetcherDelegate | |
| 52 | |
| 53 // This will be called when the URL has been fetched, successfully or not. | |
| 54 // Use accessor methods on |source| to get the results. | |
| 55 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | |
| 56 | |
| 57 // This will be called when some part of the response is read. |current| | |
| 58 // denotes the number of bytes received up to the call, and |total| is the | |
| 59 // expected total size of the response (or -1 if not determined). | |
| 60 virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source, | |
| 61 int64 current, int64 total) OVERRIDE; | |
| 62 | |
| 63 // Methods inherited from ImageDecoder::Delegate | |
| 64 | |
| 65 // Called when image is decoded. |decoder| is used to identify the image in | |
| 66 // case of decoding several images simultaneously. This will not be called | |
| 67 // on the UI thread. | |
| 68 virtual void OnImageDecoded(const ImageDecoder* decoder, | |
| 69 const SkBitmap& decoded_image) OVERRIDE; | |
| 70 | |
| 71 // Called when decoding image failed. | |
| 72 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; | |
| 73 | |
| 74 private: | |
| 75 scoped_ptr<net::URLFetcher> url_fetcher_; | |
| 76 scoped_refptr<ImageDecoder> image_decoder_; | |
| 77 // |image_ready_| will be set to true once the image is fetched and decoded. | |
| 78 bool image_ready_; | |
| 79 // |image_failed_| will be set to true if we cannot fetch or decode the image. | |
| 80 bool image_failed_; | |
| 81 GURL url_; | |
| 82 scoped_ptr<SkBitmap> bitmap_; | |
| 83 int64 progress_current_; | |
| 84 int64 progress_total_; | |
| 85 | |
| 86 // Used to pass in a fetcher for dependency injection in tests. | |
| 87 void SetURLFetcherForTest(scoped_ptr<net::URLFetcher>& url_fetcher); | |
| 88 | |
| 89 FRIEND_TEST_ALL_PREFIXES(NotificationBitmapFetcherTest, ImageReadyTest); | |
| 90 FRIEND_TEST_ALL_PREFIXES(NotificationBitmapFetcherTest, StartFetchTest); | |
| 91 FRIEND_TEST_ALL_PREFIXES(NotificationBitmapFetcherTest, | |
| 92 HandleImageDecodedTest); | |
| 93 FRIEND_TEST_ALL_PREFIXES(NotificationBitmapFetcherTest, | |
| 94 HandleImageFailedTest); | |
| 95 FRIEND_TEST_ALL_PREFIXES(NotificationBitmapFetcherBrowserTest, | |
| 96 OnURLFetchCompleteTest); | |
| 97 FRIEND_TEST_ALL_PREFIXES(NotificationBitmapFetcherBrowserTest, | |
| 98 OnDecodeImageFailedTest); | |
| 99 FRIEND_TEST_ALL_PREFIXES(NotificationBitmapFetcherBrowserTest, | |
| 100 OnURLFetchFailureTest); | |
| 101 | |
| 102 DISALLOW_COPY_AND_ASSIGN(NotificationBitmapFetcher); | |
| 103 }; | |
| 104 | |
| 105 } // namespace notifier | |
| 106 | |
| 107 #endif // CHROME_BROWSER_NOTIFICATIONS_SYNC_NOTIFIER_NOTIFICATION_BITMAP_FETCHE R_H_ | |
| OLD | NEW |