| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_CORE_SPDY_PINNABLE_BUFFER_PIECE_H_ | 5 #ifndef NET_SPDY_CORE_SPDY_PINNABLE_BUFFER_PIECE_H_ |
| 6 #define NET_SPDY_CORE_SPDY_PINNABLE_BUFFER_PIECE_H_ | 6 #define NET_SPDY_CORE_SPDY_PINNABLE_BUFFER_PIECE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "net/spdy/platform/api/spdy_export.h" | 12 #include "net/spdy/platform/api/spdy_export.h" |
| 13 #include "net/spdy/platform/api/spdy_string_piece.h" | 13 #include "net/spdy/platform/api/spdy_string_piece.h" |
| 14 | 14 |
| 15 namespace net { | 15 namespace net { |
| 16 | 16 |
| 17 class SpdyPrefixedBufferReader; | 17 class SpdyPrefixedBufferReader; |
| 18 | 18 |
| 19 // Helper class of SpdyPrefixedBufferReader. | 19 // Helper class of SpdyPrefixedBufferReader. |
| 20 // Represents a piece of consumed buffer which may (or may not) own its | 20 // Represents a piece of consumed buffer which may (or may not) own its |
| 21 // underlying storage. Users may "pin" the buffer at a later time to ensure | 21 // underlying storage. Users may "pin" the buffer at a later time to ensure |
| 22 // a SpdyPinnableBufferPiece owns and retains storage of the buffer. | 22 // a SpdyPinnableBufferPiece owns and retains storage of the buffer. |
| 23 struct SPDY_EXPORT_PRIVATE SpdyPinnableBufferPiece { | 23 struct SPDY_EXPORT_PRIVATE SpdyPinnableBufferPiece { |
| 24 public: | 24 public: |
| 25 SpdyPinnableBufferPiece(); | 25 SpdyPinnableBufferPiece(); |
| 26 ~SpdyPinnableBufferPiece(); | 26 ~SpdyPinnableBufferPiece(); |
| 27 | 27 |
| 28 const char * buffer() const { | 28 const char* buffer() const { return buffer_; } |
| 29 return buffer_; | |
| 30 } | |
| 31 | 29 |
| 32 size_t length() const { | 30 size_t length() const { return length_; } |
| 33 return length_; | |
| 34 } | |
| 35 | 31 |
| 36 explicit operator SpdyStringPiece() const { | 32 explicit operator SpdyStringPiece() const { |
| 37 return SpdyStringPiece(buffer_, length_); | 33 return SpdyStringPiece(buffer_, length_); |
| 38 } | 34 } |
| 39 | 35 |
| 40 // Allocates and copies the buffer to internal storage. | 36 // Allocates and copies the buffer to internal storage. |
| 41 void Pin(); | 37 void Pin(); |
| 42 | 38 |
| 43 bool IsPinned() const { return storage_ != nullptr; } | 39 bool IsPinned() const { return storage_ != nullptr; } |
| 44 | 40 |
| 45 // Swaps buffers, including internal storage, with |other|. | 41 // Swaps buffers, including internal storage, with |other|. |
| 46 void Swap(SpdyPinnableBufferPiece* other); | 42 void Swap(SpdyPinnableBufferPiece* other); |
| 47 | 43 |
| 48 private: | 44 private: |
| 49 friend class SpdyPrefixedBufferReader; | 45 friend class SpdyPrefixedBufferReader; |
| 50 | 46 |
| 51 const char * buffer_; | 47 const char* buffer_; |
| 52 size_t length_; | 48 size_t length_; |
| 53 // Null iff |buffer_| isn't pinned. | 49 // Null iff |buffer_| isn't pinned. |
| 54 std::unique_ptr<char[]> storage_; | 50 std::unique_ptr<char[]> storage_; |
| 55 }; | 51 }; |
| 56 | 52 |
| 57 } // namespace net | 53 } // namespace net |
| 58 | 54 |
| 59 #endif // NET_SPDY_CORE_SPDY_PINNABLE_BUFFER_PIECE_H_ | 55 #endif // NET_SPDY_CORE_SPDY_PINNABLE_BUFFER_PIECE_H_ |
| OLD | NEW |