Index: net/base/upload_data.cc |
diff --git a/net/base/upload_data.cc b/net/base/upload_data.cc |
index 664285dca6b3b7b874a93ba1f1798ec87b91ff28..56f8b9658cb5a696d397001c84a76b05db0b8e10 100644 |
--- a/net/base/upload_data.cc |
+++ b/net/base/upload_data.cc |
@@ -7,6 +7,7 @@ |
#include "base/file_util.h" |
#include "base/logging.h" |
#include "net/base/file_stream.h" |
+#include "base/string_util.h" |
#include "net/base/net_errors.h" |
namespace net { |
@@ -30,7 +31,7 @@ uint64 UploadData::Element::GetContentLength() { |
if (override_content_length_ || content_length_computed_) |
return content_length_; |
- if (type_ == TYPE_BYTES) |
+ if (type_ == TYPE_BYTES || type_ == TYPE_CHUNK) |
vandebo (ex-Chrome)
2011/01/14 05:53:44
GetContentLength doesn't make sense for TYPE_CHUNK
Satish
2011/01/14 18:09:29
This is UploadData::Element and GetContentLength m
|
return static_cast<uint64>(bytes_.size()); |
else if (type_ == TYPE_BLOB) |
// The blob reference will be resolved later. |
@@ -65,6 +66,22 @@ uint64 UploadData::Element::GetContentLength() { |
return content_length_; |
} |
+void UploadData::Element::SetToChunk(const char* bytes, int bytes_len) { |
+ std::string chunk_length = StringPrintf("%X\r\n", bytes_len); |
+ bytes_.clear(); |
+ bytes_.insert(bytes_.end(), chunk_length.c_str(), |
+ chunk_length.c_str() + chunk_length.length()); |
+ bytes_.insert(bytes_.end(), bytes, bytes + bytes_len); |
+ const char* crlf = "\r\n"; |
+ bytes_.insert(bytes_.end(), crlf, crlf + 2); |
+ type_ = TYPE_CHUNK; |
+} |
+ |
+void UploadData::Element::SetToLastChunk() { |
wtc
2011/01/14 03:09:31
Let's name this method SetToEndOfChunksMarker.
In
Satish
2011/01/14 18:09:29
Done.
|
+ bytes_.clear(); |
vandebo (ex-Chrome)
2011/01/14 05:53:44
Doesn't this need to be "0\r\n\r\n"? It might be
Satish
2011/01/14 18:09:29
No, the previous chunk would be "0\r\n\r\n". This
|
+ type_ = TYPE_CHUNK; |
+} |
+ |
FileStream* UploadData::Element::NewFileStreamForReading() { |
// In common usage GetContentLength() will call this first and store the |
// result into |file_| and a subsequent call (from UploadDataStream) will |
@@ -97,10 +114,14 @@ FileStream* UploadData::Element::NewFileStreamForReading() { |
return file.release(); |
} |
-UploadData::UploadData() : identifier_(0) { |
+UploadData::UploadData() |
+ : identifier_(0), |
+ chunk_callback_(NULL), |
+ is_chunked_(false) { |
vandebo (ex-Chrome)
2011/01/14 05:53:44
Instead of an explicit is_chunked_, could you just
Satish
2011/01/14 18:09:29
This flag is also used by UploadDataStream and URL
|
} |
void UploadData::AppendBytes(const char* bytes, int bytes_len) { |
+ DCHECK(!is_chunked_); |
if (bytes_len > 0) { |
elements_.push_back(Element()); |
elements_.back().SetToBytes(bytes, bytes_len); |
@@ -108,6 +129,7 @@ void UploadData::AppendBytes(const char* bytes, int bytes_len) { |
} |
void UploadData::AppendFile(const FilePath& file_path) { |
+ DCHECK(!is_chunked_); |
elements_.push_back(Element()); |
elements_.back().SetToFilePath(file_path); |
} |
@@ -115,16 +137,36 @@ void UploadData::AppendFile(const FilePath& file_path) { |
void UploadData::AppendFileRange(const FilePath& file_path, |
uint64 offset, uint64 length, |
const base::Time& expected_modification_time) { |
+ DCHECK(!is_chunked_); |
elements_.push_back(Element()); |
elements_.back().SetToFilePathRange(file_path, offset, length, |
expected_modification_time); |
} |
void UploadData::AppendBlob(const GURL& blob_url) { |
+ DCHECK(!is_chunked_); |
elements_.push_back(Element()); |
elements_.back().SetToBlobUrl(blob_url); |
} |
+void UploadData::AppendChunk(const char* bytes, int bytes_len) { |
+ DCHECK(is_chunked_); |
+ elements_.push_back(Element()); |
+ elements_.back().SetToChunk(bytes, bytes_len); |
+ if (!bytes_len) { |
+ // End of chunked stream is marked internally with a chunk of length 0. |
wtc
2011/01/14 03:09:31
"a chunk of length 0" is not accurate. You may wa
Satish
2011/01/14 18:09:29
Done.
|
+ elements_.push_back(Element()); |
+ elements_.back().SetToLastChunk(); |
+ } |
+ if (chunk_callback_) |
+ chunk_callback_->OnChunkAvailable(); |
+} |
+ |
+void UploadData::set_chunk_callback(ChunkCallback* callback) { |
+ DCHECK(!chunk_callback_); |
+ chunk_callback_ = callback; |
+} |
+ |
uint64 UploadData::GetContentLength() { |
uint64 len = 0; |
std::vector<Element>::iterator it = elements_.begin(); |