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

Side by Side Diff: headless/public/util/deterministic_dispatcher.h

Issue 2260793002: Headless utility classes for making deterministic protocol handlers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing comments Created 4 years, 4 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
« no previous file with comments | « headless/BUILD.gn ('k') | headless/public/util/deterministic_dispatcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_DISPATCHER_H_
6 #define HEADLESS_PUBLIC_UTIL_DETERMINISTIC_DISPATCHER_H_
7
8 #include <deque>
9 #include <map>
10
11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/single_thread_task_runner.h"
14 #include "base/synchronization/lock.h"
15 #include "headless/public/util/url_request_dispatcher.h"
16 #include "net/base/net_errors.h"
17
18 namespace headless {
19
20 class ManagedDispatchURLRequestJob;
21
22 // The purpose of this class is to queue up calls to OnHeadersComplete and
23 // OnStartError and dispatch them in order of URLRequestJob creation. This
24 // helps make renders deterministic at the cost of slower page loads.
25 class DeterministicDispatcher : public URLRequestDispatcher {
26 public:
27 explicit DeterministicDispatcher(
28 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner);
29
30 ~DeterministicDispatcher() override;
31
32 // UrlRequestDispatcher implementation:
33 void JobCreated(ManagedDispatchURLRequestJob* job) override;
34 void JobKilled(ManagedDispatchURLRequestJob* job) override;
35 void JobFailed(ManagedDispatchURLRequestJob* job, net::Error error) override;
36 void DataReady(ManagedDispatchURLRequestJob* job) override;
37 void JobDeleted(ManagedDispatchURLRequestJob* job) override;
38
39 private:
40 void MaybeDispatchJobLocked();
41 void MaybeDispatchJobOnIOThreadTask();
42
43 scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner_;
44
45 // Protects all members below.
46 base::Lock lock_;
47
48 std::deque<ManagedDispatchURLRequestJob*> pending_requests_;
49
50 using StatusMap = std::map<ManagedDispatchURLRequestJob*, net::Error>;
51 StatusMap ready_status_map_;
52
53 // Whether or not a MaybeDispatchJobOnIoThreadTask has been posted on the
54 // |io_thread_task_runner_|
55 bool dispatch_pending_;
56
57 DISALLOW_COPY_AND_ASSIGN(DeterministicDispatcher);
58 };
59
60 } // namespace headless
61
62 #endif // HEADLESS_PUBLIC_UTIL_DETERMINISTIC_DISPATCHER_H_
OLDNEW
« no previous file with comments | « headless/BUILD.gn ('k') | headless/public/util/deterministic_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698