| 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 "headless/public/util/deterministic_http_protocol_handler.h" | 5 #include "headless/public/util/deterministic_http_protocol_handler.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "headless/public/headless_browser_context.h" | 9 #include "headless/public/headless_browser_context.h" |
| 10 #include "headless/public/util/deterministic_dispatcher.h" | 10 #include "headless/public/util/deterministic_dispatcher.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 size_t body_size) override {} | 37 size_t body_size) override {} |
| 38 | 38 |
| 39 private: | 39 private: |
| 40 DISALLOW_COPY_AND_ASSIGN(NopGenericURLRequestJobDelegate); | 40 DISALLOW_COPY_AND_ASSIGN(NopGenericURLRequestJobDelegate); |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 DeterministicHttpProtocolHandler::DeterministicHttpProtocolHandler( | 43 DeterministicHttpProtocolHandler::DeterministicHttpProtocolHandler( |
| 44 DeterministicDispatcher* deterministic_dispatcher, | 44 DeterministicDispatcher* deterministic_dispatcher, |
| 45 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) | 45 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) |
| 46 : deterministic_dispatcher_(deterministic_dispatcher), | 46 : deterministic_dispatcher_(deterministic_dispatcher), |
| 47 headless_browser_context_(nullptr), |
| 47 io_task_runner_(io_task_runner), | 48 io_task_runner_(io_task_runner), |
| 48 nop_delegate_(new NopGenericURLRequestJobDelegate()) {} | 49 nop_delegate_(new NopGenericURLRequestJobDelegate()) {} |
| 49 | 50 |
| 50 DeterministicHttpProtocolHandler::~DeterministicHttpProtocolHandler() { | 51 DeterministicHttpProtocolHandler::~DeterministicHttpProtocolHandler() { |
| 51 if (url_request_context_) | 52 if (url_request_context_) |
| 52 io_task_runner_->DeleteSoon(FROM_HERE, url_request_context_.release()); | 53 io_task_runner_->DeleteSoon(FROM_HERE, url_request_context_.release()); |
| 53 if (url_request_job_factory_) | 54 if (url_request_job_factory_) |
| 54 io_task_runner_->DeleteSoon(FROM_HERE, url_request_job_factory_.release()); | 55 io_task_runner_->DeleteSoon(FROM_HERE, url_request_job_factory_.release()); |
| 55 } | 56 } |
| 56 | 57 |
| 57 net::URLRequestJob* DeterministicHttpProtocolHandler::MaybeCreateJob( | 58 net::URLRequestJob* DeterministicHttpProtocolHandler::MaybeCreateJob( |
| 58 net::URLRequest* request, | 59 net::URLRequest* request, |
| 59 net::NetworkDelegate* network_delegate) const { | 60 net::NetworkDelegate* network_delegate) const { |
| 60 if (!url_request_context_) { | 61 if (!url_request_context_) { |
| 61 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 62 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 62 // Create our own URLRequestContext with an empty URLRequestJobFactoryImpl | 63 // Create our own URLRequestContext with an empty URLRequestJobFactoryImpl |
| 63 // which lets us use the default http(s) RequestJobs. | 64 // which lets us use the default http(s) RequestJobs. |
| 64 url_request_context_.reset(new net::URLRequestContext()); | 65 url_request_context_.reset(new net::URLRequestContext()); |
| 65 url_request_context_->CopyFrom(request->context()); | 66 url_request_context_->CopyFrom(request->context()); |
| 66 url_request_job_factory_.reset(new net::URLRequestJobFactoryImpl()); | 67 url_request_job_factory_.reset(new net::URLRequestJobFactoryImpl()); |
| 67 url_request_context_->set_job_factory(url_request_job_factory_.get()); | 68 url_request_context_->set_job_factory(url_request_job_factory_.get()); |
| 68 } | 69 } |
| 69 return new GenericURLRequestJob( | 70 return new GenericURLRequestJob( |
| 70 request, network_delegate, deterministic_dispatcher_, | 71 request, network_delegate, deterministic_dispatcher_, |
| 71 base::MakeUnique<HttpURLFetcher>(url_request_context_.get()), | 72 base::MakeUnique<HttpURLFetcher>(url_request_context_.get()), |
| 72 nop_delegate_.get()); | 73 nop_delegate_.get(), headless_browser_context_); |
| 73 } | 74 } |
| 74 | 75 |
| 75 } // namespace headless | 76 } // namespace headless |
| OLD | NEW |