OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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_BITMAP_FETCHER_BITMAP_BATCH_FETCHER_H_ |
| 6 #define CHROME_BROWSER_BITMAP_FETCHER_BITMAP_BATCH_FETCHER_H_ |
| 7 |
| 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_delegate.h" |
| 10 #include "chrome/browser/image_batch_decoder.h" |
| 11 #include "content/public/browser/browser_thread.h" |
| 12 #include "net/url_request/url_fetcher_delegate.h" |
| 13 #include "net/url_request/url_request.h" |
| 14 #include "third_party/skia/include/core/SkBitmap.h" |
| 15 #include "url/gurl.h" |
| 16 |
| 17 namespace net { |
| 18 class URLFetcher; |
| 19 class URLRequestContextGetter; |
| 20 } // namespace net |
| 21 |
| 22 namespace chrome { |
| 23 |
| 24 // Asynchrounously fetches images from the URLs provided in calls to ::Start |
| 25 // and returns the decoded Bitmaps to the provided BitmapFetcherDelegate. |
| 26 class BitmapBatchFetcher : public net::URLFetcherDelegate { |
| 27 public: |
| 28 BitmapBatchFetcher(); |
| 29 |
| 30 ~BitmapBatchFetcher() override; |
| 31 |
| 32 // Start fetching the URL. The delegate is notified asynchronously when done. |
| 33 // Arguments are used to configure the internal fetcher. |
| 34 // Values for |load_flags| are defined in net/base/load_flags.h. In general, |
| 35 // |net::LOAD_NORMAL| is appropriate. |
| 36 void Start(net::URLRequestContextGetter* request_context, |
| 37 const std::string& referrer, |
| 38 net::URLRequest::ReferrerPolicy referrer_policy, |
| 39 int load_flags, |
| 40 const GURL& url, |
| 41 BitmapFetcherDelegate* delegate); |
| 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 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 void OnURLFetchDownloadProgress(const net::URLFetcher* source, |
| 53 int64 current, |
| 54 int64 total) override; |
| 55 |
| 56 private: |
| 57 scoped_refptr<ImageBatchDecoder> image_batch_decoder_; |
| 58 std::map<const net::URLFetcher*, std::pair<GURL, BitmapFetcherDelegate*>> |
| 59 url_fetcher_map_; |
| 60 |
| 61 class Delegate : public ImageBatchDecoder::Delegate { |
| 62 public: |
| 63 Delegate(const GURL& url, BitmapFetcherDelegate* delegate) |
| 64 : url_(url), delegate_(delegate) {} |
| 65 |
| 66 // Methods inherited from ImageBatchDecoder::Delegate |
| 67 |
| 68 // Called when image is decoded. |decoder| is used to identify the image in |
| 69 // case of decoding several images simultaneously. This will not be called |
| 70 // on the UI thread. |
| 71 void OnImageDecoded(const ImageBatchDecoder* decoder, |
| 72 const SkBitmap& decoded_image) override; |
| 73 |
| 74 // Called when decoding image failed. |
| 75 void OnDecodeImageFailed(const ImageBatchDecoder* decoder) override; |
| 76 |
| 77 private: |
| 78 const GURL url_; |
| 79 BitmapFetcherDelegate* delegate_; |
| 80 }; |
| 81 |
| 82 DISALLOW_COPY_AND_ASSIGN(BitmapBatchFetcher); |
| 83 }; |
| 84 |
| 85 } // namespace chrome |
| 86 |
| 87 #endif // CHROME_BROWSER_BITMAP_FETCHER_BITMAP_BATCH_FETCHER_H_ |
OLD | NEW |