| 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_BUFFER_H_ | 5 #ifndef NET_SPDY_SPDY_BUFFER_H_ |
| 6 #define NET_SPDY_SPDY_BUFFER_H_ | 6 #define NET_SPDY_SPDY_BUFFER_H_ |
| 7 | 7 |
| 8 #include <cstddef> | 8 #include <cstddef> |
| 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/callback_forward.h" |
| 11 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 12 #include "net/base/net_export.h" | 14 #include "net/base/net_export.h" |
| 13 | 15 |
| 14 namespace net { | 16 namespace net { |
| 15 | 17 |
| 16 class IOBuffer; | 18 class IOBuffer; |
| 17 class SpdyFrame; | 19 class SpdyFrame; |
| 18 | 20 |
| 19 // SpdyBuffer is a class to hold data read from or to be written to a | 21 // SpdyBuffer is a class to hold data read from or to be written to a |
| 20 // SPDY connection. It is similar to a DrainableIOBuffer but is not | 22 // SPDY connection. It is similar to a DrainableIOBuffer but is not |
| 21 // ref-counted and will include a way to get notified when Consume() | 23 // ref-counted and will include a way to get notified when Consume() |
| 22 // is called. | 24 // is called. |
| 23 // | 25 // |
| 24 // NOTE(akalin): This explicitly does not inherit from IOBuffer to | 26 // NOTE(akalin): This explicitly does not inherit from IOBuffer to |
| 25 // avoid the needless ref-counting and to avoid working around the | 27 // avoid the needless ref-counting and to avoid working around the |
| 26 // fact that IOBuffer member functions are not virtual. | 28 // fact that IOBuffer member functions are not virtual. |
| 27 class NET_EXPORT_PRIVATE SpdyBuffer { | 29 class NET_EXPORT_PRIVATE SpdyBuffer { |
| 28 public: | 30 public: |
| 31 // A Callback that gets called whenever Consume() is called with the |
| 32 // number of bytes consumed. |
| 33 typedef base::Callback<void(size_t)> ConsumeCallback; |
| 34 |
| 29 // Construct with the data in the given frame. Assumes that data is | 35 // Construct with the data in the given frame. Assumes that data is |
| 30 // owned by |frame| or outlives it. | 36 // owned by |frame| or outlives it. |
| 31 explicit SpdyBuffer(scoped_ptr<SpdyFrame> frame); | 37 explicit SpdyBuffer(scoped_ptr<SpdyFrame> frame); |
| 32 | 38 |
| 33 // Construct with a copy of the given raw data. |data| must be | 39 // Construct with a copy of the given raw data. |data| must be |
| 34 // non-NULL and |size| must be non-zero. | 40 // non-NULL and |size| must be non-zero. |
| 35 SpdyBuffer(const char* data, size_t size); | 41 SpdyBuffer(const char* data, size_t size); |
| 36 | 42 |
| 37 ~SpdyBuffer(); | 43 ~SpdyBuffer(); |
| 38 | 44 |
| 39 // Returns the remaining (unconsumed) data. | 45 // Returns the remaining (unconsumed) data. |
| 40 const char* GetRemainingData() const; | 46 const char* GetRemainingData() const; |
| 41 | 47 |
| 42 // Returns the number of remaining (unconsumed) bytes. | 48 // Returns the number of remaining (unconsumed) bytes. |
| 43 size_t GetRemainingSize() const; | 49 size_t GetRemainingSize() const; |
| 44 | 50 |
| 51 // Add a callback which is called whenever Consume() is called. Used |
| 52 // mainly to update flow control windows. |
| 53 void AddConsumeCallback(const ConsumeCallback& consume_callback); |
| 54 |
| 45 // Consume the given number of bytes, which must be positive but not | 55 // Consume the given number of bytes, which must be positive but not |
| 46 // greater than GetRemainingSize(). | 56 // greater than GetRemainingSize(). |
| 47 // | |
| 48 // TODO(akalin): Add a way to get notified when Consume() is called. | |
| 49 void Consume(size_t consume_size); | 57 void Consume(size_t consume_size); |
| 50 | 58 |
| 51 // Returns an IOBuffer pointing to the data starting at | 59 // Returns an IOBuffer pointing to the data starting at |
| 52 // GetRemainingData(). Use with care; the returned IOBuffer must not | 60 // GetRemainingData(). Use with care; the returned IOBuffer must not |
| 53 // be used past the lifetime of this object, and it is not updated | 61 // be used past the lifetime of this object, and it is not updated |
| 54 // when Consume() is called. | 62 // when Consume() is called. |
| 55 IOBuffer* GetIOBufferForRemainingData(); | 63 IOBuffer* GetIOBufferForRemainingData(); |
| 56 | 64 |
| 57 private: | 65 private: |
| 58 const scoped_ptr<SpdyFrame> frame_; | 66 const scoped_ptr<SpdyFrame> frame_; |
| 67 std::vector<ConsumeCallback> consume_callbacks_; |
| 59 size_t offset_; | 68 size_t offset_; |
| 60 | 69 |
| 61 DISALLOW_COPY_AND_ASSIGN(SpdyBuffer); | 70 DISALLOW_COPY_AND_ASSIGN(SpdyBuffer); |
| 62 }; | 71 }; |
| 63 | 72 |
| 64 } // namespace net | 73 } // namespace net |
| 65 | 74 |
| 66 #endif // NET_SPDY_SPDY_BUFFER_H_ | 75 #endif // NET_SPDY_SPDY_BUFFER_H_ |
| OLD | NEW |