| 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 COMPONENTS_IMAGE_FETCHER_IMAGE_FETCHER_IMPL_H_ | 5 #ifndef COMPONENTS_IMAGE_FETCHER_IMAGE_FETCHER_IMPL_H_ |
| 6 #define COMPONENTS_IMAGE_FETCHER_IMAGE_FETCHER_IMPL_H_ | 6 #define COMPONENTS_IMAGE_FETCHER_IMAGE_FETCHER_IMPL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <utility> | 11 #include <utility> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "components/image_fetcher/image_data_fetcher.h" | 16 #include "components/image_fetcher/image_data_fetcher.h" |
| 17 #include "components/image_fetcher/image_decoder.h" | 17 #include "components/image_fetcher/image_decoder.h" |
| 18 #include "components/image_fetcher/image_fetcher.h" | 18 #include "components/image_fetcher/image_fetcher.h" |
| 19 #include "ui/gfx/geometry/size.h" |
| 19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 20 | 21 |
| 21 namespace gfx { | 22 namespace gfx { |
| 22 class Image; | 23 class Image; |
| 23 } | 24 } |
| 24 | 25 |
| 25 namespace net { | 26 namespace net { |
| 26 class URLRequestContextGetter; | 27 class URLRequestContextGetter; |
| 27 } | 28 } |
| 28 | 29 |
| 29 namespace image_fetcher { | 30 namespace image_fetcher { |
| 30 | 31 |
| 31 // The standard (non-test) implementation of ImageFetcher. | 32 // The standard (non-test) implementation of ImageFetcher. |
| 32 class ImageFetcherImpl : public image_fetcher::ImageFetcher { | 33 class ImageFetcherImpl : public image_fetcher::ImageFetcher { |
| 33 public: | 34 public: |
| 34 ImageFetcherImpl( | 35 ImageFetcherImpl( |
| 35 std::unique_ptr<ImageDecoder> image_decoder, | 36 std::unique_ptr<ImageDecoder> image_decoder, |
| 36 net::URLRequestContextGetter* url_request_context); | 37 net::URLRequestContextGetter* url_request_context); |
| 37 ~ImageFetcherImpl() override; | 38 ~ImageFetcherImpl() override; |
| 38 | 39 |
| 39 // Sets the |delegate| of the ImageFetcherImpl. The |delegate| has to be alive | 40 // Sets the |delegate| of the ImageFetcherImpl. The |delegate| has to be alive |
| 40 // during the lifetime of the ImageFetcherImpl object. It is the caller's | 41 // during the lifetime of the ImageFetcherImpl object. It is the caller's |
| 41 // responsibility to ensure this. | 42 // responsibility to ensure this. |
| 42 void SetImageFetcherDelegate(ImageFetcherDelegate* delegate) override; | 43 void SetImageFetcherDelegate(ImageFetcherDelegate* delegate) override; |
| 43 | 44 |
| 44 // Sets a service name against which to track data usage. | 45 // Sets a service name against which to track data usage. |
| 45 void SetDataUseServiceName(DataUseServiceName data_use_service_name) override; | 46 void SetDataUseServiceName(DataUseServiceName data_use_service_name) override; |
| 46 | 47 |
| 48 void SetDesiredImageFrameSize(const gfx::Size& size) override; |
| 49 |
| 47 void StartOrQueueNetworkRequest( | 50 void StartOrQueueNetworkRequest( |
| 48 const std::string& id, | 51 const std::string& id, |
| 49 const GURL& image_url, | 52 const GURL& image_url, |
| 50 base::Callback<void(const std::string&, const gfx::Image&)> callback) | 53 base::Callback<void(const std::string&, const gfx::Image&)> callback) |
| 51 override; | 54 override; |
| 52 | 55 |
| 53 private: | 56 private: |
| 54 using CallbackVector = | 57 using CallbackVector = |
| 55 std::vector<base::Callback<void(const std::string&, const gfx::Image&)>>; | 58 std::vector<base::Callback<void(const std::string&, const gfx::Image&)>>; |
| 56 | 59 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 76 // Processes image URL fetched events. This is the continuation method used | 79 // Processes image URL fetched events. This is the continuation method used |
| 77 // for creating callbacks that are passed to the ImageDataFetcher. | 80 // for creating callbacks that are passed to the ImageDataFetcher. |
| 78 void OnImageURLFetched(const GURL& image_url, | 81 void OnImageURLFetched(const GURL& image_url, |
| 79 const std::string& image_data, | 82 const std::string& image_data, |
| 80 const RequestMetadata& metadata); | 83 const RequestMetadata& metadata); |
| 81 | 84 |
| 82 // Processes image decoded events. This is the continuation method used for | 85 // Processes image decoded events. This is the continuation method used for |
| 83 // creating callbacks that are passed to the ImageDecoder. | 86 // creating callbacks that are passed to the ImageDecoder. |
| 84 void OnImageDecoded(const GURL& image_url, const gfx::Image& image); | 87 void OnImageDecoded(const GURL& image_url, const gfx::Image& image); |
| 85 | 88 |
| 89 ImageFetcherDelegate* delegate_; |
| 86 | 90 |
| 87 ImageFetcherDelegate* delegate_; | 91 gfx::Size desired_image_frame_size_; |
| 88 | 92 |
| 89 scoped_refptr<net::URLRequestContextGetter> url_request_context_; | 93 scoped_refptr<net::URLRequestContextGetter> url_request_context_; |
| 90 | 94 |
| 91 std::unique_ptr<ImageDecoder> image_decoder_; | 95 std::unique_ptr<ImageDecoder> image_decoder_; |
| 92 | 96 |
| 93 std::unique_ptr<ImageDataFetcher> image_data_fetcher_; | 97 std::unique_ptr<ImageDataFetcher> image_data_fetcher_; |
| 94 | 98 |
| 95 // Map from each image URL to the request information (associated website | 99 // Map from each image URL to the request information (associated website |
| 96 // url, fetcher, pending callbacks). | 100 // url, fetcher, pending callbacks). |
| 97 ImageRequestMap pending_net_requests_; | 101 ImageRequestMap pending_net_requests_; |
| 98 | 102 |
| 99 DISALLOW_COPY_AND_ASSIGN(ImageFetcherImpl); | 103 DISALLOW_COPY_AND_ASSIGN(ImageFetcherImpl); |
| 100 }; | 104 }; |
| 101 | 105 |
| 102 } // namespace image_fetcher | 106 } // namespace image_fetcher |
| 103 | 107 |
| 104 #endif // COMPONENTS_IMAGE_FETCHER_IMAGE_FETCHER_IMPL_H_ | 108 #endif // COMPONENTS_IMAGE_FETCHER_IMAGE_FETCHER_IMPL_H_ |
| OLD | NEW |