[SPDY] Avoid leaking bytes from the session flow control receive window

Add a way to add ConsumeCallbacks to a SpdyBuffer in order to be notified
when Consume() is called. Use that to ensure that flow control receive
windows are updated appropriately regardless of what the SpdyStream's
delegate does.

Make IncreaseRevWindowSize private in both SpdyStream
and SpdySession.

BUG=176592

Review URL: https://codereview.chromium.org/14311002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194655 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/net/spdy/spdy_buffer_unittest.cc b/net/spdy/spdy_buffer_unittest.cc
index fbd7705..bcf25d2 100644
--- a/net/spdy/spdy_buffer_unittest.cc
+++ b/net/spdy/spdy_buffer_unittest.cc
@@ -8,6 +8,7 @@
 #include <string>
 
 #include "base/basictypes.h"
+#include "base/bind.h"
 #include "base/memory/ref_counted.h"
 #include "base/memory/scoped_ptr.h"
 #include "net/base/io_buffer.h"
@@ -53,18 +54,45 @@
   EXPECT_EQ(std::string(kData, kDataSize), BufferToString(buffer));
 }
 
+void IncrementBy(size_t* x, size_t delta) {
+  *x += delta;
+}
+
 // Construct a SpdyBuffer and call Consume() on it, which should
-// update the remaining data pointer and size appropriately.
+// update the remaining data pointer and size appropriately, as well
+// as calling the consume callbacks.
 TEST_F(SpdyBufferTest, Consume) {
   SpdyBuffer buffer(kData, kDataSize);
 
+  size_t x1 = 0;
+  size_t x2 = 0;
+  buffer.AddConsumeCallback(base::Bind(&IncrementBy, &x1));
+  buffer.AddConsumeCallback(base::Bind(&IncrementBy, &x2));
+
   EXPECT_EQ(std::string(kData, kDataSize), BufferToString(buffer));
 
   buffer.Consume(5);
   EXPECT_EQ(std::string(kData + 5, kDataSize - 5), BufferToString(buffer));
+  EXPECT_EQ(5u, x1);
+  EXPECT_EQ(5u, x2);
 
   buffer.Consume(kDataSize - 5);
   EXPECT_EQ(0u, buffer.GetRemainingSize());
+  EXPECT_EQ(kDataSize, x1);
+  EXPECT_EQ(kDataSize, x2);
+}
+
+// Construct a SpdyBuffer and attach a ConsumeCallback to it. The
+// callback should be called when the SpdyBuffer is destroyed.
+TEST_F(SpdyBufferTest, ConsumeOnDestruction) {
+  size_t x = 0;
+
+  {
+    SpdyBuffer buffer(kData, kDataSize);
+    buffer.AddConsumeCallback(base::Bind(&IncrementBy, &x));
+  }
+
+  EXPECT_EQ(kDataSize, x);
 }
 
 // Make sure the IOBuffer returned by GetIOBufferForRemainingData()