| 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 #include <utility> |
| 8 | 9 |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 11 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 12 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 13 #include "base/sequenced_task_runner.h" | 14 #include "base/sequenced_task_runner.h" |
| 14 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 15 #include "base/threading/sequenced_task_runner_handle.h" | 16 #include "base/threading/sequenced_task_runner_handle.h" |
| 16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 17 #include "net/base/io_buffer.h" | 18 #include "net/base/io_buffer.h" |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 return new PartialResponseJob(make_scoped_ptr(new Parameters(parameters)), | 207 return new PartialResponseJob(make_scoped_ptr(new Parameters(parameters)), |
| 207 interceptor, request, delegate); | 208 interceptor, request, delegate); |
| 208 } | 209 } |
| 209 | 210 |
| 210 TestDownloadRequestHandler::PartialResponseJob::PartialResponseJob( | 211 TestDownloadRequestHandler::PartialResponseJob::PartialResponseJob( |
| 211 scoped_ptr<Parameters> parameters, | 212 scoped_ptr<Parameters> parameters, |
| 212 base::WeakPtr<Interceptor> interceptor, | 213 base::WeakPtr<Interceptor> interceptor, |
| 213 net::URLRequest* request, | 214 net::URLRequest* request, |
| 214 net::NetworkDelegate* network_delegate) | 215 net::NetworkDelegate* network_delegate) |
| 215 : net::URLRequestJob(request, network_delegate), | 216 : net::URLRequestJob(request, network_delegate), |
| 216 parameters_(parameters.Pass()), | 217 parameters_(std::move(parameters)), |
| 217 interceptor_(interceptor), | 218 interceptor_(interceptor), |
| 218 weak_factory_(this) { | 219 weak_factory_(this) { |
| 219 DCHECK(parameters_.get()); | 220 DCHECK(parameters_.get()); |
| 220 DCHECK_LT(0, parameters_->size); | 221 DCHECK_LT(0, parameters_->size); |
| 221 DCHECK_NE(-1, parameters_->pattern_generator_seed); | 222 DCHECK_NE(-1, parameters_->pattern_generator_seed); |
| 222 } | 223 } |
| 223 | 224 |
| 224 TestDownloadRequestHandler::PartialResponseJob::~PartialResponseJob() {} | 225 TestDownloadRequestHandler::PartialResponseJob::~PartialResponseJob() {} |
| 225 | 226 |
| 226 void TestDownloadRequestHandler::PartialResponseJob::Start() { | 227 void TestDownloadRequestHandler::PartialResponseJob::Start() { |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 // static | 482 // static |
| 482 base::WeakPtr<TestDownloadRequestHandler::Interceptor> | 483 base::WeakPtr<TestDownloadRequestHandler::Interceptor> |
| 483 TestDownloadRequestHandler::Interceptor::Register( | 484 TestDownloadRequestHandler::Interceptor::Register( |
| 484 const GURL& url, | 485 const GURL& url, |
| 485 scoped_refptr<base::SequencedTaskRunner> client_task_runner) { | 486 scoped_refptr<base::SequencedTaskRunner> client_task_runner) { |
| 486 DCHECK(url.is_valid()); | 487 DCHECK(url.is_valid()); |
| 487 scoped_ptr<Interceptor> interceptor(new Interceptor(url, client_task_runner)); | 488 scoped_ptr<Interceptor> interceptor(new Interceptor(url, client_task_runner)); |
| 488 base::WeakPtr<Interceptor> weak_reference = | 489 base::WeakPtr<Interceptor> weak_reference = |
| 489 interceptor->weak_ptr_factory_.GetWeakPtr(); | 490 interceptor->weak_ptr_factory_.GetWeakPtr(); |
| 490 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); | 491 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); |
| 491 filter->AddUrlInterceptor(url, interceptor.Pass()); | 492 filter->AddUrlInterceptor(url, std::move(interceptor)); |
| 492 return weak_reference; | 493 return weak_reference; |
| 493 } | 494 } |
| 494 | 495 |
| 495 void TestDownloadRequestHandler::Interceptor::Unregister() { | 496 void TestDownloadRequestHandler::Interceptor::Unregister() { |
| 496 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); | 497 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); |
| 497 filter->RemoveUrlHandler(url_); | 498 filter->RemoveUrlHandler(url_); |
| 498 // We are deleted now since the filter owned |this|. | 499 // We are deleted now since the filter owned |this|. |
| 499 } | 500 } |
| 500 | 501 |
| 501 void TestDownloadRequestHandler::Interceptor::SetJobFactory( | 502 void TestDownloadRequestHandler::Interceptor::SetJobFactory( |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 base::RunLoop run_loop; | 664 base::RunLoop run_loop; |
| 664 BrowserThread::PostTaskAndReply( | 665 BrowserThread::PostTaskAndReply( |
| 665 BrowserThread::IO, FROM_HERE, | 666 BrowserThread::IO, FROM_HERE, |
| 666 base::Bind(&Interceptor::GetAndResetCompletedRequests, interceptor_, | 667 base::Bind(&Interceptor::GetAndResetCompletedRequests, interceptor_, |
| 667 requests), | 668 requests), |
| 668 run_loop.QuitClosure()); | 669 run_loop.QuitClosure()); |
| 669 run_loop.Run(); | 670 run_loop.Run(); |
| 670 } | 671 } |
| 671 | 672 |
| 672 } // namespace content | 673 } // namespace content |
| OLD | NEW |