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 #include "components/image_fetcher/core/image_data_fetcher.h" | 5 #include "components/image_fetcher/core/image_data_fetcher.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "net/base/load_flags.h" | 9 #include "net/base/load_flags.h" |
10 #include "net/http/http_response_headers.h" | 10 #include "net/http/http_response_headers.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 data_use_service_name_ = data_use_service_name; | 53 data_use_service_name_ = data_use_service_name; |
54 } | 54 } |
55 | 55 |
56 void ImageDataFetcher::SetImageDownloadLimit( | 56 void ImageDataFetcher::SetImageDownloadLimit( |
57 base::Optional<int64_t> max_download_bytes) { | 57 base::Optional<int64_t> max_download_bytes) { |
58 max_download_bytes_ = max_download_bytes; | 58 max_download_bytes_ = max_download_bytes; |
59 } | 59 } |
60 | 60 |
61 void ImageDataFetcher::FetchImageData( | 61 void ImageDataFetcher::FetchImageData( |
62 const GURL& image_url, | 62 const GURL& image_url, |
63 const ImageDataFetcherCallback& callback) { | 63 const ImageDataFetcherCallback& callback, |
| 64 const net::NetworkTrafficAnnotationTag& traffic_annotation) { |
64 FetchImageData( | 65 FetchImageData( |
65 image_url, callback, /*referrer=*/std::string(), | 66 image_url, callback, /*referrer=*/std::string(), |
66 net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE); | 67 net::URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE, |
| 68 traffic_annotation); |
67 } | 69 } |
68 | 70 |
69 void ImageDataFetcher::FetchImageData( | 71 void ImageDataFetcher::FetchImageData( |
70 const GURL& image_url, | 72 const GURL& image_url, |
71 const ImageDataFetcherCallback& callback, | 73 const ImageDataFetcherCallback& callback, |
72 const std::string& referrer, | 74 const std::string& referrer, |
73 net::URLRequest::ReferrerPolicy referrer_policy) { | 75 net::URLRequest::ReferrerPolicy referrer_policy, |
74 std::unique_ptr<net::URLFetcher> url_fetcher = net::URLFetcher::Create( | 76 const net::NetworkTrafficAnnotationTag& traffic_annotation) { |
75 next_url_fetcher_id_++, image_url, net::URLFetcher::GET, this); | 77 std::unique_ptr<net::URLFetcher> url_fetcher = |
| 78 net::URLFetcher::Create(next_url_fetcher_id_++, image_url, |
| 79 net::URLFetcher::GET, this, traffic_annotation); |
76 | 80 |
77 DataUseUserData::AttachToFetcher(url_fetcher.get(), data_use_service_name_); | 81 DataUseUserData::AttachToFetcher(url_fetcher.get(), data_use_service_name_); |
78 | 82 |
79 std::unique_ptr<ImageDataFetcherRequest> request( | 83 std::unique_ptr<ImageDataFetcherRequest> request( |
80 new ImageDataFetcherRequest(callback, std::move(url_fetcher))); | 84 new ImageDataFetcherRequest(callback, std::move(url_fetcher))); |
81 request->url_fetcher->SetRequestContext(url_request_context_getter_.get()); | 85 request->url_fetcher->SetRequestContext(url_request_context_getter_.get()); |
82 request->url_fetcher->SetReferrer(referrer); | 86 request->url_fetcher->SetReferrer(referrer); |
83 request->url_fetcher->SetReferrerPolicy(referrer_policy); | 87 request->url_fetcher->SetReferrerPolicy(referrer_policy); |
84 request->url_fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 88 request->url_fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
85 net::LOAD_DO_NOT_SAVE_COOKIES | | 89 net::LOAD_DO_NOT_SAVE_COOKIES | |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 void ImageDataFetcher::FinishRequest(const net::URLFetcher* source, | 139 void ImageDataFetcher::FinishRequest(const net::URLFetcher* source, |
136 const RequestMetadata& metadata, | 140 const RequestMetadata& metadata, |
137 const std::string& image_data) { | 141 const std::string& image_data) { |
138 auto request_iter = pending_requests_.find(source); | 142 auto request_iter = pending_requests_.find(source); |
139 DCHECK(request_iter != pending_requests_.end()); | 143 DCHECK(request_iter != pending_requests_.end()); |
140 request_iter->second->callback.Run(image_data, metadata); | 144 request_iter->second->callback.Run(image_data, metadata); |
141 pending_requests_.erase(request_iter); | 145 pending_requests_.erase(request_iter); |
142 } | 146 } |
143 | 147 |
144 } // namespace image_fetcher | 148 } // namespace image_fetcher |
OLD | NEW |