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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef HEADLESS_PUBLIC_UTIL_DETERMINISTIC_HTTP_PROTOCOL_HANDLER_H_
6 #define HEADLESS_PUBLIC_UTIL_DETERMINISTIC_HTTP_PROTOCOL_HANDLER_H_
7
8 #include <memory>
9
10 #include "base/single_thread_task_runner.h"
11 #include "net/url_request/url_request_job_factory.h"
12
13 namespace net {
14 class URLRequestContext;
15 class URLRequestJobFactory;
16 } // namespace
17
18 namespace headless {
19 class DeterministicDispatcher;
20 class HeadlessBrowserContext;
21
22 // A deterministic protocol handler. Requests made to this protocol handler
23 // will return in order of creation, regardless of what order the network
24 // returns them in. This helps remove one large source of network related
25 // non determinism at the cost of slower page loads.
26 class DeterministicHttpProtocolHandler
27 : public net::URLRequestJobFactory::ProtocolHandler {
28 public:
29 // Note |deterministic_dispatcher| is expected to be shared across a number of
30 // protocol handlers, e.g. for http & https protocols.
31 DeterministicHttpProtocolHandler(
32 DeterministicDispatcher* deterministic_dispatcher,
33 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner);
34 ~DeterministicHttpProtocolHandler() override;
35
36 net::URLRequestJob* MaybeCreateJob(
37 net::URLRequest* request,
38 net::NetworkDelegate* network_delegate) const override;
39
40 private:
41 class NopGenericURLRequestJobDelegate;
42
43 DeterministicDispatcher* deterministic_dispatcher_; // NOT OWNED.
44 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
45 std::unique_ptr<NopGenericURLRequestJobDelegate> nop_delegate_;
46
47 // |url_request_context_| and |url_request_job_factory_| are lazily created on
48 // the IO thread. The URLRequestContext is setup to bypass any user-specified
49 // protocol handlers including this one. This is necessary to actually fetch
50 // http resources.
51 mutable std::unique_ptr<net::URLRequestContext> url_request_context_;
52 mutable std::unique_ptr<net::URLRequestJobFactory> url_request_job_factory_;
53
54 DISALLOW_COPY_AND_ASSIGN(DeterministicHttpProtocolHandler);
55 };
56
57 } // namespace headless
58
59 #endif // HEADLESS_PUBLIC_UTIL_DETERMINISTIC_HTTP_PROTOCOL_HANDLER_H_
OLDNEW
« 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