ozone: drm: Crash immediately if no usable GPU is found
[chromium-blink-merge.git] / net / spdy / spdy_pinnable_buffer_piece.h
blob42bae12a50bab67cd4ddf7f1c39d99a7eff56e2a
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
3 // found in the LICENSE file.
5 #ifndef NET_SPDY_SPDY_PINNABLE_BUFFER_PIECE_H_
6 #define NET_SPDY_SPDY_PINNABLE_BUFFER_PIECE_H_
8 #include <memory>
10 #include "base/memory/scoped_ptr.h"
11 #include "base/strings/string_piece.h"
12 #include "net/base/net_export.h"
14 namespace net {
16 class SpdyPrefixedBufferReader;
18 // Helper class of SpdyPrefixedBufferReader.
19 // Represents a piece of consumed buffer which may (or may not) own its
20 // underlying storage. Users may "pin" the buffer at a later time to ensure
21 // a SpdyPinnableBufferPiece owns and retains storage of the buffer.
22 struct NET_EXPORT_PRIVATE SpdyPinnableBufferPiece {
23 public:
24 SpdyPinnableBufferPiece();
25 ~SpdyPinnableBufferPiece();
27 const char * buffer() const {
28 return buffer_;
31 size_t length() const {
32 return length_;
35 operator base::StringPiece() const {
36 return base::StringPiece(buffer_, length_);
39 // Allocates and copies the buffer to internal storage.
40 void Pin();
42 bool IsPinned() const { return storage_ != nullptr; }
44 // Swaps buffers, including internal storage, with |other|.
45 void Swap(SpdyPinnableBufferPiece* other);
47 private:
48 friend class SpdyPrefixedBufferReader;
50 const char * buffer_;
51 size_t length_;
52 // Null iff |buffer_| isn't pinned.
53 scoped_ptr<char[]> storage_;
56 } // namespace net
58 #endif // NET_SPDY_SPDY_PINNABLE_BUFFER_PIECE_H_