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

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

Issue 2352663003: Adds a --deterministic-fetch flag to headless_shell (Closed)
Patch Set: Changes for Sami 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..da0a70d1e4bebce9be1f5c1902ba315ae7fcc78e
--- /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 made 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.
+ 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_delegate_;
+
+ // |url_request_context_| and |url_request_job_factory_| are lazily created on
+ // the IO thread. The URLRequestContext is setup to bypass any 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_
« no previous file with comments | « headless/app/headless_shell_switches.cc ('k') | headless/public/util/deterministic_http_protocol_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698