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

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

Issue 14311002: [SPDY] Avoid leaking bytes from the session flow control receive window (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « net/spdy/spdy_buffer.h ('k') | net/spdy/spdy_buffer_unittest.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 #include "net/spdy/spdy_buffer.h" 5 #include "net/spdy/spdy_buffer.h"
6 6
7 #include <cstring> 7 #include <cstring>
8 8
9 #include "base/callback.h"
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "net/base/io_buffer.h" 11 #include "net/base/io_buffer.h"
11 #include "net/spdy/spdy_protocol.h" 12 #include "net/spdy/spdy_protocol.h"
12 13
13 namespace net { 14 namespace net {
14 15
15 namespace { 16 namespace {
16 17
17 // Makes a SpdyFrame with |size| bytes of data copied from 18 // Makes a SpdyFrame with |size| bytes of data copied from
18 // |data|. |data| must be non-NULL and |size| must be positive. 19 // |data|. |data| must be non-NULL and |size| must be positive.
(...skipping 12 matching lines...) Expand all
31 SpdyBuffer::SpdyBuffer(scoped_ptr<SpdyFrame> frame) 32 SpdyBuffer::SpdyBuffer(scoped_ptr<SpdyFrame> frame)
32 : frame_(frame.Pass()), 33 : frame_(frame.Pass()),
33 offset_(0) {} 34 offset_(0) {}
34 35
35 // The given data may not be strictly a SPDY frame; we (ab)use 36 // The given data may not be strictly a SPDY frame; we (ab)use
36 // |frame_| just as a container. 37 // |frame_| just as a container.
37 SpdyBuffer::SpdyBuffer(const char* data, size_t size) : 38 SpdyBuffer::SpdyBuffer(const char* data, size_t size) :
38 frame_(MakeSpdyFrame(data, size)), 39 frame_(MakeSpdyFrame(data, size)),
39 offset_(0) {} 40 offset_(0) {}
40 41
41 SpdyBuffer::~SpdyBuffer() {} 42 SpdyBuffer::~SpdyBuffer() {
43 if (GetRemainingSize() > 0)
44 Consume(GetRemainingSize());
45 }
42 46
43 const char* SpdyBuffer::GetRemainingData() const { 47 const char* SpdyBuffer::GetRemainingData() const {
44 return frame_->data() + offset_; 48 return frame_->data() + offset_;
45 } 49 }
46 50
47 size_t SpdyBuffer::GetRemainingSize() const { 51 size_t SpdyBuffer::GetRemainingSize() const {
48 return frame_->size() - offset_; 52 return frame_->size() - offset_;
49 } 53 }
50 54
55 void SpdyBuffer::AddConsumeCallback(const ConsumeCallback& consume_callback) {
56 consume_callbacks_.push_back(consume_callback);
57 }
58
51 void SpdyBuffer::Consume(size_t consume_size) { 59 void SpdyBuffer::Consume(size_t consume_size) {
52 DCHECK_GE(consume_size, 1u); 60 DCHECK_GE(consume_size, 1u);
53 DCHECK_LE(consume_size, GetRemainingSize()); 61 DCHECK_LE(consume_size, GetRemainingSize());
54 offset_ += consume_size; 62 offset_ += consume_size;
63 for (std::vector<ConsumeCallback>::const_iterator it =
64 consume_callbacks_.begin(); it != consume_callbacks_.end(); ++it) {
65 it->Run(consume_size);
Ryan Hamilton 2013/04/16 23:41:32 Is there any chance that executing one of these ca
akalin 2013/04/16 23:53:10 I think for the ConsumeCallback's use case, it's b
Ryan Hamilton 2013/04/17 00:14:32 sgtm
66 }
55 }; 67 };
56 68
57 IOBuffer* SpdyBuffer::GetIOBufferForRemainingData() { 69 IOBuffer* SpdyBuffer::GetIOBufferForRemainingData() {
58 return new WrappedIOBuffer(GetRemainingData()); 70 return new WrappedIOBuffer(GetRemainingData());
59 } 71 }
60 72
61 } // namespace net 73 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_buffer.h ('k') | net/spdy/spdy_buffer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698