Index: headless/public/util/deterministic_http_protocol_handler.cc |
diff --git a/headless/public/util/deterministic_http_protocol_handler.cc b/headless/public/util/deterministic_http_protocol_handler.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ea98a44cd7eb31f480a23d11a2890d3c8dc461f8 |
--- /dev/null |
+++ b/headless/public/util/deterministic_http_protocol_handler.cc |
@@ -0,0 +1,67 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "headless/public/util/deterministic_http_protocol_handler.h" |
+ |
+#include "base/memory/ptr_util.h" |
+#include "headless/public/headless_browser_context.h" |
+#include "headless/public/util/deterministic_dispatcher.h" |
+#include "headless/public/util/generic_url_request_job.h" |
+#include "headless/public/util/http_url_fetcher.h" |
+#include "net/url_request/url_request_context.h" |
+ |
+namespace headless { |
+ |
+class DeterministicHttpProtocolHandler::NopGenericURLRequestJobDelegate |
+ : public GenericURLRequestJob::Delegate { |
+ public: |
+ NopGenericURLRequestJobDelegate() {} |
+ ~NopGenericURLRequestJobDelegate() override {} |
+ |
+ // GenericURLRequestJob::Delegate methods: |
+ bool BlockOrRewriteRequest( |
+ const GURL& url, |
+ const std::string& referrer, |
+ GenericURLRequestJob::RewriteCallback callback) override { |
+ return false; |
+ } |
+ |
+ const GenericURLRequestJob::HttpResponse* MaybeMatchResource( |
+ const GURL& url, |
+ const net::HttpRequestHeaders& request_headers) override { |
+ return nullptr; |
+ } |
+ |
+ void OnResourceLoadComplete(const GURL& final_url, |
+ const std::string& mime_type, |
+ int http_response_code) override {} |
+}; |
Sami
2016/09/22 12:09:40
DISALLOW_COPY_AND_ASSIGN
alex clarke (OOO till 29th)
2016/09/23 13:29:21
Done.
|
+ |
+DeterministicHttpProtocolHandler::DeterministicHttpProtocolHandler( |
+ DeterministicDispatcher* deterministic_dispatcher) |
+ : deterministic_dispatcher_(deterministic_dispatcher), |
+ browser_context_(nullptr), |
+ nop_delagate_(new NopGenericURLRequestJobDelegate()) {} |
+ |
+DeterministicHttpProtocolHandler::~DeterministicHttpProtocolHandler() {} |
+ |
+net::URLRequestJob* DeterministicHttpProtocolHandler::MaybeCreateJob( |
+ net::URLRequest* request, |
+ net::NetworkDelegate* network_delegate) const { |
+ std::unique_ptr<net::URLRequestContext> url_request_context( |
Sami
2016/09/22 12:09:40
This is a pretty big object. Could we construct it
alex clarke (OOO till 29th)
2016/09/23 13:29:21
It's shared at the ProtocolHandler level now.
|
+ new net::URLRequestContext()); |
+ |
+ url_request_context->set_http_transaction_factory( |
Sami
2016/09/22 12:09:40
Should we use CopyFrom instead? Otherwise the cont
alex clarke (OOO till 29th)
2016/09/23 13:29:21
Done.
|
+ browser_context_->GetRequestContext()->http_transaction_factory()); |
+ |
+ url_request_context->set_cookie_store( |
+ browser_context_->GetRequestContext()->cookie_store()); |
+ |
+ return new GenericURLRequestJob( |
+ request, network_delegate, deterministic_dispatcher_, |
+ base::MakeUnique<HttpUrlFetcher>(std::move(url_request_context)), |
+ nop_delagate_.get()); |
+} |
+ |
+} // namespace headless |