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/blob | |
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/blob')
-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 |
6 files changed, 70 insertions, 164 deletions
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': [ |