OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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_CORE_IMAGE_DATA_FETCHER_H_ | 5 #ifndef COMPONENTS_IMAGE_FETCHER_CORE_IMAGE_DATA_FETCHER_H_ |
6 #define COMPONENTS_IMAGE_FETCHER_CORE_IMAGE_DATA_FETCHER_H_ | 6 #define COMPONENTS_IMAGE_FETCHER_CORE_IMAGE_DATA_FETCHER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/optional.h" | 15 #include "base/optional.h" |
16 #include "components/data_use_measurement/core/data_use_user_data.h" | 16 #include "components/data_use_measurement/core/data_use_user_data.h" |
17 #include "components/image_fetcher/core/request_metadata.h" | 17 #include "components/image_fetcher/core/request_metadata.h" |
18 #include "net/traffic_annotation/network_traffic_annotation.h" | |
18 #include "net/url_request/url_fetcher_delegate.h" | 19 #include "net/url_request/url_fetcher_delegate.h" |
19 #include "net/url_request/url_request.h" | 20 #include "net/url_request/url_request.h" |
20 #include "url/gurl.h" | 21 #include "url/gurl.h" |
21 | 22 |
22 namespace net { | 23 namespace net { |
23 class URLFetcher; | 24 class URLFetcher; |
24 class URLRequestContextGetter; | 25 class URLRequestContextGetter; |
25 } // namespace net | 26 } // namespace net |
26 | 27 |
27 namespace image_fetcher { | 28 namespace image_fetcher { |
28 | 29 |
29 class ImageDataFetcher : public net::URLFetcherDelegate { | 30 class ImageDataFetcher : public net::URLFetcherDelegate { |
30 public: | 31 public: |
31 // Callback with the |image_data|. If an error prevented a http response, | 32 // Callback with the |image_data|. If an error prevented a http response, |
32 // |request_metadata.response_code| will be RESPONSE_CODE_INVALID. | 33 // |request_metadata.response_code| will be RESPONSE_CODE_INVALID. |
33 // TODO(treib): Pass |image_data| out by value, or use RefCountedBytes, to | 34 // TODO(treib): Pass |image_data| out by value, or use RefCountedBytes, to |
34 // avoid copying. | 35 // avoid copying. |
35 using ImageDataFetcherCallback = | 36 using ImageDataFetcherCallback = |
36 base::Callback<void(const std::string& image_data, | 37 base::Callback<void(const std::string& image_data, |
37 const RequestMetadata& request_metadata)>; | 38 const RequestMetadata& request_metadata)>; |
38 | 39 |
39 using DataUseServiceName = data_use_measurement::DataUseUserData::ServiceName; | 40 using DataUseServiceName = data_use_measurement::DataUseUserData::ServiceName; |
40 | 41 |
41 explicit ImageDataFetcher( | 42 explicit ImageDataFetcher( |
42 net::URLRequestContextGetter* url_request_context_getter); | 43 net::URLRequestContextGetter* url_request_context_getter, |
44 const net::NetworkTrafficAnnotationTag& traffic_annotation); | |
43 ~ImageDataFetcher() override; | 45 ~ImageDataFetcher() override; |
44 | 46 |
45 // Sets a service name against which to track data usage. | 47 // Sets a service name against which to track data usage. |
46 void SetDataUseServiceName(DataUseServiceName data_use_service_name); | 48 void SetDataUseServiceName(DataUseServiceName data_use_service_name); |
47 | 49 |
48 // Sets an upper limit for image downloads. | 50 // Sets an upper limit for image downloads. |
49 // Already running downloads are affected. | 51 // Already running downloads are affected. |
50 void SetImageDownloadLimit(base::Optional<int64_t> max_download_bytes); | 52 void SetImageDownloadLimit(base::Optional<int64_t> max_download_bytes); |
51 | 53 |
52 // Fetches the raw image bytes from the given |image_url| and calls the given | 54 // Fetches the raw image bytes from the given |image_url| and calls the given |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 // The next ID to use for a newly created URLFetcher. Each URLFetcher gets an | 88 // The next ID to use for a newly created URLFetcher. Each URLFetcher gets an |
87 // id when it is created. The |url_fetcher_id_| is incremented by one for each | 89 // id when it is created. The |url_fetcher_id_| is incremented by one for each |
88 // newly created URLFetcher. The URLFetcher ID can be used during testing to | 90 // newly created URLFetcher. The URLFetcher ID can be used during testing to |
89 // get individual URLFetchers and modify their state. Outside of tests this ID | 91 // get individual URLFetchers and modify their state. Outside of tests this ID |
90 // is not used. | 92 // is not used. |
91 int next_url_fetcher_id_; | 93 int next_url_fetcher_id_; |
92 | 94 |
93 // Upper limit for the number of bytes to download per image. | 95 // Upper limit for the number of bytes to download per image. |
94 base::Optional<int64_t> max_download_bytes_; | 96 base::Optional<int64_t> max_download_bytes_; |
95 | 97 |
98 const net::NetworkTrafficAnnotationTag& traffic_annotation_; | |
Marc Treib
2017/05/09 09:43:47
This should probably not be a reference, but an in
Ramin Halavati
2017/05/09 11:08:24
Done.
| |
99 | |
96 DISALLOW_COPY_AND_ASSIGN(ImageDataFetcher); | 100 DISALLOW_COPY_AND_ASSIGN(ImageDataFetcher); |
97 }; | 101 }; |
98 | 102 |
99 } // namespace image_fetcher | 103 } // namespace image_fetcher |
100 | 104 |
101 #endif // COMPONENTS_IMAGE_FETCHER_CORE_IMAGE_DATA_FETCHER_H_ | 105 #endif // COMPONENTS_IMAGE_FETCHER_CORE_IMAGE_DATA_FETCHER_H_ |
OLD | NEW |