Index: headless/public/util/deterministic_dispatcher.h |
diff --git a/headless/public/util/deterministic_dispatcher.h b/headless/public/util/deterministic_dispatcher.h |
index 0fea383b9cc42e747b8daa65ad1ca3bf0193c649..56c7c7e6390f3204a05377d93592fca673ca0c9e 100644 |
--- a/headless/public/util/deterministic_dispatcher.h |
+++ b/headless/public/util/deterministic_dispatcher.h |
@@ -20,8 +20,8 @@ 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 |
+// The purpose of this class is to queue up navigations and calls to |
+// OnHeadersComplete / OnStartError and dispatch them in order of creation. This |
// helps make renders deterministic at the cost of slower page loads. |
class DeterministicDispatcher : public URLRequestDispatcher { |
public: |
@@ -36,17 +36,34 @@ class DeterministicDispatcher : public URLRequestDispatcher { |
void JobFailed(ManagedDispatchURLRequestJob* job, net::Error error) override; |
void DataReady(ManagedDispatchURLRequestJob* job) override; |
void JobDeleted(ManagedDispatchURLRequestJob* job) override; |
+ void NavigationRequested( |
+ std::unique_ptr<NavigationRequest> navigation_request) override; |
private: |
+ void MaybeDispatchNavigationJobLocked(); |
void MaybeDispatchJobLocked(); |
void MaybeDispatchJobOnIOThreadTask(); |
+ void NavigationDoneTask(); |
scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner_; |
// Protects all members below. |
base::Lock lock_; |
- std::deque<ManagedDispatchURLRequestJob*> pending_requests_; |
+ // TODO(alexclarke): Use std::variant when c++17 is allowed in chromium. |
+ struct Request { |
+ Request(); |
+ explicit Request(ManagedDispatchURLRequestJob* url_request); |
+ explicit Request(std::unique_ptr<NavigationRequest> navigation_request); |
+ ~Request(); |
+ |
+ Request& operator=(Request&& other); |
+ |
+ ManagedDispatchURLRequestJob* url_request; // NOT OWNED |
+ std::unique_ptr<NavigationRequest> navigation_request; |
+ }; |
+ |
+ std::deque<Request> pending_requests_; |
using StatusMap = std::map<ManagedDispatchURLRequestJob*, net::Error>; |
StatusMap ready_status_map_; |
@@ -54,6 +71,7 @@ class DeterministicDispatcher : public URLRequestDispatcher { |
// Whether or not a MaybeDispatchJobOnIoThreadTask has been posted on the |
// |io_thread_task_runner_| |
bool dispatch_pending_; |
+ bool navigation_in_progress_; |
base::WeakPtrFactory<DeterministicDispatcher> weak_ptr_factory_; |