diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-23 14:32:43 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-23 14:32:43 +0000 |
commit | 9ff2b229efc1edb5497f018ad29f1233c2dd8061 (patch) | |
tree | 4444c57e41354c7f259547df8fba5bafe6a91bfc /webkit | |
parent | c6c43e39863b182ffffdda09cb07e11db2b62770 (diff) | |
download | chromium_src-9ff2b229efc1edb5497f018ad29f1233c2dd8061.zip chromium_src-9ff2b229efc1edb5497f018ad29f1233c2dd8061.tar.gz chromium_src-9ff2b229efc1edb5497f018ad29f1233c2dd8061.tar.bz2 |
Factor out common Element struct from BlobData and ResourceRequestBody
BUG=110119
TEST=none
Review URL: https://chromiumcodereview.appspot.com/10827414
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152987 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/base/data_element.cc | 38 | ||||
-rw-r--r-- | webkit/base/data_element.h | 116 | ||||
-rw-r--r-- | webkit/base/webkit_base.gypi | 32 | ||||
-rw-r--r-- | webkit/base/webkit_base_export.h | 29 | ||||
-rw-r--r-- | webkit/blob/blob_data.cc | 25 | ||||
-rw-r--r-- | webkit/blob/blob_data.h | 87 | ||||
-rw-r--r-- | webkit/blob/blob_storage_controller.cc | 55 | ||||
-rw-r--r-- | webkit/blob/blob_url_request_job.cc | 34 | ||||
-rw-r--r-- | webkit/blob/view_blob_internals_job.cc | 32 | ||||
-rw-r--r-- | webkit/blob/webkit_blob.gypi | 1 | ||||
-rw-r--r-- | webkit/glue/resource_request_body.cc | 50 | ||||
-rw-r--r-- | webkit/glue/resource_request_body.h | 121 | ||||
-rw-r--r-- | webkit/glue/resource_request_body_unittest.cc | 14 | ||||
-rw-r--r-- | webkit/glue/webkit_glue.gypi | 1 | ||||
-rw-r--r-- | webkit/support/webkit_support.gyp | 1 | ||||
-rw-r--r-- | webkit/support/webkit_support.gypi | 1 | ||||
-rw-r--r-- | webkit/tools/test_shell/simple_file_system.cc | 2 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell.gypi | 1 |
18 files changed, 322 insertions, 318 deletions
diff --git a/webkit/base/data_element.cc b/webkit/base/data_element.cc new file mode 100644 index 0000000..2e8fcf3 --- /dev/null +++ b/webkit/base/data_element.cc @@ -0,0 +1,38 @@ +// 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/base/data_element.h" + +namespace webkit_base { + +DataElement::DataElement() + : type_(TYPE_UNKNOWN), + bytes_(NULL), + offset_(0), + length_(kuint64max) { +} + +DataElement::~DataElement() {} + +void DataElement::SetToFilePathRange( + const FilePath& path, + uint64 offset, uint64 length, + const base::Time& expected_modification_time) { + type_ = TYPE_FILE; + path_ = path; + offset_ = offset; + length_ = length; + expected_modification_time_ = expected_modification_time; +} + +void DataElement::SetToBlobUrlRange( + const GURL& blob_url, + uint64 offset, uint64 length) { + type_ = TYPE_BLOB; + url_ = blob_url; + offset_ = offset; + length_ = length; +} + +} // webkit_base diff --git a/webkit/base/data_element.h b/webkit/base/data_element.h new file mode 100644 index 0000000..61737e6 --- /dev/null +++ b/webkit/base/data_element.h @@ -0,0 +1,116 @@ +// 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_BASE_DATA_ELEMENT_H_ +#define WEBKIT_BASE_DATA_ELEMENT_H_ + +#include <vector> + +#include "base/basictypes.h" +#include "base/file_path.h" +#include "base/logging.h" +#include "base/time.h" +#include "googleurl/src/gurl.h" +#include "webkit/base/webkit_base_export.h" + +namespace webkit_base { + +// Represents a base Web data element. This could be either one of +// bytes, file or blob data. +class WEBKIT_BASE_EXPORT DataElement { + public: + enum Type { + TYPE_UNKNOWN = -1, + TYPE_BYTES, + TYPE_FILE, + TYPE_BLOB, + }; + + DataElement(); + ~DataElement(); + + Type type() const { return type_; } + const char* bytes() const { return bytes_ ? bytes_ : &buf_[0]; } + const FilePath& path() const { return path_; } + const GURL& url() const { return url_; } + uint64 offset() const { return offset_; } + uint64 length() const { return length_; } + const base::Time& expected_modification_time() const { + return expected_modification_time_; + } + + // Sets TYPE_BYTES data. This copies the given data into the element. + void SetToBytes(const char* bytes, int bytes_len) { + type_ = TYPE_BYTES; + buf_.assign(bytes, bytes + bytes_len); + length_ = buf_.size(); + } + + // Sets TYPE_BYTES data. This does NOT copy the given data and the caller + // should make sure the data is alive when this element is accessed. + void SetToSharedBytes(const char* bytes, int bytes_len) { + type_ = TYPE_BYTES; + bytes_ = bytes; + length_ = bytes_len; + } + + // Sets TYPE_FILE data. + void SetToFilePath(const FilePath& path) { + SetToFilePathRange(path, 0, kuint64max, base::Time()); + } + + // Sets TYPE_BLOB data. + void SetToBlobUrl(const GURL& blob_url) { + SetToBlobUrlRange(blob_url, 0, kuint64max); + } + + // Sets TYPE_FILE data with range. + void SetToFilePathRange(const FilePath& path, + uint64 offset, uint64 length, + const base::Time& expected_modification_time); + + // Sets TYPE_BLOB data with range. + void SetToBlobUrlRange(const GURL& blob_url, + uint64 offset, uint64 length); + + private: + Type type_; + std::vector<char> buf_; + const char* bytes_; + FilePath path_; + GURL url_; + uint64 offset_; + uint64 length_; + base::Time expected_modification_time_; +}; + +#if defined(UNIT_TEST) +inline bool operator==(const DataElement& a, const DataElement& b) { + if (a.type() != b.type() || + a.offset() != b.offset() || + a.length() != b.length()) + return false; + switch (a.type()) { + case DataElement::TYPE_BYTES: + return memcmp(a.bytes(), b.bytes(), b.length()) == 0; + case DataElement::TYPE_FILE: + return a.path() == b.path() && + a.expected_modification_time() == b.expected_modification_time(); + case DataElement::TYPE_BLOB: + return a.url() == b.url(); + case DataElement::TYPE_UNKNOWN: + NOTREACHED(); + return false; + } + return false; +} + +inline bool operator!=(const DataElement& a, const DataElement& b) { + return !(a == b); +} +#endif // defined(UNIT_TEST) + +} // namespace webkit_base + +#endif // WEBKIT_BASE_DATA_ELEMENT_H_ diff --git a/webkit/base/webkit_base.gypi b/webkit/base/webkit_base.gypi new file mode 100644 index 0000000..cf10301 --- /dev/null +++ b/webkit/base/webkit_base.gypi @@ -0,0 +1,32 @@ +# 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. + +{ + 'targets': [ + { + 'target_name': 'webkit_base', + 'type': '<(component)', + 'variables': { 'enable_wexit_time_destructors': 1, }, + 'dependencies': [ + '<(DEPTH)/base/base.gyp:base', + '<(DEPTH)/build/temp_gyp/googleurl.gyp:googleurl', + '<(DEPTH)/net/net.gyp:net', + '<(webkit_src_dir)/Source/WebKit/chromium/WebKit.gyp:webkit', + ], + 'defines': ['WEBKIT_BASE_IMPLEMENTATION'], + 'sources': [ + 'data_element.cc', + 'data_element.h', + 'webkit_base_export.h', + ], + 'conditions': [ + ['inside_chromium_build==0', { + 'dependencies': [ + '<(DEPTH)/webkit/support/setup_third_party.gyp:third_party_headers', + ], + }], + ], + }, + ], +} diff --git a/webkit/base/webkit_base_export.h b/webkit/base/webkit_base_export.h new file mode 100644 index 0000000..2c452ac --- /dev/null +++ b/webkit/base/webkit_base_export.h @@ -0,0 +1,29 @@ +// 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_BASE_WEBKIT_BASE_EXPORT_H_ +#define WEBKIT_BASE_WEBKIT_BASE_EXPORT_H_ + +#if defined(COMPONENT_BUILD) +#if defined(WIN32) + +#if defined(WEBKIT_BASE_IMPLEMENTATION) +#define WEBKIT_BASE_EXPORT __declspec(dllexport) +#else +#define WEBKIT_BASE_EXPORT __declspec(dllimport) +#endif // defined(WEBKIT_BASE_IMPLEMENTATION) + +#else // defined(WIN32) +#if defined(WEBKIT_BASE_IMPLEMENTATION) +#define WEBKIT_BASE_EXPORT __attribute__((visibility("default"))) +#else +#define WEBKIT_BASE_EXPORT +#endif +#endif + +#else // defined(COMPONENT_BUILD) +#define WEBKIT_BASE_EXPORT +#endif + +#endif // WEBKIT_BASE_WEBKIT_BASE_EXPORT_H_ diff --git a/webkit/blob/blob_data.cc b/webkit/blob/blob_data.cc index 8947367..e000ee2 100644 --- a/webkit/blob/blob_data.cc +++ b/webkit/blob/blob_data.cc @@ -11,15 +11,6 @@ namespace webkit_blob { -BlobData::Item::Item() - : type(TYPE_DATA), - data_external(NULL), - offset(0), - length(0) { -} - -BlobData::Item::~Item() {} - BlobData::BlobData() {} BlobData::~BlobData() {} @@ -27,30 +18,30 @@ BlobData::~BlobData() {} void BlobData::AppendData(const char* data, size_t length) { DCHECK(length > 0); items_.push_back(Item()); - items_.back().SetToData(data, length); + items_.back().SetToBytes(data, length); } -void BlobData::AppendFile(const FilePath& file_path, uint64 offset, - uint64 length, +void BlobData::AppendFile(const FilePath& file_path, + uint64 offset, uint64 length, const base::Time& expected_modification_time) { DCHECK(length > 0); items_.push_back(Item()); - items_.back().SetToFile(file_path, offset, length, - expected_modification_time); + items_.back().SetToFilePathRange(file_path, offset, length, + expected_modification_time); } void BlobData::AppendBlob(const GURL& blob_url, uint64 offset, uint64 length) { DCHECK(length > 0); items_.push_back(Item()); - items_.back().SetToBlob(blob_url, offset, length); + items_.back().SetToBlobUrlRange(blob_url, offset, length); } int64 BlobData::GetMemoryUsage() const { int64 memory = 0; for (std::vector<Item>::const_iterator iter = items_.begin(); iter != items_.end(); ++iter) { - if (iter->type == TYPE_DATA) - memory += iter->data.size(); + if (iter->type() == Item::TYPE_BYTES) + memory += iter->length(); } return memory; } diff --git a/webkit/blob/blob_data.h b/webkit/blob/blob_data.h index 9599394..63947f4 100644 --- a/webkit/blob/blob_data.h +++ b/webkit/blob/blob_data.h @@ -14,69 +14,13 @@ #include "googleurl/src/gurl.h" #include "webkit/blob/blob_export.h" #include "webkit/blob/shareable_file_reference.h" - -namespace WebKit { -class WebBlobData; -} +#include "webkit/base/data_element.h" namespace webkit_blob { class BLOB_EXPORT BlobData : public base::RefCounted<BlobData> { public: - enum Type { - TYPE_DATA, - TYPE_DATA_EXTERNAL, - TYPE_FILE, - TYPE_BLOB - }; - - struct BLOB_EXPORT Item { - Item(); - ~Item(); - - void SetToData(const std::string& data) { - SetToData(data.c_str(), data.size()); - } - - void SetToData(const char* data, size_t length) { - type = TYPE_DATA; - this->data.assign(data, length); - this->offset = 0; - this->length = length; - } - - void SetToDataExternal(const char* data, size_t length) { - type = TYPE_DATA_EXTERNAL; - this->data_external = data; - this->offset = 0; - this->length = length; - } - - void SetToFile(const FilePath& file_path, uint64 offset, uint64 length, - const base::Time& expected_modification_time) { - type = TYPE_FILE; - this->file_path = file_path; - this->offset = offset; - this->length = length; - this->expected_modification_time = expected_modification_time; - } - - void SetToBlob(const GURL& blob_url, uint64 offset, uint64 length) { - type = TYPE_BLOB; - this->blob_url = blob_url; - this->offset = offset; - this->length = length; - } - - Type type; - std::string data; // For Data type. - const char* data_external; // For DataExternal type. - GURL blob_url; // For Blob type. - FilePath file_path; // For File type. - base::Time expected_modification_time; // Also for File type. - uint64 offset; - uint64 length; - }; + typedef webkit_base::DataElement Item; BlobData(); @@ -113,7 +57,6 @@ class BLOB_EXPORT BlobData : public base::RefCounted<BlobData> { private: friend class base::RefCounted<BlobData>; - virtual ~BlobData(); std::string content_type_; @@ -125,32 +68,6 @@ class BLOB_EXPORT BlobData : public base::RefCounted<BlobData> { }; #if defined(UNIT_TEST) -inline bool operator==(const BlobData::Item& a, const BlobData::Item& b) { - if (a.type != b.type) - return false; - if (a.type == BlobData::TYPE_DATA) { - return a.data == b.data && - a.offset == b.offset && - a.length == b.length; - } - if (a.type == BlobData::TYPE_FILE) { - return a.file_path == b.file_path && - a.offset == b.offset && - a.length == b.length && - a.expected_modification_time == b.expected_modification_time; - } - if (a.type == BlobData::TYPE_BLOB) { - return a.blob_url == b.blob_url && - a.offset == b.offset && - a.length == b.length; - } - return false; -} - -inline bool operator!=(const BlobData::Item& a, const BlobData::Item& b) { - return !(a == b); -} - inline bool operator==(const BlobData& a, const BlobData& b) { if (a.content_type() != b.content_type()) return false; diff --git a/webkit/blob/blob_storage_controller.cc b/webkit/blob/blob_storage_controller.cc index cf5534e..1092248 100644 --- a/webkit/blob/blob_storage_controller.cc +++ b/webkit/blob/blob_storage_controller.cc @@ -67,32 +67,31 @@ void BlobStorageController::AppendBlobDataItem( // All the Blob items in the passing blob data are resolved and expanded into // a set of Data and File items. - DCHECK(item.length > 0); - switch (item.type) { - case BlobData::TYPE_DATA: - // WebBlobData does not allow partial data. - DCHECK(!(item.offset) && item.length == item.data.size()); - target_blob_data->AppendData(item.data.c_str(), item.data.size()); + DCHECK(item.length() > 0); + switch (item.type()) { + case BlobData::Item::TYPE_BYTES: + DCHECK(!item.offset()); + target_blob_data->AppendData(item.bytes(), item.length()); break; - case BlobData::TYPE_DATA_EXTERNAL: - DCHECK(!item.offset); - target_blob_data->AppendData(item.data_external, item.length); - break; - case BlobData::TYPE_FILE: + case BlobData::Item::TYPE_FILE: AppendFileItem(target_blob_data, - item.file_path, - item.offset, - item.length, - item.expected_modification_time); + item.path(), + item.offset(), + item.length(), + item.expected_modification_time()); break; - case BlobData::TYPE_BLOB: - BlobData* src_blob_data = GetBlobDataFromUrl(item.blob_url); + case BlobData::Item::TYPE_BLOB: { + BlobData* src_blob_data = GetBlobDataFromUrl(item.url()); DCHECK(src_blob_data); if (src_blob_data) AppendStorageItems(target_blob_data, src_blob_data, - item.offset, - item.length); + item.offset(), + item.length()); + break; + } + default: + NOTREACHED(); break; } @@ -178,27 +177,27 @@ void BlobStorageController::AppendStorageItems( src_blob_data->items().begin(); if (offset) { for (; iter != src_blob_data->items().end(); ++iter) { - if (offset >= iter->length) - offset -= iter->length; + if (offset >= iter->length()) + offset -= iter->length(); else break; } } for (; iter != src_blob_data->items().end() && length > 0; ++iter) { - uint64 current_length = iter->length - offset; + uint64 current_length = iter->length() - offset; uint64 new_length = current_length > length ? length : current_length; - if (iter->type == BlobData::TYPE_DATA) { + if (iter->type() == BlobData::Item::TYPE_BYTES) { target_blob_data->AppendData( - iter->data.c_str() + static_cast<size_t>(iter->offset + offset), + iter->bytes() + static_cast<size_t>(iter->offset() + offset), static_cast<uint32>(new_length)); } else { - DCHECK(iter->type == BlobData::TYPE_FILE); + DCHECK(iter->type() == BlobData::Item::TYPE_FILE); AppendFileItem(target_blob_data, - iter->file_path, - iter->offset + offset, + iter->path(), + iter->offset() + offset, new_length, - iter->expected_modification_time); + iter->expected_modification_time()); } length -= new_length; offset = 0; diff --git a/webkit/blob/blob_url_request_job.cc b/webkit/blob/blob_url_request_job.cc index 80e382b..edda7fc 100644 --- a/webkit/blob/blob_url_request_job.cc +++ b/webkit/blob/blob_url_request_job.cc @@ -176,7 +176,7 @@ void BlobURLRequestJob::CountSize() { for (size_t i = 0; i < blob_data_->items().size(); ++i) { const BlobData::Item& item = blob_data_->items().at(i); - if (item.type == BlobData::TYPE_FILE) { + if (item.type() == BlobData::Item::TYPE_FILE) { ++pending_get_file_info_count_; GetFileStreamReader(i)->GetLength( base::Bind(&BlobURLRequestJob::DidGetFileItemLength, @@ -184,7 +184,7 @@ void BlobURLRequestJob::CountSize() { continue; } // Cache the size and add it to the total size. - int64 item_length = static_cast<int64>(item.length); + int64 item_length = static_cast<int64>(item.length()); item_length_list_[i] = item_length; total_size_ += item_length; } @@ -234,13 +234,13 @@ void BlobURLRequestJob::DidGetFileItemLength(size_t index, int64 result) { DCHECK_LT(index, blob_data_->items().size()); const BlobData::Item& item = blob_data_->items().at(index); - DCHECK(item.type == BlobData::TYPE_FILE); + DCHECK(item.type() == BlobData::Item::TYPE_FILE); // If item length is -1, we need to use the file size being resolved // in the real time. - int64 item_length = static_cast<int64>(item.length); + int64 item_length = static_cast<int64>(item.length()); if (item_length == -1) - item_length = result - item.offset; + item_length = result - item.offset(); // Cache the size and add it to the total size. DCHECK_LT(index, item_length_list_.size()); @@ -268,13 +268,13 @@ void BlobURLRequestJob::Seek(int64 offset) { // Adjust the offset of the first stream if it is of file type. const BlobData::Item& item = blob_data_->items().at(current_item_index_); - if (item.type == BlobData::TYPE_FILE) { + if (item.type() == BlobData::Item::TYPE_FILE) { DeleteCurrentFileReader(); index_to_reader_[current_item_index_] = new LocalFileStreamReader( file_thread_proxy_, - item.file_path, - item.offset + offset, - item.expected_modification_time); + item.path(), + item.offset() + offset, + item.expected_modification_time()); } } @@ -301,10 +301,10 @@ bool BlobURLRequestJob::ReadItem() { // Do the reading. const BlobData::Item& item = blob_data_->items().at(current_item_index_); - switch (item.type) { - case BlobData::TYPE_DATA: + switch (item.type()) { + case BlobData::Item::TYPE_BYTES: return ReadBytesItem(item, bytes_to_read); - case BlobData::TYPE_FILE: + case BlobData::Item::TYPE_FILE: return ReadFileItem(GetFileStreamReader(current_item_index_), bytes_to_read); default: @@ -344,7 +344,7 @@ bool BlobURLRequestJob::ReadBytesItem(const BlobData::Item& item, DCHECK_GE(read_buf_->BytesRemaining(), bytes_to_read); memcpy(read_buf_->data(), - &item.data.at(0) + item.offset + current_item_offset_, + item.bytes() + item.offset() + current_item_offset_, bytes_to_read); AdvanceBytesRead(bytes_to_read); @@ -527,14 +527,14 @@ void BlobURLRequestJob::HeadersCompleted(int status_code, LocalFileStreamReader* BlobURLRequestJob::GetFileStreamReader(size_t index) { DCHECK_LT(index, blob_data_->items().size()); const BlobData::Item& item = blob_data_->items().at(index); - if (item.type != BlobData::TYPE_FILE) + if (item.type() != BlobData::Item::TYPE_FILE) return NULL; if (index_to_reader_.find(index) == index_to_reader_.end()) { index_to_reader_[index] = new LocalFileStreamReader( file_thread_proxy_, - item.file_path, - item.offset, - item.expected_modification_time); + item.path(), + item.offset(), + item.expected_modification_time()); } DCHECK(index_to_reader_[index]); return index_to_reader_[index]; diff --git a/webkit/blob/view_blob_internals_job.cc b/webkit/blob/view_blob_internals_job.cc index e5eb6aa..03029ef 100644 --- a/webkit/blob/view_blob_internals_job.cc +++ b/webkit/blob/view_blob_internals_job.cc @@ -194,38 +194,36 @@ void ViewBlobInternalsJob::GenerateHTMLForBlobData(const BlobData& blob_data, } const BlobData::Item& item = blob_data.items().at(i); - switch (item.type) { - case BlobData::TYPE_DATA: - case BlobData::TYPE_DATA_EXTERNAL: + switch (item.type()) { + case BlobData::Item::TYPE_BYTES: AddHTMLListItem(kType, "data", out); break; - case BlobData::TYPE_FILE: + case BlobData::Item::TYPE_FILE: AddHTMLListItem(kType, "file", out); AddHTMLListItem(kPath, -#if defined(OS_WIN) - net::EscapeForHTML(WideToUTF8(item.file_path.value())), -#else - net::EscapeForHTML(item.file_path.value()), -#endif + net::EscapeForHTML(item.path().AsUTF8Unsafe()), out); - if (!item.expected_modification_time.is_null()) { + if (!item.expected_modification_time().is_null()) { AddHTMLListItem(kModificationTime, UTF16ToUTF8( - TimeFormatFriendlyDateAndTime(item.expected_modification_time)), + TimeFormatFriendlyDateAndTime(item.expected_modification_time())), out); } break; - case BlobData::TYPE_BLOB: + case BlobData::Item::TYPE_BLOB: AddHTMLListItem(kType, "blob", out); - AddHTMLListItem(kURL, item.blob_url.spec(), out); + AddHTMLListItem(kURL, item.url().spec(), out); + break; + case BlobData::Item::TYPE_UNKNOWN: + NOTREACHED(); break; } - if (item.offset) { + if (item.offset()) { AddHTMLListItem(kOffset, UTF16ToUTF8(base::FormatNumber( - static_cast<int64>(item.offset))), out); + static_cast<int64>(item.offset()))), out); } - if (static_cast<int64>(item.length) != -1) { + if (static_cast<int64>(item.length()) != -1) { AddHTMLListItem(kLength, UTF16ToUTF8(base::FormatNumber( - static_cast<int64>(item.length))), out); + static_cast<int64>(item.length()))), out); } if (has_multi_items) diff --git a/webkit/blob/webkit_blob.gypi b/webkit/blob/webkit_blob.gypi index a956305..0e786c4 100644 --- a/webkit/blob/webkit_blob.gypi +++ b/webkit/blob/webkit_blob.gypi @@ -23,6 +23,7 @@ '<(DEPTH)/base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations', '<(DEPTH)/build/temp_gyp/googleurl.gyp:googleurl', '<(DEPTH)/net/net.gyp:net', + '<(DEPTH)/webkit/support/webkit_support.gyp:webkit_base', '<(webkit_src_dir)/Source/WebKit/chromium/WebKit.gyp:webkit', ], 'defines': [ diff --git a/webkit/glue/resource_request_body.cc b/webkit/glue/resource_request_body.cc index 502590d..94ff258 100644 --- a/webkit/glue/resource_request_body.cc +++ b/webkit/glue/resource_request_body.cc @@ -13,16 +13,6 @@ using webkit_blob::BlobStorageController; 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) { @@ -58,21 +48,23 @@ net::UploadData* ResourceRequestBody::ResolveElementsAndCreateUploadData( for (size_t i = 0; i < elements_.size(); ++i) { const Element& element = elements_[i]; switch (element.type()) { - case TYPE_BYTES: + case Element::TYPE_BYTES: elements->push_back(net::UploadElement()); - elements->back().SetToSharedBytes(element.bytes(), - element.bytes_length()); + elements->back().SetToSharedBytes(element.bytes(), element.length()); break; - case TYPE_FILE: + case Element::TYPE_FILE: elements->push_back(net::UploadElement()); elements->back().SetToFilePathRange( - element.file_path(), - element.file_range_offset(), - element.file_range_length(), - element.expected_file_modification_time()); + element.path(), + element.offset(), + element.length(), + element.expected_modification_time()); break; - case TYPE_BLOB: - ResolveBlobReference(blob_controller, element.blob_url(), elements); + case Element::TYPE_BLOB: + ResolveBlobReference(blob_controller, element.url(), elements); + break; + case Element::TYPE_UNKNOWN: + NOTREACHED(); break; } } @@ -104,18 +96,18 @@ void ResourceRequestBody::ResolveBlobReference( elements->push_back(net::UploadElement()); net::UploadElement& element = elements->back(); const BlobData::Item& item = blob_data->items().at(i); - switch (item.type) { - case BlobData::TYPE_DATA: + switch (item.type()) { + case BlobData::Item::TYPE_BYTES: element.SetToSharedBytes( - &item.data.at(0) + static_cast<int>(item.offset), - static_cast<int>(item.length)); + item.bytes() + static_cast<int>(item.offset()), + static_cast<int>(item.length())); break; - case BlobData::TYPE_FILE: + case BlobData::Item::TYPE_FILE: element.SetToFilePathRange( - item.file_path, - item.offset, - item.length, - item.expected_modification_time); + item.path(), + item.offset(), + item.length(), + item.expected_modification_time()); break; default: NOTREACHED(); diff --git a/webkit/glue/resource_request_body.h b/webkit/glue/resource_request_body.h index cddd496..ad98889 100644 --- a/webkit/glue/resource_request_body.h +++ b/webkit/glue/resource_request_body.h @@ -8,11 +8,9 @@ #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/base/data_element.h" #include "webkit/glue/webkit_glue_export.h" namespace net { @@ -28,90 +26,11 @@ 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_; - }; + typedef webkit_base::DataElement Element; ResourceRequestBody(); @@ -127,14 +46,8 @@ class WEBKIT_GLUE_EXPORT ResourceRequestBody net::UploadData* ResolveElementsAndCreateUploadData( webkit_blob::BlobStorageController* blob_controller); - const std::vector<Element>* elements() const { - return &elements_; - } - - std::vector<Element>* elements_mutable() { - return &elements_; - } - + 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); } @@ -161,32 +74,6 @@ class WEBKIT_GLUE_EXPORT ResourceRequestBody 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 index 28c6e80..269067e 100644 --- a/webkit/glue/resource_request_body_unittest.cc +++ b/webkit/glue/resource_request_body_unittest.cc @@ -78,14 +78,14 @@ TEST(ResourceRequestBodyTest, ResolveBlobAndCreateUploadData) { // Setup upload data elements for comparison. 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), - static_cast<int>(blob_data->items().at(0).length)); + blob_data->items().at(0).bytes() + + static_cast<int>(blob_data->items().at(0).offset()), + static_cast<int>(blob_data->items().at(0).length())); blob_element2.SetToFilePathRange( - blob_data->items().at(1).file_path, - blob_data->items().at(1).offset, - blob_data->items().at(1).length, - blob_data->items().at(1).expected_modification_time); + blob_data->items().at(1).path(), + blob_data->items().at(1).offset(), + blob_data->items().at(1).length(), + blob_data->items().at(1).expected_modification_time()); net::UploadElement upload_element1, upload_element2; upload_element1.SetToBytes("Hello", 5); diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi index f7b6bed..ab78eac 100644 --- a/webkit/glue/webkit_glue.gypi +++ b/webkit/glue/webkit_glue.gypi @@ -142,6 +142,7 @@ '<(webkit_src_dir)/Source/WebKit/chromium/WebKit.gyp:webkit', 'blob', 'fileapi', + 'webkit_base', 'webkit_media', 'webkit_resources', 'webkit_strings', diff --git a/webkit/support/webkit_support.gyp b/webkit/support/webkit_support.gyp index 75ed698..a6d3e3b 100644 --- a/webkit/support/webkit_support.gyp +++ b/webkit/support/webkit_support.gyp @@ -6,6 +6,7 @@ 'includes': [ '../../build/win_precompile.gypi', '../appcache/webkit_appcache.gypi', + '../base/webkit_base.gypi', '../blob/webkit_blob.gypi', '../database/webkit_database.gypi', '../dom_storage/webkit_dom_storage.gypi', diff --git a/webkit/support/webkit_support.gypi b/webkit/support/webkit_support.gypi index 0630d08..3dbb472 100644 --- a/webkit/support/webkit_support.gypi +++ b/webkit/support/webkit_support.gypi @@ -24,6 +24,7 @@ 'dom_storage', 'fileapi', 'glue', + 'webkit_base', 'webkit_gpu', 'webkit_media', 'webkit_support_common', diff --git a/webkit/tools/test_shell/simple_file_system.cc b/webkit/tools/test_shell/simple_file_system.cc index 9272001..cc33249 100644 --- a/webkit/tools/test_shell/simple_file_system.cc +++ b/webkit/tools/test_shell/simple_file_system.cc @@ -65,7 +65,7 @@ void RegisterBlob(const GURL& blob_url, const FilePath& file_path) { net::GetWellKnownMimeTypeFromExtension(extension, &mime_type); BlobData::Item item; - item.SetToFile(file_path, 0, -1, base::Time()); + item.SetToFilePathRange(file_path, 0, -1, base::Time()); g_blob_storage_controller->StartBuildingBlob(blob_url); g_blob_storage_controller->AppendBlobDataItem(blob_url, item); g_blob_storage_controller->FinishBuildingBlob(blob_url, mime_type); diff --git a/webkit/tools/test_shell/test_shell.gypi b/webkit/tools/test_shell/test_shell.gypi index 378cfd30..b1c17d7 100644 --- a/webkit/tools/test_shell/test_shell.gypi +++ b/webkit/tools/test_shell/test_shell.gypi @@ -54,6 +54,7 @@ '<(DEPTH)/webkit/support/webkit_support.gyp:fileapi', '<(DEPTH)/webkit/support/webkit_support.gyp:glue', '<(DEPTH)/webkit/support/webkit_support.gyp:quota', + '<(DEPTH)/webkit/support/webkit_support.gyp:webkit_base', '<(DEPTH)/webkit/support/webkit_support.gyp:webkit_gpu', '<(DEPTH)/webkit/support/webkit_support.gyp:webkit_media', '<(DEPTH)/webkit/support/webkit_support.gyp:webkit_resources', |