Index: net/base/upload_data.cc |
diff --git a/net/base/upload_data.cc b/net/base/upload_data.cc |
index 664285dca6b3b7b874a93ba1f1798ec87b91ff28..6e79ac4ac1d682eef5467b83d4ae30c44955e0b9 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) |
return static_cast<uint64>(bytes_.size()); |
else if (type_ == TYPE_BLOB) |
// The blob reference will be resolved later. |
@@ -65,6 +66,20 @@ 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); |
+ |
+ // The last chunk (of length 0 bytes) is of type BYTES to indicate that |
+ // we have no more. This is used by UploadDataStream. |
wtc
2011/01/12 02:39:02
Why don't you just use the 0 chunk size to indicat
Satish
2011/01/13 17:43:27
Done, I now add a "0\r\n\r\n" chunk followed by a
|
+ type_ = (bytes_len ? TYPE_CHUNK : TYPE_BYTES); |
+} |
+ |
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 +112,11 @@ FileStream* UploadData::Element::NewFileStreamForReading() { |
return file.release(); |
} |
-UploadData::UploadData() : identifier_(0) { |
+UploadData::UploadData() : identifier_(0), data_callback_(NULL) { |
} |
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 +124,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 +132,34 @@ 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 (data_callback_) { |
+ CompletionCallback* c = data_callback_; |
+ //data_callback_ = NULL; |
wtc
2011/01/12 02:39:02
This is a sign that CompletionCallback is the wron
Satish
2011/01/13 17:43:27
Changed to an interface/method call
|
+ c->Run(0); |
+ } |
+} |
+ |
+void UploadData::set_data_callback(CompletionCallback* callback) { |
+ DCHECK(!data_callback_); |
+ data_callback_ = callback; |
+} |
+ |
uint64 UploadData::GetContentLength() { |
uint64 len = 0; |
std::vector<Element>::iterator it = elements_.begin(); |