Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: content/public/test/test_download_request_handler.cc

Issue 1958383002: [Merge M51][Downloads] Set the Referrer header for resumed requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
9 #include <memory>
8 #include <utility> 10 #include <utility>
9 11
10 #include "base/logging.h" 12 #include "base/logging.h"
11 #include "base/macros.h" 13 #include "base/macros.h"
12 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
13 #include "base/run_loop.h" 15 #include "base/run_loop.h"
14 #include "base/sequenced_task_runner.h" 16 #include "base/sequenced_task_runner.h"
15 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
16 #include "base/threading/sequenced_task_runner_handle.h" 18 #include "base/threading/sequenced_task_runner_handle.h"
17 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 56
55 // Sets |requests| to the vector of completed requests and clears the internal 57 // Sets |requests| to the vector of completed requests and clears the internal
56 // list. The returned requests are stored in the order in which they were 58 // list. The returned requests are stored in the order in which they were
57 // reported as being complete (not necessarily the order in which they were 59 // reported as being complete (not necessarily the order in which they were
58 // received). 60 // received).
59 void GetAndResetCompletedRequests( 61 void GetAndResetCompletedRequests(
60 TestDownloadRequestHandler::CompletedRequests* requests); 62 TestDownloadRequestHandler::CompletedRequests* requests);
61 63
62 // Can be called by a URLRequestJob to notify this interceptor of a completed 64 // Can be called by a URLRequestJob to notify this interceptor of a completed
63 // request. 65 // request.
64 void AddCompletedRequest( 66 void AddCompletedRequest(std::unique_ptr<CompletedRequest> request);
65 const TestDownloadRequestHandler::CompletedRequest& request);
66 67
67 // Returns the task runner that should be used for invoking any client 68 // Returns the task runner that should be used for invoking any client
68 // supplied callbacks. 69 // supplied callbacks.
69 scoped_refptr<base::SequencedTaskRunner> GetClientTaskRunner(); 70 scoped_refptr<base::SequencedTaskRunner> GetClientTaskRunner();
70 71
71 private: 72 private:
72 Interceptor(const GURL& url, 73 Interceptor(const GURL& url,
73 scoped_refptr<base::SequencedTaskRunner> client_task_runner); 74 scoped_refptr<base::SequencedTaskRunner> client_task_runner);
74 75
75 // net::URLRequestInterceptor 76 // net::URLRequestInterceptor
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 scoped_refptr<net::HttpResponseHeaders> HeadersFromString( 193 scoped_refptr<net::HttpResponseHeaders> HeadersFromString(
193 const std::string& headers_string) { 194 const std::string& headers_string) {
194 scoped_refptr<net::HttpResponseHeaders> headers = 195 scoped_refptr<net::HttpResponseHeaders> headers =
195 new net::HttpResponseHeaders(net::HttpUtil::AssembleRawHeaders( 196 new net::HttpResponseHeaders(net::HttpUtil::AssembleRawHeaders(
196 headers_string.c_str(), headers_string.size())); 197 headers_string.c_str(), headers_string.size()));
197 return headers; 198 return headers;
198 } 199 }
199 200
200 } // namespace 201 } // namespace
201 202
203 TestDownloadRequestHandler::CompletedRequest::CompletedRequest() {}
204
205 TestDownloadRequestHandler::CompletedRequest::~CompletedRequest() {}
206
207 TestDownloadRequestHandler::CompletedRequest::CompletedRequest(
208 CompletedRequest&&) = default;
209
202 // static 210 // static
203 net::URLRequestJob* TestDownloadRequestHandler::PartialResponseJob::Factory( 211 net::URLRequestJob* TestDownloadRequestHandler::PartialResponseJob::Factory(
204 const Parameters& parameters, 212 const Parameters& parameters,
205 net::URLRequest* request, 213 net::URLRequest* request,
206 net::NetworkDelegate* delegate, 214 net::NetworkDelegate* delegate,
207 base::WeakPtr<Interceptor> interceptor) { 215 base::WeakPtr<Interceptor> interceptor) {
208 return new PartialResponseJob(make_scoped_ptr(new Parameters(parameters)), 216 return new PartialResponseJob(make_scoped_ptr(new Parameters(parameters)),
209 interceptor, request, delegate); 217 interceptor, request, delegate);
210 } 218 }
211 219
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 buf->data()); 311 buf->data());
304 DVLOG(1) << "Read " << bytes_to_copy << " bytes at offset " 312 DVLOG(1) << "Read " << bytes_to_copy << " bytes at offset "
305 << offset_of_next_read_; 313 << offset_of_next_read_;
306 offset_of_next_read_ += bytes_to_copy; 314 offset_of_next_read_ += bytes_to_copy;
307 read_byte_count_ += bytes_to_copy; 315 read_byte_count_ += bytes_to_copy;
308 return bytes_to_copy; 316 return bytes_to_copy;
309 } 317 }
310 318
311 void TestDownloadRequestHandler::PartialResponseJob::ReportCompletedRequest() { 319 void TestDownloadRequestHandler::PartialResponseJob::ReportCompletedRequest() {
312 if (interceptor_.get()) { 320 if (interceptor_.get()) {
313 TestDownloadRequestHandler::CompletedRequest completed_request; 321 std::unique_ptr<CompletedRequest> completed_request(new CompletedRequest);
314 completed_request.transferred_byte_count = read_byte_count_; 322 completed_request->transferred_byte_count = read_byte_count_;
315 completed_request.request_headers = request()->extra_request_headers(); 323 completed_request->request_headers = request()->extra_request_headers();
316 interceptor_->AddCompletedRequest(completed_request); 324 completed_request->referrer = request()->referrer();
325 completed_request->referrer_policy = request()->referrer_policy();
326 completed_request->initiator = request()->initiator();
327 completed_request->first_party_for_cookies =
328 request()->first_party_for_cookies();
329 completed_request->first_party_url_policy =
330 request()->first_party_url_policy();
331 interceptor_->AddCompletedRequest(std::move(completed_request));
317 } 332 }
318 } 333 }
319 334
320 // static 335 // static
321 void TestDownloadRequestHandler::PartialResponseJob:: 336 void TestDownloadRequestHandler::PartialResponseJob::
322 OnStartResponseCallbackOnPossiblyIncorrectThread( 337 OnStartResponseCallbackOnPossiblyIncorrectThread(
323 base::WeakPtr<PartialResponseJob> job, 338 base::WeakPtr<PartialResponseJob> job,
324 const std::string& headers, 339 const std::string& headers,
325 net::Error error) { 340 net::Error error) {
326 BrowserThread::PostTask( 341 BrowserThread::PostTask(
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 job_factory_ = job_factory; 519 job_factory_ = job_factory;
505 } 520 }
506 521
507 void TestDownloadRequestHandler::Interceptor::GetAndResetCompletedRequests( 522 void TestDownloadRequestHandler::Interceptor::GetAndResetCompletedRequests(
508 TestDownloadRequestHandler::CompletedRequests* requests) { 523 TestDownloadRequestHandler::CompletedRequests* requests) {
509 requests->clear(); 524 requests->clear();
510 completed_requests_.swap(*requests); 525 completed_requests_.swap(*requests);
511 } 526 }
512 527
513 void TestDownloadRequestHandler::Interceptor::AddCompletedRequest( 528 void TestDownloadRequestHandler::Interceptor::AddCompletedRequest(
514 const TestDownloadRequestHandler::CompletedRequest& request) { 529 std::unique_ptr<CompletedRequest> request) {
515 completed_requests_.push_back(request); 530 completed_requests_.push_back(std::move(request));
516 } 531 }
517 532
518 scoped_refptr<base::SequencedTaskRunner> 533 scoped_refptr<base::SequencedTaskRunner>
519 TestDownloadRequestHandler::Interceptor::GetClientTaskRunner() { 534 TestDownloadRequestHandler::Interceptor::GetClientTaskRunner() {
520 return client_task_runner_; 535 return client_task_runner_;
521 } 536 }
522 537
523 TestDownloadRequestHandler::Interceptor::Interceptor( 538 TestDownloadRequestHandler::Interceptor::Interceptor(
524 const GURL& url, 539 const GURL& url,
525 scoped_refptr<base::SequencedTaskRunner> client_task_runner) 540 scoped_refptr<base::SequencedTaskRunner> client_task_runner)
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 base::RunLoop run_loop; 681 base::RunLoop run_loop;
667 BrowserThread::PostTaskAndReply( 682 BrowserThread::PostTaskAndReply(
668 BrowserThread::IO, FROM_HERE, 683 BrowserThread::IO, FROM_HERE,
669 base::Bind(&Interceptor::GetAndResetCompletedRequests, interceptor_, 684 base::Bind(&Interceptor::GetAndResetCompletedRequests, interceptor_,
670 requests), 685 requests),
671 run_loop.QuitClosure()); 686 run_loop.QuitClosure());
672 run_loop.Run(); 687 run_loop.Run();
673 } 688 }
674 689
675 } // namespace content 690 } // namespace content
OLDNEW
« no previous file with comments | « content/public/test/test_download_request_handler.h ('k') | content/test/data/download/download-link.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698