Chromium Code Reviews| 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 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/compiler_specific.h" | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "net/base/net_export.h" | |
| 15 #include "net/base/request_priority.h" | |
| 16 | |
| 17 namespace net { | |
| 18 | |
| 19 class SpdyFrame; | |
| 20 class SpdyStream; | |
| 21 | |
| 22 // An object which provides a SpdyFrame for writing. We pass these | |
| 23 // around instead of SpdyFrames since some frames have to be generated | |
| 24 // "just in time". | |
| 25 class NET_EXPORT_PRIVATE SpdyFrameProducer { | |
| 26 public: | |
| 27 SpdyFrameProducer(); | |
| 28 | |
| 29 // Produces the frame to be written. Will be called at most once. | |
| 30 virtual scoped_ptr<SpdyFrame> ProduceFrame() = 0; | |
| 31 | |
| 32 virtual ~SpdyFrameProducer(); | |
| 33 | |
| 34 private: | |
| 35 DISALLOW_COPY_AND_ASSIGN(SpdyFrameProducer); | |
| 36 }; | |
| 37 | |
| 38 // A simple wrapper around a single SpdyFrame. | |
| 39 class NET_EXPORT_PRIVATE SimpleFrameProducer : public SpdyFrameProducer { | |
| 40 public: | |
| 41 explicit SimpleFrameProducer(scoped_ptr<SpdyFrame> frame); | |
| 42 | |
| 43 virtual ~SimpleFrameProducer(); | |
| 44 | |
| 45 virtual scoped_ptr<SpdyFrame> ProduceFrame() OVERRIDE; | |
| 46 | |
| 47 private: | |
| 48 scoped_ptr<SpdyFrame> frame_; | |
| 49 | |
| 50 DISALLOW_COPY_AND_ASSIGN(SimpleFrameProducer); | |
| 51 }; | |
| 52 | |
| 53 // A queue of SpdyFrameProducers to produce frames to write. Ordered | |
| 54 // by priority, and then FIFO. | |
| 55 class NET_EXPORT_PRIVATE SpdyWriteQueue { | |
|
Ryan Hamilton
2013/03/28 15:51:04
Since this WriteQueue is only used by the Session,
akalin
2013/04/06 01:17:48
Done.
| |
| 56 public: | |
| 57 SpdyWriteQueue(); | |
| 58 ~SpdyWriteQueue(); | |
| 59 | |
| 60 // Enqueues the given frame producer at the given priority | |
| 61 // associated with the given stream, which may be NULL if the frame | |
| 62 // producer is associated with the session. | |
|
Ryan Hamilton
2013/03/28 15:51:04
nit: if the frame is *not* associated with *a stre
akalin
2013/04/06 01:17:48
Done.
| |
| 63 void Enqueue(RequestPriority priority, | |
| 64 scoped_ptr<SpdyFrameProducer> frame_producer, | |
| 65 const scoped_refptr<SpdyStream>& stream); | |
|
Ryan Hamilton
2013/03/28 15:51:04
out of curiosity, why is this a const scoped_refpt
akalin
2013/04/06 01:17:48
it saves a ref inc/dec. habit I picked up from wil
| |
| 66 | |
| 67 // Dequeues the next frame producer and its associated | |
|
Ryan Hamilton
2013/03/28 15:51:04
nit: Can you comment on the ordering guarantees of
akalin
2013/04/06 01:17:48
Done.
| |
| 68 // stream. Returns true and fills in |frame_producer| and |stream| | |
| 69 // if successful -- otherwise, just returns false. | |
| 70 bool Dequeue(scoped_ptr<SpdyFrameProducer>* frame_producer, | |
| 71 scoped_refptr<SpdyStream>* stream); | |
| 72 | |
| 73 // Removes all pending writes for the given stream, which must be | |
| 74 // non-NULL. | |
| 75 void RemovePendingWritesForStream(const scoped_refptr<SpdyStream>& stream); | |
| 76 | |
| 77 // Removes all pending writes. | |
| 78 void Clear(); | |
| 79 | |
| 80 private: | |
| 81 // A struct holding a frame producer and its associated stream. | |
| 82 struct PendingWrite { | |
| 83 // This has to be a raw pointer since we store this in an STL | |
| 84 // container. | |
| 85 SpdyFrameProducer* frame_producer; | |
| 86 scoped_refptr<SpdyStream> stream; | |
| 87 | |
| 88 PendingWrite(); | |
| 89 PendingWrite(SpdyFrameProducer* frame_producer, | |
| 90 const scoped_refptr<SpdyStream>& stream); | |
| 91 ~PendingWrite(); | |
| 92 }; | |
| 93 | |
| 94 // The actual write queue, binned by priority. | |
| 95 std::deque<PendingWrite> queue_[NUM_PRIORITIES]; | |
| 96 | |
| 97 DISALLOW_COPY_AND_ASSIGN(SpdyWriteQueue); | |
| 98 }; | |
| 99 | |
| 100 } // namespace | |
| 101 | |
| 102 #endif // NET_SPDY_SPDY_WRITE_QUEUE_H_ | |
| OLD | NEW |