Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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_FILTER_BLOCK_BUFFER_H | |
| 6 #define NET_FILTER_BLOCK_BUFFER_H | |
| 7 | |
| 8 #include "base/memory/ref_counted.h" | |
| 9 #include "net/base/io_buffer.h" | |
| 10 | |
| 11 namespace net { | |
| 12 | |
| 13 // A refillable input buffer, wrapping an IOBuffer. | |
| 14 // The WasRefilled() and WasDrained() methods are responsible for maintaining | |
| 15 // this class's state machine. A client class should call WasDrained() when | |
| 16 // bytes are drained from the buffer, and WasRefilled() when new bytes are | |
| 17 // placed in the underlying IOBuffer. | |
| 18 class BlockBuffer { | |
|
mmenke
2016/04/29 19:10:54
Can we just use DrainableIOBuffer instead?
xunjieli
2016/07/20 21:00:47
Done.
| |
| 19 public: | |
| 20 BlockBuffer(); | |
| 21 ~BlockBuffer(); | |
| 22 | |
| 23 bool HasMoreBytes() const; | |
|
Randy Smith (Not in Mondays)
2016/04/26 21:54:01
Personal preference, therefore suggestion: I find
xunjieli
2016/07/20 21:00:47
Acknowledged. I got rid of this class per Matt's s
| |
| 24 // Marks that the buffer has been refilled |filled_bytes| bytes. It is illegal | |
|
Randy Smith (Not in Mondays)
2016/04/26 21:54:01
nit, suggestion: I think this would be clearer wit
xunjieli
2016/07/20 21:00:47
Acknowledged.
| |
| 25 // to refill the buffer when there are undrained bytes. | |
| 26 void WasRefilled(size_t filled_bytes); | |
| 27 // Marks that the buffer has been drained |drained_bytes| bytes. It is illegal | |
| 28 // to drain more bytes than that are availbale. | |
| 29 void WasDrained(size_t drained_bytes); | |
| 30 | |
| 31 // Returns the size of the IOBuffer. | |
| 32 size_t size() const; | |
| 33 // Returns the underlying IOBuffer. | |
| 34 IOBuffer* buffer() { return buffer_.get(); } | |
| 35 // Returns the pointer to the next byte that may be read or drained. | |
|
Randy Smith (Not in Mondays)
2016/04/26 21:54:01
nit, suggestion: I'd leave out the "or drained"; i
xunjieli
2016/07/20 21:00:47
Acknowledged.
| |
| 36 char* bytes() const { return bytes_; } | |
| 37 // Returns the number of bytes that are remaining. | |
|
Randy Smith (Not in Mondays)
2016/04/26 21:54:01
nit: I'd use the same language as above in the com
xunjieli
2016/07/20 21:00:47
Acknowledged.
| |
| 38 size_t bytes_left() const { return bytes_left_; } | |
| 39 | |
| 40 private: | |
| 41 scoped_refptr<IOBuffer> buffer_; | |
| 42 // Points to the next byte that may be read or drained. | |
| 43 char* bytes_; | |
| 44 size_t bytes_left_; | |
| 45 }; | |
|
Randy Smith (Not in Mondays)
2016/04/26 21:54:01
Should there be a DISALLOW_COPY_AND_ASSIGN?
xunjieli
2016/07/20 21:00:47
Acknowledged.
| |
| 46 | |
| 47 } // namespace net | |
| 48 | |
| 49 #endif // NET_FILTER_BLOCK_BUFFER_H | |
| OLD | NEW |