Chromium Code Reviews| Index: content/renderer/input/main_thread_event_queue.h |
| diff --git a/content/renderer/input/main_thread_event_queue.h b/content/renderer/input/main_thread_event_queue.h |
| index 1417771c141d33893bfbcd89b39305136263fb9b..6f02c21eb612122aeb0f12a078aad97f1577d38e 100644 |
| --- a/content/renderer/input/main_thread_event_queue.h |
| +++ b/content/renderer/input/main_thread_event_queue.h |
| @@ -42,13 +42,14 @@ class EventWithDispatchType : public ScopedWebInputEventWithLatencyInfo { |
| class CONTENT_EXPORT MainThreadEventQueueClient { |
| public: |
| - // Send an |event| that was previously queued (possibly |
| + // Handle an |event| that was previously queued (possibly |
| // coalesced with another event) to the |routing_id|'s |
| // channel. Implementors must implement this callback. |
| - virtual void SendEventToMainThread(int routing_id, |
| - const blink::WebInputEvent* event, |
| - const ui::LatencyInfo& latency, |
| - InputEventDispatchType dispatch_type) = 0; |
| + virtual void HandleEventOnMainThread( |
| + int routing_id, |
| + const blink::WebInputEvent* event, |
| + const ui::LatencyInfo& latency, |
| + InputEventDispatchType dispatch_type) = 0; |
| virtual void SendInputEventAck(int routing_id, |
| blink::WebInputEvent::Type type, |
| @@ -56,15 +57,10 @@ class CONTENT_EXPORT MainThreadEventQueueClient { |
| uint32_t touch_event_id) = 0; |
| }; |
| -// MainThreadEventQueue implements a series of queues (one touch |
| -// and one mouse wheel) for events that need to be queued between |
| -// the compositor and main threads. When an event is sent |
| -// from the compositor to main it can either be sent directly if no |
| -// outstanding events of that type are in flight; or it needs to |
| -// wait in a queue until the main thread has finished processing |
| -// the in-flight event. This class tracks the state and queues |
| -// for the event types. Methods on this class should only be called |
| -// from the compositor thread. |
| +// MainThreadEventQueue implements a queue for events that need to be |
| +// queued between the compositor and main threads. This queue is managed |
| +// by a lock primarily where events are enqued by the compositor thread |
|
tdresser
2016/08/04 18:02:22
enqued -> enqueued
tdresser
2016/08/04 18:02:22
Is the "primarily" required here? When is this not
dtapuska
2016/08/08 15:34:03
Done.
dtapuska
2016/08/08 15:34:03
Done.
|
| +// and dequed by the main thread. |
|
tdresser
2016/08/04 18:02:22
dequed -> dequeued.
dtapuska
2016/08/08 15:34:03
Done.
|
| // |
| // Below some example flows are how the code behaves. |
| // Legend: B=Browser, C=Compositor, M=Main Thread, NB=Non-blocking |
| @@ -73,29 +69,36 @@ class CONTENT_EXPORT MainThreadEventQueueClient { |
| // Normal blocking event sent to main thread. |
| // B C M |
| // ---(BL)--> |
| +// (queue) |
| // ---(PT)--> |
| +// (deque) |
| // <-------(ACK)------ |
| // |
| // Non-blocking event sent to main thread. |
| // B C M |
| // ---(NB)--> |
| +// (queue) |
| // ---(PT)--> |
| -// <--(PT)--- |
| +// (deque) |
| // |
| // Non-blocking followed by blocking event sent to main thread. |
| // B C M |
| // ---(NB)--> |
| +// (queue) |
| // ---(PT)--> |
| // ---(BL)--> |
| -// <--(PT)--- // Notify from NB event. |
| -// ---(PT)--> // Release blocking event. |
| -// <--(PT)--- // Notify from BL event. |
| +// (queue) |
| +// (deque) |
| +// (deque) |
| // <-------(ACK)------ |
|
tdresser
2016/08/04 18:02:22
Thanks, this looks great.
dtapuska
2016/08/08 15:34:03
Acknowledged.
|
| // |
| -class CONTENT_EXPORT MainThreadEventQueue { |
| +class CONTENT_EXPORT MainThreadEventQueue |
| + : public base::RefCountedThreadSafe<MainThreadEventQueue> { |
| public: |
| - MainThreadEventQueue(int routing_id, MainThreadEventQueueClient* client); |
| - ~MainThreadEventQueue(); |
| + MainThreadEventQueue( |
| + int routing_id, |
| + MainThreadEventQueueClient* client, |
| + const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner); |
| // Called once the compositor has handled |event| and indicated that it is |
| // a non-blocking event to be queued to the main thread. |
| @@ -112,6 +115,15 @@ class CONTENT_EXPORT MainThreadEventQueue { |
| void set_is_flinging(bool is_flinging) { is_flinging_ = is_flinging; } |
| private: |
| + friend class base::RefCountedThreadSafe<MainThreadEventQueue>; |
| + ~MainThreadEventQueue(); |
| + void QueueEvent(std::unique_ptr<EventWithDispatchType>&& event); |
| + void SendEventNotificationToMainThread(); |
| + void PopEventOnMainThread(); |
| + void SendEventToMainThread(const blink::WebInputEvent* event, |
| + const ui::LatencyInfo& latency, |
| + InputEventDispatchType original_dispatch_type); |
| + |
| friend class MainThreadEventQueueTest; |
| int routing_id_; |
| MainThreadEventQueueClient* client_; |
| @@ -120,6 +132,9 @@ class CONTENT_EXPORT MainThreadEventQueue { |
| bool is_flinging_; |
| bool sent_notification_to_main_; |
| + base::Lock event_queue_lock_; |
| + scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueue); |
| }; |