OLD | NEW |
| (Empty) |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_INPUT_QUEUE_H_ | |
6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_INPUT_QUEUE_H_ | |
7 | |
8 #include "base/basictypes.h" | |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "content/common/content_export.h" | |
11 #include "content/common/input/input_event_disposition.h" | |
12 | |
13 namespace content { | |
14 | |
15 class BrowserInputEvent; | |
16 class EventPacketAck; | |
17 class InputQueueClient; | |
18 | |
19 // |InputQueue| handles browser input event batching and response. | |
20 // Event packets are assembled into sequential event packets. A flush entails | |
21 // delivery and dispatch of a single event packet, and continues until the | |
22 // packet is ack'ed and all its events have been dispatched to the renderer. | |
23 class CONTENT_EXPORT InputQueue { | |
24 public: | |
25 // The |client| should outlive the InputQueue. | |
26 InputQueue(InputQueueClient* client); | |
27 virtual ~InputQueue(); | |
28 | |
29 // If a flush is in progress, |event| will be dispatched in the next flush. | |
30 // If no flush is in progress, a flush will be requested if necessary. | |
31 // |event| is assumed to be both non-NULL and valid. | |
32 void QueueEvent(scoped_ptr<BrowserInputEvent> event); | |
33 | |
34 // Initiates the flush of the pending event packet to |client_|, if necessary. | |
35 // This should only be called in response to |client_->SetNeedsFlush()|. | |
36 void BeginFlush(); | |
37 | |
38 // Called by the owner upon EventPacket responses from the sender target. This | |
39 // will dispatch event acks for events with a corresponding |ack_handler|. | |
40 enum AckResult { | |
41 ACK_OK, // |acked_packet| was processed successfully. | |
42 ACK_UNEXPECTED, // |acked_packet| was unexpected; no flush was in-progress. | |
43 ACK_INVALID, // |acked_packet| contains invalid data. | |
44 ACK_SHUTDOWN // |acked_packet| processing triggered queue shutdown. | |
45 }; | |
46 AckResult OnEventPacketAck(int64 packet_id, | |
47 const InputEventDispositions& dispositions); | |
48 | |
49 // Total number of evenst in the queue, both being flushed and pending flush. | |
50 size_t QueuedEventCount() const; | |
51 | |
52 protected: | |
53 friend class InputQueueTest; | |
54 | |
55 // Delivers |in_flush_packet_| to the client. | |
56 void DeliverInFlushPacket(); | |
57 | |
58 // Requests a flush via |client_| if the necessary request has not been made. | |
59 void RequestFlushIfNecessary(); | |
60 | |
61 // True when |in_flush_packet_| is non-empty. | |
62 bool FlushInProgress() const; | |
63 | |
64 private: | |
65 InputQueueClient* client_; | |
66 | |
67 // Used to assign unique, non-zero ID's to each delivered EventPacket. | |
68 int64 next_packet_id_; | |
69 | |
70 // Avoid spamming the client with redundant flush requests. | |
71 bool flush_requested_; | |
72 | |
73 class BrowserEventPacket; | |
74 scoped_ptr<BrowserEventPacket> in_flush_packet_; | |
75 scoped_ptr<BrowserEventPacket> pending_flush_packet_; | |
76 | |
77 DISALLOW_COPY_AND_ASSIGN(InputQueue); | |
78 }; | |
79 | |
80 } // namespace content | |
81 | |
82 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_INPUT_QUEUE_H_ | |
OLD | NEW |