summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-21 08:20:57 +0000
committerkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-21 08:20:57 +0000
commit611a071344e691fdc368593ae0deaf15ab1ce34c (patch)
tree2f82ac7e9b295db2983f28d891caa94954416415
parent2c03980fa0873647293a0e8fade9b6d0adc1193c (diff)
downloadchromium_src-611a071344e691fdc368593ae0deaf15ab1ce34c.zip
chromium_src-611a071344e691fdc368593ae0deaf15ab1ce34c.tar.gz
chromium_src-611a071344e691fdc368593ae0deaf15ab1ce34c.tar.bz2
Revert 152528 - 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 Review URL: https://chromiumcodereview.appspot.com/10834289 TBR=kinuko@chromium.org Review URL: https://chromiumcodereview.appspot.com/10831402 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152529 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/policy/device_management_service_browsertest.cc10
-rw-r--r--content/browser/renderer_host/resource_dispatcher_host_impl.cc24
-rw-r--r--content/common/resource_dispatcher.cc52
-rw-r--r--content/common/resource_messages.h7
-rw-r--r--content/public/common/common_param_traits.cc131
-rw-r--r--content/public/common/common_param_traits.h13
-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.h18
-rw-r--r--webkit/blob/blob_storage_controller.cc29
-rw-r--r--webkit/blob/blob_storage_controller.h13
-rw-r--r--webkit/blob/blob_storage_controller_unittest.cc163
-rw-r--r--webkit/glue/resource_loader_bridge.h30
-rw-r--r--webkit/glue/resource_request_body.cc76
-rw-r--r--webkit/glue/resource_request_body.h181
-rw-r--r--webkit/glue/resource_request_body_unittest.cc48
-rw-r--r--webkit/glue/webkit_glue.gypi2
-rw-r--r--webkit/glue/weburlloader_impl.cc16
-rw-r--r--webkit/tools/test_shell/simple_resource_loader_bridge.cc46
-rw-r--r--webkit/tools/test_shell/test_shell.gypi1
22 files changed, 278 insertions, 616 deletions
diff --git a/chrome/browser/policy/device_management_service_browsertest.cc b/chrome/browser/policy/device_management_service_browsertest.cc
index ff532ba..12e5ba5 100644
--- a/chrome/browser/policy/device_management_service_browsertest.cc
+++ b/chrome/browser/policy/device_management_service_browsertest.cc
@@ -50,9 +50,7 @@ class CannedResponseInterceptor : public net::URLRequest::Interceptor {
upload != NULL &&
upload->elements()->size() == 1) {
std::string response_data;
- ConstructResponse(upload->elements()->at(0).bytes(),
- upload->elements()->at(0).bytes_length(),
- &response_data);
+ ConstructResponse(upload->elements()->at(0).bytes(), &response_data);
return new net::URLRequestTestJob(request,
net::URLRequestTestJob::test_headers(),
response_data,
@@ -63,11 +61,11 @@ class CannedResponseInterceptor : public net::URLRequest::Interceptor {
}
private:
- void ConstructResponse(const char* request_data,
- uint64 request_data_length,
+ void ConstructResponse(const std::vector<char>& request_data,
std::string* response_data) {
em::DeviceManagementRequest request;
- ASSERT_TRUE(request.ParseFromArray(request_data, request_data_length));
+ ASSERT_TRUE(request.ParseFromArray(vector_as_array(&request_data),
+ request_data.size()));
em::DeviceManagementResponse response;
if (request.has_register_request()) {
response.mutable_register_response()->set_device_management_token(
diff --git a/content/browser/renderer_host/resource_dispatcher_host_impl.cc b/content/browser/renderer_host/resource_dispatcher_host_impl.cc
index 5a46634..c816bd6 100644
--- a/content/browser/renderer_host/resource_dispatcher_host_impl.cc
+++ b/content/browser/renderer_host/resource_dispatcher_host_impl.cc
@@ -40,10 +40,10 @@
#include "content/browser/renderer_host/render_view_host_delegate.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/renderer_host/resource_message_filter.h"
+#include "content/browser/renderer_host/transfer_navigation_resource_throttle.h"
#include "content/browser/renderer_host/resource_request_info_impl.h"
#include "content/browser/renderer_host/sync_resource_handler.h"
#include "content/browser/renderer_host/throttling_resource_handler.h"
-#include "content/browser/renderer_host/transfer_navigation_resource_throttle.h"
#include "content/browser/resource_context_impl.h"
#include "content/browser/worker_host/worker_service_impl.h"
#include "content/common/resource_messages.h"
@@ -82,14 +82,12 @@
#include "webkit/appcache/appcache_interfaces.h"
#include "webkit/blob/blob_storage_controller.h"
#include "webkit/blob/shareable_file_reference.h"
-#include "webkit/glue/resource_request_body.h"
#include "webkit/glue/webkit_glue.h"
using base::Time;
using base::TimeDelta;
using base::TimeTicks;
using webkit_blob::ShareableFileReference;
-using webkit_glue::ResourceRequestBody;
// ----------------------------------------------------------------------------
@@ -173,12 +171,12 @@ bool ShouldServiceRequest(ProcessType process_type,
}
// Check if the renderer is permitted to upload the requested files.
- if (request_data.request_body) {
- const std::vector<ResourceRequestBody::Element>* uploads =
- request_data.request_body->elements();
- std::vector<ResourceRequestBody::Element>::const_iterator iter;
+ if (request_data.upload_data) {
+ const std::vector<net::UploadElement>* uploads =
+ request_data.upload_data->elements();
+ std::vector<net::UploadElement>::const_iterator iter;
for (iter = uploads->begin(); iter != uploads->end(); ++iter) {
- if (iter->type() == ResourceRequestBody::TYPE_FILE &&
+ if (iter->type() == net::UploadElement::TYPE_FILE &&
!policy->CanReadFile(child_id, iter->file_path())) {
NOTREACHED() << "Denied unauthorized upload of "
<< iter->file_path().value();
@@ -901,9 +899,9 @@ void ResourceDispatcherHostImpl::BeginRequest(
CHECK(ContainsKey(active_resource_contexts_, resource_context));
// Might need to resolve the blob references in the upload data.
- if (request_data.request_body) {
+ if (request_data.upload_data) {
GetBlobStorageControllerForResourceContext(resource_context)->
- ResolveBlobReferencesInRequestBody(request_data.request_body.get());
+ ResolveBlobReferencesInUploadData(request_data.upload_data.get());
}
if (is_shutdown_ ||
@@ -965,11 +963,11 @@ void ResourceDispatcherHostImpl::BeginRequest(
// Set upload data.
uint64 upload_size = 0;
- if (request_data.request_body) {
- request->set_upload(request_data.request_body->CreateUploadData());
+ if (request_data.upload_data) {
+ request->set_upload(request_data.upload_data);
// This results in performing file IO. crbug.com/112607.
base::ThreadRestrictions::ScopedAllowIO allow_io;
- upload_size = request->get_upload_mutable()->GetContentLengthSync();
+ upload_size = request_data.upload_data->GetContentLengthSync();
}
bool allow_download = request_data.allow_download &&
diff --git a/content/common/resource_dispatcher.cc b/content/common/resource_dispatcher.cc
index 5fc9091..610d20c 100644
--- a/content/common/resource_dispatcher.cc
+++ b/content/common/resource_dispatcher.cc
@@ -20,12 +20,11 @@
#include "content/public/common/resource_response.h"
#include "net/base/net_errors.h"
#include "net/base/net_util.h"
+#include "net/base/upload_data.h"
#include "net/http/http_response_headers.h"
-#include "webkit/glue/resource_request_body.h"
#include "webkit/glue/resource_type.h"
using webkit_glue::ResourceLoaderBridge;
-using webkit_glue::ResourceRequestBody;
using webkit_glue::ResourceResponseInfo;
namespace content {
@@ -48,7 +47,14 @@ class IPCResourceLoaderBridge : public ResourceLoaderBridge {
virtual ~IPCResourceLoaderBridge();
// ResourceLoaderBridge
- virtual void SetRequestBody(ResourceRequestBody* request_body);
+ virtual void AppendDataToUpload(const char* data, int data_len);
+ virtual void AppendFileRangeToUpload(
+ const FilePath& path,
+ uint64 offset,
+ uint64 length,
+ const base::Time& expected_modification_time);
+ virtual void AppendBlobToUpload(const GURL& blob_url);
+ virtual void SetUploadIdentifier(int64 identifier);
virtual bool Start(Peer* peer);
virtual void Cancel();
virtual void SetDefersLoading(bool value);
@@ -136,10 +142,44 @@ IPCResourceLoaderBridge::~IPCResourceLoaderBridge() {
}
}
-void IPCResourceLoaderBridge::SetRequestBody(
- ResourceRequestBody* request_body) {
+void IPCResourceLoaderBridge::AppendDataToUpload(const char* data,
+ int data_len) {
DCHECK(request_id_ == -1) << "request already started";
- request_.request_body = request_body;
+
+ // don't bother appending empty data segments
+ if (data_len == 0)
+ return;
+
+ if (!request_.upload_data)
+ request_.upload_data = new net::UploadData();
+ request_.upload_data->AppendBytes(data, data_len);
+}
+
+void IPCResourceLoaderBridge::AppendFileRangeToUpload(
+ const FilePath& path, uint64 offset, uint64 length,
+ const base::Time& expected_modification_time) {
+ DCHECK(request_id_ == -1) << "request already started";
+
+ if (!request_.upload_data)
+ request_.upload_data = new net::UploadData();
+ request_.upload_data->AppendFileRange(path, offset, length,
+ expected_modification_time);
+}
+
+void IPCResourceLoaderBridge::AppendBlobToUpload(const GURL& blob_url) {
+ DCHECK(request_id_ == -1) << "request already started";
+
+ if (!request_.upload_data)
+ request_.upload_data = new net::UploadData();
+ request_.upload_data->AppendBlob(blob_url);
+}
+
+void IPCResourceLoaderBridge::SetUploadIdentifier(int64 identifier) {
+ DCHECK(request_id_ == -1) << "request already started";
+
+ if (!request_.upload_data)
+ request_.upload_data = new net::UploadData();
+ request_.upload_data->set_identifier(identifier);
}
// Writes a footer on the message and sends it
diff --git a/content/common/resource_messages.h b/content/common/resource_messages.h
index 638d238..69a2ae6 100644
--- a/content/common/resource_messages.h
+++ b/content/common/resource_messages.h
@@ -9,7 +9,7 @@
#include "content/public/common/common_param_traits.h"
#include "content/public/common/resource_response.h"
#include "ipc/ipc_message_macros.h"
-#include "webkit/glue/resource_request_body.h"
+#include "net/base/upload_data.h"
#define IPC_MESSAGE_START ResourceMsgStart
#undef IPC_MESSAGE_EXPORT
@@ -94,9 +94,8 @@ IPC_STRUCT_BEGIN(ResourceHostMsg_Request)
// or kNoHostId.
IPC_STRUCT_MEMBER(int, appcache_host_id)
- // Optional resource request body (may be null).
- IPC_STRUCT_MEMBER(scoped_refptr<webkit_glue::ResourceRequestBody>,
- request_body)
+ // Optional upload data (may be null).
+ IPC_STRUCT_MEMBER(scoped_refptr<net::UploadData>, upload_data)
IPC_STRUCT_MEMBER(bool, download_to_file)
diff --git a/content/public/common/common_param_traits.cc b/content/public/common/common_param_traits.cc
index 81a1e2d..6e5e3da 100644
--- a/content/public/common/common_param_traits.cc
+++ b/content/public/common/common_param_traits.cc
@@ -13,7 +13,6 @@
#include "ui/base/range/range.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/rect_f.h"
-#include "webkit/glue/resource_request_body.h"
namespace {
@@ -134,17 +133,17 @@ struct ParamTraits<net::UploadElement> {
WriteParam(m, static_cast<int>(p.type()));
switch (p.type()) {
case net::UploadElement::TYPE_BYTES: {
- m->WriteData(p.bytes(), static_cast<int>(p.bytes_length()));
+ m->WriteData(&p.bytes()[0], static_cast<int>(p.bytes().size()));
break;
}
case net::UploadElement::TYPE_CHUNK: {
std::string chunk_length = StringPrintf(
- "%X\r\n", static_cast<unsigned int>(p.bytes_length()));
+ "%X\r\n", static_cast<unsigned int>(p.bytes().size()));
std::vector<char> bytes;
bytes.insert(bytes.end(), chunk_length.data(),
chunk_length.data() + chunk_length.length());
- const char* data = p.bytes();
- bytes.insert(bytes.end(), data, data + p.bytes_length());
+ const char* data = &p.bytes()[0];
+ bytes.insert(bytes.end(), data, data + p.bytes().size());
const char* crlf = "\r\n";
bytes.insert(bytes.end(), crlf, crlf + strlen(crlf));
if (p.is_last_chunk()) {
@@ -158,14 +157,17 @@ struct ParamTraits<net::UploadElement> {
WriteParam(m, p.is_last_chunk());
break;
}
- default: {
- DCHECK(p.type() == net::UploadElement::TYPE_FILE);
+ case net::UploadElement::TYPE_FILE: {
WriteParam(m, p.file_path());
WriteParam(m, p.file_range_offset());
WriteParam(m, p.file_range_length());
WriteParam(m, p.expected_file_modification_time());
break;
}
+ default: {
+ WriteParam(m, p.blob_url());
+ break;
+ }
}
}
static bool Read(const Message* m, PickleIterator* iter, param_type* r) {
@@ -196,8 +198,7 @@ struct ParamTraits<net::UploadElement> {
r->set_is_last_chunk(is_last_chunk);
break;
}
- default: {
- DCHECK(type == net::UploadElement::TYPE_FILE);
+ case net::UploadElement::TYPE_FILE: {
FilePath file_path;
uint64 offset, length;
base::Time expected_modification_time;
@@ -213,6 +214,14 @@ struct ParamTraits<net::UploadElement> {
expected_modification_time);
break;
}
+ default: {
+ DCHECK(type == net::UploadElement::TYPE_BLOB);
+ GURL blob_url;
+ if (!ReadParam(m, iter, &blob_url))
+ return false;
+ r->SetToBlobUrl(blob_url);
+ break;
+ }
}
return true;
}
@@ -260,110 +269,6 @@ void ParamTraits<scoped_refptr<net::UploadData> >::Log(const param_type& p,
l->append("<net::UploadData>");
}
-template <>
-struct ParamTraits<webkit_glue::ResourceRequestBody::Element> {
- typedef webkit_glue::ResourceRequestBody::Element param_type;
- static void Write(Message* m, const param_type& p) {
- WriteParam(m, static_cast<int>(p.type()));
- switch (p.type()) {
- case webkit_glue::ResourceRequestBody::TYPE_BYTES: {
- m->WriteData(p.bytes(), static_cast<int>(p.bytes_length()));
- break;
- }
- case webkit_glue::ResourceRequestBody::TYPE_FILE: {
- WriteParam(m, p.file_path());
- WriteParam(m, p.file_range_offset());
- WriteParam(m, p.file_range_length());
- WriteParam(m, p.expected_file_modification_time());
- break;
- }
- default: {
- WriteParam(m, p.blob_url());
- break;
- }
- }
- }
- static bool Read(const Message* m, PickleIterator* iter, param_type* r) {
- int type;
- if (!ReadParam(m, iter, &type))
- return false;
- switch (type) {
- case webkit_glue::ResourceRequestBody::TYPE_BYTES: {
- const char* data;
- int len;
- if (!m->ReadData(iter, &data, &len))
- return false;
- r->SetToBytes(data, len);
- break;
- }
- case webkit_glue::ResourceRequestBody::TYPE_FILE: {
- FilePath file_path;
- uint64 offset, length;
- base::Time expected_modification_time;
- if (!ReadParam(m, iter, &file_path))
- return false;
- if (!ReadParam(m, iter, &offset))
- return false;
- if (!ReadParam(m, iter, &length))
- return false;
- if (!ReadParam(m, iter, &expected_modification_time))
- return false;
- r->SetToFilePathRange(file_path, offset, length,
- expected_modification_time);
- break;
- }
- default: {
- DCHECK(type == webkit_glue::ResourceRequestBody::TYPE_BLOB);
- GURL blob_url;
- if (!ReadParam(m, iter, &blob_url))
- return false;
- r->SetToBlobUrl(blob_url);
- break;
- }
- }
- return true;
- }
- static void Log(const param_type& p, std::string* l) {
- l->append("<webkit_glue::ResourceRequestBody::Element>");
- }
-};
-
-void ParamTraits<scoped_refptr<webkit_glue::ResourceRequestBody> >::Write(
- Message* m,
- const param_type& p) {
- WriteParam(m, p.get() != NULL);
- if (p) {
- WriteParam(m, *p->elements());
- WriteParam(m, p->identifier());
- }
-}
-
-bool ParamTraits<scoped_refptr<webkit_glue::ResourceRequestBody> >::Read(
- const Message* m,
- PickleIterator* iter,
- param_type* r) {
- bool has_object;
- if (!ReadParam(m, iter, &has_object))
- return false;
- if (!has_object)
- return true;
- std::vector<webkit_glue::ResourceRequestBody::Element> elements;
- if (!ReadParam(m, iter, &elements))
- return false;
- int64 identifier;
- if (!ReadParam(m, iter, &identifier))
- return false;
- *r = new webkit_glue::ResourceRequestBody;
- (*r)->swap_elements(&elements);
- (*r)->set_identifier(identifier);
- return true;
-}
-
-void ParamTraits<scoped_refptr<webkit_glue::ResourceRequestBody> >::Log(
- const param_type& p, std::string* l) {
- l->append("<webkit_glue::ResourceRequestBody>");
-}
-
void ParamTraits<net::HostPortPair>::Write(Message* m, const param_type& p) {
WriteParam(m, p.host());
WriteParam(m, p.port());
diff --git a/content/public/common/common_param_traits.h b/content/public/common/common_param_traits.h
index 0742c79..df0ddc3 100644
--- a/content/public/common/common_param_traits.h
+++ b/content/public/common/common_param_traits.h
@@ -47,10 +47,6 @@ namespace ui {
class Range;
}
-namespace webkit_glue {
-class ResourceRequestBody;
-}
-
namespace IPC {
template <>
@@ -77,15 +73,6 @@ struct CONTENT_EXPORT ParamTraits<scoped_refptr<net::UploadData> > {
static void Log(const param_type& p, std::string* l);
};
-template <>
-struct CONTENT_EXPORT ParamTraits<scoped_refptr<
- webkit_glue::ResourceRequestBody> > {
- typedef scoped_refptr<webkit_glue::ResourceRequestBody> param_type;
- static void Write(Message* m, const param_type& p);
- static bool Read(const Message* m, PickleIterator* iter, param_type* r);
- static void Log(const param_type& p, std::string* l);
-};
-
template<>
struct CONTENT_EXPORT ParamTraits<net::HostPortPair> {
typedef net::HostPortPair param_type;
diff --git a/net/base/upload_data.cc b/net/base/upload_data.cc
index ca35d12..a36ea06 100644
--- a/net/base/upload_data.cc
+++ b/net/base/upload_data.cc
@@ -45,6 +45,12 @@ 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 7e4f54b..20675d0 100644
--- a/net/base/upload_data.h
+++ b/net/base/upload_data.h
@@ -53,6 +53,8 @@ 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 98bb23d..63636a2 100644
--- a/net/base/upload_data_unittest.cc
+++ b/net/base/upload_data_unittest.cc
@@ -103,6 +103,12 @@ 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());
@@ -143,6 +149,11 @@ 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 b6bdbed..afa5b0a 100644
--- a/net/base/upload_element.cc
+++ b/net/base/upload_element.cc
@@ -15,8 +15,6 @@ 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),
@@ -40,8 +38,9 @@ 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;
}
@@ -50,7 +49,10 @@ uint64 UploadElement::GetContentLength() {
return content_length_;
if (type_ == TYPE_BYTES || type_ == TYPE_CHUNK)
- return bytes_length();
+ return static_cast<uint64>(bytes_.size());
+ else if (type_ == TYPE_BLOB)
+ // The blob reference will be resolved later.
+ return 0;
DCHECK_EQ(TYPE_FILE, type_);
DCHECK(!file_stream_);
@@ -144,8 +146,9 @@ 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 ef09d67..65e7701 100644
--- a/net/base/upload_element.h
+++ b/net/base/upload_element.h
@@ -41,8 +41,7 @@ class NET_EXPORT UploadElement {
type_ = type;
}
- const char* bytes() const { return bytes_start_ ? bytes_start_ : &buf_[0]; }
- uint64 bytes_length() const { return buf_.size() + bytes_length_; }
+ const std::vector<char>& bytes() const { return bytes_; }
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_; }
@@ -54,16 +53,7 @@ class NET_EXPORT UploadElement {
void SetToBytes(const char* bytes, int bytes_len) {
type_ = TYPE_BYTES;
- 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;
+ bytes_.assign(bytes, bytes + bytes_len);
}
void SetToFilePath(const FilePath& path) {
@@ -138,9 +128,7 @@ class NET_EXPORT UploadElement {
}
Type type_;
- std::vector<char> buf_;
- const char* bytes_start_;
- uint64 bytes_length_;
+ std::vector<char> bytes_;
FilePath file_path_;
uint64 file_range_offset_;
uint64 file_range_length_;
diff --git a/webkit/blob/blob_storage_controller.cc b/webkit/blob/blob_storage_controller.cc
index 4c3c3bb..6a10811 100644
--- a/webkit/blob/blob_storage_controller.cc
+++ b/webkit/blob/blob_storage_controller.cc
@@ -6,10 +6,8 @@
#include "base/logging.h"
#include "googleurl/src/gurl.h"
+#include "net/base/upload_data.h"
#include "webkit/blob/blob_data.h"
-#include "webkit/glue/resource_request_body.h"
-
-using webkit_glue::ResourceRequestBody;
namespace webkit_blob {
@@ -171,15 +169,15 @@ BlobData* BlobStorageController::GetBlobDataFromUrl(const GURL& url) {
return (found != blob_map_.end()) ? found->second : NULL;
}
-void BlobStorageController::ResolveBlobReferencesInRequestBody(
- ResourceRequestBody* request_body) {
- DCHECK(request_body);
+void BlobStorageController::ResolveBlobReferencesInUploadData(
+ net::UploadData* upload_data) {
+ DCHECK(upload_data);
- std::vector<ResourceRequestBody::Element>* uploads =
- request_body->elements_mutable();
- std::vector<ResourceRequestBody::Element>::iterator iter;
+ std::vector<net::UploadElement>* uploads =
+ upload_data->elements_mutable();
+ std::vector<net::UploadElement>::iterator iter;
for (iter = uploads->begin(); iter != uploads->end();) {
- if (iter->type() != ResourceRequestBody::TYPE_BLOB) {
+ if (iter->type() != net::UploadElement::TYPE_BLOB) {
iter++;
continue;
}
@@ -204,19 +202,22 @@ void BlobStorageController::ResolveBlobReferencesInRequestBody(
// Ensure the blob and any attached shareable files survive until
// upload completion.
- request_body->SetUserData(
- blob_data, new base::UserDataAdapter<BlobData>(blob_data));
+ upload_data->SetUserData(blob_data,
+ new base::UserDataAdapter<BlobData>(blob_data));
// Insert the elements in the referred blob data.
// Note that we traverse from the bottom so that the elements can be
// inserted in the original order.
for (size_t i = blob_data->items().size(); i > 0; --i) {
- iter = uploads->insert(iter, ResourceRequestBody::Element());
+ iter = uploads->insert(iter, net::UploadElement());
const BlobData::Item& item = blob_data->items().at(i - 1);
switch (item.type) {
case BlobData::TYPE_DATA:
- iter->SetToSharedBytes(
+ // TODO(jianli): Figure out how to avoid copying the data.
+ // TODO(michaeln): Now that blob_data surives for the duration,
+ // maybe UploadData could take a raw ptr without having to copy.
+ iter->SetToBytes(
&item.data.at(0) + static_cast<int>(item.offset),
static_cast<int>(item.length));
break;
diff --git a/webkit/blob/blob_storage_controller.h b/webkit/blob/blob_storage_controller.h
index fddd6ff..a32fab3 100644
--- a/webkit/blob/blob_storage_controller.h
+++ b/webkit/blob/blob_storage_controller.h
@@ -13,7 +13,6 @@
#include "base/process.h"
#include "webkit/blob/blob_data.h"
#include "webkit/blob/blob_export.h"
-#include "webkit/glue/resource_request_body.h"
class GURL;
class FilePath;
@@ -21,9 +20,8 @@ class FilePath;
namespace base {
class Time;
}
-
-namespace webkit_glue {
-class ResourceRequestBody;
+namespace net {
+class UploadData;
}
namespace webkit_blob {
@@ -42,10 +40,9 @@ class BLOB_EXPORT BlobStorageController {
void RemoveBlob(const GURL& url);
BlobData* GetBlobDataFromUrl(const GURL& url);
- // If there is any blob reference in the resource request body, it will get
- // resolved and updated in place.
- void ResolveBlobReferencesInRequestBody(
- webkit_glue::ResourceRequestBody* request_body);
+ // If there is any blob reference in the upload data, it will get resolved
+ // and updated in place.
+ void ResolveBlobReferencesInUploadData(net::UploadData* upload_data);
private:
friend class ViewBlobInternalsJob;
diff --git a/webkit/blob/blob_storage_controller_unittest.cc b/webkit/blob/blob_storage_controller_unittest.cc
index 48699a4..ff98e22 100644
--- a/webkit/blob/blob_storage_controller_unittest.cc
+++ b/webkit/blob/blob_storage_controller_unittest.cc
@@ -6,12 +6,12 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/time.h"
+#include "net/base/upload_data.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/blob/blob_data.h"
#include "webkit/blob/blob_storage_controller.h"
-#include "webkit/glue/resource_request_body.h"
-using webkit_glue::ResourceRequestBody;
+using net::UploadData;
namespace webkit_blob {
@@ -76,7 +76,7 @@ TEST(BlobStorageControllerTest, RegisterBlobUrl) {
EXPECT_TRUE(!blob_data_found);
}
-TEST(BlobStorageControllerTest, ResolveBlobReferencesInRequestBody) {
+TEST(BlobStorageControllerTest, ResolveBlobReferencesInUploadData) {
// Setup blob data for testing.
base::Time time1, time2;
base::Time::FromString("Tue, 15 Nov 1994, 12:45:26 GMT", &time1);
@@ -102,7 +102,7 @@ TEST(BlobStorageControllerTest, ResolveBlobReferencesInRequestBody) {
blob_storage_controller.CloneBlob(blob_url3, blob_url2);
// Setup upload data elements for comparison.
- ResourceRequestBody::Element blob_element1, blob_element2;
+ net::UploadElement blob_element1, blob_element2;
blob_element1.SetToBytes(
blob_data->items().at(0).data.c_str() +
static_cast<int>(blob_data->items().at(0).offset),
@@ -113,131 +113,124 @@ TEST(BlobStorageControllerTest, ResolveBlobReferencesInRequestBody) {
blob_data->items().at(1).length,
blob_data->items().at(1).expected_modification_time);
- ResourceRequestBody::Element upload_element1, upload_element2;
+ net::UploadElement upload_element1, upload_element2;
upload_element1.SetToBytes("Hello", 5);
upload_element2.SetToFilePathRange(
FilePath(FILE_PATH_LITERAL("foo1.txt")), 0, 20, time2);
// Test no blob reference.
- scoped_refptr<ResourceRequestBody> request_body(new ResourceRequestBody());
- request_body->AppendBytes(
- upload_element1.bytes(),
- upload_element1.bytes_length());
- request_body->AppendFileRange(
+ scoped_refptr<UploadData> upload_data(new UploadData());
+ upload_data->AppendBytes(
+ &upload_element1.bytes().at(0),
+ upload_element1.bytes().size());
+ upload_data->AppendFileRange(
upload_element2.file_path(),
upload_element2.file_range_offset(),
upload_element2.file_range_length(),
upload_element2.expected_file_modification_time());
- blob_storage_controller.ResolveBlobReferencesInRequestBody(
- request_body.get());
- ASSERT_EQ(request_body->elements()->size(), 2U);
- EXPECT_TRUE(request_body->elements()->at(0) == upload_element1);
- EXPECT_TRUE(request_body->elements()->at(1) == upload_element2);
+ blob_storage_controller.ResolveBlobReferencesInUploadData(upload_data.get());
+ ASSERT_EQ(upload_data->elements()->size(), 2U);
+ EXPECT_TRUE(upload_data->elements()->at(0) == upload_element1);
+ EXPECT_TRUE(upload_data->elements()->at(1) == upload_element2);
// Test having only one blob reference that refers to empty blob data.
- request_body = new ResourceRequestBody();
- request_body->AppendBlob(blob_url0);
+ upload_data = new UploadData();
+ upload_data->AppendBlob(blob_url0);
- blob_storage_controller.ResolveBlobReferencesInRequestBody(
- request_body.get());
- ASSERT_EQ(request_body->elements()->size(), 0U);
+ blob_storage_controller.ResolveBlobReferencesInUploadData(upload_data.get());
+ ASSERT_EQ(upload_data->elements()->size(), 0U);
// Test having only one blob reference.
- request_body = new ResourceRequestBody();
- request_body->AppendBlob(blob_url1);
+ upload_data = new UploadData();
+ upload_data->AppendBlob(blob_url1);
- blob_storage_controller.ResolveBlobReferencesInRequestBody(
- request_body.get());
- ASSERT_EQ(request_body->elements()->size(), 2U);
- EXPECT_TRUE(request_body->elements()->at(0) == blob_element1);
- EXPECT_TRUE(request_body->elements()->at(1) == blob_element2);
+ blob_storage_controller.ResolveBlobReferencesInUploadData(upload_data.get());
+ ASSERT_EQ(upload_data->elements()->size(), 2U);
+ EXPECT_TRUE(upload_data->elements()->at(0) == blob_element1);
+ EXPECT_TRUE(upload_data->elements()->at(1) == blob_element2);
// Test having one blob reference at the beginning.
- request_body = new ResourceRequestBody();
- request_body->AppendBlob(blob_url1);
- request_body->AppendBytes(
- upload_element1.bytes(),
- upload_element1.bytes_length());
- request_body->AppendFileRange(
+ upload_data = new UploadData();
+ upload_data->AppendBlob(blob_url1);
+ upload_data->AppendBytes(
+ &upload_element1.bytes().at(0),
+ upload_element1.bytes().size());
+ upload_data->AppendFileRange(
upload_element2.file_path(),
upload_element2.file_range_offset(),
upload_element2.file_range_length(),
upload_element2.expected_file_modification_time());
- blob_storage_controller.ResolveBlobReferencesInRequestBody(
- request_body.get());
- ASSERT_EQ(request_body->elements()->size(), 4U);
- EXPECT_TRUE(request_body->elements()->at(0) == blob_element1);
- EXPECT_TRUE(request_body->elements()->at(1) == blob_element2);
- EXPECT_TRUE(request_body->elements()->at(2) == upload_element1);
- EXPECT_TRUE(request_body->elements()->at(3) == upload_element2);
+ blob_storage_controller.ResolveBlobReferencesInUploadData(upload_data.get());
+ ASSERT_EQ(upload_data->elements()->size(), 4U);
+ EXPECT_TRUE(upload_data->elements()->at(0) == blob_element1);
+ EXPECT_TRUE(upload_data->elements()->at(1) == blob_element2);
+ EXPECT_TRUE(upload_data->elements()->at(2) == upload_element1);
+ EXPECT_TRUE(upload_data->elements()->at(3) == upload_element2);
// Test having one blob reference at the end.
- request_body = new ResourceRequestBody();
- request_body->AppendBytes(
- upload_element1.bytes(),
- upload_element1.bytes_length());
- request_body->AppendFileRange(
+ upload_data = new UploadData();
+ upload_data->AppendBytes(
+ &upload_element1.bytes().at(0),
+ upload_element1.bytes().size());
+ upload_data->AppendFileRange(
upload_element2.file_path(),
upload_element2.file_range_offset(),
upload_element2.file_range_length(),
upload_element2.expected_file_modification_time());
- request_body->AppendBlob(blob_url1);
+ upload_data->AppendBlob(blob_url1);
- blob_storage_controller.ResolveBlobReferencesInRequestBody(
- request_body.get());
- ASSERT_EQ(request_body->elements()->size(), 4U);
- EXPECT_TRUE(request_body->elements()->at(0) == upload_element1);
- EXPECT_TRUE(request_body->elements()->at(1) == upload_element2);
- EXPECT_TRUE(request_body->elements()->at(2) == blob_element1);
- EXPECT_TRUE(request_body->elements()->at(3) == blob_element2);
+ blob_storage_controller.ResolveBlobReferencesInUploadData(upload_data.get());
+ ASSERT_EQ(upload_data->elements()->size(), 4U);
+ EXPECT_TRUE(upload_data->elements()->at(0) == upload_element1);
+ EXPECT_TRUE(upload_data->elements()->at(1) == upload_element2);
+ EXPECT_TRUE(upload_data->elements()->at(2) == blob_element1);
+ EXPECT_TRUE(upload_data->elements()->at(3) == blob_element2);
// Test having one blob reference in the middle.
- request_body = new ResourceRequestBody();
- request_body->AppendBytes(
- upload_element1.bytes(),
- upload_element1.bytes_length());
- request_body->AppendBlob(blob_url1);
- request_body->AppendFileRange(
+ upload_data = new UploadData();
+ upload_data->AppendBytes(
+ &upload_element1.bytes().at(0),
+ upload_element1.bytes().size());
+ upload_data->AppendBlob(blob_url1);
+ upload_data->AppendFileRange(
upload_element2.file_path(),
upload_element2.file_range_offset(),
upload_element2.file_range_length(),
upload_element2.expected_file_modification_time());
- blob_storage_controller.ResolveBlobReferencesInRequestBody(
- request_body.get());
- ASSERT_EQ(request_body->elements()->size(), 4U);
- EXPECT_TRUE(request_body->elements()->at(0) == upload_element1);
- EXPECT_TRUE(request_body->elements()->at(1) == blob_element1);
- EXPECT_TRUE(request_body->elements()->at(2) == blob_element2);
- EXPECT_TRUE(request_body->elements()->at(3) == upload_element2);
+ blob_storage_controller.ResolveBlobReferencesInUploadData(upload_data.get());
+ ASSERT_EQ(upload_data->elements()->size(), 4U);
+ EXPECT_TRUE(upload_data->elements()->at(0) == upload_element1);
+ EXPECT_TRUE(upload_data->elements()->at(1) == blob_element1);
+ EXPECT_TRUE(upload_data->elements()->at(2) == blob_element2);
+ EXPECT_TRUE(upload_data->elements()->at(3) == upload_element2);
// Test having multiple blob references.
- request_body = new ResourceRequestBody();
- request_body->AppendBlob(blob_url1);
- request_body->AppendBytes(
- upload_element1.bytes(),
- upload_element1.bytes_length());
- request_body->AppendBlob(blob_url2);
- request_body->AppendBlob(blob_url3);
- request_body->AppendFileRange(
+ upload_data = new UploadData();
+ upload_data->AppendBlob(blob_url1);
+ upload_data->AppendBytes(
+ &upload_element1.bytes().at(0),
+ upload_element1.bytes().size());
+ upload_data->AppendBlob(blob_url2);
+ upload_data->AppendBlob(blob_url3);
+ upload_data->AppendFileRange(
upload_element2.file_path(),
upload_element2.file_range_offset(),
upload_element2.file_range_length(),
upload_element2.expected_file_modification_time());
- blob_storage_controller.ResolveBlobReferencesInRequestBody(
- request_body.get());
- ASSERT_EQ(request_body->elements()->size(), 8U);
- EXPECT_TRUE(request_body->elements()->at(0) == blob_element1);
- EXPECT_TRUE(request_body->elements()->at(1) == blob_element2);
- EXPECT_TRUE(request_body->elements()->at(2) == upload_element1);
- EXPECT_TRUE(request_body->elements()->at(3) == blob_element1);
- EXPECT_TRUE(request_body->elements()->at(4) == blob_element2);
- EXPECT_TRUE(request_body->elements()->at(5) == blob_element1);
- EXPECT_TRUE(request_body->elements()->at(6) == blob_element2);
- EXPECT_TRUE(request_body->elements()->at(7) == upload_element2);
+ blob_storage_controller.ResolveBlobReferencesInUploadData(upload_data.get());
+ ASSERT_EQ(upload_data->elements()->size(), 8U);
+ EXPECT_TRUE(upload_data->elements()->at(0) == blob_element1);
+ EXPECT_TRUE(upload_data->elements()->at(1) == blob_element2);
+ EXPECT_TRUE(upload_data->elements()->at(2) == upload_element1);
+ EXPECT_TRUE(upload_data->elements()->at(3) == blob_element1);
+ EXPECT_TRUE(upload_data->elements()->at(4) == blob_element2);
+ EXPECT_TRUE(upload_data->elements()->at(5) == blob_element1);
+ EXPECT_TRUE(upload_data->elements()->at(6) == blob_element2);
+ EXPECT_TRUE(upload_data->elements()->at(7) == upload_element2);
}
} // namespace webkit_blob
diff --git a/webkit/glue/resource_loader_bridge.h b/webkit/glue/resource_loader_bridge.h
index e699574..70db933 100644
--- a/webkit/glue/resource_loader_bridge.h
+++ b/webkit/glue/resource_loader_bridge.h
@@ -41,7 +41,6 @@ class HttpResponseHeaders;
}
namespace webkit_glue {
-class ResourceRequestBody;
// Structure containing timing information for the request. It addresses
// http://groups.google.com/group/http-archive-specification/web/har-1-1-spec
@@ -349,9 +348,32 @@ class ResourceLoaderBridge {
// anybody can delete at any time, INCLUDING during processing of callbacks.
WEBKIT_GLUE_EXPORT virtual ~ResourceLoaderBridge();
- // Call this method before calling Start() to set the request body.
- // May only be used with HTTP(S) POST requests.
- virtual void SetRequestBody(ResourceRequestBody* request_body) = 0;
+ // Call this method before calling Start() to append a chunk of binary data
+ // to the request body. May only be used with HTTP(S) POST requests.
+ virtual void AppendDataToUpload(const char* data, int data_len) = 0;
+
+ // Call this method before calling Start() to append the contents of a file
+ // to the request body. May only be used with HTTP(S) POST requests.
+ void AppendFileToUpload(const FilePath& file_path) {
+ AppendFileRangeToUpload(file_path, 0, kuint64max, base::Time());
+ }
+
+ // Call this method before calling Start() to append the contents of a file
+ // to the request body. May only be used with HTTP(S) POST requests.
+ virtual void AppendFileRangeToUpload(
+ const FilePath& file_path,
+ uint64 offset,
+ uint64 length,
+ const base::Time& expected_modification_time) = 0;
+
+ // Call this method before calling Start() to append the contents of a blob
+ // to the request body. May only be used with HTTP(S) POST requests.
+ virtual void AppendBlobToUpload(const GURL& blob_url) = 0;
+
+ // Call this method before calling Start() to assign an upload identifier to
+ // this request. This is used to enable caching of POST responses. A value
+ // of 0 implies the unspecified identifier.
+ virtual void SetUploadIdentifier(int64 identifier) = 0;
// Call this method to initiate the request. If this method succeeds, then
// the peer's methods will be called asynchronously to report various events.
diff --git a/webkit/glue/resource_request_body.cc b/webkit/glue/resource_request_body.cc
deleted file mode 100644
index 1cd10e8..0000000
--- a/webkit/glue/resource_request_body.cc
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "webkit/glue/resource_request_body.h"
-
-#include "base/logging.h"
-#include "net/base/upload_data.h"
-
-namespace webkit_glue {
-
-ResourceRequestBody::Element::Element()
- : type_(TYPE_BYTES),
- bytes_start_(NULL),
- bytes_length_(0),
- file_range_offset_(0),
- file_range_length_(kuint64max) {
-}
-
-ResourceRequestBody::Element::~Element() {}
-
-ResourceRequestBody::ResourceRequestBody() : identifier_(0) {}
-
-void ResourceRequestBody::AppendBytes(const char* bytes, int bytes_len) {
- if (bytes_len > 0) {
- elements_.push_back(Element());
- elements_.back().SetToBytes(bytes, bytes_len);
- }
-}
-
-void ResourceRequestBody::AppendFileRange(
- const FilePath& file_path,
- uint64 offset, uint64 length,
- const base::Time& expected_modification_time) {
- elements_.push_back(Element());
- elements_.back().SetToFilePathRange(file_path, offset, length,
- expected_modification_time);
-}
-
-void ResourceRequestBody::AppendBlob(const GURL& blob_url) {
- elements_.push_back(Element());
- elements_.back().SetToBlobUrl(blob_url);
-}
-
-net::UploadData* ResourceRequestBody::CreateUploadData() {
- net::UploadData* upload_data = new net::UploadData;
- // We attach 'this' to UploadData so that we do not need to copy
- // bytes for TYPE_BYTES.
- upload_data->SetUserData(
- this, new base::UserDataAdapter<ResourceRequestBody>(this));
- std::vector<net::UploadElement>* uploads =
- upload_data->elements_mutable();
- for (size_t i = 0; i < elements_.size(); ++i) {
- const Element& element = elements_[i];
- if (element.type() == TYPE_BYTES) {
- uploads->push_back(net::UploadElement());
- uploads->back().SetToSharedBytes(element.bytes(),
- element.bytes_length());
- continue;
- }
-
- DCHECK(element.type() == TYPE_FILE);
- uploads->push_back(net::UploadElement());
- uploads->back().SetToFilePathRange(
- element.file_path(),
- element.file_range_offset(),
- element.file_range_length(),
- element.expected_file_modification_time());
- }
- upload_data->set_identifier(identifier_);
- return upload_data;
-}
-
-ResourceRequestBody::~ResourceRequestBody() {}
-
-} // namespace webkit_glue
diff --git a/webkit/glue/resource_request_body.h b/webkit/glue/resource_request_body.h
deleted file mode 100644
index 0b3ef0d..0000000
--- a/webkit/glue/resource_request_body.h
+++ /dev/null
@@ -1,181 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef WEBKIT_GLUE_RESOURCE_REQUEST_BODY_H_
-#define WEBKIT_GLUE_RESOURCE_REQUEST_BODY_H_
-
-#include <vector>
-
-#include "base/basictypes.h"
-#include "base/file_path.h"
-#include "base/memory/ref_counted.h"
-#include "base/supports_user_data.h"
-#include "base/time.h"
-#include "googleurl/src/gurl.h"
-#include "webkit/glue/webkit_glue_export.h"
-
-namespace net {
-class UploadData;
-}
-
-namespace webkit_glue {
-
-// A struct used to represent upload data. The data field is populated by
-// WebURLLoader from the data given as WebHTTPBody.
-// TODO(kinuko): This is basically a duplicate of net::UploadData but
-// with support for higher-level abstraction data. We should reduce the
-// code duplicate by sharing code for similar data structs:
-// ResourceRequestBody::Element and BlobData::Item.
-class WEBKIT_GLUE_EXPORT ResourceRequestBody
- : public base::RefCounted<ResourceRequestBody>,
- public base::SupportsUserData {
- public:
- enum Type {
- TYPE_BYTES,
- TYPE_FILE,
- TYPE_BLOB,
- };
-
- class WEBKIT_GLUE_EXPORT Element {
- public:
- Element();
- ~Element();
-
- Type type() const { return type_; }
- // Explicitly sets the type of this Element. Used during IPC
- // marshalling.
- void set_type(Type type) {
- type_ = type;
- }
-
- 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_; }
- // If NULL time is returned, we do not do the check.
- 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;
- 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) {
- SetToFilePathRange(path, 0, kuint64max, base::Time());
- }
-
- // If expected_modification_time is NULL, we do not check for the file
- // change. Also note that the granularity for comparison is time_t, not
- // the full precision.
- void SetToFilePathRange(const FilePath& path,
- uint64 offset, uint64 length,
- const base::Time& expected_modification_time) {
- type_ = TYPE_FILE;
- file_path_ = path;
- file_range_offset_ = offset;
- file_range_length_ = length;
- expected_file_modification_time_ = expected_modification_time;
- }
-
- void SetToBlobUrl(const GURL& blob_url) {
- type_ = TYPE_BLOB;
- blob_url_ = blob_url;
- }
-
- private:
- Type type_;
- 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_;
- };
-
- ResourceRequestBody();
-
- void AppendBytes(const char* bytes, int bytes_len);
- void AppendFileRange(const FilePath& file_path,
- uint64 offset, uint64 length,
- const base::Time& expected_modification_time);
- void AppendBlob(const GURL& blob_url);
-
- // Creates a new UploadData from this request body.
- // At this stage the elements should not contain any TYPE_BLOB items
- // (i.e. must have resolved them by ResolveBlobReferencesInUploadData).
- // TODO(kinuko): Clean up this hack.
- net::UploadData* CreateUploadData();
-
- const std::vector<Element>* elements() const {
- return &elements_;
- }
-
- std::vector<Element>* elements_mutable() {
- return &elements_;
- }
-
- void swap_elements(std::vector<Element>* elements) {
- elements_.swap(*elements);
- }
-
- // Identifies a particular upload instance, which is used by the cache to
- // formulate a cache key. This value should be unique across browser
- // sessions. A value of 0 is used to indicate an unspecified identifier.
- void set_identifier(int64 id) { identifier_ = id; }
- int64 identifier() const { return identifier_; }
-
- private:
- friend class base::RefCounted<ResourceRequestBody>;
- virtual ~ResourceRequestBody();
-
- std::vector<Element> elements_;
- int64 identifier_;
-
- DISALLOW_COPY_AND_ASSIGN(ResourceRequestBody);
-};
-
-#if defined(UNIT_TEST)
-inline bool operator==(const ResourceRequestBody::Element& a,
- const ResourceRequestBody::Element& b) {
- if (a.type() != b.type())
- return false;
- if (a.type() == ResourceRequestBody::TYPE_BYTES)
- return a.bytes_length() == b.bytes_length() &&
- memcmp(a.bytes(), b.bytes(), b.bytes_length()) == 0;
- if (a.type() == ResourceRequestBody::TYPE_FILE) {
- return a.file_path() == b.file_path() &&
- a.file_range_offset() == b.file_range_offset() &&
- a.file_range_length() == b.file_range_length() &&
- a.expected_file_modification_time() ==
- b.expected_file_modification_time();
- }
- if (a.type() == ResourceRequestBody::TYPE_BLOB)
- return a.blob_url() == b.blob_url();
- return false;
-}
-
-inline bool operator!=(const ResourceRequestBody::Element& a,
- const ResourceRequestBody::Element& b) {
- return !(a == b);
-}
-#endif // defined(UNIT_TEST)
-
-} // namespace webkit_glue
-
-#endif // WEBKIT_GLUE_RESOURCE_REQUEST_BODY_H_
diff --git a/webkit/glue/resource_request_body_unittest.cc b/webkit/glue/resource_request_body_unittest.cc
deleted file mode 100644
index 897eb56..0000000
--- a/webkit/glue/resource_request_body_unittest.cc
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "webkit/glue/resource_request_body.h"
-
-#include "base/file_path.h"
-#include "base/file_util.h"
-#include "base/time.h"
-#include "googleurl/src/gurl.h"
-#include "net/base/upload_data.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace webkit_glue {
-
-TEST(ResourceRequestBodyTest, CreateUploadDataTest) {
- scoped_refptr<ResourceRequestBody> request_body = new ResourceRequestBody;
-
- const char kData[] = "123";
- const FilePath::StringType kFilePath = FILE_PATH_LITERAL("abc");
- const uint64 kFileOffset = 10U;
- const uint64 kFileLength = 100U;
- const base::Time kFileTime = base::Time::FromDoubleT(999);
- const int64 kIdentifier = 12345;
-
- request_body->AppendBytes(kData, arraysize(kData) - 1);
- request_body->AppendFileRange(FilePath(kFilePath),
- kFileOffset, kFileLength, kFileTime);
- request_body->set_identifier(kIdentifier);
-
- scoped_refptr<net::UploadData> upload = request_body->CreateUploadData();
-
- EXPECT_EQ(kIdentifier, upload->identifier());
- ASSERT_EQ(request_body->elements()->size(), upload->elements()->size());
-
- const net::UploadElement& e1 = upload->elements()->at(0);
- EXPECT_EQ(net::UploadElement::TYPE_BYTES, e1.type());
- EXPECT_EQ(kData, std::string(e1.bytes(), e1.bytes_length()));
-
- const net::UploadElement& e2 = upload->elements()->at(1);
- EXPECT_EQ(net::UploadElement::TYPE_FILE, e2.type());
- EXPECT_EQ(kFilePath, e2.file_path().value());
- EXPECT_EQ(kFileOffset, e2.file_range_offset());
- EXPECT_EQ(kFileLength, e2.file_range_length());
- EXPECT_EQ(kFileTime, e2.expected_file_modification_time());
-}
-
-} // namespace webkit_glue
diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi
index fa06cbd..ab23ee8 100644
--- a/webkit/glue/webkit_glue.gypi
+++ b/webkit/glue/webkit_glue.gypi
@@ -378,8 +378,6 @@
'resource_fetcher.h',
'resource_loader_bridge.cc',
'resource_loader_bridge.h',
- 'resource_request_body.cc',
- 'resource_request_body.h',
'resource_type.cc',
'resource_type.h',
'scoped_clipboard_writer_glue.cc',
diff --git a/webkit/glue/weburlloader_impl.cc b/webkit/glue/weburlloader_impl.cc
index edc15424..104795d 100644
--- a/webkit/glue/weburlloader_impl.cc
+++ b/webkit/glue/weburlloader_impl.cc
@@ -32,7 +32,6 @@
#include "webkit/glue/ftp_directory_listing_response_delegate.h"
#include "webkit/glue/multipart_response_delegate.h"
#include "webkit/glue/resource_loader_bridge.h"
-#include "webkit/glue/resource_request_body.h"
#include "webkit/glue/webkit_glue.h"
#include "webkit/glue/webkitplatformsupport_impl.h"
#include "webkit/glue/weburlrequest_extradata_impl.h"
@@ -445,24 +444,22 @@ void WebURLLoaderImpl::Context::Start(
const WebHTTPBody& httpBody = request.httpBody();
size_t i = 0;
WebHTTPBody::Element element;
- scoped_refptr<ResourceRequestBody> request_body = new ResourceRequestBody;
while (httpBody.elementAt(i++, element)) {
switch (element.type) {
case WebHTTPBody::Element::TypeData:
if (!element.data.isEmpty()) {
// WebKit sometimes gives up empty data to append. These aren't
// necessary so we just optimize those out here.
- request_body->AppendBytes(
+ bridge_->AppendDataToUpload(
element.data.data(), static_cast<int>(element.data.size()));
}
break;
case WebHTTPBody::Element::TypeFile:
if (element.fileLength == -1) {
- request_body->AppendFileRange(
- WebStringToFilePath(element.filePath),
- 0, kuint64max, base::Time());
+ bridge_->AppendFileToUpload(
+ WebStringToFilePath(element.filePath));
} else {
- request_body->AppendFileRange(
+ bridge_->AppendFileRangeToUpload(
WebStringToFilePath(element.filePath),
static_cast<uint64>(element.fileStart),
static_cast<uint64>(element.fileLength),
@@ -470,14 +467,13 @@ void WebURLLoaderImpl::Context::Start(
}
break;
case WebHTTPBody::Element::TypeBlob:
- request_body->AppendBlob(GURL(element.blobURL));
+ bridge_->AppendBlobToUpload(GURL(element.blobURL));
break;
default:
NOTREACHED();
}
}
- request_body->set_identifier(request.httpBody().identifier());
- bridge_->SetRequestBody(request_body);
+ bridge_->SetUploadIdentifier(request.httpBody().identifier());
}
if (sync_load_response) {
diff --git a/webkit/tools/test_shell/simple_resource_loader_bridge.cc b/webkit/tools/test_shell/simple_resource_loader_bridge.cc
index 6af385a..e8caad4 100644
--- a/webkit/tools/test_shell/simple_resource_loader_bridge.cc
+++ b/webkit/tools/test_shell/simple_resource_loader_bridge.cc
@@ -68,7 +68,6 @@
#include "webkit/fileapi/file_system_dir_url_request_job.h"
#include "webkit/fileapi/file_system_url_request_job.h"
#include "webkit/glue/resource_loader_bridge.h"
-#include "webkit/glue/resource_request_body.h"
#include "webkit/glue/webkit_glue.h"
#include "webkit/tools/test_shell/simple_appcache_system.h"
#include "webkit/tools/test_shell/simple_file_system.h"
@@ -82,7 +81,6 @@
#endif
using webkit_glue::ResourceLoaderBridge;
-using webkit_glue::ResourceRequestBody;
using webkit_glue::ResourceResponseInfo;
using net::StaticCookiePolicy;
using net::HttpResponseHeaders;
@@ -281,7 +279,7 @@ struct RequestParams {
ResourceType::Type request_type;
int appcache_host_id;
bool download_to_file;
- scoped_refptr<ResourceRequestBody> request_body;
+ scoped_refptr<net::UploadData> upload;
};
// The interval for calls to RequestProxy::MaybeUpdateUploadProgress
@@ -417,10 +415,10 @@ class RequestProxy
void AsyncStart(RequestParams* params) {
// Might need to resolve the blob references in the upload data.
- if (params->request_body) {
+ if (params->upload) {
static_cast<TestShellRequestContext*>(g_request_context)->
- blob_storage_controller()->ResolveBlobReferencesInRequestBody(
- params->request_body.get());
+ blob_storage_controller()->ResolveBlobReferencesInUploadData(
+ params->upload.get());
}
request_.reset(new net::URLRequest(params->url, this, g_request_context));
@@ -433,8 +431,7 @@ class RequestProxy
headers.AddHeadersFromString(params->headers);
request_->SetExtraRequestHeaders(headers);
request_->set_load_flags(params->load_flags);
- if (params->request_body)
- request_->set_upload(params->request_body->CreateUploadData());
+ request_->set_upload(params->upload.get());
SimpleAppCacheSystem::SetExtraRequestInfo(
request_.get(), params->appcache_host_id, params->request_type);
@@ -877,10 +874,37 @@ class ResourceLoaderBridgeImpl : public ResourceLoaderBridge {
// --------------------------------------------------------------------------
// ResourceLoaderBridge implementation:
- virtual void SetRequestBody(ResourceRequestBody* request_body) {
+ virtual void AppendDataToUpload(const char* data, int data_len) {
DCHECK(params_.get());
- DCHECK(!params_->request_body);
- params_->request_body = request_body;
+ if (!params_->upload)
+ params_->upload = new net::UploadData();
+ params_->upload->AppendBytes(data, data_len);
+ }
+
+ virtual void AppendFileRangeToUpload(
+ const FilePath& file_path,
+ uint64 offset,
+ uint64 length,
+ const base::Time& expected_modification_time) {
+ DCHECK(params_.get());
+ if (!params_->upload)
+ params_->upload = new net::UploadData();
+ params_->upload->AppendFileRange(file_path, offset, length,
+ expected_modification_time);
+ }
+
+ virtual void AppendBlobToUpload(const GURL& blob_url) {
+ DCHECK(params_.get());
+ if (!params_->upload)
+ params_->upload = new net::UploadData();
+ params_->upload->AppendBlob(blob_url);
+ }
+
+ virtual void SetUploadIdentifier(int64 identifier) {
+ DCHECK(params_.get());
+ if (!params_->upload)
+ params_->upload = new net::UploadData();
+ params_->upload->set_identifier(identifier);
}
virtual bool Start(Peer* peer) {
diff --git a/webkit/tools/test_shell/test_shell.gypi b/webkit/tools/test_shell/test_shell.gypi
index 378cfd30..7a832b2 100644
--- a/webkit/tools/test_shell/test_shell.gypi
+++ b/webkit/tools/test_shell/test_shell.gypi
@@ -372,7 +372,6 @@
'../../glue/multipart_response_delegate_unittest.cc',
'../../glue/regular_expression_unittest.cc',
'../../glue/resource_fetcher_unittest.cc',
- '../../glue/resource_request_body_unittest.cc',
'../../glue/unittest_test_server.h',
'../../glue/webcursor_unittest.cc',
'../../glue/webkit_glue_unittest.cc',