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