diff options
author | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-18 08:31:58 +0000 |
---|---|---|
committer | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-18 08:31:58 +0000 |
commit | 8a938fed0b68373c2f4b3222b9dc8a6c534e7e7a (patch) | |
tree | 6a11658779d98ea44c2a195d9ba1009e27e46e43 /net/spdy/spdy_buffer.h | |
parent | f9961d8588581ef6aac7b112c59fe8bd762cda44 (diff) | |
download | chromium_src-8a938fed0b68373c2f4b3222b9dc8a6c534e7e7a.zip chromium_src-8a938fed0b68373c2f4b3222b9dc8a6c534e7e7a.tar.gz chromium_src-8a938fed0b68373c2f4b3222b9dc8a6c534e7e7a.tar.bz2 |
[SPDY] Avoid leaking bytes from the session flow control send window
Add a ConsumeSource parameter to SpdyBuffer::ConsumeCallback. Use
it to detect when a DATA frame to be written is dropped before it
is written.
Put all the flow control functions together and clean them up a bit.
BUG=176592
Review URL: https://chromiumcodereview.appspot.com/14188025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194851 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/spdy/spdy_buffer.h')
-rw-r--r-- | net/spdy/spdy_buffer.h | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/net/spdy/spdy_buffer.h b/net/spdy/spdy_buffer.h index 4d04184..69d39ea 100644 --- a/net/spdy/spdy_buffer.h +++ b/net/spdy/spdy_buffer.h @@ -28,9 +28,21 @@ class SpdyFrame; // fact that IOBuffer member functions are not virtual. class NET_EXPORT_PRIVATE SpdyBuffer { public: - // A Callback that gets called whenever Consume() is called with the - // number of bytes consumed. - typedef base::Callback<void(size_t)> ConsumeCallback; + // The source of a call to a ConsumeCallback. + enum ConsumeSource { + // Called via a call to Consume(). + CONSUME, + // Called via the SpdyBuffer being destroyed. + DISCARD + }; + + // A Callback that gets called when bytes are consumed with the + // (non-zero) number of bytes consumed and the source of the + // consume. May be called any number of times with CONSUME as the + // source followed by at most one call with DISCARD as the + // source. The sum of the number of bytes consumed equals the total + // size of the buffer. + typedef base::Callback<void(size_t, ConsumeSource)> ConsumeCallback; // Construct with the data in the given frame. Assumes that data is // owned by |frame| or outlives it. @@ -40,6 +52,8 @@ class NET_EXPORT_PRIVATE SpdyBuffer { // non-NULL and |size| must be non-zero. SpdyBuffer(const char* data, size_t size); + // If there are bytes remaining in the buffer, triggers a call to + // any consume callbacks with a DISCARD source. ~SpdyBuffer(); // Returns the remaining (unconsumed) data. @@ -48,11 +62,10 @@ class NET_EXPORT_PRIVATE SpdyBuffer { // Returns the number of remaining (unconsumed) bytes. size_t GetRemainingSize() const; - // Add a callback which is called whenever Consume() is called. Used - // mainly to update flow control windows. The ConsumeCallback should - // not do anything complicated; ideally it should only update a - // counter. In particular, it must *not* cause the SpdyBuffer itself - // to be destroyed. + // Add a callback to be called when bytes are consumed. The + // ConsumeCallback should not do anything complicated; ideally it + // should only update a counter. In particular, it must *not* cause + // the SpdyBuffer itself to be destroyed. void AddConsumeCallback(const ConsumeCallback& consume_callback); // Consume the given number of bytes, which must be positive but not @@ -66,6 +79,8 @@ class NET_EXPORT_PRIVATE SpdyBuffer { IOBuffer* GetIOBufferForRemainingData(); private: + void ConsumeHelper(size_t consume_size, ConsumeSource consume_source); + const scoped_ptr<SpdyFrame> frame_; std::vector<ConsumeCallback> consume_callbacks_; size_t offset_; |