Index: net/base/upload_data_stream.cc |
=================================================================== |
--- net/base/upload_data_stream.cc (revision 42417) |
+++ net/base/upload_data_stream.cc (working copy) |
@@ -4,12 +4,25 @@ |
#include "net/base/upload_data_stream.h" |
+#include "base/file_util.h" |
#include "base/logging.h" |
#include "net/base/io_buffer.h" |
#include "net/base/net_errors.h" |
namespace net { |
+UploadDataStream* UploadDataStream::Create(const UploadData* data, |
+ int* error_code) { |
+ scoped_ptr<UploadDataStream> stream(new UploadDataStream(data)); |
+ int rv = stream->FillBuf(); |
+ if (error_code) |
+ *error_code = rv; |
+ if (rv != OK) |
+ return NULL; |
+ |
+ return stream.release(); |
+} |
+ |
UploadDataStream::UploadDataStream(const UploadData* data) |
: data_(data), |
buf_(new IOBuffer(kBufSize)), |
@@ -20,7 +33,6 @@ |
total_size_(data->GetContentLength()), |
current_position_(0), |
eof_(false) { |
- FillBuf(); |
} |
UploadDataStream::~UploadDataStream() { |
@@ -39,7 +51,7 @@ |
current_position_ += num_bytes; |
} |
-void UploadDataStream::FillBuf() { |
+int UploadDataStream::FillBuf() { |
std::vector<UploadData::Element>::const_iterator end = |
data_->elements().end(); |
@@ -66,6 +78,18 @@ |
} else { |
DCHECK(element.type() == UploadData::TYPE_FILE); |
+ // If the underlying file has been changed, treat it as error. |
+ // Note that the expected modification time from WebKit is based on |
+ // time_t precision. So we have to convert both to time_t to compare. |
+ if (!element.expected_file_modification_time().is_null()) { |
+ file_util::FileInfo info; |
+ if (file_util::GetFileInfo(element.file_path(), &info) && |
+ element.expected_file_modification_time().ToTimeT() != |
+ info.last_modified.ToTimeT()) { |
+ return ERR_UPLOAD_FILE_CHANGED; |
+ } |
+ } |
+ |
if (!next_element_stream_.IsOpen()) { |
int flags = base::PLATFORM_FILE_OPEN | |
base::PLATFORM_FILE_READ; |
@@ -110,6 +134,8 @@ |
if (next_element_ == end && !buf_len_) |
eof_ = true; |
+ |
+ return OK; |
} |
} // namespace net |