diff options
author | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-25 07:17:11 +0000 |
---|---|---|
committer | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-25 07:17:11 +0000 |
commit | 699efe606ab0e0995e3613f5fb880babbc66e8fc (patch) | |
tree | 7a06b83d08b940a4c04c96ee994a600399c7a5ed /net/base/upload_data_stream.cc | |
parent | 2d6a4beb5df1d9377a141b12dbb2bf6225cb3d5d (diff) | |
download | chromium_src-699efe606ab0e0995e3613f5fb880babbc66e8fc.zip chromium_src-699efe606ab0e0995e3613f5fb880babbc66e8fc.tar.gz chromium_src-699efe606ab0e0995e3613f5fb880babbc66e8fc.tar.bz2 |
Prototype of chunked transfer encoded POST.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6134003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72471 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/upload_data_stream.cc')
-rw-r--r-- | net/base/upload_data_stream.cc | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/net/base/upload_data_stream.cc b/net/base/upload_data_stream.cc index 0ec4c97..1f77f06 100644 --- a/net/base/upload_data_stream.cc +++ b/net/base/upload_data_stream.cc @@ -12,9 +12,6 @@ namespace net { -UploadDataStream::~UploadDataStream() { -} - UploadDataStream* UploadDataStream::Create(UploadData* data, int* error_code) { scoped_ptr<UploadDataStream> stream(new UploadDataStream(data)); int rv = stream->FillBuf(); @@ -26,13 +23,15 @@ UploadDataStream* UploadDataStream::Create(UploadData* data, int* error_code) { return stream.release(); } -void UploadDataStream::DidConsume(size_t num_bytes) { +void UploadDataStream::MarkConsumedAndFillBuffer(size_t num_bytes) { DCHECK_LE(num_bytes, buf_len_); DCHECK(!eof_); - buf_len_ -= num_bytes; - if (buf_len_) - memmove(buf_->data(), buf_->data() + num_bytes, buf_len_); + if (num_bytes) { + buf_len_ -= num_bytes; + if (buf_len_) + memmove(buf_->data(), buf_->data() + num_bytes, buf_len_); + } FillBuf(); @@ -43,25 +42,28 @@ UploadDataStream::UploadDataStream(UploadData* data) : data_(data), buf_(new IOBuffer(kBufSize)), buf_len_(0), - next_element_(data->elements()->begin()), + next_element_(0), next_element_offset_(0), next_element_remaining_(0), - total_size_(data->GetContentLength()), + total_size_(data->is_chunked() ? 0 : data->GetContentLength()), current_position_(0), eof_(false) { } +UploadDataStream::~UploadDataStream() { +} + int UploadDataStream::FillBuf() { - std::vector<UploadData::Element>::iterator end = - data_->elements()->end(); + std::vector<UploadData::Element>& elements = *data_->elements(); - while (buf_len_ < kBufSize && next_element_ != end) { + while (buf_len_ < kBufSize && next_element_ < elements.size()) { bool advance_to_next_element = false; - UploadData::Element& element = *next_element_; + UploadData::Element& element = elements[next_element_]; size_t size_remaining = kBufSize - buf_len_; - if (element.type() == UploadData::TYPE_BYTES) { + if (element.type() == UploadData::TYPE_BYTES || + element.type() == UploadData::TYPE_CHUNK) { const std::vector<char>& d = element.bytes(); size_t count = d.size() - next_element_offset_; @@ -126,8 +128,12 @@ int UploadDataStream::FillBuf() { } } - if (next_element_ == end && !buf_len_) - eof_ = true; + if (next_element_ == elements.size() && !buf_len_) { + if (!data_->is_chunked() || + (!elements.empty() && elements.back().is_last_chunk())) { + eof_ = true; + } + } return OK; } |