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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « headless/BUILD.gn ('k') | headless/public/util/deterministic_dispatcher.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: headless/public/util/deterministic_dispatcher.h
diff --git a/headless/public/util/deterministic_dispatcher.h b/headless/public/util/deterministic_dispatcher.h
new file mode 100644
index 0000000000000000000000000000000000000000..c2e73b6171084cef0a291821bc98b6b8223aa921
--- /dev/null
+++ b/headless/public/util/deterministic_dispatcher.h
@@ -0,0 +1,62 @@
+// 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_DISPATCHER_H_
+#define HEADLESS_PUBLIC_UTIL_DETERMINISTIC_DISPATCHER_H_
+
+#include <deque>
+#include <map>
+
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/single_thread_task_runner.h"
+#include "base/synchronization/lock.h"
+#include "headless/public/util/url_request_dispatcher.h"
+#include "net/base/net_errors.h"
+
+namespace headless {
+
+class ManagedDispatchURLRequestJob;
+
+// The purpose of this class is to queue up calls to OnHeadersComplete and
+// OnStartError and dispatch them in order of URLRequestJob creation. This
+// helps make renders deterministic at the cost of slower page loads.
+class DeterministicDispatcher : public URLRequestDispatcher {
+ public:
+ explicit DeterministicDispatcher(
+ scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner);
+
+ ~DeterministicDispatcher() override;
+
+ // UrlRequestDispatcher implementation:
+ void JobCreated(ManagedDispatchURLRequestJob* job) override;
+ void JobKilled(ManagedDispatchURLRequestJob* job) override;
+ void JobFailed(ManagedDispatchURLRequestJob* job, net::Error error) override;
+ void DataReady(ManagedDispatchURLRequestJob* job) override;
+ void JobDeleted(ManagedDispatchURLRequestJob* job) override;
+
+ private:
+ void MaybeDispatchJobLocked();
+ void MaybeDispatchJobOnIOThreadTask();
+
+ scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner_;
+
+ // Protects all members below.
+ base::Lock lock_;
+
+ std::deque<ManagedDispatchURLRequestJob*> pending_requests_;
+
+ using StatusMap = std::map<ManagedDispatchURLRequestJob*, net::Error>;
+ StatusMap ready_status_map_;
+
+ // Whether or not a MaybeDispatchJobOnIoThreadTask has been posted on the
+ // |io_thread_task_runner_|
+ bool dispatch_pending_;
+
+ DISALLOW_COPY_AND_ASSIGN(DeterministicDispatcher);
+};
+
+} // namespace headless
+
+#endif // HEADLESS_PUBLIC_UTIL_DETERMINISTIC_DISPATCHER_H_
« 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