| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_SPDY_SPDY_WRITE_QUEUE_H_ | 5 #ifndef NET_SPDY_SPDY_WRITE_QUEUE_H_ |
| 6 #define NET_SPDY_SPDY_WRITE_QUEUE_H_ | 6 #define NET_SPDY_SPDY_WRITE_QUEUE_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "net/base/net_export.h" | 13 #include "net/base/net_export.h" |
| 14 #include "net/base/request_priority.h" | 14 #include "net/base/request_priority.h" |
| 15 #include "net/spdy/spdy_protocol.h" | 15 #include "net/spdy/spdy_protocol.h" |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 | 18 |
| 19 class SpdyFrameProducer; | 19 class SpdyBuffer; |
| 20 class SpdyBufferProducer; |
| 20 class SpdyStream; | 21 class SpdyStream; |
| 21 | 22 |
| 22 // A queue of SpdyFrameProducers to produce frames to write. Ordered | 23 // A queue of SpdyBufferProducers to produce frames to write. Ordered |
| 23 // by priority, and then FIFO. | 24 // by priority, and then FIFO. |
| 24 class NET_EXPORT_PRIVATE SpdyWriteQueue { | 25 class NET_EXPORT_PRIVATE SpdyWriteQueue { |
| 25 public: | 26 public: |
| 26 SpdyWriteQueue(); | 27 SpdyWriteQueue(); |
| 27 ~SpdyWriteQueue(); | 28 ~SpdyWriteQueue(); |
| 28 | 29 |
| 29 // Enqueues the given frame producer of the given type at the given | 30 // Enqueues the given frame producer of the given type at the given |
| 30 // priority associated with the given stream, which may be NULL if | 31 // priority associated with the given stream, which may be NULL if |
| 31 // the frame producer is not associated with a stream. If |stream| | 32 // the frame producer is not associated with a stream. If |stream| |
| 32 // is non-NULL, its priority must be equal to |priority|. | 33 // is non-NULL, its priority must be equal to |priority|. |
| 33 void Enqueue(RequestPriority priority, | 34 void Enqueue(RequestPriority priority, |
| 34 SpdyFrameType frame_type, | 35 SpdyFrameType frame_type, |
| 35 scoped_ptr<SpdyFrameProducer> frame_producer, | 36 scoped_ptr<SpdyBufferProducer> frame_producer, |
| 36 const scoped_refptr<SpdyStream>& stream); | 37 const scoped_refptr<SpdyStream>& stream); |
| 37 | 38 |
| 38 // Dequeues the frame producer with the highest priority that was | 39 // Dequeues the frame producer with the highest priority that was |
| 39 // enqueued the earliest and its associated stream. Returns true and | 40 // enqueued the earliest and its associated stream. Returns true and |
| 40 // fills in |frame_type|, |frame_producer|, and |stream| if | 41 // fills in |frame_type|, |frame_producer|, and |stream| if |
| 41 // successful -- otherwise, just returns false. | 42 // successful -- otherwise, just returns false. |
| 42 bool Dequeue(SpdyFrameType* frame_type, | 43 bool Dequeue(SpdyFrameType* frame_type, |
| 43 scoped_ptr<SpdyFrameProducer>* frame_producer, | 44 scoped_ptr<SpdyBufferProducer>* frame_producer, |
| 44 scoped_refptr<SpdyStream>* stream); | 45 scoped_refptr<SpdyStream>* stream); |
| 45 | 46 |
| 46 // Removes all pending writes for the given stream, which must be | 47 // Removes all pending writes for the given stream, which must be |
| 47 // non-NULL. | 48 // non-NULL. |
| 48 void RemovePendingWritesForStream(const scoped_refptr<SpdyStream>& stream); | 49 void RemovePendingWritesForStream(const scoped_refptr<SpdyStream>& stream); |
| 49 | 50 |
| 50 // Removes all pending writes. | 51 // Removes all pending writes. |
| 51 void Clear(); | 52 void Clear(); |
| 52 | 53 |
| 53 private: | 54 private: |
| 54 // A struct holding a frame producer and its associated stream. | 55 // A struct holding a frame producer and its associated stream. |
| 55 struct PendingWrite { | 56 struct PendingWrite { |
| 56 SpdyFrameType frame_type; | 57 SpdyFrameType frame_type; |
| 57 // This has to be a raw pointer since we store this in an STL | 58 // This has to be a raw pointer since we store this in an STL |
| 58 // container. | 59 // container. |
| 59 SpdyFrameProducer* frame_producer; | 60 SpdyBufferProducer* frame_producer; |
| 60 scoped_refptr<SpdyStream> stream; | 61 scoped_refptr<SpdyStream> stream; |
| 61 | 62 |
| 62 PendingWrite(); | 63 PendingWrite(); |
| 63 PendingWrite(SpdyFrameType frame_type, | 64 PendingWrite(SpdyFrameType frame_type, |
| 64 SpdyFrameProducer* frame_producer, | 65 SpdyBufferProducer* frame_producer, |
| 65 const scoped_refptr<SpdyStream>& stream); | 66 const scoped_refptr<SpdyStream>& stream); |
| 66 ~PendingWrite(); | 67 ~PendingWrite(); |
| 67 }; | 68 }; |
| 68 | 69 |
| 69 // The actual write queue, binned by priority. | 70 // The actual write queue, binned by priority. |
| 70 std::deque<PendingWrite> queue_[NUM_PRIORITIES]; | 71 std::deque<PendingWrite> queue_[NUM_PRIORITIES]; |
| 71 | 72 |
| 72 DISALLOW_COPY_AND_ASSIGN(SpdyWriteQueue); | 73 DISALLOW_COPY_AND_ASSIGN(SpdyWriteQueue); |
| 73 }; | 74 }; |
| 74 | 75 |
| 75 } // namespace net | 76 } // namespace net |
| 76 | 77 |
| 77 #endif // NET_SPDY_SPDY_WRITE_QUEUE_H_ | 78 #endif // NET_SPDY_SPDY_WRITE_QUEUE_H_ |
| OLD | NEW |