OLD | NEW |
| (Empty) |
1 // Copyright (c) 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 NET_SPDY_SPDY_WRITE_QUEUE_H_ | |
6 #define NET_SPDY_SPDY_WRITE_QUEUE_H_ | |
7 | |
8 #include <deque> | |
9 #include <memory> | |
10 | |
11 #include "base/macros.h" | |
12 #include "base/memory/weak_ptr.h" | |
13 #include "net/base/net_export.h" | |
14 #include "net/base/request_priority.h" | |
15 #include "net/spdy/spdy_protocol.h" | |
16 | |
17 namespace net { | |
18 | |
19 class SpdyBufferProducer; | |
20 class SpdyStream; | |
21 | |
22 // A queue of SpdyBufferProducers to produce frames to write. Ordered | |
23 // by priority, and then FIFO. | |
24 class NET_EXPORT_PRIVATE SpdyWriteQueue { | |
25 public: | |
26 SpdyWriteQueue(); | |
27 ~SpdyWriteQueue(); | |
28 | |
29 // Returns whether there is anything in the write queue, | |
30 // i.e. whether the next call to Dequeue will return true. | |
31 bool IsEmpty() const; | |
32 | |
33 // Enqueues the given frame producer of the given type at the given | |
34 // priority associated with the given stream, which may be NULL if | |
35 // the frame producer is not associated with a stream. If |stream| | |
36 // is non-NULL, its priority must be equal to |priority|, and it | |
37 // must remain non-NULL until the write is dequeued or removed. | |
38 void Enqueue(RequestPriority priority, | |
39 SpdyFrameType frame_type, | |
40 std::unique_ptr<SpdyBufferProducer> frame_producer, | |
41 const base::WeakPtr<SpdyStream>& stream); | |
42 | |
43 // Dequeues the frame producer with the highest priority that was | |
44 // enqueued the earliest and its associated stream. Returns true and | |
45 // fills in |frame_type|, |frame_producer|, and |stream| if | |
46 // successful -- otherwise, just returns false. | |
47 bool Dequeue(SpdyFrameType* frame_type, | |
48 std::unique_ptr<SpdyBufferProducer>* frame_producer, | |
49 base::WeakPtr<SpdyStream>* stream); | |
50 | |
51 // Removes all pending writes for the given stream, which must be | |
52 // non-NULL. | |
53 void RemovePendingWritesForStream(const base::WeakPtr<SpdyStream>& stream); | |
54 | |
55 // Removes all pending writes for streams after |last_good_stream_id| | |
56 // and streams with no stream id. | |
57 void RemovePendingWritesForStreamsAfter(SpdyStreamId last_good_stream_id); | |
58 | |
59 // Removes all pending writes. | |
60 void Clear(); | |
61 | |
62 // Returns the estimate of dynamically allocated memory in bytes. | |
63 size_t EstimateMemoryUsage() const; | |
64 | |
65 private: | |
66 // A struct holding a frame producer and its associated stream. | |
67 struct PendingWrite { | |
68 SpdyFrameType frame_type; | |
69 std::unique_ptr<SpdyBufferProducer> frame_producer; | |
70 base::WeakPtr<SpdyStream> stream; | |
71 // Whether |stream| was non-NULL when enqueued. | |
72 bool has_stream; | |
73 | |
74 PendingWrite(); | |
75 PendingWrite(SpdyFrameType frame_type, | |
76 std::unique_ptr<SpdyBufferProducer> frame_producer, | |
77 const base::WeakPtr<SpdyStream>& stream); | |
78 ~PendingWrite(); | |
79 PendingWrite(PendingWrite&& other); | |
80 PendingWrite& operator=(PendingWrite&& other); | |
81 | |
82 size_t EstimateMemoryUsage() const; | |
83 | |
84 DISALLOW_COPY_AND_ASSIGN(PendingWrite); | |
85 }; | |
86 | |
87 bool removing_writes_; | |
88 | |
89 // The actual write queue, binned by priority. | |
90 std::deque<PendingWrite> queue_[NUM_PRIORITIES]; | |
91 | |
92 DISALLOW_COPY_AND_ASSIGN(SpdyWriteQueue); | |
93 }; | |
94 | |
95 } // namespace net | |
96 | |
97 #endif // NET_SPDY_SPDY_WRITE_QUEUE_H_ | |
OLD | NEW |