summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-21 13:57:42 +0000
committerkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-21 13:57:42 +0000
commite3e402c11b05ae0562199543ca6a17e09bbab6b2 (patch)
treee6d1bf0123934b7580a302ae35467f3fd4c3ada6 /net
parent4b88b74e5e7ccf857104b2212518c65940489699 (diff)
downloadchromium_src-e3e402c11b05ae0562199543ca6a17e09bbab6b2.zip
chromium_src-e3e402c11b05ae0562199543ca6a17e09bbab6b2.tar.gz
chromium_src-e3e402c11b05ae0562199543ca6a17e09bbab6b2.tar.bz2
Split net::UploadData into two: for resource request IPC and for upload handling
Introducing webkit_glue::ResourceRequestBody as a content-level abstraction corresponding to WebHTTPBody and as an alternative of net::UploadData in ResourceRequest. This interface can contain content-level objects like Blob (or FileSystem URL in later patches) while net::UploadData should NOT. This patch also removes Blob support in net::UploadData. BUG=110119 TEST=existing tests Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=152528 Review URL: https://chromiumcodereview.appspot.com/10834289 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152553 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/base/upload_data.cc6
-rw-r--r--net/base/upload_data.h2
-rw-r--r--net/base/upload_data_unittest.cc11
-rw-r--r--net/base/upload_element.cc15
-rw-r--r--net/base/upload_element.h33
5 files changed, 23 insertions, 44 deletions
diff --git a/net/base/upload_data.cc b/net/base/upload_data.cc
index a36ea06..ca35d12 100644
--- a/net/base/upload_data.cc
+++ b/net/base/upload_data.cc
@@ -45,12 +45,6 @@ void UploadData::AppendFileRange(const FilePath& file_path,
expected_modification_time);
}
-void UploadData::AppendBlob(const GURL& blob_url) {
- DCHECK(!is_chunked_);
- elements_.push_back(UploadElement());
- elements_.back().SetToBlobUrl(blob_url);
-}
-
void UploadData::AppendChunk(const char* bytes,
int bytes_len,
bool is_last_chunk) {
diff --git a/net/base/upload_data.h b/net/base/upload_data.h
index 20675d0..7e4f54b 100644
--- a/net/base/upload_data.h
+++ b/net/base/upload_data.h
@@ -53,8 +53,6 @@ class NET_EXPORT UploadData
uint64 offset, uint64 length,
const base::Time& expected_modification_time);
- void AppendBlob(const GURL& blob_url);
-
// Adds the given chunk of bytes to be sent immediately with chunked transfer
// encoding.
void AppendChunk(const char* bytes, int bytes_len, bool is_last_chunk);
diff --git a/net/base/upload_data_unittest.cc b/net/base/upload_data_unittest.cc
index 63636a2..98bb23d 100644
--- a/net/base/upload_data_unittest.cc
+++ b/net/base/upload_data_unittest.cc
@@ -103,12 +103,6 @@ TEST_F(UploadDataTest, IsInMemory_File) {
ASSERT_FALSE(upload_data_->IsInMemory());
}
-TEST_F(UploadDataTest, IsInMemory_Blob) {
- upload_data_->AppendBlob(GURL("blog:internal:12345"));
- // Until it's resolved, we don't know what blob contains.
- ASSERT_FALSE(upload_data_->IsInMemory());
-}
-
TEST_F(UploadDataTest, IsInMemory_Chunk) {
upload_data_->set_is_chunked(true);
ASSERT_FALSE(upload_data_->IsInMemory());
@@ -149,11 +143,6 @@ TEST_F(UploadDataTest, GetContentLength_File) {
ASSERT_EQ(kData.size(), callback.WaitForResult());
}
-TEST_F(UploadDataTest, GetContentLength_Blob) {
- upload_data_->AppendBlob(GURL("blog:internal:12345"));
- ASSERT_EQ(0U, upload_data_->GetContentLengthSync());
-}
-
TEST_F(UploadDataTest, GetContentLength_Chunk) {
upload_data_->set_is_chunked(true);
ASSERT_EQ(0U, upload_data_->GetContentLengthSync());
diff --git a/net/base/upload_element.cc b/net/base/upload_element.cc
index afa5b0a..b6bdbed 100644
--- a/net/base/upload_element.cc
+++ b/net/base/upload_element.cc
@@ -15,6 +15,8 @@ namespace net {
UploadElement::UploadElement()
: type_(TYPE_BYTES),
+ bytes_start_(NULL),
+ bytes_length_(0),
file_range_offset_(0),
file_range_length_(kuint64max),
is_last_chunk_(false),
@@ -38,9 +40,8 @@ UploadElement::~UploadElement() {
void UploadElement::SetToChunk(const char* bytes,
int bytes_len,
bool is_last_chunk) {
- bytes_.clear();
- bytes_.insert(bytes_.end(), bytes, bytes + bytes_len);
type_ = TYPE_CHUNK;
+ buf_.assign(bytes, bytes + bytes_len);
is_last_chunk_ = is_last_chunk;
}
@@ -49,10 +50,7 @@ uint64 UploadElement::GetContentLength() {
return content_length_;
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.
- return 0;
+ return bytes_length();
DCHECK_EQ(TYPE_FILE, type_);
DCHECK(!file_stream_);
@@ -146,9 +144,8 @@ int UploadElement::ReadFromMemorySync(char* buf, int buf_len) {
// Check if we have anything to copy first, because we are getting
// the address of an element in |bytes_| and that will throw an
// exception if |bytes_| is an empty vector.
- if (num_bytes_to_read > 0) {
- memcpy(buf, &bytes_[offset_], num_bytes_to_read);
- }
+ if (num_bytes_to_read > 0)
+ memcpy(buf, bytes() + offset_, num_bytes_to_read);
offset_ += num_bytes_to_read;
return num_bytes_to_read;
diff --git a/net/base/upload_element.h b/net/base/upload_element.h
index 65e7701..90444d6 100644
--- a/net/base/upload_element.h
+++ b/net/base/upload_element.h
@@ -24,7 +24,6 @@ class NET_EXPORT UploadElement {
enum Type {
TYPE_BYTES,
TYPE_FILE,
- TYPE_BLOB,
// A block of bytes to be sent in chunked encoding immediately, without
// waiting for rest of the data.
@@ -41,7 +40,8 @@ class NET_EXPORT UploadElement {
type_ = type;
}
- const std::vector<char>& bytes() const { return bytes_; }
+ const char* bytes() const { return bytes_start_ ? bytes_start_ : &buf_[0]; }
+ uint64 bytes_length() const { return buf_.size() + bytes_length_; }
const FilePath& file_path() const { return file_path_; }
uint64 file_range_offset() const { return file_range_offset_; }
uint64 file_range_length() const { return file_range_length_; }
@@ -49,11 +49,19 @@ class NET_EXPORT UploadElement {
const base::Time& expected_file_modification_time() const {
return expected_file_modification_time_;
}
- const GURL& blob_url() const { return blob_url_; }
void SetToBytes(const char* bytes, int bytes_len) {
type_ = TYPE_BYTES;
- bytes_.assign(bytes, bytes + bytes_len);
+ buf_.assign(bytes, bytes + bytes_len);
+ }
+
+ // This does not copy the given data and the caller should make sure
+ // the data is secured somewhere else (e.g. by attaching the data
+ // using SetUserData).
+ void SetToSharedBytes(const char* bytes, int bytes_len) {
+ type_ = TYPE_BYTES;
+ bytes_start_ = bytes;
+ bytes_length_ = bytes_len;
}
void SetToFilePath(const FilePath& path) {
@@ -73,13 +81,6 @@ class NET_EXPORT UploadElement {
expected_file_modification_time_ = expected_modification_time;
}
- // TODO(jianli): UploadData should not contain any blob reference. We need
- // to define another structure to represent WebKit::WebHTTPBody.
- void SetToBlobUrl(const GURL& blob_url) {
- type_ = TYPE_BLOB;
- blob_url_ = blob_url;
- }
-
// Though similar to bytes, a chunk indicates that the element is sent via
// chunked transfer encoding and not buffered until the full upload data
// is available.
@@ -128,12 +129,13 @@ class NET_EXPORT UploadElement {
}
Type type_;
- std::vector<char> bytes_;
+ std::vector<char> buf_;
+ const char* bytes_start_;
+ uint64 bytes_length_;
FilePath file_path_;
uint64 file_range_offset_;
uint64 file_range_length_;
base::Time expected_file_modification_time_;
- GURL blob_url_;
bool is_last_chunk_;
bool override_content_length_;
bool content_length_computed_;
@@ -161,7 +163,8 @@ inline bool operator==(const UploadElement& a,
if (a.type() != b.type())
return false;
if (a.type() == UploadElement::TYPE_BYTES)
- return a.bytes() == b.bytes();
+ return a.bytes_length() == b.bytes_length() &&
+ memcmp(a.bytes(), b.bytes(), b.bytes_length()) == 0;
if (a.type() == UploadElement::TYPE_FILE) {
return a.file_path() == b.file_path() &&
a.file_range_offset() == b.file_range_offset() &&
@@ -169,8 +172,6 @@ inline bool operator==(const UploadElement& a,
a.expected_file_modification_time() ==
b.expected_file_modification_time();
}
- if (a.type() == UploadElement::TYPE_BLOB)
- return a.blob_url() == b.blob_url();
return false;
}