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 // Sets the desired size for images with multiple frames (like .ico files). |
| 49 void SetDesiredImageFrameSize(const gfx::Size& size) override; |
| 50 |
47 void StartOrQueueNetworkRequest( | 51 void StartOrQueueNetworkRequest( |
48 const std::string& id, | 52 const std::string& id, |
49 const GURL& image_url, | 53 const GURL& image_url, |
50 base::Callback<void(const std::string&, const gfx::Image&)> callback) | 54 base::Callback<void(const std::string&, const gfx::Image&)> callback) |
51 override; | 55 override; |
52 | 56 |
53 private: | 57 private: |
54 using CallbackVector = | 58 using CallbackVector = |
55 std::vector<base::Callback<void(const std::string&, const gfx::Image&)>>; | 59 std::vector<base::Callback<void(const std::string&, const gfx::Image&)>>; |
56 | 60 |
(...skipping 19 matching lines...) Expand all Loading... |
76 // Processes image URL fetched events. This is the continuation method used | 80 // Processes image URL fetched events. This is the continuation method used |
77 // for creating callbacks that are passed to the ImageDataFetcher. | 81 // for creating callbacks that are passed to the ImageDataFetcher. |
78 void OnImageURLFetched(const GURL& image_url, | 82 void OnImageURLFetched(const GURL& image_url, |
79 const std::string& image_data, | 83 const std::string& image_data, |
80 const RequestMetadata& metadata); | 84 const RequestMetadata& metadata); |
81 | 85 |
82 // Processes image decoded events. This is the continuation method used for | 86 // Processes image decoded events. This is the continuation method used for |
83 // creating callbacks that are passed to the ImageDecoder. | 87 // creating callbacks that are passed to the ImageDecoder. |
84 void OnImageDecoded(const GURL& image_url, const gfx::Image& image); | 88 void OnImageDecoded(const GURL& image_url, const gfx::Image& image); |
85 | 89 |
| 90 ImageFetcherDelegate* delegate_; |
86 | 91 |
87 ImageFetcherDelegate* delegate_; | 92 gfx::Size desired_image_frame_size_; |
88 | 93 |
89 scoped_refptr<net::URLRequestContextGetter> url_request_context_; | 94 scoped_refptr<net::URLRequestContextGetter> url_request_context_; |
90 | 95 |
91 std::unique_ptr<ImageDecoder> image_decoder_; | 96 std::unique_ptr<ImageDecoder> image_decoder_; |
92 | 97 |
93 std::unique_ptr<ImageDataFetcher> image_data_fetcher_; | 98 std::unique_ptr<ImageDataFetcher> image_data_fetcher_; |
94 | 99 |
95 // Map from each image URL to the request information (associated website | 100 // Map from each image URL to the request information (associated website |
96 // url, fetcher, pending callbacks). | 101 // url, fetcher, pending callbacks). |
97 ImageRequestMap pending_net_requests_; | 102 ImageRequestMap pending_net_requests_; |
98 | 103 |
99 DISALLOW_COPY_AND_ASSIGN(ImageFetcherImpl); | 104 DISALLOW_COPY_AND_ASSIGN(ImageFetcherImpl); |
100 }; | 105 }; |
101 | 106 |
102 } // namespace image_fetcher | 107 } // namespace image_fetcher |
103 | 108 |
104 #endif // COMPONENTS_IMAGE_FETCHER_IMAGE_FETCHER_IMPL_H_ | 109 #endif // COMPONENTS_IMAGE_FETCHER_IMAGE_FETCHER_IMPL_H_ |
OLD | NEW |