OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_IO_BUFFER_H_ | 5 #ifndef NET_SPDY_SPDY_IO_BUFFER_H_ |
6 #define NET_SPDY_SPDY_IO_BUFFER_H_ | 6 #define NET_SPDY_SPDY_IO_BUFFER_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
10 #include "net/base/net_export.h" | 10 #include "net/base/net_export.h" |
11 #include "net/base/request_priority.h" | |
12 | 11 |
13 namespace net { | 12 namespace net { |
14 | 13 |
15 class SpdyStream; | 14 class SpdyStream; |
16 | 15 |
17 // A class for managing SPDY IO buffers. These buffers need to be prioritized | 16 // A class for managing SPDY write buffers. These write buffers need |
18 // so that the SpdySession sends them in the right order. Further, they need | 17 // to track the SpdyStream which they are associated with so that the |
19 // to track the SpdyStream which they are associated with so that incremental | 18 // session can activate the stream lazily and also notify the stream |
20 // completion of the IO can notify the appropriate stream of completion. | 19 // on completion of the write. |
21 class NET_EXPORT_PRIVATE SpdyIOBuffer { | 20 class NET_EXPORT_PRIVATE SpdyIOBuffer { |
22 public: | 21 public: |
| 22 SpdyIOBuffer(); |
| 23 |
23 // Constructor | 24 // Constructor |
24 // |buffer| is the actual data buffer. | 25 // |buffer| is the actual data buffer. |
25 // |size| is the size of the data buffer. | 26 // |size| is the size of the data buffer. |
26 // |priority| is the priority of this buffer. | 27 // |stream| is a pointer to the stream which is managing this buffer |
27 // |stream| is a pointer to the stream which is managing this buffer. | 28 // (can be NULL if the write is for the session itself). |
28 SpdyIOBuffer(IOBuffer* buffer, int size, RequestPriority priority, | 29 SpdyIOBuffer(IOBuffer* buffer, int size, SpdyStream* stream); |
29 SpdyStream* stream); | 30 |
30 // Declare this instead of using the default so that we avoid needing to | 31 // Declare this instead of using the default so that we avoid needing to |
31 // include spdy_stream.h. | 32 // include spdy_stream.h. |
32 SpdyIOBuffer(const SpdyIOBuffer& rhs); | 33 SpdyIOBuffer(const SpdyIOBuffer& rhs); |
33 SpdyIOBuffer(); | 34 |
34 ~SpdyIOBuffer(); | 35 ~SpdyIOBuffer(); |
| 36 |
35 // Declare this instead of using the default so that we avoid needing to | 37 // Declare this instead of using the default so that we avoid needing to |
36 // include spdy_stream.h. | 38 // include spdy_stream.h. |
37 SpdyIOBuffer& operator=(const SpdyIOBuffer& rhs); | 39 SpdyIOBuffer& operator=(const SpdyIOBuffer& rhs); |
38 | 40 |
| 41 void Swap(SpdyIOBuffer* other); |
| 42 |
| 43 void Release(); |
| 44 |
39 // Accessors. | 45 // Accessors. |
40 DrainableIOBuffer* buffer() const { return buffer_; } | 46 DrainableIOBuffer* buffer() const { return buffer_; } |
41 size_t size() const { return buffer_->size(); } | |
42 void release(); | |
43 RequestPriority priority() const { return priority_; } | |
44 const scoped_refptr<SpdyStream>& stream() const { return stream_; } | 47 const scoped_refptr<SpdyStream>& stream() const { return stream_; } |
45 | 48 |
46 // Comparison operator to support sorting. | |
47 bool operator<(const SpdyIOBuffer& other) const { | |
48 if (priority_ != other.priority_) | |
49 return priority_ < other.priority_; | |
50 return position_ > other.position_; | |
51 } | |
52 | |
53 private: | 49 private: |
54 scoped_refptr<DrainableIOBuffer> buffer_; | 50 scoped_refptr<DrainableIOBuffer> buffer_; |
55 RequestPriority priority_; | |
56 uint64 position_; | |
57 scoped_refptr<SpdyStream> stream_; | 51 scoped_refptr<SpdyStream> stream_; |
58 static uint64 order_; // Maintains a FIFO order for equal priorities. | |
59 }; | 52 }; |
60 | 53 |
61 } // namespace net | 54 } // namespace net |
62 | 55 |
63 #endif // NET_SPDY_SPDY_IO_BUFFER_H_ | 56 #endif // NET_SPDY_SPDY_IO_BUFFER_H_ |
OLD | NEW |