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 fe58023f5777bb8923b5138e8354f21a29ba6b8d..344677fa47caaf9211f8e2e39a5d6be1917f490c 100644 |
| --- a/content/renderer/input/main_thread_event_queue.h |
| +++ b/content/renderer/input/main_thread_event_queue.h |
| @@ -6,6 +6,7 @@ |
| #define CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_ |
| #include <deque> |
| +#include "base/memory/ref_counted.h" |
| #include "content/common/content_export.h" |
| #include "content/common/input/event_with_latency_info.h" |
| #include "content/common/input/input_event_ack_state.h" |
| @@ -17,51 +18,34 @@ |
| namespace content { |
| -template <typename BaseClass, typename BaseType> |
| -class EventWithDispatchType : public BaseClass { |
| +class EventWithDispatchType : public ScopedWebInputEventWithLatencyInfo { |
| public: |
| - EventWithDispatchType(const BaseType& e, |
| - const ui::LatencyInfo& l, |
| - InputEventDispatchType t) |
| - : BaseClass(e, l), type(t) {} |
| - |
| - InputEventDispatchType type; |
| - std::deque<uint32_t> eventsToAck; |
| - |
| + EventWithDispatchType(const blink::WebInputEvent& event, |
| + const ui::LatencyInfo& latency, |
| + InputEventDispatchType dispatch_type); |
| + ~EventWithDispatchType(); |
| bool CanCoalesceWith(const EventWithDispatchType& other) const |
| - WARN_UNUSED_RESULT { |
| - return other.type == type && BaseClass::CanCoalesceWith(other); |
| - } |
| - |
| - void CoalesceWith(const EventWithDispatchType& other) { |
| - // If we are blocking and are coalescing touch, make sure to keep |
| - // the touch ids that need to be acked. |
| - if (type == DISPATCH_TYPE_BLOCKING_NOTIFY_MAIN) { |
| - // We should only have blocking touch events that need coalescing. |
| - DCHECK(blink::WebInputEvent::isTouchEventType(other.event.type)); |
| - eventsToAck.push_back( |
| - WebInputEventTraits::GetUniqueTouchEventId(other.event)); |
| - } |
| - BaseClass::CoalesceWith(other); |
| - } |
| -}; |
| + WARN_UNUSED_RESULT; |
| + void CoalesceWith(const EventWithDispatchType& other); |
| -using PendingMouseWheelEvent = |
| - EventWithDispatchType<MouseWheelEventWithLatencyInfo, |
| - blink::WebMouseWheelEvent>; |
| + const std::deque<uint32_t>& eventsToAck() const { return eventsToAck_; } |
| + InputEventDispatchType dispatchType() const { return dispatch_type_; } |
| -using PendingTouchEvent = |
| - EventWithDispatchType<TouchEventWithLatencyInfo, blink::WebTouchEvent>; |
| + private: |
| + InputEventDispatchType dispatch_type_; |
| + std::deque<uint32_t> eventsToAck_; |
|
tdresser
2016/07/20 20:52:27
Make it clear this is touch only.
dtapuska
2016/07/27 05:29:00
Acknowledged.
|
| +}; |
| 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, |
| @@ -105,10 +89,13 @@ class CONTENT_EXPORT MainThreadEventQueueClient { |
| // <--(PT)--- // Notify from BL event. |
| // <-------(ACK)------ |
| // |
| -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. |
| @@ -125,17 +112,23 @@ 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_; |
| - WebInputEventQueue<PendingMouseWheelEvent> wheel_events_; |
| - WebInputEventQueue<PendingTouchEvent> touch_events_; |
| + WebInputEventQueue<EventWithDispatchType> events_; |
| + std::unique_ptr<EventWithDispatchType> in_flight_event_; |
| bool is_flinging_; |
|
tdresser
2016/07/20 20:52:27
Do we still need is_flinging?
dtapuska
2016/07/27 05:29:00
yes sorry that was missing code.
|
| - |
| - // TODO(dtapuska): These can be removed when the queues are dequeued |
| - // on the main thread. See crbug.com/624021 |
| - std::unique_ptr<PendingMouseWheelEvent> in_flight_wheel_event_; |
| - std::unique_ptr<PendingTouchEvent> in_flight_touch_event_; |
| + base::Lock event_queue_mutex_; |
| + scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
| DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueue); |
| }; |