Index: headless/public/util/deterministic_http_protocol_handler.h |
diff --git a/headless/public/util/deterministic_http_protocol_handler.h b/headless/public/util/deterministic_http_protocol_handler.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..94933aa4cb30289f61693ae4cc2e366cca7bcd4d |
--- /dev/null |
+++ b/headless/public/util/deterministic_http_protocol_handler.h |
@@ -0,0 +1,53 @@ |
+// 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. |
+ |
+#ifndef HEADLESS_PUBLIC_UTIL_DETERMINISTIC_HTTP_PROTOCOL_HANDLER_H_ |
+#define HEADLESS_PUBLIC_UTIL_DETERMINISTIC_HTTP_PROTOCOL_HANDLER_H_ |
+ |
+#include <memory> |
+ |
+#include "net/url_request/url_request_job_factory.h" |
+ |
+namespace net { |
+class URLRequestContext; |
+} // namespace |
+ |
+namespace headless { |
+class DeterministicDispatcher; |
+class HeadlessBrowserContext; |
+ |
+// A deterministic protocol handler. Requests make to this protocol handler |
+// will return in order of creation, regardless of what order the network |
+// returns them in. This helps remove one large source of network related |
+// non determinism at the cost of slower page loads. |
+class DeterministicHttpProtocolHandler |
+ : public net::URLRequestJobFactory::ProtocolHandler { |
+ public: |
+ // Note |deterministic_dispatcher| is expected to be shared across a number of |
+ // protocol handlers, e.g. for http & https protocols. |
+ explicit DeterministicHttpProtocolHandler( |
+ DeterministicDispatcher* deterministic_dispatcher); |
+ ~DeterministicHttpProtocolHandler() override; |
+ |
+ net::URLRequestJob* MaybeCreateJob( |
+ net::URLRequest* request, |
+ net::NetworkDelegate* network_delegate) const override; |
+ |
+ void set_browser_context(HeadlessBrowserContext* browser_context) { |
Sami
2016/09/22 12:09:40
I wonder if we could avoid the dependency on the b
alex clarke (OOO till 29th)
2016/09/23 13:29:21
We can get the context from the request itself.
|
+ browser_context_ = browser_context; |
+ } |
+ |
+ private: |
+ class NopGenericURLRequestJobDelegate; |
+ |
+ DeterministicDispatcher* deterministic_dispatcher_; // NOT OWNED. |
+ HeadlessBrowserContext* browser_context_; // NOT OWNED. |
+ std::unique_ptr<NopGenericURLRequestJobDelegate> nop_delagate_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(DeterministicHttpProtocolHandler); |
+}; |
+ |
+} // namespace headless |
+ |
+#endif // HEADLESS_PUBLIC_UTIL_DETERMINISTIC_HTTP_PROTOCOL_HANDLER_H_ |