Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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_BITMAP_FETCHER_H_ | 5 #ifndef CHROME_BROWSER_BITMAP_FETCHER_H_ |
| 6 #define CHROME_BROWSER_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/bitmap_fetcher_delegate.h" | 9 #include "chrome/browser/bitmap_fetcher_delegate.h" |
| 10 #include "chrome/browser/image_decoder.h" | 10 #include "chrome/browser/image_decoder.h" |
| 11 #include "net/url_request/url_fetcher_delegate.h" | 11 #include "net/url_request/url_fetcher_delegate.h" |
| 12 #include "net/url_request/url_request.h" | |
| 12 #include "third_party/skia/include/core/SkBitmap.h" | 13 #include "third_party/skia/include/core/SkBitmap.h" |
| 13 #include "url/gurl.h" | 14 #include "url/gurl.h" |
| 14 | 15 |
| 15 namespace net { | 16 namespace net { |
| 16 class URLFetcher; | 17 class URLFetcher; |
| 17 class URLRequestContextGetter; | 18 class URLRequestContextGetter; |
| 18 } // namespace net | 19 } // namespace net |
| 19 | 20 |
| 20 namespace chrome { | 21 namespace chrome { |
| 21 | 22 |
| 22 // Asynchrounously fetches an image from the given URL and returns the | 23 // Asynchrounously fetches an image from the given URL and returns the |
| 23 // decoded Bitmap to the provided BitmapFetcherDelegate. | 24 // decoded Bitmap to the provided BitmapFetcherDelegate. |
| 24 class BitmapFetcher : public net::URLFetcherDelegate, | 25 class BitmapFetcher : public net::URLFetcherDelegate, |
| 25 public ImageDecoder::Delegate { | 26 public ImageDecoder::Delegate { |
| 26 public: | 27 public: |
| 27 BitmapFetcher(const GURL& url, BitmapFetcherDelegate* delegate); | 28 BitmapFetcher(const GURL& url, BitmapFetcherDelegate* delegate); |
| 28 virtual ~BitmapFetcher(); | 29 virtual ~BitmapFetcher(); |
| 29 | 30 |
| 30 const GURL& url() const { return url_; } | 31 const GURL& url() const { return url_; } |
| 31 | 32 |
| 32 // Start fetching the URL with the fetcher. The delegate is notified | 33 // Start fetching the URL with the fetcher. The delegate is notified |
| 33 // asynchronously when done. Start may be called more than once in some | 34 // asynchronously when done. Start may be called more than once in some |
| 34 // cases. If so, subsequent starts will be ignored since the operation is | 35 // cases. If so, subsequent starts will be ignored since the operation is |
| 35 // already in progress. | 36 // already in progress. |
| 36 void Start(net::URLRequestContextGetter* request_context); | 37 void Start(net::URLRequestContextGetter* request_context); |
| 37 | 38 |
| 39 // Same as the above Start function, but with additional arguments to | |
| 40 // configure |url_fetcher_|. | |
| 41 void Start(net::URLRequestContextGetter* request_context, | |
|
sky
2014/05/06 00:30:47
Can you convert callers to this new function so th
Kibeom Kim (inactive)
2014/05/06 01:48:51
Done.
| |
| 42 const std::string& referrer, | |
| 43 net::URLRequest::ReferrerPolicy referrer_policy, | |
| 44 int load_flags); | |
| 45 | |
| 38 // Methods inherited from URLFetcherDelegate | 46 // Methods inherited from URLFetcherDelegate |
| 39 | 47 |
| 40 // 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. |
| 41 // Use accessor methods on |source| to get the results. | 49 // Use accessor methods on |source| to get the results. |
| 42 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 50 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 43 | 51 |
| 44 // 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| |
| 45 // 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 |
| 46 // expected total size of the response (or -1 if not determined). | 54 // expected total size of the response (or -1 if not determined). |
| 47 virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source, | 55 virtual void OnURLFetchDownloadProgress(const net::URLFetcher* source, |
| 48 int64 current, | 56 int64 current, |
| 49 int64 total) OVERRIDE; | 57 int64 total) OVERRIDE; |
| 50 | 58 |
| 51 // Methods inherited from ImageDecoder::Delegate | 59 // Methods inherited from ImageDecoder::Delegate |
| 52 | 60 |
| 53 // 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 |
| 54 // case of decoding several images simultaneously. This will not be called | 62 // case of decoding several images simultaneously. This will not be called |
| 55 // on the UI thread. | 63 // on the UI thread. |
| 56 virtual void OnImageDecoded(const ImageDecoder* decoder, | 64 virtual void OnImageDecoded(const ImageDecoder* decoder, |
| 57 const SkBitmap& decoded_image) OVERRIDE; | 65 const SkBitmap& decoded_image) OVERRIDE; |
| 58 | 66 |
| 59 // Called when decoding image failed. | 67 // Called when decoding image failed. |
| 60 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; | 68 virtual void OnDecodeImageFailed(const ImageDecoder* decoder) OVERRIDE; |
| 61 | 69 |
| 62 private: | 70 private: |
| 71 void Fetch(net::URLRequestContextGetter* request_context, | |
| 72 const std::string* referrer, | |
| 73 const net::URLRequest::ReferrerPolicy* referrer_policy, | |
| 74 const int* load_flags); | |
| 75 | |
| 63 // Alerts the delegate that a failure occurred. | 76 // Alerts the delegate that a failure occurred. |
| 64 void ReportFailure(); | 77 void ReportFailure(); |
| 65 | 78 |
| 66 scoped_ptr<net::URLFetcher> url_fetcher_; | 79 scoped_ptr<net::URLFetcher> url_fetcher_; |
| 67 scoped_refptr<ImageDecoder> image_decoder_; | 80 scoped_refptr<ImageDecoder> image_decoder_; |
| 68 const GURL url_; | 81 const GURL url_; |
| 69 BitmapFetcherDelegate* const delegate_; | 82 BitmapFetcherDelegate* const delegate_; |
| 70 | 83 |
| 71 DISALLOW_COPY_AND_ASSIGN(BitmapFetcher); | 84 DISALLOW_COPY_AND_ASSIGN(BitmapFetcher); |
| 72 }; | 85 }; |
| 73 | 86 |
| 74 } // namespace chrome | 87 } // namespace chrome |
| 75 | 88 |
| 76 #endif // CHROME_BROWSER_BITMAP_FETCHER_H_ | 89 #endif // CHROME_BROWSER_BITMAP_FETCHER_H_ |
| OLD | NEW |