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> |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 void SetImageFetcherDelegate(ImageFetcherDelegate* delegate) override; | 43 void SetImageFetcherDelegate(ImageFetcherDelegate* delegate) override; |
44 | 44 |
45 // Sets a service name against which to track data usage. | 45 // Sets a service name against which to track data usage. |
46 void SetDataUseServiceName(DataUseServiceName data_use_service_name) override; | 46 void SetDataUseServiceName(DataUseServiceName data_use_service_name) override; |
47 | 47 |
48 void SetDesiredImageFrameSize(const gfx::Size& size) override; | 48 void SetDesiredImageFrameSize(const gfx::Size& size) override; |
49 | 49 |
50 void StartOrQueueNetworkRequest( | 50 void StartOrQueueNetworkRequest( |
51 const std::string& id, | 51 const std::string& id, |
52 const GURL& image_url, | 52 const GURL& image_url, |
53 base::Callback<void(const std::string&, const gfx::Image&)> callback) | 53 const ImageFetcherCallback& callback) override; |
54 override; | |
55 | 54 |
56 ImageDecoder* GetImageDecoder() override; | 55 ImageDecoder* GetImageDecoder() override; |
57 | 56 |
58 private: | 57 private: |
59 using CallbackVector = | |
60 std::vector<base::Callback<void(const std::string&, const gfx::Image&)>>; | |
61 | |
62 // State related to an image fetch (id, pending callbacks). | 58 // State related to an image fetch (id, pending callbacks). |
63 struct ImageRequest { | 59 struct ImageRequest { |
64 ImageRequest(); | 60 ImageRequest(); |
65 ImageRequest(const ImageRequest& other); | 61 ImageRequest(const ImageRequest& other); |
66 ~ImageRequest(); | 62 ~ImageRequest(); |
67 | 63 |
68 void swap(ImageRequest* other) { | 64 void swap(ImageRequest* other) { |
69 std::swap(id, other->id); | 65 std::swap(id, other->id); |
70 std::swap(callbacks, other->callbacks); | 66 std::swap(callbacks, other->callbacks); |
71 } | 67 } |
72 | 68 |
73 std::string id; | 69 std::string id; |
74 // Queue for pending callbacks, which may accumulate while the request is in | 70 // Queue for pending callbacks, which may accumulate while the request is in |
75 // flight. | 71 // flight. |
76 CallbackVector callbacks; | 72 std::vector<ImageFetcherCallback> callbacks; |
77 }; | 73 }; |
78 | 74 |
79 using ImageRequestMap = std::map<const GURL, ImageRequest>; | 75 using ImageRequestMap = std::map<const GURL, ImageRequest>; |
80 | 76 |
81 // Processes image URL fetched events. This is the continuation method used | 77 // Processes image URL fetched events. This is the continuation method used |
82 // for creating callbacks that are passed to the ImageDataFetcher. | 78 // for creating callbacks that are passed to the ImageDataFetcher. |
83 void OnImageURLFetched(const GURL& image_url, | 79 void OnImageURLFetched(const GURL& image_url, |
84 const std::string& image_data, | 80 const std::string& image_data, |
85 const RequestMetadata& metadata); | 81 const RequestMetadata& metadata); |
86 | 82 |
87 // Processes image decoded events. This is the continuation method used for | 83 // Processes image decoded events. This is the continuation method used for |
88 // creating callbacks that are passed to the ImageDecoder. | 84 // creating callbacks that are passed to the ImageDecoder. |
89 void OnImageDecoded(const GURL& image_url, const gfx::Image& image); | 85 void OnImageDecoded(const GURL& image_url, |
| 86 const RequestMetadata& metadata, |
| 87 const gfx::Image& image); |
90 | 88 |
91 ImageFetcherDelegate* delegate_; | 89 ImageFetcherDelegate* delegate_; |
92 | 90 |
93 gfx::Size desired_image_frame_size_; | 91 gfx::Size desired_image_frame_size_; |
94 | 92 |
95 scoped_refptr<net::URLRequestContextGetter> url_request_context_; | 93 scoped_refptr<net::URLRequestContextGetter> url_request_context_; |
96 | 94 |
97 std::unique_ptr<ImageDecoder> image_decoder_; | 95 std::unique_ptr<ImageDecoder> image_decoder_; |
98 | 96 |
99 std::unique_ptr<ImageDataFetcher> image_data_fetcher_; | 97 std::unique_ptr<ImageDataFetcher> image_data_fetcher_; |
100 | 98 |
101 // Map from each image URL to the request information (associated website | 99 // Map from each image URL to the request information (associated website |
102 // url, fetcher, pending callbacks). | 100 // url, fetcher, pending callbacks). |
103 ImageRequestMap pending_net_requests_; | 101 ImageRequestMap pending_net_requests_; |
104 | 102 |
105 DISALLOW_COPY_AND_ASSIGN(ImageFetcherImpl); | 103 DISALLOW_COPY_AND_ASSIGN(ImageFetcherImpl); |
106 }; | 104 }; |
107 | 105 |
108 } // namespace image_fetcher | 106 } // namespace image_fetcher |
109 | 107 |
110 #endif // COMPONENTS_IMAGE_FETCHER_IMAGE_FETCHER_IMPL_H_ | 108 #endif // COMPONENTS_IMAGE_FETCHER_IMAGE_FETCHER_IMPL_H_ |
OLD | NEW |