| 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_SPDY_PINNABLE_BUFFER_PIECE_H_ | 5 #ifndef NET_SPDY_SPDY_PINNABLE_BUFFER_PIECE_H_ |
| 6 #define NET_SPDY_SPDY_PINNABLE_BUFFER_PIECE_H_ | 6 #define NET_SPDY_SPDY_PINNABLE_BUFFER_PIECE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 return length_; | 32 return length_; |
| 33 } | 33 } |
| 34 | 34 |
| 35 operator base::StringPiece() const { | 35 operator base::StringPiece() const { |
| 36 return base::StringPiece(buffer_, length_); | 36 return base::StringPiece(buffer_, length_); |
| 37 } | 37 } |
| 38 | 38 |
| 39 // Allocates and copies the buffer to internal storage. | 39 // Allocates and copies the buffer to internal storage. |
| 40 void Pin(); | 40 void Pin(); |
| 41 | 41 |
| 42 bool IsPinned() const { | 42 bool IsPinned() const { return storage_ != nullptr; } |
| 43 return storage_.get() != NULL; | |
| 44 } | |
| 45 | 43 |
| 46 // Swaps buffers, including internal storage, with |other|. | 44 // Swaps buffers, including internal storage, with |other|. |
| 47 void Swap(SpdyPinnableBufferPiece* other); | 45 void Swap(SpdyPinnableBufferPiece* other); |
| 48 | 46 |
| 49 private: | 47 private: |
| 50 friend class SpdyPrefixedBufferReader; | 48 friend class SpdyPrefixedBufferReader; |
| 51 | 49 |
| 52 const char * buffer_; | 50 const char * buffer_; |
| 53 size_t length_; | 51 size_t length_; |
| 54 // Null iff |buffer_| isn't pinned. | 52 // Null iff |buffer_| isn't pinned. |
| 55 scoped_ptr<char[]> storage_; | 53 scoped_ptr<char[]> storage_; |
| 56 }; | 54 }; |
| 57 | 55 |
| 58 } // namespace net | 56 } // namespace net |
| 59 | 57 |
| 60 #endif // NET_SPDY_SPDY_PINNABLE_BUFFER_PIECE_H_ | 58 #endif // NET_SPDY_SPDY_PINNABLE_BUFFER_PIECE_H_ |
| OLD | NEW |