OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 COMPONENTS_IMAGE_FETCHER_IMAGE_DATA_FETCHER_H_ |
| 6 #define COMPONENTS_IMAGE_FETCHER_IMAGE_DATA_FETCHER_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <memory> |
| 10 #include <string> |
| 11 |
| 12 #include "base/callback.h" |
| 13 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" |
| 15 #include "url/gurl.h" |
| 16 |
| 17 namespace net { |
| 18 class URLRequestContextGetter; |
| 19 } // namespace net |
| 20 |
| 21 namespace image_fetcher { |
| 22 |
| 23 class ImageDataFetcher { |
| 24 public: |
| 25 using ImageDataFetcherCallback = |
| 26 base::Callback<void(const std::string& image_data)>; |
| 27 |
| 28 explicit ImageDataFetcher( |
| 29 net::URLRequestContextGetter* url_request_context_getter); |
| 30 ~ImageDataFetcher(); |
| 31 |
| 32 // Fetches the raw image bytes from the given |image_url| and calls the given |
| 33 // |callback|. The callback is run even if fetching the URL fails. In case |
| 34 // of an error an empty string is passed to the callback. |
| 35 void FetchImageData(const GURL& image_url, |
| 36 const ImageDataFetcherCallback& callback); |
| 37 |
| 38 private: |
| 39 class ImageDataFetcherRequest; |
| 40 |
| 41 // Removes the ImageDataFetcherRequest for the given |image_url| from the |
| 42 // internal request queue. |
| 43 void RemoveImageDataFetcherRequest(const GURL& image_url); |
| 44 |
| 45 // All active image url requests. |
| 46 std::map<const GURL, std::unique_ptr<ImageDataFetcherRequest>> |
| 47 pending_requests_; |
| 48 |
| 49 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
| 50 |
| 51 DISALLOW_COPY_AND_ASSIGN(ImageDataFetcher); |
| 52 }; |
| 53 |
| 54 } // namespace image_fetcher |
| 55 |
| 56 #endif // COMPONENTS_IMAGE_FETCHER_IMAGE_DATA_FETCHER_H_ |
OLD | NEW |