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

Unified Diff: content/browser/byte_stream.cc

Issue 22908008: Limit the total memory usage for Stream instances (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/byte_stream.cc
diff --git a/content/browser/byte_stream.cc b/content/browser/byte_stream.cc
index a8b8f29e9e63b326229b8c09aa3818eefd98adbd..dc13f3f2395f08bf26aa76f79dd7a2e0933dcaf6 100644
--- a/content/browser/byte_stream.cc
+++ b/content/browser/byte_stream.cc
@@ -61,6 +61,7 @@ class ByteStreamWriterImpl : public ByteStreamWriter {
virtual void Flush() OVERRIDE;
virtual void Close(int status) OVERRIDE;
virtual void RegisterCallback(const base::Closure& source_callback) OVERRIDE;
+ virtual size_t TotalBufferedBytes() const OVERRIDE;
// PostTask target from |ByteStreamReaderImpl::MaybeUpdateInput|.
static void UpdateWindow(scoped_refptr<LifetimeFlag> lifetime_flag,
@@ -193,6 +194,7 @@ ByteStreamWriterImpl::ByteStreamWriterImpl(
}
ByteStreamWriterImpl::~ByteStreamWriterImpl() {
+ DCHECK(my_task_runner_->RunsTasksOnCurrentThread());
my_lifetime_flag_->is_alive = false;
}
@@ -216,7 +218,7 @@ bool ByteStreamWriterImpl::Write(
if (input_contents_size_ > total_buffer_size_ / kFractionBufferBeforeSending)
PostToPeer(false, 0);
- return (input_contents_size_ + output_size_used_ <= total_buffer_size_);
+ return (TotalBufferedBytes() <= total_buffer_size_);
}
void ByteStreamWriterImpl::Flush() {
@@ -236,6 +238,11 @@ void ByteStreamWriterImpl::RegisterCallback(
space_available_callback_ = source_callback;
}
+size_t ByteStreamWriterImpl::TotalBufferedBytes() const {
+ DCHECK(my_task_runner_->RunsTasksOnCurrentThread());
+ return input_contents_size_ + output_size_used_;
kinuko 2013/08/14 09:32:23 Could this overflow?
tyoshino (SeeGerritForStatus) 2013/08/15 04:15:33 Added overflow check in Write()
+}
+
// static
void ByteStreamWriterImpl::UpdateWindow(
scoped_refptr<LifetimeFlag> lifetime_flag, ByteStreamWriterImpl* target,
@@ -302,6 +309,7 @@ ByteStreamReaderImpl::ByteStreamReaderImpl(
}
ByteStreamReaderImpl::~ByteStreamReaderImpl() {
+ DCHECK(my_task_runner_->RunsTasksOnCurrentThread());
my_lifetime_flag_->is_alive = false;
}

Powered by Google App Engine
This is Rietveld 408576698