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

Unified Diff: net/base/upload_data_stream.cc

Issue 594036: Support sending a sliced file in chromium.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 9 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
« no previous file with comments | « net/base/upload_data_stream.h ('k') | net/base/upload_data_stream_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « net/base/upload_data_stream.h ('k') | net/base/upload_data_stream_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698