diff options
author | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-21 13:57:42 +0000 |
---|---|---|
committer | kinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-21 13:57:42 +0000 |
commit | e3e402c11b05ae0562199543ca6a17e09bbab6b2 (patch) | |
tree | e6d1bf0123934b7580a302ae35467f3fd4c3ada6 /webkit/blob | |
parent | 4b88b74e5e7ccf857104b2212518c65940489699 (diff) | |
download | chromium_src-e3e402c11b05ae0562199543ca6a17e09bbab6b2.zip chromium_src-e3e402c11b05ae0562199543ca6a17e09bbab6b2.tar.gz chromium_src-e3e402c11b05ae0562199543ca6a17e09bbab6b2.tar.bz2 |
Split net::UploadData into two: for resource request IPC and for upload handling
Introducing webkit_glue::ResourceRequestBody as a content-level abstraction corresponding to WebHTTPBody and as an alternative of net::UploadData in ResourceRequest.
This interface can contain content-level objects like Blob (or FileSystem URL in later patches) while net::UploadData should NOT.
This patch also removes Blob support in net::UploadData.
BUG=110119
TEST=existing tests
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=152528
Review URL: https://chromiumcodereview.appspot.com/10834289
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152553 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/blob')
-rw-r--r-- | webkit/blob/blob_storage_controller.cc | 68 | ||||
-rw-r--r-- | webkit/blob/blob_storage_controller.h | 7 | ||||
-rw-r--r-- | webkit/blob/blob_storage_controller_unittest.cc | 160 |
3 files changed, 0 insertions, 235 deletions
diff --git a/webkit/blob/blob_storage_controller.cc b/webkit/blob/blob_storage_controller.cc index 6a10811..cf5534e 100644 --- a/webkit/blob/blob_storage_controller.cc +++ b/webkit/blob/blob_storage_controller.cc @@ -6,7 +6,6 @@ #include "base/logging.h" #include "googleurl/src/gurl.h" -#include "net/base/upload_data.h" #include "webkit/blob/blob_data.h" namespace webkit_blob { @@ -169,73 +168,6 @@ BlobData* BlobStorageController::GetBlobDataFromUrl(const GURL& url) { return (found != blob_map_.end()) ? found->second : NULL; } -void BlobStorageController::ResolveBlobReferencesInUploadData( - net::UploadData* upload_data) { - DCHECK(upload_data); - - 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() != net::UploadElement::TYPE_BLOB) { - iter++; - continue; - } - - // Find the referred blob data. - BlobData* blob_data = GetBlobDataFromUrl(iter->blob_url()); - DCHECK(blob_data); - if (!blob_data) { - // TODO(jianli): We should probably fail uploading the data - iter++; - continue; - } - - // Remove this element. - iter = uploads->erase(iter); - - // If there is no element in the referred blob data, continue the loop. - // Note that we should not increase iter since it already points to the one - // after the removed element. - if (blob_data->items().empty()) - continue; - - // Ensure the blob and any attached shareable files survive until - // upload completion. - 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, net::UploadElement()); - - const BlobData::Item& item = blob_data->items().at(i - 1); - switch (item.type) { - case BlobData::TYPE_DATA: - // 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; - case BlobData::TYPE_FILE: - iter->SetToFilePathRange( - item.file_path, - item.offset, - item.length, - item.expected_modification_time); - break; - default: - NOTREACHED(); - break; - } - } - } -} - void BlobStorageController::AppendStorageItems( BlobData* target_blob_data, BlobData* src_blob_data, uint64 offset, uint64 length) { diff --git a/webkit/blob/blob_storage_controller.h b/webkit/blob/blob_storage_controller.h index a32fab3..c464da4 100644 --- a/webkit/blob/blob_storage_controller.h +++ b/webkit/blob/blob_storage_controller.h @@ -20,9 +20,6 @@ class FilePath; namespace base { class Time; } -namespace net { -class UploadData; -} namespace webkit_blob { @@ -40,10 +37,6 @@ class BLOB_EXPORT BlobStorageController { void RemoveBlob(const GURL& url); BlobData* GetBlobDataFromUrl(const GURL& url); - // 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 ff98e22..ecd112b 100644 --- a/webkit/blob/blob_storage_controller_unittest.cc +++ b/webkit/blob/blob_storage_controller_unittest.cc @@ -6,13 +6,10 @@ #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" -using net::UploadData; - namespace webkit_blob { TEST(BlobStorageControllerTest, RegisterBlobUrl) { @@ -76,161 +73,4 @@ TEST(BlobStorageControllerTest, RegisterBlobUrl) { EXPECT_TRUE(!blob_data_found); } -TEST(BlobStorageControllerTest, ResolveBlobReferencesInUploadData) { - // Setup blob data for testing. - base::Time time1, time2; - base::Time::FromString("Tue, 15 Nov 1994, 12:45:26 GMT", &time1); - base::Time::FromString("Mon, 14 Nov 1994, 11:30:49 GMT", &time2); - - BlobStorageController blob_storage_controller; - scoped_refptr<BlobData> blob_data(new BlobData()); - - GURL blob_url0("blob://url_0"); - blob_storage_controller.AddFinishedBlob(blob_url0, blob_data); - - blob_data->AppendData("BlobData"); - blob_data->AppendFile( - FilePath(FILE_PATH_LITERAL("BlobFile.txt")), 0, 20, time1); - - GURL blob_url1("blob://url_1"); - blob_storage_controller.AddFinishedBlob(blob_url1, blob_data); - - GURL blob_url2("blob://url_2"); - blob_storage_controller.CloneBlob(blob_url2, blob_url1); - - GURL blob_url3("blob://url_3"); - blob_storage_controller.CloneBlob(blob_url3, blob_url2); - - // 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_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); - - 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<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.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. - upload_data = new UploadData(); - upload_data->AppendBlob(blob_url0); - - blob_storage_controller.ResolveBlobReferencesInUploadData(upload_data.get()); - ASSERT_EQ(upload_data->elements()->size(), 0U); - - // Test having only one blob reference. - upload_data = new UploadData(); - upload_data->AppendBlob(blob_url1); - - 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. - 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.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. - 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()); - upload_data->AppendBlob(blob_url1); - - 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. - 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.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. - 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.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 |