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

Unified Diff: content/common/input/web_input_event_queue.h

Issue 2170913002: Generalize the main thread event queue into a common event queue. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix nits Created 4 years, 5 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 | « content/common/input/event_with_latency_info.cc ('k') | content/renderer/input/main_thread_event_queue.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/input/web_input_event_queue.h
diff --git a/content/common/input/web_input_event_queue.h b/content/common/input/web_input_event_queue.h
index eab05997a377c91bea57ba07bdb309b4fee21baf..5677c539d7ebd90737ff316b2b3926140bd75967 100644
--- a/content/common/input/web_input_event_queue.h
+++ b/content/common/input/web_input_event_queue.h
@@ -10,42 +10,30 @@
namespace content {
-enum class WebInputEventQueueState { ITEM_PENDING, ITEM_NOT_PENDING };
-
-// WebInputEventQueue is a coalescing queue with the addition of a state
-// variable that represents whether an item is pending to be processed.
-// The desired usage sending with this queue is:
-// if (queue.state() == WebInputEventQueueState::ITEM_PENDING) {
-// queue.Queue(T);
-// } else {
-// send T
-// queue.set_state(WebInputEventQueueState::ITEM_PENDING);
-// }
-//
-// Processing the event response:
-// if (!queue.empty()) {
-// T = queue.Pop();
-// send T now
-// } else {
-// queue.set_state(WebInputEventQueueState::ITEM_NOT_PENDING);
-// }
-//
+// WebInputEventQueue is a coalescing queue. It will examine
+// the current events in the queue and will attempt to coalesce with
+// the last event of the same class type.
template <typename T>
class WebInputEventQueue {
public:
- WebInputEventQueue() : state_(WebInputEventQueueState::ITEM_NOT_PENDING) {}
+ WebInputEventQueue() {}
// Adds an event to the queue. The event may be coalesced with previously
// queued events.
- void Queue(const T& event) {
- if (!queue_.empty()) {
- std::unique_ptr<T>& last_event = queue_.back();
- if (last_event->CanCoalesceWith(event)) {
- last_event->CoalesceWith(event);
+ void Queue(std::unique_ptr<T> event) {
+ for (auto last_event_iter = queue_.rbegin();
+ last_event_iter != queue_.rend(); ++last_event_iter) {
+ if (!(*last_event_iter)->event().isSameEventClass(event->event())) {
+ continue;
+ }
+
+ if ((*last_event_iter)->CanCoalesceWith(*event.get())) {
+ (*last_event_iter)->CoalesceWith(*event.get());
return;
}
+ break;
}
- queue_.emplace_back(std::unique_ptr<T>(new T(event)));
+ queue_.emplace_back(std::move(event));
}
std::unique_ptr<T> Pop() {
@@ -61,14 +49,9 @@ class WebInputEventQueue {
size_t size() const { return queue_.size(); }
- void set_state(WebInputEventQueueState state) { state_ = state; }
-
- WebInputEventQueueState state() const WARN_UNUSED_RESULT { return state_; }
-
private:
typedef std::deque<std::unique_ptr<T>> EventQueue;
EventQueue queue_;
- WebInputEventQueueState state_;
DISALLOW_COPY_AND_ASSIGN(WebInputEventQueue);
};
« no previous file with comments | « content/common/input/event_with_latency_info.cc ('k') | content/renderer/input/main_thread_event_queue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698