Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(617)

Side by Side Diff: net/spdy/spdy_buffer.h

Issue 1852423004: Implement SpdySerializedFrame move semantics. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/spdy/buffered_spdy_framer_unittest.cc ('k') | net/spdy/spdy_buffer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <vector>
10 10
11 #include "base/callback_forward.h" 11 #include "base/callback_forward.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "net/base/net_export.h" 15 #include "net/base/net_export.h"
16 16
17 namespace net { 17 namespace net {
18 18
19 class IOBuffer; 19 class IOBuffer;
20 class SpdyFrame; 20 class SpdySerializedFrame;
21 21
22 // SpdyBuffer is a class to hold data read from or to be written to a 22 // SpdyBuffer is a class to hold data read from or to be written to a
23 // SPDY connection. It is similar to a DrainableIOBuffer but is not 23 // SPDY connection. It is similar to a DrainableIOBuffer but is not
24 // ref-counted and will include a way to get notified when Consume() 24 // ref-counted and will include a way to get notified when Consume()
25 // is called. 25 // is called.
26 // 26 //
27 // NOTE(akalin): This explicitly does not inherit from IOBuffer to 27 // NOTE(akalin): This explicitly does not inherit from IOBuffer to
28 // avoid the needless ref-counting and to avoid working around the 28 // avoid the needless ref-counting and to avoid working around the
29 // fact that IOBuffer member functions are not virtual. 29 // fact that IOBuffer member functions are not virtual.
30 class NET_EXPORT_PRIVATE SpdyBuffer { 30 class NET_EXPORT_PRIVATE SpdyBuffer {
31 public: 31 public:
32 // The source of a call to a ConsumeCallback. 32 // The source of a call to a ConsumeCallback.
33 enum ConsumeSource { 33 enum ConsumeSource {
34 // Called via a call to Consume(). 34 // Called via a call to Consume().
35 CONSUME, 35 CONSUME,
36 // Called via the SpdyBuffer being destroyed. 36 // Called via the SpdyBuffer being destroyed.
37 DISCARD 37 DISCARD
38 }; 38 };
39 39
40 // A Callback that gets called when bytes are consumed with the 40 // A Callback that gets called when bytes are consumed with the
41 // (non-zero) number of bytes consumed and the source of the 41 // (non-zero) number of bytes consumed and the source of the
42 // consume. May be called any number of times with CONSUME as the 42 // consume. May be called any number of times with CONSUME as the
43 // source followed by at most one call with DISCARD as the 43 // source followed by at most one call with DISCARD as the
44 // source. The sum of the number of bytes consumed equals the total 44 // source. The sum of the number of bytes consumed equals the total
45 // size of the buffer. 45 // size of the buffer.
46 typedef base::Callback<void(size_t, ConsumeSource)> ConsumeCallback; 46 typedef base::Callback<void(size_t, ConsumeSource)> ConsumeCallback;
47 47
48 // Construct with the data in the given frame. Assumes that data is 48 // Construct with the data in the given frame. Assumes that data is
49 // owned by |frame| or outlives it. 49 // owned by |frame| or outlives it.
50 explicit SpdyBuffer(scoped_ptr<SpdyFrame> frame); 50 explicit SpdyBuffer(scoped_ptr<SpdySerializedFrame> frame);
51 51
52 // Construct with a copy of the given raw data. |data| must be 52 // Construct with a copy of the given raw data. |data| must be
53 // non-NULL and |size| must be non-zero. 53 // non-NULL and |size| must be non-zero.
54 SpdyBuffer(const char* data, size_t size); 54 SpdyBuffer(const char* data, size_t size);
55 55
56 // If there are bytes remaining in the buffer, triggers a call to 56 // If there are bytes remaining in the buffer, triggers a call to
57 // any consume callbacks with a DISCARD source. 57 // any consume callbacks with a DISCARD source.
58 ~SpdyBuffer(); 58 ~SpdyBuffer();
59 59
60 // Returns the remaining (unconsumed) data. 60 // Returns the remaining (unconsumed) data.
(...skipping 18 matching lines...) Expand all
79 // past the lifetime of this object. 79 // past the lifetime of this object.
80 // 80 //
81 // This is used with Socket::Write(), which takes an IOBuffer* that 81 // This is used with Socket::Write(), which takes an IOBuffer* that
82 // may be written to even after the socket itself is destroyed. (See 82 // may be written to even after the socket itself is destroyed. (See
83 // http://crbug.com/249725 .) 83 // http://crbug.com/249725 .)
84 IOBuffer* GetIOBufferForRemainingData(); 84 IOBuffer* GetIOBufferForRemainingData();
85 85
86 private: 86 private:
87 void ConsumeHelper(size_t consume_size, ConsumeSource consume_source); 87 void ConsumeHelper(size_t consume_size, ConsumeSource consume_source);
88 88
89 // Ref-count the passed-in SpdyFrame to support the semantics of 89 // Ref-count the passed-in SpdySerializedFrame to support the semantics of
90 // |GetIOBufferForRemainingData()|. 90 // |GetIOBufferForRemainingData()|.
91 typedef base::RefCountedData<scoped_ptr<SpdyFrame> > SharedFrame; 91 typedef base::RefCountedData<scoped_ptr<SpdySerializedFrame>> SharedFrame;
92 92
93 class SharedFrameIOBuffer; 93 class SharedFrameIOBuffer;
94 94
95 const scoped_refptr<SharedFrame> shared_frame_; 95 const scoped_refptr<SharedFrame> shared_frame_;
96 std::vector<ConsumeCallback> consume_callbacks_; 96 std::vector<ConsumeCallback> consume_callbacks_;
97 size_t offset_; 97 size_t offset_;
98 98
99 DISALLOW_COPY_AND_ASSIGN(SpdyBuffer); 99 DISALLOW_COPY_AND_ASSIGN(SpdyBuffer);
100 }; 100 };
101 101
102 } // namespace net 102 } // namespace net
103 103
104 #endif // NET_SPDY_SPDY_BUFFER_H_ 104 #endif // NET_SPDY_SPDY_BUFFER_H_
OLDNEW
« no previous file with comments | « net/spdy/buffered_spdy_framer_unittest.cc ('k') | net/spdy/spdy_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698