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

Unified Diff: headless/public/util/deterministic_http_protocol_handler.h

Issue 2352663003: Adds a --deterministic-fetch flag to headless_shell (Closed)
Patch Set: Changed a few comments Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
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..3b3882bb7874cf3439ee97818c09b1149f5564eb
--- /dev/null
+++ b/headless/public/util/deterministic_http_protocol_handler.h
@@ -0,0 +1,59 @@
+// 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 "base/single_thread_task_runner.h"
+#include "net/url_request/url_request_job_factory.h"
+
+namespace net {
+class URLRequestContext;
+class URLRequestJobFactory;
+} // namespace
+
+namespace headless {
+class DeterministicDispatcher;
+class HeadlessBrowserContext;
+
+// A deterministic protocol handler. Requests make to this protocol handler
Sami 2016/09/23 14:27:29 s/make/made/
alex clarke (OOO till 29th) 2016/09/23 16:40:26 Done.
+// 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.
+ DeterministicHttpProtocolHandler(
+ DeterministicDispatcher* deterministic_dispatcher,
+ scoped_refptr<base::SingleThreadTaskRunner> io_task_runner);
+ ~DeterministicHttpProtocolHandler() override;
+
+ net::URLRequestJob* MaybeCreateJob(
+ net::URLRequest* request,
+ net::NetworkDelegate* network_delegate) const override;
+
+ private:
+ class NopGenericURLRequestJobDelegate;
+
+ DeterministicDispatcher* deterministic_dispatcher_; // NOT OWNED.
+ scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
+ std::unique_ptr<NopGenericURLRequestJobDelegate> nop_delagate_;
+
+ // |url_request_context_| and |url_request_job_factory_| are lazily created on
+ // the IO thread. The URLRequestContextis setup to bypassing any
Sami 2016/09/23 14:27:29 s/Contextis/Context is/
alex clarke (OOO till 29th) 2016/09/23 16:40:26 Done.
+ // user-specified protocol handlers including this one. This is necessary to
+ // actually fetch http resources.
+ mutable std::unique_ptr<net::URLRequestContext> url_request_context_;
+ mutable std::unique_ptr<net::URLRequestJobFactory> url_request_job_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(DeterministicHttpProtocolHandler);
+};
+
+} // namespace headless
+
+#endif // HEADLESS_PUBLIC_UTIL_DETERMINISTIC_HTTP_PROTOCOL_HANDLER_H_

Powered by Google App Engine
This is Rietveld 408576698