OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/public/test/test_download_request_handler.h" | 5 #include "content/public/test/test_download_request_handler.h" |
6 | 6 |
7 #include <inttypes.h> | 7 #include <inttypes.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 static net::URLRequestJob* Factory(const Parameters& parameters, | 102 static net::URLRequestJob* Factory(const Parameters& parameters, |
103 net::URLRequest* request, | 103 net::URLRequest* request, |
104 net::NetworkDelegate* delegate, | 104 net::NetworkDelegate* delegate, |
105 base::WeakPtr<Interceptor> interceptor); | 105 base::WeakPtr<Interceptor> interceptor); |
106 | 106 |
107 // URLRequestJob | 107 // URLRequestJob |
108 void Start() override; | 108 void Start() override; |
109 void GetResponseInfo(net::HttpResponseInfo* response_info) override; | 109 void GetResponseInfo(net::HttpResponseInfo* response_info) override; |
110 int64_t GetTotalReceivedBytes() const override; | 110 int64_t GetTotalReceivedBytes() const override; |
111 bool GetMimeType(std::string* mime_type) const override; | 111 bool GetMimeType(std::string* mime_type) const override; |
112 int GetResponseCode() const override; | |
113 int ReadRawData(net::IOBuffer* buf, int buf_size) override; | 112 int ReadRawData(net::IOBuffer* buf, int buf_size) override; |
114 | 113 |
115 private: | 114 private: |
116 PartialResponseJob(std::unique_ptr<Parameters> parameters, | 115 PartialResponseJob(std::unique_ptr<Parameters> parameters, |
117 base::WeakPtr<Interceptor> interceptor, | 116 base::WeakPtr<Interceptor> interceptor, |
118 net::URLRequest* url_request, | 117 net::URLRequest* url_request, |
119 net::NetworkDelegate* network_delegate); | 118 net::NetworkDelegate* network_delegate); |
120 | 119 |
121 ~PartialResponseJob() override; | 120 ~PartialResponseJob() override; |
122 void ReportCompletedRequest(); | 121 void ReportCompletedRequest(); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 const { | 267 const { |
269 return offset_of_next_read_ - requested_range_begin_; | 268 return offset_of_next_read_ - requested_range_begin_; |
270 } | 269 } |
271 | 270 |
272 bool TestDownloadRequestHandler::PartialResponseJob::GetMimeType( | 271 bool TestDownloadRequestHandler::PartialResponseJob::GetMimeType( |
273 std::string* mime_type) const { | 272 std::string* mime_type) const { |
274 *mime_type = parameters_->content_type; | 273 *mime_type = parameters_->content_type; |
275 return !parameters_->content_type.empty(); | 274 return !parameters_->content_type.empty(); |
276 } | 275 } |
277 | 276 |
278 int TestDownloadRequestHandler::PartialResponseJob::GetResponseCode() const { | |
279 return response_info_.headers.get() ? response_info_.headers->response_code() | |
280 : 0; | |
281 } | |
282 | |
283 int TestDownloadRequestHandler::PartialResponseJob::ReadRawData( | 277 int TestDownloadRequestHandler::PartialResponseJob::ReadRawData( |
284 net::IOBuffer* buf, | 278 net::IOBuffer* buf, |
285 int buf_size) { | 279 int buf_size) { |
286 DVLOG(1) << "Preparing to read " << buf_size << " bytes"; | 280 DVLOG(1) << "Preparing to read " << buf_size << " bytes"; |
287 | 281 |
288 // requested_range_begin_ == -1 implies that the body was empty. | 282 // requested_range_begin_ == -1 implies that the body was empty. |
289 if (offset_of_next_read_ > requested_range_end_ || | 283 if (offset_of_next_read_ > requested_range_end_ || |
290 requested_range_begin_ == -1) { | 284 requested_range_begin_ == -1) { |
291 DVLOG(1) << "Done reading."; | 285 DVLOG(1) << "Done reading."; |
292 return 0; | 286 return 0; |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 base::RunLoop run_loop; | 685 base::RunLoop run_loop; |
692 BrowserThread::PostTaskAndReply( | 686 BrowserThread::PostTaskAndReply( |
693 BrowserThread::IO, FROM_HERE, | 687 BrowserThread::IO, FROM_HERE, |
694 base::Bind(&Interceptor::GetAndResetCompletedRequests, interceptor_, | 688 base::Bind(&Interceptor::GetAndResetCompletedRequests, interceptor_, |
695 requests), | 689 requests), |
696 run_loop.QuitClosure()); | 690 run_loop.QuitClosure()); |
697 run_loop.Run(); | 691 run_loop.Run(); |
698 } | 692 } |
699 | 693 |
700 } // namespace content | 694 } // namespace content |
OLD | NEW |