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 "net/base/load_flags.h" | 7 #include "net/base/load_flags.h" |
8 #include "net/http/http_response_headers.h" | 8 #include "net/http/http_response_headers.h" |
9 #include "net/http/http_status_code.h" | 9 #include "net/http/http_status_code.h" |
10 #include "net/url_request/url_fetcher.h" | 10 #include "net/url_request/url_fetcher.h" |
(...skipping 18 matching lines...) Expand all Loading... | |
29 // be run even if the image data could not be fetched successfully. | 29 // be run even if the image data could not be fetched successfully. |
30 ImageDataFetcherCallback callback; | 30 ImageDataFetcherCallback callback; |
31 | 31 |
32 std::unique_ptr<net::URLFetcher> url_fetcher; | 32 std::unique_ptr<net::URLFetcher> url_fetcher; |
33 }; | 33 }; |
34 | 34 |
35 ImageDataFetcher::ImageDataFetcher( | 35 ImageDataFetcher::ImageDataFetcher( |
36 net::URLRequestContextGetter* url_request_context_getter) | 36 net::URLRequestContextGetter* url_request_context_getter) |
37 : url_request_context_getter_(url_request_context_getter), | 37 : url_request_context_getter_(url_request_context_getter), |
38 data_use_service_name_(DataUseUserData::IMAGE_FETCHER_UNTAGGED), | 38 data_use_service_name_(DataUseUserData::IMAGE_FETCHER_UNTAGGED), |
39 next_url_fetcher_id_(0) {} | 39 next_url_fetcher_id_(0), |
40 max_download_bytes_(-1) {} // No download limitation. | |
40 | 41 |
41 ImageDataFetcher::~ImageDataFetcher() {} | 42 ImageDataFetcher::~ImageDataFetcher() {} |
42 | 43 |
43 void ImageDataFetcher::SetDataUseServiceName( | 44 void ImageDataFetcher::SetDataUseServiceName( |
44 DataUseServiceName data_use_service_name) { | 45 DataUseServiceName data_use_service_name) { |
45 data_use_service_name_ = data_use_service_name; | 46 data_use_service_name_ = data_use_service_name; |
46 } | 47 } |
47 | 48 |
48 void ImageDataFetcher::FetchImageData( | 49 void ImageDataFetcher::FetchImageData( |
49 const GURL& image_url, | 50 const GURL& image_url, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 std::string image_data; | 94 std::string image_data; |
94 if (success) { | 95 if (success) { |
95 source->GetResponseAsString(&image_data); | 96 source->GetResponseAsString(&image_data); |
96 } | 97 } |
97 request_iter->second->callback.Run(image_data, metadata); | 98 request_iter->second->callback.Run(image_data, metadata); |
98 | 99 |
99 // Remove the finished request. | 100 // Remove the finished request. |
100 pending_requests_.erase(request_iter); | 101 pending_requests_.erase(request_iter); |
101 } | 102 } |
102 | 103 |
104 void ImageDataFetcher::OnURLFetchDownloadProgress( | |
105 const net::URLFetcher* source, | |
106 int64_t current, | |
107 int64_t total, | |
108 int64_t current_network_bytes) { | |
109 if (max_download_bytes_ < 0) { | |
110 return; | |
111 } | |
112 if (total <= max_download_bytes_ && current <= max_download_bytes_) { | |
113 return; | |
114 } | |
115 auto request_iter = pending_requests_.find(source); | |
fhorschig
2017/03/27 12:57:25
I am aware that I duplicate 4 operations here from
Marc Treib
2017/03/27 13:16:42
We could have a "FinishRequest(source, result, met
fhorschig
2017/03/27 14:33:43
Hmm, for the sake of the argument, I introduced th
Marc Treib
2017/03/27 14:49:18
Sure, that's fine. Though duplicating the DCHECKs
| |
116 DCHECK(request_iter != pending_requests_.end()); | |
117 | |
118 LOG(WARNING) << "Image data exceededs download size limit."; | |
Marc Treib
2017/03/27 13:16:42
s/exceededs/exceeded/
Also DLOG?
fhorschig
2017/03/27 14:33:42
Done.
LOG was intentional, check below whether you
Marc Treib
2017/03/27 14:49:18
Non-"D" LOG is rarely useful IMO. Any particular u
Marc Treib
2017/03/27 16:40:12
This is still open
fhorschig
2017/03/28 08:28:53
Change uploaded.
| |
119 RequestMetadata metadata; | |
120 metadata.http_response_code = net::URLFetcher::RESPONSE_CODE_INVALID; | |
Marc Treib
2017/03/27 13:16:42
Hm. I wonder if we should somehow signal to the cl
fhorschig
2017/03/27 14:33:42
An empty image in combination with the warning see
Marc Treib
2017/03/27 14:49:18
Okay, fair enough.
Marc Treib
2017/03/27 16:40:12
Did you file a bug for this?
fhorschig
2017/03/28 08:28:53
There is a bug now:
https://crbug.com/705888
I am
| |
121 | |
122 request_iter->second->callback.Run(std::string(), metadata); | |
123 // Abort the finished request. | |
Marc Treib
2017/03/27 13:16:42
nit: not actually finished
fhorschig
2017/03/27 14:33:42
Gone.
| |
124 pending_requests_.erase(request_iter); | |
125 } | |
126 | |
103 } // namespace image_fetcher | 127 } // namespace image_fetcher |
OLD | NEW |