| Index: webkit/glue/webupload_data.cc
|
| diff --git a/webkit/glue/webupload_data.cc b/webkit/glue/webupload_data.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..740c94a06d0f17507a42eb5a7238e6df4328c4a7
|
| --- /dev/null
|
| +++ b/webkit/glue/webupload_data.cc
|
| @@ -0,0 +1,66 @@
|
| +// 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/webupload_data.h"
|
| +
|
| +#include "base/logging.h"
|
| +#include "net/base/upload_data.h"
|
| +
|
| +WebUploadData::Element::Element()
|
| + : type_(TYPE_BYTES),
|
| + file_range_offset_(0),
|
| + file_range_length_(kuint64max) {
|
| +}
|
| +
|
| +WebUploadData::Element::~Element() {}
|
| +
|
| +WebUploadData::WebUploadData() : identifier_(0) {}
|
| +
|
| +void WebUploadData::AppendBytes(const char* bytes, int bytes_len) {
|
| + if (bytes_len > 0) {
|
| + elements_.push_back(Element());
|
| + elements_.back().SetToBytes(bytes, bytes_len);
|
| + }
|
| +}
|
| +
|
| +void WebUploadData::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 WebUploadData::AppendBlob(const GURL& blob_url) {
|
| + elements_.push_back(Element());
|
| + elements_.back().SetToBlobUrl(blob_url);
|
| +}
|
| +
|
| +void WebUploadData::PopulateUploadData(net::UploadData* upload_data) const {
|
| + DCHECK(upload_data);
|
| + DCHECK(!upload_data->is_chunked());
|
| + std::vector<net::UploadData::Element>* 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::UploadData::Element());
|
| + // TODO(kinuko): Avoid this data copy.
|
| + uploads->back().SetToBytes(element.bytes().data(),
|
| + element.bytes().size());
|
| + continue;
|
| + }
|
| +
|
| + DCHECK(element.type() == TYPE_FILE);
|
| + uploads->push_back(net::UploadData::Element());
|
| + uploads->back().SetToFilePathRange(
|
| + element.file_path(),
|
| + element.file_range_offset(),
|
| + element.file_range_length(),
|
| + element.expected_file_modification_time());
|
| + }
|
| +}
|
| +
|
| +WebUploadData::~WebUploadData() {}
|
|
|