diff --git a/chrome/browser/chromeos/drive/fileapi/async_file_util.cc b/chrome/browser/chromeos/drive/fileapi/async_file_util.cc index fa80c0ac1e8fed..9adf7871e25c3c 100644 --- a/chrome/browser/chromeos/drive/fileapi/async_file_util.cc +++ b/chrome/browser/chromeos/drive/fileapi/async_file_util.cc @@ -13,9 +13,9 @@ #include "chrome/browser/chromeos/drive/fileapi/fileapi_worker.h" #include "content/public/browser/browser_thread.h" #include "google_apis/drive/task_util.h" +#include "storage/browser/blob/shareable_file_reference.h" #include "storage/browser/fileapi/file_system_operation_context.h" #include "storage/browser/fileapi/file_system_url.h" -#include "storage/common/blob/shareable_file_reference.h" using content::BrowserThread; diff --git a/chrome/browser/chromeos/drive/fileapi/fileapi_worker.h b/chrome/browser/chromeos/drive/fileapi/fileapi_worker.h index 4edbd44b4a12cd..e6d620578b93bb 100644 --- a/chrome/browser/chromeos/drive/fileapi/fileapi_worker.h +++ b/chrome/browser/chromeos/drive/fileapi/fileapi_worker.h @@ -25,7 +25,7 @@ #include "base/callback_forward.h" #include "base/memory/weak_ptr.h" #include "chrome/browser/chromeos/drive/file_errors.h" -#include "storage/common/blob/scoped_file.h" +#include "storage/browser/blob/scoped_file.h" namespace base { class FilePath; diff --git a/chrome/browser/chromeos/file_manager/snapshot_manager.cc b/chrome/browser/chromeos/file_manager/snapshot_manager.cc index d25c7a9f8d8519..5ebb08a98be0ed 100644 --- a/chrome/browser/chromeos/file_manager/snapshot_manager.cc +++ b/chrome/browser/chromeos/file_manager/snapshot_manager.cc @@ -11,8 +11,8 @@ #include "chrome/browser/profiles/profile.h" #include "content/public/browser/browser_thread.h" #include "google_apis/drive/task_util.h" +#include "storage/browser/blob/shareable_file_reference.h" #include "storage/browser/fileapi/file_system_context.h" -#include "storage/common/blob/shareable_file_reference.h" #include "third_party/cros_system_api/constants/cryptohome.h" namespace file_manager { diff --git a/chrome/browser/chromeos/file_system_provider/fileapi/provider_async_file_util.cc b/chrome/browser/chromeos/file_system_provider/fileapi/provider_async_file_util.cc index 6fa910873e1e7b..7ef074a3381195 100644 --- a/chrome/browser/chromeos/file_system_provider/fileapi/provider_async_file_util.cc +++ b/chrome/browser/chromeos/file_system_provider/fileapi/provider_async_file_util.cc @@ -11,9 +11,9 @@ #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" #include "chrome/browser/chromeos/file_system_provider/provided_file_system_interface.h" #include "content/public/browser/browser_thread.h" +#include "storage/browser/blob/shareable_file_reference.h" #include "storage/browser/fileapi/file_system_operation_context.h" #include "storage/browser/fileapi/file_system_url.h" -#include "storage/common/blob/shareable_file_reference.h" using content::BrowserThread; diff --git a/chrome/browser/chromeos/file_system_provider/fileapi/provider_async_file_util_unittest.cc b/chrome/browser/chromeos/file_system_provider/fileapi/provider_async_file_util_unittest.cc index 7015bf15f21c27..f3789cf21d6870 100644 --- a/chrome/browser/chromeos/file_system_provider/fileapi/provider_async_file_util_unittest.cc +++ b/chrome/browser/chromeos/file_system_provider/fileapi/provider_async_file_util_unittest.cc @@ -22,11 +22,11 @@ #include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_file_system_context.h" #include "extensions/browser/extension_registry.h" +#include "storage/browser/blob/shareable_file_reference.h" #include "storage/browser/fileapi/async_file_util.h" #include "storage/browser/fileapi/external_mount_points.h" #include "storage/browser/fileapi/file_system_context.h" #include "storage/browser/fileapi/file_system_url.h" -#include "storage/common/blob/shareable_file_reference.h" #include "testing/gtest/include/gtest/gtest.h" namespace chromeos { diff --git a/chrome/browser/extensions/api/developer_private/developer_private_api.cc b/chrome/browser/extensions/api/developer_private/developer_private_api.cc index 70ac235194c4b3..b87d5662f4d72b 100644 --- a/chrome/browser/extensions/api/developer_private/developer_private_api.cc +++ b/chrome/browser/extensions/api/developer_private/developer_private_api.cc @@ -70,12 +70,12 @@ #include "extensions/common/switches.h" #include "extensions/grit/extensions_browser_resources.h" #include "net/base/net_util.h" +#include "storage/browser/blob/shareable_file_reference.h" #include "storage/browser/fileapi/external_mount_points.h" #include "storage/browser/fileapi/file_system_context.h" #include "storage/browser/fileapi/file_system_operation.h" #include "storage/browser/fileapi/file_system_operation_runner.h" #include "storage/browser/fileapi/isolated_context.h" -#include "storage/common/blob/shareable_file_reference.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" #include "ui/base/webui/web_ui_util.h" diff --git a/chrome/browser/extensions/api/page_capture/page_capture_api.h b/chrome/browser/extensions/api/page_capture/page_capture_api.h index 0c1aa1c35dc622..ad467bbd171fc8 100644 --- a/chrome/browser/extensions/api/page_capture/page_capture_api.h +++ b/chrome/browser/extensions/api/page_capture/page_capture_api.h @@ -10,7 +10,7 @@ #include "base/memory/ref_counted.h" #include "chrome/browser/extensions/chrome_extension_function.h" #include "chrome/common/extensions/api/page_capture.h" -#include "storage/common/blob/shareable_file_reference.h" +#include "storage/browser/blob/shareable_file_reference.h" namespace base { class FilePath; diff --git a/chrome/browser/media_galleries/fileapi/device_media_async_file_util.cc b/chrome/browser/media_galleries/fileapi/device_media_async_file_util.cc index dce3a583e734f4..1cacf712253d4b 100644 --- a/chrome/browser/media_galleries/fileapi/device_media_async_file_util.cc +++ b/chrome/browser/media_galleries/fileapi/device_media_async_file_util.cc @@ -16,11 +16,11 @@ #include "chrome/browser/media_galleries/fileapi/readahead_file_stream_reader.h" #include "content/public/browser/browser_thread.h" #include "storage/browser/blob/file_stream_reader.h" +#include "storage/browser/blob/shareable_file_reference.h" #include "storage/browser/fileapi/file_system_context.h" #include "storage/browser/fileapi/file_system_operation_context.h" #include "storage/browser/fileapi/file_system_url.h" #include "storage/browser/fileapi/native_file_util.h" -#include "storage/common/blob/shareable_file_reference.h" using storage::AsyncFileUtil; using storage::FileSystemOperationContext; diff --git a/chrome/browser/media_galleries/fileapi/device_media_async_file_util.h b/chrome/browser/media_galleries/fileapi/device_media_async_file_util.h index ebfd6b83d0a6eb..3716c446cafcb2 100644 --- a/chrome/browser/media_galleries/fileapi/device_media_async_file_util.h +++ b/chrome/browser/media_galleries/fileapi/device_media_async_file_util.h @@ -10,8 +10,8 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" +#include "storage/browser/blob/shareable_file_reference.h" #include "storage/browser/fileapi/async_file_util.h" -#include "storage/common/blob/shareable_file_reference.h" namespace storage { class FileSystemOperationContext; diff --git a/chrome/browser/media_galleries/fileapi/iphoto_file_util.cc b/chrome/browser/media_galleries/fileapi/iphoto_file_util.cc index ab47addd7f8852..317d19fe98bca6 100644 --- a/chrome/browser/media_galleries/fileapi/iphoto_file_util.cc +++ b/chrome/browser/media_galleries/fileapi/iphoto_file_util.cc @@ -16,10 +16,10 @@ #include "chrome/browser/media_galleries/fileapi/media_path_filter.h" #include "chrome/browser/media_galleries/imported_media_gallery_registry.h" #include "content/public/browser/browser_thread.h" +#include "storage/browser/blob/shareable_file_reference.h" #include "storage/browser/fileapi/file_system_operation_context.h" #include "storage/browser/fileapi/file_system_url.h" #include "storage/browser/fileapi/native_file_util.h" -#include "storage/common/blob/shareable_file_reference.h" #include "storage/common/fileapi/directory_entry.h" #include "storage/common/fileapi/file_system_util.h" diff --git a/chrome/browser/media_galleries/fileapi/itunes_file_util.cc b/chrome/browser/media_galleries/fileapi/itunes_file_util.cc index 41185eee5620c6..add99820321411 100644 --- a/chrome/browser/media_galleries/fileapi/itunes_file_util.cc +++ b/chrome/browser/media_galleries/fileapi/itunes_file_util.cc @@ -15,10 +15,10 @@ #include "chrome/browser/media_galleries/fileapi/media_path_filter.h" #include "chrome/browser/media_galleries/imported_media_gallery_registry.h" #include "content/public/browser/browser_thread.h" +#include "storage/browser/blob/shareable_file_reference.h" #include "storage/browser/fileapi/file_system_operation_context.h" #include "storage/browser/fileapi/file_system_url.h" #include "storage/browser/fileapi/native_file_util.h" -#include "storage/common/blob/shareable_file_reference.h" #include "storage/common/fileapi/file_system_util.h" using storage::DirectoryEntry; diff --git a/chrome/browser/media_galleries/fileapi/native_media_file_util.cc b/chrome/browser/media_galleries/fileapi/native_media_file_util.cc index 9d7d362dc9c94a..9584beded6c49a 100644 --- a/chrome/browser/media_galleries/fileapi/native_media_file_util.cc +++ b/chrome/browser/media_galleries/fileapi/native_media_file_util.cc @@ -16,10 +16,10 @@ #include "content/public/browser/browser_thread.h" #include "net/base/io_buffer.h" #include "net/base/mime_sniffer.h" +#include "storage/browser/blob/shareable_file_reference.h" #include "storage/browser/fileapi/file_system_context.h" #include "storage/browser/fileapi/file_system_operation_context.h" #include "storage/browser/fileapi/native_file_util.h" -#include "storage/common/blob/shareable_file_reference.h" #include "url/gurl.h" namespace { diff --git a/chrome/browser/media_galleries/fileapi/picasa_file_util_unittest.cc b/chrome/browser/media_galleries/fileapi/picasa_file_util_unittest.cc index 91711513633841..d7f532a597444f 100644 --- a/chrome/browser/media_galleries/fileapi/picasa_file_util_unittest.cc +++ b/chrome/browser/media_galleries/fileapi/picasa_file_util_unittest.cc @@ -28,13 +28,13 @@ #include "content/public/test/mock_special_storage_policy.h" #include "content/public/test/test_browser_thread.h" #include "content/public/test/test_file_system_options.h" +#include "storage/browser/blob/shareable_file_reference.h" #include "storage/browser/fileapi/async_file_util.h" #include "storage/browser/fileapi/external_mount_points.h" #include "storage/browser/fileapi/file_system_context.h" #include "storage/browser/fileapi/file_system_operation_context.h" #include "storage/browser/fileapi/file_system_operation_runner.h" #include "storage/browser/fileapi/isolated_context.h" -#include "storage/common/blob/shareable_file_reference.h" #include "testing/gtest/include/gtest/gtest.h" using storage::FileSystemOperationContext; diff --git a/chrome/browser/sync_file_system/drive_backend/drive_backend_util.h b/chrome/browser/sync_file_system/drive_backend/drive_backend_util.h index 6bf5f63947c2df..6b17e50418663a 100644 --- a/chrome/browser/sync_file_system/drive_backend/drive_backend_util.h +++ b/chrome/browser/sync_file_system/drive_backend/drive_backend_util.h @@ -14,7 +14,7 @@ #include "chrome/browser/sync_file_system/drive_backend/metadata_database.pb.h" #include "chrome/browser/sync_file_system/sync_status_code.h" #include "google_apis/drive/gdata_errorcode.h" -#include "storage/common/blob/scoped_file.h" +#include "storage/browser/blob/scoped_file.h" namespace google_apis { class ChangeResource; diff --git a/chrome/browser/sync_file_system/drive_backend/sync_engine.cc b/chrome/browser/sync_file_system/drive_backend/sync_engine.cc index c0b2fea78c6436..8520f8e618e6ea 100644 --- a/chrome/browser/sync_file_system/drive_backend/sync_engine.cc +++ b/chrome/browser/sync_file_system/drive_backend/sync_engine.cc @@ -54,7 +54,7 @@ #include "google_apis/drive/drive_api_url_generator.h" #include "google_apis/drive/gdata_wapi_url_generator.h" #include "net/url_request/url_request_context_getter.h" -#include "storage/common/blob/scoped_file.h" +#include "storage/browser/blob/scoped_file.h" #include "storage/common/fileapi/file_system_util.h" namespace sync_file_system { diff --git a/chrome/browser/sync_file_system/local/canned_syncable_file_system.cc b/chrome/browser/sync_file_system/local/canned_syncable_file_system.cc index c636e35ed25b8f..2e6f1fcac4756f 100644 --- a/chrome/browser/sync_file_system/local/canned_syncable_file_system.cc +++ b/chrome/browser/sync_file_system/local/canned_syncable_file_system.cc @@ -24,13 +24,13 @@ #include "content/public/test/mock_blob_url_request_context.h" #include "content/public/test/mock_special_storage_policy.h" #include "content/public/test/test_file_system_options.h" +#include "storage/browser/blob/shareable_file_reference.h" #include "storage/browser/fileapi/external_mount_points.h" #include "storage/browser/fileapi/file_system_backend.h" #include "storage/browser/fileapi/file_system_context.h" #include "storage/browser/fileapi/file_system_operation_context.h" #include "storage/browser/fileapi/file_system_operation_runner.h" #include "storage/browser/quota/quota_manager.h" -#include "storage/common/blob/shareable_file_reference.h" #include "testing/gtest/include/gtest/gtest.h" using base::File; diff --git a/chrome/browser/sync_file_system/local/local_file_sync_context.cc b/chrome/browser/sync_file_system/local/local_file_sync_context.cc index 88273abc1d2135..0aafc6d6c44b40 100644 --- a/chrome/browser/sync_file_system/local/local_file_sync_context.cc +++ b/chrome/browser/sync_file_system/local/local_file_sync_context.cc @@ -19,11 +19,11 @@ #include "chrome/browser/sync_file_system/logger.h" #include "chrome/browser/sync_file_system/sync_file_metadata.h" #include "chrome/browser/sync_file_system/syncable_file_system_util.h" +#include "storage/browser/blob/scoped_file.h" #include "storage/browser/fileapi/file_system_context.h" #include "storage/browser/fileapi/file_system_file_util.h" #include "storage/browser/fileapi/file_system_operation_context.h" #include "storage/browser/fileapi/file_system_operation_runner.h" -#include "storage/common/blob/scoped_file.h" #include "storage/common/fileapi/file_system_util.h" using storage::FileSystemContext; diff --git a/chrome/browser/sync_file_system/local/local_file_sync_context_unittest.cc b/chrome/browser/sync_file_system/local/local_file_sync_context_unittest.cc index e74826ff703cb7..c2e23883c2e48d 100644 --- a/chrome/browser/sync_file_system/local/local_file_sync_context_unittest.cc +++ b/chrome/browser/sync_file_system/local/local_file_sync_context_unittest.cc @@ -21,10 +21,10 @@ #include "content/public/browser/browser_thread.h" #include "content/public/test/mock_blob_url_request_context.h" #include "content/public/test/test_browser_thread_bundle.h" +#include "storage/browser/blob/scoped_file.h" #include "storage/browser/fileapi/file_system_context.h" #include "storage/browser/fileapi/file_system_operation_runner.h" #include "storage/browser/fileapi/isolated_context.h" -#include "storage/common/blob/scoped_file.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/leveldatabase/src/helpers/memenv/memenv.h" #include "third_party/leveldatabase/src/include/leveldb/env.h" diff --git a/chrome/browser/sync_file_system/local/local_file_sync_service.cc b/chrome/browser/sync_file_system/local/local_file_sync_service.cc index cb4f0f2e9976c9..51ab55a6468700 100644 --- a/chrome/browser/sync_file_system/local/local_file_sync_service.cc +++ b/chrome/browser/sync_file_system/local/local_file_sync_service.cc @@ -22,9 +22,9 @@ #include "content/public/browser/storage_partition.h" #include "extensions/browser/extension_registry.h" #include "extensions/common/extension_set.h" +#include "storage/browser/blob/scoped_file.h" #include "storage/browser/fileapi/file_system_context.h" #include "storage/browser/fileapi/file_system_url.h" -#include "storage/common/blob/scoped_file.h" #include "url/gurl.h" using content::BrowserThread; diff --git a/chrome/browser/sync_file_system/local/syncable_file_system_operation.cc b/chrome/browser/sync_file_system/local/syncable_file_system_operation.cc index 5a2e7b57738ace..d751a56fa706f0 100644 --- a/chrome/browser/sync_file_system/local/syncable_file_system_operation.cc +++ b/chrome/browser/sync_file_system/local/syncable_file_system_operation.cc @@ -10,12 +10,12 @@ #include "chrome/browser/sync_file_system/local/syncable_file_operation_runner.h" #include "chrome/browser/sync_file_system/syncable_file_system_util.h" #include "net/url_request/url_request.h" +#include "storage/browser/blob/shareable_file_reference.h" #include "storage/browser/fileapi/file_system_context.h" #include "storage/browser/fileapi/file_system_operation.h" #include "storage/browser/fileapi/file_system_operation_context.h" #include "storage/browser/fileapi/file_system_url.h" #include "storage/browser/fileapi/file_writer_delegate.h" -#include "storage/common/blob/shareable_file_reference.h" using storage::FileSystemURL; diff --git a/content/browser/fileapi/blob_storage_context_unittest.cc b/content/browser/fileapi/blob_storage_context_unittest.cc index 6ac1832894c3a2..dccc86966c2702 100644 --- a/content/browser/fileapi/blob_storage_context_unittest.cc +++ b/content/browser/fileapi/blob_storage_context_unittest.cc @@ -9,18 +9,24 @@ #include "base/run_loop.h" #include "base/time/time.h" #include "content/browser/fileapi/blob_storage_host.h" +#include "storage/browser/blob/blob_data_builder.h" #include "storage/browser/blob/blob_data_handle.h" +#include "storage/browser/blob/blob_data_snapshot.h" #include "storage/browser/blob/blob_storage_context.h" #include "testing/gtest/include/gtest/gtest.h" +using storage::BlobDataBuilder; using storage::BlobDataHandle; +using storage::BlobDataSnapshot; +using storage::BlobStorageContext; +using storage::DataElement; namespace content { namespace { void SetupBasicBlob(BlobStorageHost* host, const std::string& id) { EXPECT_TRUE(host->StartBuildingBlob(id)); - BlobData::Item item; + DataElement item; item.SetToBytes("1", 1); EXPECT_TRUE(host->AppendBlobDataItem(id, item)); EXPECT_TRUE(host->FinishBuildingBlob(id, "text/plain")); @@ -66,6 +72,22 @@ TEST(BlobStorageContextTest, IncrementDecrementRef) { EXPECT_FALSE(host.IncrementBlobRefCount(kId)); } +TEST(BlobStorageContextTest, CancelBuildingBlob) { + BlobStorageContext context; + BlobStorageHost host(&context); + base::MessageLoop fake_io_message_loop; + + // Build up a basic blob. + const std::string kId("id"); + EXPECT_TRUE(host.StartBuildingBlob(kId)); + DataElement item; + item.SetToBytes("1", 1); + EXPECT_TRUE(host.AppendBlobDataItem(kId, item)); + EXPECT_TRUE(host.CancelBuildingBlob(kId)); + EXPECT_FALSE(host.FinishBuildingBlob(kId, "text/plain")); + EXPECT_TRUE(host.StartBuildingBlob(kId)); +} + TEST(BlobStorageContextTest, BlobDataHandle) { BlobStorageContext context; BlobStorageHost host(&context); @@ -111,19 +133,20 @@ TEST(BlobStorageContextTest, CompoundBlobs) { base::Time::FromString("Tue, 15 Nov 1994, 12:45:26 GMT", &time1); base::Time::FromString("Mon, 14 Nov 1994, 11:30:49 GMT", &time2); - scoped_refptr blob_data1(new BlobData(kId1)); + scoped_ptr blob_data1(new BlobDataBuilder(kId1)); blob_data1->AppendData("Data1"); blob_data1->AppendData("Data2"); blob_data1->AppendFile(base::FilePath(FILE_PATH_LITERAL("File1.txt")), 10, 1024, time1); - scoped_refptr blob_data2(new BlobData(kId2)); + scoped_ptr blob_data2(new BlobDataBuilder(kId2)); blob_data2->AppendData("Data3"); blob_data2->AppendBlob(kId1, 8, 100); blob_data2->AppendFile(base::FilePath(FILE_PATH_LITERAL("File2.txt")), 0, 20, time2); - scoped_refptr canonicalized_blob_data2(new BlobData(kId2Prime)); + scoped_ptr canonicalized_blob_data2( + new BlobDataBuilder(kId2Prime)); canonicalized_blob_data2->AppendData("Data3"); canonicalized_blob_data2->AppendData("a2___", 2); canonicalized_blob_data2->AppendFile( @@ -136,14 +159,18 @@ TEST(BlobStorageContextTest, CompoundBlobs) { scoped_ptr blob_data_handle; // Test a blob referring to only data and a file. - blob_data_handle = context.AddFinishedBlob(blob_data1.get()); - ASSERT_TRUE(blob_data_handle.get()); - EXPECT_TRUE(*(blob_data_handle->data()) == *blob_data1.get()); + blob_data_handle = context.AddFinishedBlob(*blob_data1.get()); + ASSERT_TRUE(blob_data_handle); + scoped_ptr data = blob_data_handle->CreateSnapshot(); + ASSERT_TRUE(blob_data_handle); + EXPECT_EQ(*data, *blob_data1); // Test a blob composed in part with another blob. - blob_data_handle = context.AddFinishedBlob(blob_data2.get()); - ASSERT_TRUE(blob_data_handle.get()); - EXPECT_TRUE(*(blob_data_handle->data()) == *canonicalized_blob_data2.get()); + blob_data_handle = context.AddFinishedBlob(*blob_data2.get()); + data = blob_data_handle->CreateSnapshot(); + ASSERT_TRUE(blob_data_handle); + ASSERT_TRUE(data); + EXPECT_EQ(*data, *canonicalized_blob_data2); blob_data_handle.reset(); { // Clean up for ASAN @@ -167,7 +194,8 @@ TEST(BlobStorageContextTest, PublicBlobUrls) { scoped_ptr blob_data_handle = context.GetBlobDataFromPublicURL(kUrl); ASSERT_TRUE(blob_data_handle.get()); - EXPECT_EQ(kId, blob_data_handle->data()->uuid()); + EXPECT_EQ(kId, blob_data_handle->uuid()); + scoped_ptr data = blob_data_handle->CreateSnapshot(); blob_data_handle.reset(); { // Clean up for ASAN base::RunLoop run_loop; @@ -222,7 +250,7 @@ TEST(BlobStorageContextTest, EarlyContextDeletion) { const std::string kId("id"); GURL kUrl("blob:id"); EXPECT_FALSE(host.StartBuildingBlob(kId)); - BlobData::Item item; + DataElement item; item.SetToBytes("1", 1); EXPECT_FALSE(host.AppendBlobDataItem(kId, item)); EXPECT_FALSE(host.FinishBuildingBlob(kId, "text/plain")); diff --git a/content/browser/fileapi/blob_storage_host.cc b/content/browser/fileapi/blob_storage_host.cc index 87e675ce5d1a30..faf81010dd3f20 100644 --- a/content/browser/fileapi/blob_storage_host.cc +++ b/content/browser/fileapi/blob_storage_host.cc @@ -6,12 +6,10 @@ #include "base/sequenced_task_runner.h" #include "base/strings/string_util.h" -#include "storage/browser/blob/blob_data_handle.h" #include "storage/browser/blob/blob_storage_context.h" #include "url/gurl.h" using storage::BlobStorageContext; -using storage::BlobData; namespace content { @@ -42,7 +40,8 @@ bool BlobStorageHost::StartBuildingBlob(const std::string& uuid) { } bool BlobStorageHost::AppendBlobDataItem( - const std::string& uuid, const BlobData::Item& data_item) { + const std::string& uuid, + const storage::DataElement& data_item) { if (!context_.get() || !IsBeingBuiltInHost(uuid)) return false; context_->AppendBlobDataItem(uuid, data_item); diff --git a/content/browser/fileapi/blob_storage_host.h b/content/browser/fileapi/blob_storage_host.h index 3544f398b7def9..8fd8453ff928c2 100644 --- a/content/browser/fileapi/blob_storage_host.h +++ b/content/browser/fileapi/blob_storage_host.h @@ -12,7 +12,7 @@ #include "base/compiler_specific.h" #include "base/memory/weak_ptr.h" #include "content/common/content_export.h" -#include "storage/common/blob/blob_data.h" +#include "storage/common/data_element.h" class GURL; @@ -22,9 +22,6 @@ class BlobStorageHost; class BlobStorageContext; } -using storage::BlobStorageContext; -using storage::BlobData; - namespace content { // This class handles the logistics of blob storage for a single child process. @@ -34,7 +31,7 @@ namespace content { // only be used on the IO thread. class CONTENT_EXPORT BlobStorageHost { public: - explicit BlobStorageHost(BlobStorageContext* context); + explicit BlobStorageHost(storage::BlobStorageContext* context); ~BlobStorageHost(); // Methods to support the IPC message protocol. @@ -42,7 +39,8 @@ class CONTENT_EXPORT BlobStorageHost { // like a non-existent or pre-existent uuid or url. bool StartBuildingBlob(const std::string& uuid) WARN_UNUSED_RESULT; bool AppendBlobDataItem(const std::string& uuid, - const BlobData::Item& data_item) WARN_UNUSED_RESULT; + const storage::DataElement& data_item) + WARN_UNUSED_RESULT; bool CancelBuildingBlob(const std::string& uuid) WARN_UNUSED_RESULT; bool FinishBuildingBlob(const std::string& uuid, const std::string& type) WARN_UNUSED_RESULT; @@ -66,7 +64,7 @@ class CONTENT_EXPORT BlobStorageHost { // The set of public blob urls coined by this consumer. std::set public_blob_urls_; - base::WeakPtr context_; + base::WeakPtr context_; DISALLOW_COPY_AND_ASSIGN(BlobStorageHost); }; diff --git a/content/browser/fileapi/blob_url_request_job_unittest.cc b/content/browser/fileapi/blob_url_request_job_unittest.cc index 79824772be6a78..e7ce119671e571 100644 --- a/content/browser/fileapi/blob_url_request_job_unittest.cc +++ b/content/browser/fileapi/blob_url_request_job_unittest.cc @@ -22,14 +22,16 @@ #include "net/url_request/url_request.h" #include "net/url_request/url_request_context.h" #include "net/url_request/url_request_job_factory_impl.h" +#include "storage/browser/blob/blob_data_builder.h" +#include "storage/browser/blob/blob_data_snapshot.h" #include "storage/browser/blob/blob_url_request_job.h" #include "storage/browser/fileapi/file_system_context.h" #include "storage/browser/fileapi/file_system_operation_context.h" #include "storage/browser/fileapi/file_system_url.h" -#include "storage/common/blob/blob_data.h" #include "testing/gtest/include/gtest/gtest.h" -using storage::BlobData; +using storage::BlobDataSnapshot; +using storage::BlobDataBuilder; using storage::BlobURLRequestJob; namespace content { @@ -64,9 +66,8 @@ class BlobURLRequestJobTest : public testing::Test { net::URLRequestJob* MaybeCreateJob( net::URLRequest* request, net::NetworkDelegate* network_delegate) const override { - return new BlobURLRequestJob(request, - network_delegate, - test_->blob_data_.get(), + return new BlobURLRequestJob(request, network_delegate, + test_->blob_data_->BuildSnapshot().Pass(), test_->file_system_context_.get(), base::MessageLoopProxy::current().get()); } @@ -76,8 +77,7 @@ class BlobURLRequestJobTest : public testing::Test { }; BlobURLRequestJobTest() - : blob_data_(new BlobData()), - expected_status_code_(0) {} + : blob_data_(new BlobDataBuilder("uuid")), expected_status_code_(0) {} void SetUp() override { ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); @@ -219,10 +219,10 @@ class BlobURLRequestJobTest : public testing::Test { // Otherwise, this will fail a CHECK. int64 GetTotalBlobLength() const { int64 total = 0; - const std::vector& items = blob_data_->items(); - for (std::vector::const_iterator it = items.begin(); - it != items.end(); ++it) { - int64 length = base::checked_cast(it->length()); + scoped_ptr data = blob_data_->BuildSnapshot(); + const auto& items = data->items(); + for (const auto& item : items) { + int64 length = base::checked_cast(item->length()); CHECK(length <= kint64max - total); total += length; } @@ -243,7 +243,8 @@ class BlobURLRequestJobTest : public testing::Test { base::MessageLoopForIO message_loop_; scoped_refptr file_system_context_; - scoped_refptr blob_data_; + scoped_ptr blob_data_; + scoped_ptr blob_data_snapshot_; net::URLRequestJobFactoryImpl url_request_job_factory_; net::URLRequestContext url_request_context_; MockURLRequestDelegate url_request_delegate_; diff --git a/content/browser/fileapi/chrome_blob_storage_context.cc b/content/browser/fileapi/chrome_blob_storage_context.cc index f085242f689eab..5fc26e40f3e08e 100644 --- a/content/browser/fileapi/chrome_blob_storage_context.cc +++ b/content/browser/fileapi/chrome_blob_storage_context.cc @@ -9,6 +9,7 @@ #include "content/public/browser/blob_handle.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/browser_thread.h" +#include "storage/browser/blob/blob_data_builder.h" #include "storage/browser/blob/blob_data_handle.h" #include "storage/browser/blob/blob_storage_context.h" @@ -24,8 +25,7 @@ const char kBlobStorageContextKeyName[] = "content_blob_storage_context"; class BlobHandleImpl : public BlobHandle { public: explicit BlobHandleImpl(scoped_ptr handle) - : handle_(handle.Pass()) { - } + : handle_(handle.Pass()) {} ~BlobHandleImpl() override {} @@ -69,11 +69,12 @@ scoped_ptr ChromeBlobStorageContext::CreateMemoryBackedBlob( DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); std::string uuid(base::GenerateGUID()); - scoped_refptr blob_data = new storage::BlobData(uuid); - blob_data->AppendData(data, length); + scoped_ptr blob_data_builder( + new storage::BlobDataBuilder(uuid)); + blob_data_builder->AppendData(data, length); scoped_ptr blob_data_handle = - context_->AddFinishedBlob(blob_data.get()); + context_->AddFinishedBlob(*blob_data_builder.get()); if (!blob_data_handle) return scoped_ptr(); diff --git a/content/browser/fileapi/copy_or_move_file_validator_unittest.cc b/content/browser/fileapi/copy_or_move_file_validator_unittest.cc index ea2ba898940a0d..f9b8d1506f4583 100644 --- a/content/browser/fileapi/copy_or_move_file_validator_unittest.cc +++ b/content/browser/fileapi/copy_or_move_file_validator_unittest.cc @@ -11,13 +11,13 @@ #include "content/public/test/mock_special_storage_policy.h" #include "content/public/test/test_file_system_backend.h" #include "content/public/test/test_file_system_context.h" +#include "storage/browser/blob/shareable_file_reference.h" #include "storage/browser/fileapi/copy_or_move_file_validator.h" #include "storage/browser/fileapi/external_mount_points.h" #include "storage/browser/fileapi/file_system_backend.h" #include "storage/browser/fileapi/file_system_context.h" #include "storage/browser/fileapi/file_system_url.h" #include "storage/browser/fileapi/isolated_context.h" -#include "storage/common/blob/shareable_file_reference.h" #include "storage/common/fileapi/file_system_util.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/content/browser/fileapi/file_system_operation_impl_unittest.cc b/content/browser/fileapi/file_system_operation_impl_unittest.cc index 23a8c2d679b8d0..6f84204a4ac674 100644 --- a/content/browser/fileapi/file_system_operation_impl_unittest.cc +++ b/content/browser/fileapi/file_system_operation_impl_unittest.cc @@ -18,6 +18,7 @@ #include "content/browser/quota/mock_quota_manager_proxy.h" #include "content/public/test/async_file_test_helper.h" #include "content/public/test/sandbox_file_system_test_helper.h" +#include "storage/browser/blob/shareable_file_reference.h" #include "storage/browser/fileapi/file_system_context.h" #include "storage/browser/fileapi/file_system_file_util.h" #include "storage/browser/fileapi/file_system_operation_context.h" @@ -25,7 +26,6 @@ #include "storage/browser/fileapi/sandbox_file_system_backend.h" #include "storage/browser/quota/quota_manager.h" #include "storage/browser/quota/quota_manager_proxy.h" -#include "storage/common/blob/shareable_file_reference.h" #include "storage/common/fileapi/file_system_util.h" #include "testing/gtest/include/gtest/gtest.h" #include "url/gurl.h" diff --git a/content/browser/fileapi/file_system_operation_impl_write_unittest.cc b/content/browser/fileapi/file_system_operation_impl_write_unittest.cc index 9d3c181fdced92..ca324ae4653309 100644 --- a/content/browser/fileapi/file_system_operation_impl_write_unittest.cc +++ b/content/browser/fileapi/file_system_operation_impl_write_unittest.cc @@ -25,7 +25,6 @@ #include "storage/browser/fileapi/file_system_operation_context.h" #include "storage/browser/fileapi/file_system_operation_runner.h" #include "storage/browser/fileapi/local_file_util.h" -#include "storage/common/blob/blob_data.h" #include "storage/common/fileapi/file_system_util.h" #include "testing/gtest/include/gtest/gtest.h" #include "url/gurl.h" diff --git a/content/browser/fileapi/fileapi_message_filter.cc b/content/browser/fileapi/fileapi_message_filter.cc index 17e3abe4592346..b4ef0cea7c125c 100644 --- a/content/browser/fileapi/fileapi_message_filter.cc +++ b/content/browser/fileapi/fileapi_message_filter.cc @@ -27,13 +27,14 @@ #include "net/base/mime_util.h" #include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context_getter.h" +#include "storage/browser/blob/blob_data_builder.h" #include "storage/browser/blob/blob_storage_context.h" +#include "storage/browser/blob/shareable_file_reference.h" #include "storage/browser/fileapi/file_observers.h" #include "storage/browser/fileapi/file_permission_policy.h" #include "storage/browser/fileapi/file_system_context.h" #include "storage/browser/fileapi/isolated_context.h" -#include "storage/common/blob/blob_data.h" -#include "storage/common/blob/shareable_file_reference.h" +#include "storage/common/data_element.h" #include "storage/common/fileapi/directory_entry.h" #include "storage/common/fileapi/file_system_info.h" #include "storage/common/fileapi/file_system_types.h" @@ -44,7 +45,7 @@ using storage::FileSystemFileUtil; using storage::FileSystemBackend; using storage::FileSystemOperation; using storage::FileSystemURL; -using storage::BlobData; +using storage::BlobDataBuilder; using storage::BlobStorageContext; namespace content { @@ -519,9 +520,10 @@ void FileAPIMessageFilter::OnStartBuildingBlob(const std::string& uuid) { } void FileAPIMessageFilter::OnAppendBlobDataItemToBlob( - const std::string& uuid, const BlobData::Item& item) { + const std::string& uuid, + const storage::DataElement& item) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - if (item.type() == BlobData::Item::TYPE_FILE_FILESYSTEM) { + if (item.type() == storage::DataElement::TYPE_FILE_FILESYSTEM) { FileSystemURL filesystem_url(context_->CrackURL(item.filesystem_url())); if (!FileSystemURLIsValid(context_, filesystem_url) || !security_policy_->CanReadFileSystemFile(process_id_, filesystem_url)) { @@ -529,7 +531,7 @@ void FileAPIMessageFilter::OnAppendBlobDataItemToBlob( return; } } - if (item.type() == BlobData::Item::TYPE_FILE && + if (item.type() == storage::DataElement::TYPE_FILE && !security_policy_->CanReadFile(process_id_, item.path())) { ignore_result(blob_storage_host_->CancelBuildingBlob(uuid)); return; @@ -560,7 +562,7 @@ void FileAPIMessageFilter::OnAppendSharedMemoryToBlob( return; } - BlobData::Item item; + storage::DataElement item; item.SetToSharedBytes(static_cast(shared_memory.memory()), buffer_size); ignore_result(blob_storage_host_->AppendBlobDataItem(uuid, item)); @@ -613,7 +615,8 @@ void FileAPIMessageFilter::OnStartBuildingStream( } void FileAPIMessageFilter::OnAppendBlobDataItemToStream( - const GURL& url, const BlobData::Item& item) { + const GURL& url, + const storage::DataElement& item) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); scoped_refptr stream(GetStreamForURL(url)); @@ -623,7 +626,7 @@ void FileAPIMessageFilter::OnAppendBlobDataItemToStream( return; // Data for stream is delivered as TYPE_BYTES item. - if (item.type() != BlobData::Item::TYPE_BYTES) { + if (item.type() != storage::DataElement::TYPE_BYTES) { BadMessageReceived(); return; } diff --git a/content/browser/fileapi/fileapi_message_filter.h b/content/browser/fileapi/fileapi_message_filter.h index 8ba998a053b58d..805778b4b59eec 100644 --- a/content/browser/fileapi/fileapi_message_filter.h +++ b/content/browser/fileapi/fileapi_message_filter.h @@ -20,7 +20,6 @@ #include "content/public/browser/browser_message_filter.h" #include "storage/browser/fileapi/file_system_context.h" #include "storage/browser/fileapi/file_system_operation_runner.h" -#include "storage/common/blob/blob_data.h" #include "storage/common/fileapi/file_system_types.h" #include "storage/common/quota/quota_types.h" @@ -49,6 +48,7 @@ class BlobStorageHost; namespace storage { class ShareableFileReference; +class DataElement; } namespace content { @@ -130,7 +130,7 @@ class CONTENT_EXPORT FileAPIMessageFilter : public BrowserMessageFilter { void OnStartBuildingBlob(const std::string& uuid); void OnAppendBlobDataItemToBlob(const std::string& uuid, - const storage::BlobData::Item& item); + const storage::DataElement& item); void OnAppendSharedMemoryToBlob(const std::string& uuid, base::SharedMemoryHandle handle, size_t buffer_size); @@ -151,7 +151,7 @@ class CONTENT_EXPORT FileAPIMessageFilter : public BrowserMessageFilter { // TODO(tyoshino): Set |content_type| to the stream. void OnStartBuildingStream(const GURL& url, const std::string& content_type); void OnAppendBlobDataItemToStream(const GURL& url, - const storage::BlobData::Item& item); + const storage::DataElement& item); void OnAppendSharedMemoryToStream( const GURL& url, base::SharedMemoryHandle handle, size_t buffer_size); void OnFlushStream(const GURL& url); diff --git a/content/browser/fileapi/fileapi_message_filter_unittest.cc b/content/browser/fileapi/fileapi_message_filter_unittest.cc index 5aef43a34fddea..58f555e10fbf08 100644 --- a/content/browser/fileapi/fileapi_message_filter_unittest.cc +++ b/content/browser/fileapi/fileapi_message_filter_unittest.cc @@ -25,7 +25,7 @@ #include "net/base/io_buffer.h" #include "storage/browser/blob/blob_storage_context.h" #include "storage/browser/fileapi/file_system_context.h" -#include "storage/common/blob/blob_data.h" +#include "storage/common/data_element.h" #include "testing/gtest/include/gtest/gtest.h" namespace content { @@ -197,7 +197,7 @@ TEST_F(FileAPIMessageFilterTest, BuildNonEmptyStream) { StreamHostMsg_StartBuilding start_message(kUrl, kFakeContentType); EXPECT_TRUE(filter_->OnMessageReceived(start_message)); - storage::BlobData::Item item; + storage::DataElement item; const std::string kFakeData = "foobarbaz"; item.SetToBytes(kFakeData.data(), kFakeData.size()); StreamHostMsg_AppendBlobDataItem append_message(kUrl, item); diff --git a/content/browser/fileapi/transient_file_util_unittest.cc b/content/browser/fileapi/transient_file_util_unittest.cc index faf20caa4c5390..2ed8b746495699 100644 --- a/content/browser/fileapi/transient_file_util_unittest.cc +++ b/content/browser/fileapi/transient_file_util_unittest.cc @@ -9,11 +9,11 @@ #include "base/memory/scoped_ptr.h" #include "base/run_loop.h" #include "content/public/test/test_file_system_context.h" +#include "storage/browser/blob/scoped_file.h" #include "storage/browser/fileapi/file_system_context.h" #include "storage/browser/fileapi/file_system_operation_context.h" #include "storage/browser/fileapi/isolated_context.h" #include "storage/browser/fileapi/transient_file_util.h" -#include "storage/common/blob/scoped_file.h" #include "testing/gtest/include/gtest/gtest.h" using storage::FileSystemURL; diff --git a/content/browser/indexed_db/indexed_db_active_blob_registry.h b/content/browser/indexed_db/indexed_db_active_blob_registry.h index b0ebe27fd7cf97..8f78f191b697e0 100644 --- a/content/browser/indexed_db/indexed_db_active_blob_registry.h +++ b/content/browser/indexed_db/indexed_db_active_blob_registry.h @@ -12,7 +12,7 @@ #include "base/files/file_path.h" #include "base/memory/weak_ptr.h" #include "content/common/content_export.h" -#include "storage/common/blob/shareable_file_reference.h" +#include "storage/browser/blob/shareable_file_reference.h" namespace content { diff --git a/content/browser/indexed_db/indexed_db_blob_info.h b/content/browser/indexed_db/indexed_db_blob_info.h index 5001b4bb765661..02d039d207bca4 100644 --- a/content/browser/indexed_db/indexed_db_blob_info.h +++ b/content/browser/indexed_db/indexed_db_blob_info.h @@ -11,7 +11,7 @@ #include "base/files/file_path.h" #include "base/time/time.h" #include "content/common/content_export.h" -#include "storage/common/blob/shareable_file_reference.h" +#include "storage/browser/blob/shareable_file_reference.h" namespace content { diff --git a/content/browser/indexed_db/indexed_db_callbacks.cc b/content/browser/indexed_db/indexed_db_callbacks.cc index e38c8989ff3a1b..147c5ab10e6dc8 100644 --- a/content/browser/indexed_db/indexed_db_callbacks.cc +++ b/content/browser/indexed_db/indexed_db_callbacks.cc @@ -22,9 +22,8 @@ #include "content/common/indexed_db/indexed_db_constants.h" #include "content/common/indexed_db/indexed_db_messages.h" #include "storage/browser/blob/blob_storage_context.h" +#include "storage/browser/blob/shareable_file_reference.h" #include "storage/browser/quota/quota_manager.h" -#include "storage/common/blob/blob_data.h" -#include "storage/common/blob/shareable_file_reference.h" using storage::ShareableFileReference; diff --git a/content/browser/indexed_db/indexed_db_dispatcher_host.cc b/content/browser/indexed_db/indexed_db_dispatcher_host.cc index bbfe9eed61f27a..02bf1977907d8c 100644 --- a/content/browser/indexed_db/indexed_db_dispatcher_host.cc +++ b/content/browser/indexed_db/indexed_db_dispatcher_host.cc @@ -27,6 +27,7 @@ #include "content/public/browser/user_metrics.h" #include "content/public/common/content_switches.h" #include "content/public/common/result_codes.h" +#include "storage/browser/blob/blob_data_builder.h" #include "storage/browser/blob/blob_storage_context.h" #include "storage/browser/database/database_util.h" #include "storage/common/database/database_identifier.h" @@ -226,11 +227,11 @@ std::string IndexedDBDispatcherHost::HoldBlobData( scoped_ptr blob_data_handle; if (uuid.empty()) { uuid = base::GenerateGUID(); - scoped_refptr blob_data = new storage::BlobData(uuid); - blob_data->set_content_type(base::UTF16ToUTF8(blob_info.type())); - blob_data->AppendFile(blob_info.file_path(), 0, blob_info.size(), - blob_info.last_modified()); - blob_data_handle = context->AddFinishedBlob(blob_data.get()); + storage::BlobDataBuilder blob_data_builder(uuid); + blob_data_builder.set_content_type(base::UTF16ToUTF8(blob_info.type())); + blob_data_builder.AppendFile(blob_info.file_path(), 0, blob_info.size(), + blob_info.last_modified()); + blob_data_handle = context->AddFinishedBlob(blob_data_builder); } else { auto iter = blob_data_handle_map_.find(uuid); if (iter != blob_data_handle_map_.end()) { diff --git a/content/browser/loader/redirect_to_file_resource_handler.cc b/content/browser/loader/redirect_to_file_resource_handler.cc index 00e63928076765..6f402135c88377 100644 --- a/content/browser/loader/redirect_to_file_resource_handler.cc +++ b/content/browser/loader/redirect_to_file_resource_handler.cc @@ -15,7 +15,7 @@ #include "net/base/io_buffer.h" #include "net/base/mime_sniffer.h" #include "net/base/net_errors.h" -#include "storage/common/blob/shareable_file_reference.h" +#include "storage/browser/blob/shareable_file_reference.h" using storage::ShareableFileReference; diff --git a/content/browser/loader/resource_dispatcher_host_impl.cc b/content/browser/loader/resource_dispatcher_host_impl.cc index 31a53f7c1da299..332b7ec84a98ee 100644 --- a/content/browser/loader/resource_dispatcher_host_impl.cc +++ b/content/browser/loader/resource_dispatcher_host_impl.cc @@ -94,10 +94,9 @@ #include "storage/browser/blob/blob_data_handle.h" #include "storage/browser/blob/blob_storage_context.h" #include "storage/browser/blob/blob_url_request_job_factory.h" +#include "storage/browser/blob/shareable_file_reference.h" #include "storage/browser/fileapi/file_permission_policy.h" #include "storage/browser/fileapi/file_system_context.h" -#include "storage/common/blob/blob_data.h" -#include "storage/common/blob/shareable_file_reference.h" #include "url/url_constants.h" using base::Time; diff --git a/content/browser/loader/resource_dispatcher_host_unittest.cc b/content/browser/loader/resource_dispatcher_host_unittest.cc index 999ad4a9d52e0f..332e7263bb9cf1 100644 --- a/content/browser/loader/resource_dispatcher_host_unittest.cc +++ b/content/browser/loader/resource_dispatcher_host_unittest.cc @@ -49,7 +49,7 @@ #include "net/url_request/url_request_simple_job.h" #include "net/url_request/url_request_test_job.h" #include "net/url_request/url_request_test_util.h" -#include "storage/common/blob/shareable_file_reference.h" +#include "storage/browser/blob/shareable_file_reference.h" #include "testing/gtest/include/gtest/gtest.h" // TODO(eroman): Write unit tests for SafeBrowsing that exercise diff --git a/content/browser/loader/resource_loader_unittest.cc b/content/browser/loader/resource_loader_unittest.cc index 9123107b4b5982..c9d3398f290806 100644 --- a/content/browser/loader/resource_loader_unittest.cc +++ b/content/browser/loader/resource_loader_unittest.cc @@ -27,7 +27,7 @@ #include "net/url_request/url_request_job_factory_impl.h" #include "net/url_request/url_request_test_job.h" #include "net/url_request/url_request_test_util.h" -#include "storage/common/blob/shareable_file_reference.h" +#include "storage/browser/blob/shareable_file_reference.h" #include "testing/gtest/include/gtest/gtest.h" using storage::ShareableFileReference; diff --git a/content/browser/loader/temporary_file_stream.cc b/content/browser/loader/temporary_file_stream.cc index e904d88e107ae5..eb3ea9e6b89b22 100644 --- a/content/browser/loader/temporary_file_stream.cc +++ b/content/browser/loader/temporary_file_stream.cc @@ -10,7 +10,7 @@ #include "base/memory/ref_counted.h" #include "content/public/browser/browser_thread.h" #include "net/base/file_stream.h" -#include "storage/common/blob/shareable_file_reference.h" +#include "storage/browser/blob/shareable_file_reference.h" using storage::ShareableFileReference; diff --git a/content/browser/loader/temporary_file_stream_unittest.cc b/content/browser/loader/temporary_file_stream_unittest.cc index 854a5ddf5ab7c4..af57f0824ec558 100644 --- a/content/browser/loader/temporary_file_stream_unittest.cc +++ b/content/browser/loader/temporary_file_stream_unittest.cc @@ -18,7 +18,7 @@ #include "net/base/io_buffer.h" #include "net/base/net_errors.h" #include "net/base/test_completion_callback.h" -#include "storage/common/blob/shareable_file_reference.h" +#include "storage/browser/blob/shareable_file_reference.h" #include "testing/gtest/include/gtest/gtest.h" using storage::ShareableFileReference; diff --git a/content/browser/loader/upload_data_stream_builder.cc b/content/browser/loader/upload_data_stream_builder.cc index 376e221d2a6e2e..c497c16c0a769e 100644 --- a/content/browser/loader/upload_data_stream_builder.cc +++ b/content/browser/loader/upload_data_stream_builder.cc @@ -11,12 +11,9 @@ #include "net/base/upload_bytes_element_reader.h" #include "net/base/upload_file_element_reader.h" #include "storage/browser/blob/blob_data_handle.h" +#include "storage/browser/blob/blob_data_snapshot.h" #include "storage/browser/blob/blob_storage_context.h" -using storage::BlobData; -using storage::BlobDataHandle; -using storage::BlobStorageContext; - namespace content { namespace { @@ -64,6 +61,7 @@ class FileElementReader : public net::UploadFileElementReader { }; void ResolveBlobReference( + ResourceRequestBody* body, storage::BlobStorageContext* blob_context, const ResourceRequestBody::Element& element, std::vector* resolved_elements) { @@ -74,23 +72,29 @@ void ResolveBlobReference( if (!handle) return; + // TODO(dmurph): Create a reader for blobs instead of decomposing the blob + // and storing the snapshot on the request to keep the resources around. + // Currently a handle is attached to the request in the resource dispatcher + // host, so we know the blob won't go away, but it's not very clear or useful. + scoped_ptr snapshot = handle->CreateSnapshot(); // If there is no element in the referred blob data, just return. - if (handle->data()->items().empty()) + if (snapshot->items().empty()) return; // Append the elements in the referenced blob data. - for (size_t i = 0; i < handle->data()->items().size(); ++i) { - const BlobData::Item& item = handle->data()->items().at(i); - DCHECK_NE(BlobData::Item::TYPE_BLOB, item.type()); - resolved_elements->push_back(&item); + for (const auto& item : snapshot->items()) { + DCHECK_NE(storage::DataElement::TYPE_BLOB, item->type()); + resolved_elements->push_back(item->data_element_ptr()); } + const void* key = snapshot.get(); + body->SetUserData(key, snapshot.release()); } } // namespace scoped_ptr UploadDataStreamBuilder::Build( ResourceRequestBody* body, - BlobStorageContext* blob_context, + storage::BlobStorageContext* blob_context, storage::FileSystemContext* file_system_context, base::TaskRunner* file_task_runner) { // Resolve all blob elements. @@ -98,7 +102,7 @@ scoped_ptr UploadDataStreamBuilder::Build( for (size_t i = 0; i < body->elements()->size(); ++i) { const ResourceRequestBody::Element& element = (*body->elements())[i]; if (element.type() == ResourceRequestBody::Element::TYPE_BLOB) - ResolveBlobReference(blob_context, element, &resolved_elements); + ResolveBlobReference(body, blob_context, element, &resolved_elements); else resolved_elements.push_back(&element); } @@ -128,6 +132,7 @@ scoped_ptr UploadDataStreamBuilder::Build( break; case ResourceRequestBody::Element::TYPE_BLOB: // Blob elements should be resolved beforehand. + // TODO(dmurph): Create blob reader and store the snapshot in there. NOTREACHED(); break; case ResourceRequestBody::Element::TYPE_UNKNOWN: diff --git a/content/browser/loader/upload_data_stream_builder_unittest.cc b/content/browser/loader/upload_data_stream_builder_unittest.cc index dfd22b25317978..4f8e8d40883e8d 100644 --- a/content/browser/loader/upload_data_stream_builder_unittest.cc +++ b/content/browser/loader/upload_data_stream_builder_unittest.cc @@ -16,11 +16,12 @@ #include "net/base/upload_bytes_element_reader.h" #include "net/base/upload_data_stream.h" #include "net/base/upload_file_element_reader.h" +#include "storage/browser/blob/blob_data_builder.h" #include "storage/browser/blob/blob_storage_context.h" #include "testing/gtest/include/gtest/gtest.h" #include "url/gurl.h" -using storage::BlobData; +using storage::BlobDataBuilder; using storage::BlobDataHandle; using storage::BlobStorageContext; @@ -105,29 +106,30 @@ TEST(UploadDataStreamBuilderTest, ResolveBlobAndCreateUploadDataStream) { BlobStorageContext blob_storage_context; const std::string blob_id0("id-0"); - scoped_refptr blob_data(new BlobData(blob_id0)); + scoped_ptr blob_data_builder( + new BlobDataBuilder(blob_id0)); scoped_ptr handle1 = - blob_storage_context.AddFinishedBlob(blob_data.get()); + blob_storage_context.AddFinishedBlob(*blob_data_builder.get()); const std::string blob_id1("id-1"); - blob_data = new BlobData(blob_id1); - blob_data->AppendData("BlobData"); - blob_data->AppendFile( + blob_data_builder.reset(new BlobDataBuilder(blob_id1)); + blob_data_builder->AppendData("BlobData"); + blob_data_builder->AppendFile( base::FilePath(FILE_PATH_LITERAL("BlobFile.txt")), 0, 20, time1); scoped_ptr handle2 = - blob_storage_context.AddFinishedBlob(blob_data.get()); + blob_storage_context.AddFinishedBlob(*blob_data_builder.get()); // Setup upload data elements for comparison. + auto blob_data = blob_data_builder->BuildSnapshot(); ResourceRequestBody::Element blob_element1, blob_element2; blob_element1.SetToBytes( - blob_data->items().at(0).bytes() + - static_cast(blob_data->items().at(0).offset()), - static_cast(blob_data->items().at(0).length())); + blob_data->items().at(0)->bytes() + + static_cast(blob_data->items().at(0)->offset()), + static_cast(blob_data->items().at(0)->length())); blob_element2.SetToFilePathRange( - 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()); + 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()); ResourceRequestBody::Element upload_element1, upload_element2; upload_element1.SetToBytes("Hello", 5); diff --git a/content/browser/media/android/media_resource_getter_impl.cc b/content/browser/media/android/media_resource_getter_impl.cc index 686e01c331c43c..99142e11398bef 100644 --- a/content/browser/media/android/media_resource_getter_impl.cc +++ b/content/browser/media/android/media_resource_getter_impl.cc @@ -28,6 +28,8 @@ #include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context_getter.h" #include "storage/browser/blob/blob_data_handle.h" +#include "storage/browser/blob/blob_data_item.h" +#include "storage/browser/blob/blob_data_snapshot.h" #include "storage/browser/blob/blob_storage_context.h" #include "url/gurl.h" @@ -59,18 +61,19 @@ static void RequestPlatformPathFromBlobURL( ReturnResultOnUIThread(callback, std::string()); return; } - storage::BlobData* data = handle->data(); + scoped_ptr data = handle->CreateSnapshot(); if (!data) { ReturnResultOnUIThread(callback, std::string()); NOTREACHED(); return; } - const std::vector items = data->items(); + const std::vector>& items = + data->items(); // TODO(qinmin): handle the case when the blob data is not a single file. DLOG_IF(WARNING, items.size() != 1u) - << "More than one blob data are present: " << items.size(); - ReturnResultOnUIThread(callback, items[0].path().value()); + << "More than one blob item is present: " << items.size(); + ReturnResultOnUIThread(callback, items[0]->path().value()); } static void RequestPlaformPathFromFileSystemURL( diff --git a/content/browser/service_worker/service_worker_browsertest.cc b/content/browser/service_worker/service_worker_browsertest.cc index f65a7ee1ffd264..21a9f2b7d2366a 100644 --- a/content/browser/service_worker/service_worker_browsertest.cc +++ b/content/browser/service_worker/service_worker_browsertest.cc @@ -37,8 +37,8 @@ #include "net/url_request/url_request_interceptor.h" #include "net/url_request/url_request_test_job.h" #include "storage/browser/blob/blob_data_handle.h" +#include "storage/browser/blob/blob_data_snapshot.h" #include "storage/browser/blob/blob_storage_context.h" -#include "storage/common/blob/blob_data.h" namespace content { @@ -124,9 +124,10 @@ ServiceWorkerVersion::FetchCallback CreateResponseReceiver( void ReadResponseBody(std::string* body, storage::BlobDataHandle* blob_data_handle) { ASSERT_TRUE(blob_data_handle); - ASSERT_EQ(1U, blob_data_handle->data()->items().size()); - *body = std::string(blob_data_handle->data()->items()[0].bytes(), - blob_data_handle->data()->items()[0].length()); + scoped_ptr data = + blob_data_handle->CreateSnapshot(); + ASSERT_EQ(1U, data->items().size()); + *body = std::string(data->items()[0]->bytes(), data->items()[0]->length()); } void ExpectResultAndRun(bool expected, diff --git a/content/browser/service_worker/service_worker_cache.cc b/content/browser/service_worker/service_worker_cache.cc index 3011356f4f17f3..6da4ebe9ce7625 100644 --- a/content/browser/service_worker/service_worker_cache.cc +++ b/content/browser/service_worker/service_worker_cache.cc @@ -17,6 +17,7 @@ #include "net/base/net_errors.h" #include "net/disk_cache/disk_cache.h" #include "net/url_request/url_request_context.h" +#include "storage/browser/blob/blob_data_builder.h" #include "storage/browser/blob/blob_data_handle.h" #include "storage/browser/blob/blob_storage_context.h" #include "storage/browser/blob/blob_url_request_job_factory.h" @@ -343,7 +344,7 @@ struct ServiceWorkerCache::MatchContext { // Output scoped_ptr response; - scoped_refptr blob_data; + scoped_ptr blob_data; // For reading the cache entry data into a blob. scoped_refptr response_body_buffer; @@ -735,7 +736,8 @@ void ServiceWorkerCache::MatchDidReadMetadata( response->blob_uuid = base::GenerateGUID(); - match_context->blob_data = new storage::BlobData(response->blob_uuid); + match_context->blob_data.reset( + new storage::BlobDataBuilder(response->blob_uuid)); match_context->response_body_buffer = new net::IOBufferWithSize(kBufferSize); disk_cache::Entry* tmp_entry_ptr = match_context->entry; @@ -810,7 +812,7 @@ void ServiceWorkerCache::MatchDoneWithBody( scoped_ptr blob_data_handle( match_context->blob_storage_context->AddFinishedBlob( - match_context->blob_data.get())); + *match_context->blob_data.get())); match_context->original_callback.Run(ServiceWorkerCache::ErrorTypeOK, match_context->response.Pass(), diff --git a/content/browser/service_worker/service_worker_cache.h b/content/browser/service_worker/service_worker_cache.h index 15da159eebbdce..ededda6781928c 100644 --- a/content/browser/service_worker/service_worker_cache.h +++ b/content/browser/service_worker/service_worker_cache.h @@ -19,7 +19,7 @@ class IOBufferWithSize; } namespace storage { -class BlobData; +class BlobDataBuilder; class BlobDataHandle; class BlobStorageContext; class QuotaManagerProxy; diff --git a/content/browser/service_worker/service_worker_cache_unittest.cc b/content/browser/service_worker/service_worker_cache_unittest.cc index e7dbb07ef8c975..ea53968fd1fd7a 100644 --- a/content/browser/service_worker/service_worker_cache_unittest.cc +++ b/content/browser/service_worker/service_worker_cache_unittest.cc @@ -18,11 +18,12 @@ #include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_job_factory_impl.h" +#include "storage/browser/blob/blob_data_builder.h" #include "storage/browser/blob/blob_data_handle.h" +#include "storage/browser/blob/blob_data_snapshot.h" #include "storage/browser/blob/blob_storage_context.h" #include "storage/browser/blob/blob_url_request_job_factory.h" #include "storage/browser/quota/quota_manager_proxy.h" -#include "storage/common/blob/blob_data.h" #include "testing/gtest/include/gtest/gtest.h" namespace content { @@ -227,12 +228,12 @@ class ServiceWorkerCacheTest : public testing::Test { for (int i = 0; i < 100; ++i) expected_blob_data_ += kTestData; - scoped_refptr blob_data( - new storage::BlobData("blob-id:myblob")); + scoped_ptr blob_data( + new storage::BlobDataBuilder("blob-id:myblob")); blob_data->AppendData(expected_blob_data_); blob_handle_ = - blob_storage_context->context()->AddFinishedBlob(blob_data.get()); + blob_storage_context->context()->AddFinishedBlob(*blob_data.get()); body_response_ = ServiceWorkerResponse(GURL("http://example.com/body.html"), @@ -385,10 +386,11 @@ class ServiceWorkerCacheTest : public testing::Test { } void CopyBody(storage::BlobDataHandle* blob_handle, std::string* output) { - storage::BlobData* data = blob_handle->data(); - std::vector items = data->items(); - for (size_t i = 0, max = items.size(); i < max; ++i) - output->append(items[i].bytes(), items[i].length()); + scoped_ptr data = blob_handle->CreateSnapshot(); + const auto& items = data->items(); + for (const auto& item : items) { + output->append(item->bytes(), item->length()); + } } bool VerifyKeys(const std::vector& expected_keys) { diff --git a/content/browser/service_worker/service_worker_url_request_job.cc b/content/browser/service_worker/service_worker_url_request_job.cc index b2d836b947d3d9..c7723b39dcc9d0 100644 --- a/content/browser/service_worker/service_worker_url_request_job.cc +++ b/content/browser/service_worker/service_worker_url_request_job.cc @@ -10,6 +10,7 @@ #include "base/bind.h" #include "base/guid.h" +#include "base/memory/scoped_vector.h" #include "base/profiler/scoped_tracker.h" #include "base/strings/stringprintf.h" #include "base/time/time.h" @@ -29,6 +30,7 @@ #include "net/http/http_response_headers.h" #include "net/http/http_response_info.h" #include "net/http/http_util.h" +#include "storage/browser/blob/blob_data_builder.h" #include "storage/browser/blob/blob_data_handle.h" #include "storage/browser/blob/blob_storage_context.h" #include "storage/browser/blob/blob_url_request_job_factory.h" @@ -409,27 +411,35 @@ bool ServiceWorkerURLRequestJob::CreateRequestBodyBlob(std::string* blob_uuid, if (!body_.get() || !blob_storage_context_) return false; + // To ensure the blobs stick around until the end of the reading. + ScopedVector handles; + ScopedVector snapshots; + // TODO(dmurph): Allow blobs to be added below, so that the context can + // efficiently re-use blob items for the new blob. std::vector resolved_elements; - for (size_t i = 0; i < body_->elements()->size(); ++i) { - const ResourceRequestBody::Element& element = (*body_->elements())[i]; + for (const ResourceRequestBody::Element& element : (*body_->elements())) { if (element.type() != ResourceRequestBody::Element::TYPE_BLOB) { resolved_elements.push_back(&element); continue; } scoped_ptr handle = blob_storage_context_->GetBlobDataFromUUID(element.blob_uuid()); - if (handle->data()->items().empty()) + scoped_ptr snapshot = handle->CreateSnapshot(); + if (snapshot->items().empty()) continue; - for (size_t i = 0; i < handle->data()->items().size(); ++i) { - const storage::BlobData::Item& item = handle->data()->items().at(i); - DCHECK_NE(storage::BlobData::Item::TYPE_BLOB, item.type()); - resolved_elements.push_back(&item); + const auto& items = snapshot->items(); + for (const auto& item : items) { + DCHECK_NE(storage::DataElement::TYPE_BLOB, item->type()); + resolved_elements.push_back(item->data_element_ptr()); } + handles.push_back(handle.release()); + snapshots.push_back(snapshot.release()); } const std::string uuid(base::GenerateGUID()); uint64 total_size = 0; - scoped_refptr blob_data = new storage::BlobData(uuid); + + storage::BlobDataBuilder blob_builder(uuid); for (size_t i = 0; i < resolved_elements.size(); ++i) { const ResourceRequestBody::Element& element = *resolved_elements[i]; if (total_size != kuint64max && element.length() != kuint64max) @@ -438,23 +448,21 @@ bool ServiceWorkerURLRequestJob::CreateRequestBodyBlob(std::string* blob_uuid, total_size = kuint64max; switch (element.type()) { case ResourceRequestBody::Element::TYPE_BYTES: - blob_data->AppendData(element.bytes(), element.length()); + blob_builder.AppendData(element.bytes(), element.length()); break; case ResourceRequestBody::Element::TYPE_FILE: - blob_data->AppendFile(element.path(), - element.offset(), - element.length(), - element.expected_modification_time()); + blob_builder.AppendFile(element.path(), element.offset(), + element.length(), + element.expected_modification_time()); break; case ResourceRequestBody::Element::TYPE_BLOB: // Blob elements should be resolved beforehand. NOTREACHED(); break; case ResourceRequestBody::Element::TYPE_FILE_FILESYSTEM: - blob_data->AppendFileSystemFile(element.filesystem_url(), - element.offset(), - element.length(), - element.expected_modification_time()); + blob_builder.AppendFileSystemFile(element.filesystem_url(), + element.offset(), element.length(), + element.expected_modification_time()); break; default: NOTIMPLEMENTED(); @@ -462,7 +470,7 @@ bool ServiceWorkerURLRequestJob::CreateRequestBodyBlob(std::string* blob_uuid, } request_body_blob_data_handle_ = - blob_storage_context_->AddFinishedBlob(blob_data.get()); + blob_storage_context_->AddFinishedBlob(blob_builder); *blob_uuid = uuid; *blob_size = total_size; return true; diff --git a/content/browser/service_worker/service_worker_url_request_job_unittest.cc b/content/browser/service_worker/service_worker_url_request_job_unittest.cc index 4199dd9c988b95..28986dea607564 100644 --- a/content/browser/service_worker/service_worker_url_request_job_unittest.cc +++ b/content/browser/service_worker/service_worker_url_request_job_unittest.cc @@ -36,10 +36,10 @@ #include "net/url_request/url_request.h" #include "net/url_request/url_request_context.h" #include "net/url_request/url_request_job_factory_impl.h" +#include "storage/browser/blob/blob_data_builder.h" #include "storage/browser/blob/blob_storage_context.h" #include "storage/browser/blob/blob_url_request_job.h" #include "storage/browser/blob/blob_url_request_job_factory.h" -#include "storage/common/blob/blob_data.h" #include "testing/gtest/include/gtest/gtest.h" namespace content { @@ -104,7 +104,7 @@ class ServiceWorkerURLRequestJobTest : public testing::Test { protected: ServiceWorkerURLRequestJobTest() : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), - blob_data_(new storage::BlobData("blob-id:myblob")) {} + blob_data_(new storage::BlobDataBuilder("blob-id:myblob")) {} ~ServiceWorkerURLRequestJobTest() override {} void SetUp() override { @@ -198,7 +198,7 @@ class ServiceWorkerURLRequestJobTest : public testing::Test { MockURLRequestDelegate url_request_delegate_; scoped_ptr request_; - scoped_refptr blob_data_; + scoped_ptr blob_data_; private: DISALLOW_COPY_AND_ASSIGN(ServiceWorkerURLRequestJobTest); @@ -255,7 +255,7 @@ TEST_F(ServiceWorkerURLRequestJobTest, BlobResponse) { expected_response += kTestData; } scoped_ptr blob_handle = - blob_storage_context->context()->AddFinishedBlob(blob_data_.get()); + blob_storage_context->context()->AddFinishedBlob(*blob_data_.get()); SetUpWithHelper(new BlobResponder( kProcessID, blob_handle->uuid(), expected_response.size())); diff --git a/content/common/shareable_file_reference_unittest.cc b/content/browser/shareable_file_reference_unittest.cc similarity index 94% rename from content/common/shareable_file_reference_unittest.cc rename to content/browser/shareable_file_reference_unittest.cc index 5e697b9eb24e43..84d035fd43ddd2 100644 --- a/content/common/shareable_file_reference_unittest.cc +++ b/content/browser/shareable_file_reference_unittest.cc @@ -1,8 +1,8 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. +// Copyright 2015 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 "storage/common/blob/shareable_file_reference.h" +#include "storage/browser/blob/shareable_file_reference.h" #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" diff --git a/content/browser/storage_partition_impl_map.cc b/content/browser/storage_partition_impl_map.cc index d8b2e12704edc1..afd9c17875fa71 100644 --- a/content/browser/storage_partition_impl_map.cc +++ b/content/browser/storage_partition_impl_map.cc @@ -39,7 +39,6 @@ #include "storage/browser/blob/blob_storage_context.h" #include "storage/browser/blob/blob_url_request_job_factory.h" #include "storage/browser/fileapi/file_system_url_request_job_factory.h" -#include "storage/common/blob/blob_data.h" using storage::FileSystemContext; using storage::BlobStorageContext; diff --git a/content/child/webblobregistry_impl.cc b/content/child/webblobregistry_impl.cc index d673c2a657fddc..ee5313b7e6b5f2 100644 --- a/content/child/webblobregistry_impl.cc +++ b/content/child/webblobregistry_impl.cc @@ -12,7 +12,7 @@ #include "content/child/child_thread.h" #include "content/child/thread_safe_sender.h" #include "content/common/fileapi/webblob_messages.h" -#include "storage/common/blob/blob_data.h" +#include "storage/common/data_element.h" #include "third_party/WebKit/public/platform/WebBlobData.h" #include "third_party/WebKit/public/platform/WebString.h" #include "third_party/WebKit/public/platform/WebThreadSafeData.h" @@ -56,7 +56,7 @@ void WebBlobRegistryImpl::registerBlobData( } case WebBlobData::Item::TypeFile: if (data_item.length) { - storage::BlobData::Item item; + storage::DataElement item; item.SetToFilePathRange( base::FilePath::FromUTF16Unsafe(data_item.filePath), static_cast(data_item.offset), @@ -68,7 +68,7 @@ void WebBlobRegistryImpl::registerBlobData( break; case WebBlobData::Item::TypeBlob: if (data_item.length) { - storage::BlobData::Item item; + storage::DataElement item; item.SetToBlobRange( data_item.blobUUID.utf8(), static_cast(data_item.offset), @@ -81,7 +81,7 @@ void WebBlobRegistryImpl::registerBlobData( if (data_item.length) { // We only support filesystem URL as of now. DCHECK(GURL(data_item.fileSystemURL).SchemeIsFileSystem()); - storage::BlobData::Item item; + storage::DataElement item; item.SetToFileSystemUrlRange( data_item.fileSystemURL, static_cast(data_item.offset), @@ -122,7 +122,7 @@ void WebBlobRegistryImpl::SendDataForBlob(const std::string& uuid_str, if (data.size() == 0) return; if (data.size() < kLargeThresholdBytes) { - storage::BlobData::Item item; + storage::DataElement item; item.SetToBytes(data.data(), data.size()); sender_->Send(new BlobHostMsg_AppendBlobDataItem(uuid_str, item)); } else { @@ -170,7 +170,7 @@ void WebBlobRegistryImpl::addDataToStream(const WebURL& url, if (length == 0) return; if (length < kLargeThresholdBytes) { - storage::BlobData::Item item; + storage::DataElement item; item.SetToBytes(data, length); sender_->Send(new StreamHostMsg_AppendBlobDataItem(url, item)); } else { diff --git a/content/common/fileapi/webblob_messages.h b/content/common/fileapi/webblob_messages.h index aad38c35d5d8bb..7527b18ef153fa 100644 --- a/content/common/fileapi/webblob_messages.h +++ b/content/common/fileapi/webblob_messages.h @@ -8,7 +8,7 @@ #include "content/common/content_export.h" #include "content/public/common/common_param_traits.h" #include "ipc/ipc_message_macros.h" -#include "storage/common/blob/blob_data.h" +#include "storage/common/data_element.h" #undef IPC_MESSAGE_EXPORT #define IPC_MESSAGE_EXPORT CONTENT_EXPORT @@ -20,7 +20,7 @@ IPC_MESSAGE_CONTROL1(BlobHostMsg_StartBuilding, std::string /*uuid */) IPC_MESSAGE_CONTROL2(BlobHostMsg_AppendBlobDataItem, std::string /* uuid */, - storage::BlobData::Item) + storage::DataElement) IPC_SYNC_MESSAGE_CONTROL3_0(BlobHostMsg_SyncAppendSharedMemory, std::string /*uuid*/, base::SharedMemoryHandle, @@ -49,7 +49,7 @@ IPC_MESSAGE_CONTROL2(StreamHostMsg_StartBuilding, // Appends data to a stream being built. IPC_MESSAGE_CONTROL2(StreamHostMsg_AppendBlobDataItem, GURL /* url */, - storage::BlobData::Item) + storage::DataElement) // Appends data to a stream being built. IPC_SYNC_MESSAGE_CONTROL3_0(StreamHostMsg_SyncAppendSharedMemory, diff --git a/content/content_tests.gypi b/content/content_tests.gypi index e8c752846dbc15..c1ff6e9e025481 100644 --- a/content/content_tests.gypi +++ b/content/content_tests.gypi @@ -531,6 +531,7 @@ 'browser/service_worker/service_worker_utils_unittest.cc', 'browser/service_worker/service_worker_version_unittest.cc', 'browser/service_worker/service_worker_write_to_cache_job_unittest.cc', + 'browser/shareable_file_reference_unittest.cc', 'browser/shared_worker/shared_worker_instance_unittest.cc', 'browser/shared_worker/shared_worker_service_impl_unittest.cc', 'browser/site_instance_impl_unittest.cc', @@ -614,7 +615,6 @@ 'common/sandbox_mac_system_access_unittest.mm', 'common/sandbox_mac_unittest_helper.h', 'common/sandbox_mac_unittest_helper.mm', - 'common/shareable_file_reference_unittest.cc', 'common/webplugininfo_unittest.cc', 'renderer/android/email_detector_unittest.cc', 'renderer/android/phone_number_detector_unittest.cc', diff --git a/content/public/test/mock_blob_url_request_context.cc b/content/public/test/mock_blob_url_request_context.cc index 6ebaa655a50367..6f558700d40093 100644 --- a/content/public/test/mock_blob_url_request_context.cc +++ b/content/public/test/mock_blob_url_request_context.cc @@ -4,11 +4,10 @@ #include "content/public/test/mock_blob_url_request_context.h" +#include "storage/browser/blob/blob_data_builder.h" #include "storage/browser/blob/blob_storage_context.h" #include "storage/browser/blob/blob_url_request_job.h" #include "storage/browser/blob/blob_url_request_job_factory.h" -#include "storage/common/blob/blob_data.h" - namespace content { @@ -35,10 +34,10 @@ ScopedTextBlob::ScopedTextBlob( : blob_id_(blob_id), context_(request_context.blob_storage_context()) { DCHECK(context_); - scoped_refptr blob_data(new storage::BlobData(blob_id_)); + storage::BlobDataBuilder blob_builder(blob_id_); if (!data.empty()) - blob_data->AppendData(data); - handle_ = context_->AddFinishedBlob(blob_data.get()); + blob_builder.AppendData(data); + handle_ = context_->AddFinishedBlob(blob_builder); } ScopedTextBlob::~ScopedTextBlob() { diff --git a/storage/browser/BUILD.gn b/storage/browser/BUILD.gn index 3ca92d71cf6e17..02bd84e03139c0 100644 --- a/storage/browser/BUILD.gn +++ b/storage/browser/BUILD.gn @@ -7,8 +7,14 @@ component("browser") { output_name = "storage_browser" sources = [ "storage_browser_export.h", + "blob/blob_data_builder.cc", + "blob/blob_data_builder.h", "blob/blob_data_handle.cc", "blob/blob_data_handle.h", + "blob/blob_data_item.cc", + "blob/blob_data_item.h", + "blob/blob_data_snapshot.cc", + "blob/blob_data_snapshot.h", "blob/blob_storage_context.cc", "blob/blob_storage_context.h", "blob/blob_url_request_job.cc", @@ -19,6 +25,10 @@ component("browser") { "blob/file_stream_reader.h", "blob/local_file_stream_reader.cc", "blob/local_file_stream_reader.h", + "blob/scoped_file.cc", + "blob/scoped_file.h", + "blob/shareable_file_reference.cc", + "blob/shareable_file_reference.h", "blob/view_blob_internals_job.cc", "blob/view_blob_internals_job.h", "database/database_quota_client.cc", diff --git a/storage/browser/blob/blob_data_builder.cc b/storage/browser/blob/blob_data_builder.cc new file mode 100644 index 00000000000000..120bc44bbe492f --- /dev/null +++ b/storage/browser/blob/blob_data_builder.cc @@ -0,0 +1,82 @@ +// Copyright (c) 2015 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 +#include "base/time/time.h" + +namespace storage { + +BlobDataBuilder::BlobDataBuilder(const std::string& uuid) : uuid_(uuid) { +} +BlobDataBuilder::~BlobDataBuilder() { +} + +void BlobDataBuilder::AppendData(const char* data, size_t length) { + DCHECK(length > 0); + scoped_ptr element(new DataElement()); + element->SetToBytes(data, length); + items_.push_back(new BlobDataItem(element.Pass())); +} + +void BlobDataBuilder::AppendFile(const base::FilePath& file_path, + uint64 offset, + uint64 length, + const base::Time& expected_modification_time) { + DCHECK(length > 0); + scoped_ptr element(new DataElement()); + element->SetToFilePathRange(file_path, offset, length, + expected_modification_time); + items_.push_back(new BlobDataItem(element.Pass())); +} + +void BlobDataBuilder::AppendFile( + const base::FilePath& file_path, + uint64 offset, + uint64 length, + const base::Time& expected_modification_time, + scoped_refptr shareable_file) { + DCHECK(length > 0); + scoped_ptr element(new DataElement()); + element->SetToFilePathRange(file_path, offset, length, + expected_modification_time); + items_.push_back(new BlobDataItem(element.Pass(), shareable_file)); +} + +void BlobDataBuilder::AppendBlob(const std::string& uuid, + uint64 offset, + uint64 length) { + DCHECK_GT(length, 0ul); + scoped_ptr element(new DataElement()); + element->SetToBlobRange(uuid, offset, length); + items_.push_back(new BlobDataItem(element.Pass())); +} + +void BlobDataBuilder::AppendFileSystemFile( + const GURL& url, + uint64 offset, + uint64 length, + const base::Time& expected_modification_time) { + DCHECK(length > 0); + scoped_ptr element(new DataElement()); + element->SetToFileSystemUrlRange(url, offset, length, + expected_modification_time); + items_.push_back(new BlobDataItem(element.Pass())); +} + +size_t BlobDataBuilder::GetMemoryUsage() const { + int64 memory = 0; + for (const auto& data_item : items_) { + if (data_item->type() == DataElement::TYPE_BYTES) + memory += data_item->length(); + } + return memory; +} + +scoped_ptr BlobDataBuilder::BuildSnapshot() { + return scoped_ptr(new BlobDataSnapshot(uuid_, content_type_, + content_disposition_, + items_)).Pass(); +} + +} // namespace storage diff --git a/storage/browser/blob/blob_data_builder.h b/storage/browser/blob/blob_data_builder.h new file mode 100644 index 00000000000000..3c426406c5e129 --- /dev/null +++ b/storage/browser/blob/blob_data_builder.h @@ -0,0 +1,118 @@ +// Copyright 2015 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 STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_ +#define STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_ + +#include +#include + +#include "base/basictypes.h" +#include "base/files/file_path.h" +#include "storage/browser/blob/blob_data_item.h" +#include "storage/browser/blob/blob_data_snapshot.h" +#include "storage/browser/storage_browser_export.h" + +namespace storage { +class BlobStorageContext; + +class STORAGE_EXPORT BlobDataBuilder { + public: + explicit BlobDataBuilder(const std::string& uuid); + virtual ~BlobDataBuilder(); + + const std::string& uuid() const { return uuid_; } + + void AppendData(const std::string& data) { + AppendData(data.c_str(), data.size()); + } + + void AppendData(const char* data, size_t length); + + void AppendFile(const base::FilePath& file_path, + uint64 offset, + uint64 length, + const base::Time& expected_modification_time); + + void AppendFile(const base::FilePath& file_path, + uint64 offset, + uint64 length, + const base::Time& expected_modification_time, + scoped_refptr shareable_file); + + void AppendBlob(const std::string& uuid, uint64 offset, uint64 length); + void AppendFileSystemFile(const GURL& url, + uint64 offset, + uint64 length, + const base::Time& expected_modification_time); + + void set_content_type(const std::string& content_type) { + content_type_ = content_type; + } + + void set_content_disposition(const std::string& content_disposition) { + content_disposition_ = content_disposition; + } + + size_t GetMemoryUsage() const; + + scoped_ptr BuildSnapshot(); + + private: + friend class BlobStorageContext; + friend bool operator==(const BlobDataBuilder& a, const BlobDataBuilder& b); + friend bool operator==(const BlobDataSnapshot& a, const BlobDataBuilder& b); + + std::string uuid_; + std::string content_type_; + std::string content_disposition_; + std::vector> items_; + + DISALLOW_COPY_AND_ASSIGN(BlobDataBuilder); +}; + +#if defined(UNIT_TEST) +inline bool operator==(const BlobDataBuilder& a, const BlobDataBuilder& b) { + if (a.content_type_ != b.content_type_) + return false; + if (a.content_disposition_ != b.content_disposition_) + return false; + if (a.items_.size() != b.items_.size()) + return false; + for (size_t i = 0; i < a.items_.size(); ++i) { + if (a.items_[i] != b.items_[i]) + return false; + } + return true; +} + +inline bool operator==(const BlobDataSnapshot& a, const BlobDataBuilder& b) { + if (a.content_type() != b.content_type_) { + return false; + } + if (a.content_disposition() != b.content_disposition_) { + return false; + } + if (a.items().size() != b.items_.size()) { + return false; + } + for (size_t i = 0; i < a.items().size(); ++i) { + if (*(a.items()[i]) != *(b.items_[i])) { + return false; + } + } + return true; +} + +inline bool operator!=(const BlobDataSnapshot& a, const BlobDataBuilder& b) { + return !(a == b); +} + +inline bool operator!=(const BlobDataBuilder& a, const BlobDataBuilder& b) { + return !(a == b); +} +#endif // defined(UNIT_TEST) + +} // namespace storage +#endif // STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_ diff --git a/storage/browser/blob/blob_data_handle.cc b/storage/browser/blob/blob_data_handle.cc index cf647b4d9cc8a9..e3a4be944fe36e 100644 --- a/storage/browser/blob/blob_data_handle.cc +++ b/storage/browser/blob/blob_data_handle.cc @@ -8,38 +8,38 @@ #include "base/location.h" #include "base/logging.h" #include "base/sequenced_task_runner.h" +#include "storage/browser/blob/blob_data_snapshot.h" #include "storage/browser/blob/blob_storage_context.h" -#include "storage/common/blob/blob_data.h" namespace storage { BlobDataHandle::BlobDataHandleShared::BlobDataHandleShared( - BlobData* blob_data, + const std::string& uuid, BlobStorageContext* context, base::SequencedTaskRunner* task_runner) - : blob_data_(blob_data), - context_(context->AsWeakPtr()) { - context_->IncrementBlobRefCount(blob_data->uuid()); + : uuid_(uuid), context_(context->AsWeakPtr()) { + context_->IncrementBlobRefCount(uuid); } -BlobData* BlobDataHandle::BlobDataHandleShared::data() const { - return blob_data_.get(); +scoped_ptr +BlobDataHandle::BlobDataHandleShared::CreateSnapshot() const { + return context_->CreateSnapshot(uuid_).Pass(); } const std::string& BlobDataHandle::BlobDataHandleShared::uuid() const { - return blob_data_->uuid(); + return uuid_; } BlobDataHandle::BlobDataHandleShared::~BlobDataHandleShared() { if (context_.get()) - context_->DecrementBlobRefCount(blob_data_->uuid()); + context_->DecrementBlobRefCount(uuid_); } -BlobDataHandle::BlobDataHandle(BlobData* blob_data, +BlobDataHandle::BlobDataHandle(const std::string& uuid, BlobStorageContext* context, base::SequencedTaskRunner* task_runner) : io_task_runner_(task_runner), - shared_(new BlobDataHandleShared(blob_data, context, task_runner)) { + shared_(new BlobDataHandleShared(uuid, context, task_runner)) { DCHECK(io_task_runner_.get()); DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); } @@ -52,16 +52,16 @@ BlobDataHandle::BlobDataHandle(const BlobDataHandle& other) { BlobDataHandle::~BlobDataHandle() { BlobDataHandleShared* raw = shared_.get(); raw->AddRef(); - shared_ = 0; + shared_ = nullptr; io_task_runner_->ReleaseSoon(FROM_HERE, raw); } -BlobData* BlobDataHandle::data() const { +scoped_ptr BlobDataHandle::CreateSnapshot() const { DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); - return shared_->data(); + return shared_->CreateSnapshot().Pass(); } -std::string BlobDataHandle::uuid() const { +const std::string& BlobDataHandle::uuid() const { return shared_->uuid(); } diff --git a/storage/browser/blob/blob_data_handle.h b/storage/browser/blob/blob_data_handle.h index 0b1d151c612e07..30412415f76e68 100644 --- a/storage/browser/blob/blob_data_handle.h +++ b/storage/browser/blob/blob_data_handle.h @@ -18,31 +18,44 @@ class SequencedTaskRunner; namespace storage { -class BlobData; +class BlobDataSnapshot; class BlobStorageContext; -// A scoper object for use in chrome's main browser process, ensures -// the underlying BlobData and its uuid remain in BlobStorageContext's -// collection for the duration. This object has delete semantics and -// maybe deleted on any thread. +// BlobDataHandle ensures that the underlying blob (keyed by the uuid) remains +// in the BlobStorageContext's collection while this object is alive. Anything +// that needs to keep a blob alive needs to store this handle. +// When the blob data itself is needed, clients must call the CreateSnapshot() +// method on the IO thread to create a snapshot of the blob data. This snapshot +// is not intended to be persisted, and serves to ensure that the backing +// resources remain around for the duration of reading the blob. This snapshot +// can be read on any thread, but it must be destructed on the IO thread. +// This object has delete semantics and may be deleted on any thread. class STORAGE_EXPORT BlobDataHandle : public base::SupportsUserData::Data { public: BlobDataHandle(const BlobDataHandle& other); // May be copied on any thread. - ~BlobDataHandle() override; // Maybe be deleted on any thread. - BlobData* data() const; // May only be accessed on the IO thread. + ~BlobDataHandle() override; // May be deleted on any thread. - std::string uuid() const; // May be accessed on any thread. + // A BlobDataSnapshot is used to read the data from the blob. This object is + // intended to be transient and should not be stored for any extended period + // of time. + // This call and the destruction of the returned snapshot must be called + // on the IO thread. + scoped_ptr CreateSnapshot() const; + + const std::string& uuid() const; // May be accessed on any thread. private: + // Internal class whose destructor is guarenteed to be called on the IO + // thread. class BlobDataHandleShared : public base::RefCountedThreadSafe { public: - BlobDataHandleShared(BlobData* blob_data, + BlobDataHandleShared(const std::string& uuid, BlobStorageContext* context, base::SequencedTaskRunner* task_runner); - BlobData* data() const; + scoped_ptr CreateSnapshot() const; const std::string& uuid() const; private: @@ -52,14 +65,15 @@ class STORAGE_EXPORT BlobDataHandle virtual ~BlobDataHandleShared(); - scoped_refptr blob_data_; + const std::string uuid_; base::WeakPtr context_; DISALLOW_COPY_AND_ASSIGN(BlobDataHandleShared); }; friend class BlobStorageContext; - BlobDataHandle(BlobData* blob_data, BlobStorageContext* context, + BlobDataHandle(const std::string& uuid, + BlobStorageContext* context, base::SequencedTaskRunner* task_runner); scoped_refptr io_task_runner_; diff --git a/storage/browser/blob/blob_data_item.cc b/storage/browser/blob/blob_data_item.cc new file mode 100644 index 00000000000000..504a1c3e8be399 --- /dev/null +++ b/storage/browser/blob/blob_data_item.cc @@ -0,0 +1,18 @@ +// Copyright (c) 2015 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 "storage/browser/blob/blob_data_item.h" + +namespace storage { + +BlobDataItem::BlobDataItem(scoped_ptr item, + scoped_refptr file_handle) + : item_(item.Pass()), file_handle_(file_handle) { +} +BlobDataItem::BlobDataItem(scoped_ptr item) : item_(item.Pass()) { +} +BlobDataItem::~BlobDataItem() { +} + +} // namespace storage diff --git a/storage/browser/blob/blob_data_item.h b/storage/browser/blob/blob_data_item.h new file mode 100644 index 00000000000000..099415b6e14079 --- /dev/null +++ b/storage/browser/blob/blob_data_item.h @@ -0,0 +1,63 @@ +// Copyright (c) 2015 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 STORAGE_BROWSER_BLOB_BLOB_DATA_ITEM_H_ +#define STORAGE_BROWSER_BLOB_BLOB_DATA_ITEM_H_ + +#include "base/basictypes.h" +#include "base/memory/ref_counted.h" +#include "storage/browser/blob/shareable_file_reference.h" +#include "storage/browser/storage_browser_export.h" +#include "storage/common/data_element.h" + +namespace storage { +class BlobDataBuilder; +class BlobStorageContext; + +// Ref counted blob item. This class owns the backing data of the blob item. +// The backing data is immutable, and cannot change after creation. +// The purpose of this class is to allow the resource to stick around in the +// snapshot even after the resource was swapped in the blob (either to disk or +// to memory) by the BlobStorageContext. +class STORAGE_EXPORT BlobDataItem : public base::RefCounted { + public: + storage::DataElement::Type type() const { return item_->type(); } + const char* bytes() const { return item_->bytes(); } + const base::FilePath& path() const { return item_->path(); } + const GURL& filesystem_url() const { return item_->filesystem_url(); } + const std::string& blob_uuid() const { return item_->blob_uuid(); } + uint64 offset() const { return item_->offset(); } + uint64 length() const { return item_->length(); } + const base::Time& expected_modification_time() const { + return item_->expected_modification_time(); + } + const DataElement& data_element() const { return *item_; } + const DataElement* data_element_ptr() const { return item_.get(); } + + private: + friend class BlobDataBuilder; + friend class BlobStorageContext; + friend class base::RefCounted; + BlobDataItem(scoped_ptr item); + BlobDataItem(scoped_ptr item, + scoped_refptr file_handle); + virtual ~BlobDataItem(); + + scoped_ptr item_; + scoped_refptr file_handle_; +}; + +#if defined(UNIT_TEST) +inline bool operator==(const BlobDataItem& a, const BlobDataItem& b) { + return a.data_element() == b.data_element(); +} + +inline bool operator!=(const BlobDataItem& a, const BlobDataItem& b) { + return !(a == b); +} +#endif // defined(UNIT_TEST) + +} // namespace storage + +#endif // STORAGE_BROWSER_BLOB_BLOB_DATA_ITEM_H_ diff --git a/storage/browser/blob/blob_data_snapshot.cc b/storage/browser/blob/blob_data_snapshot.cc new file mode 100644 index 00000000000000..6ae74cd8d3220e --- /dev/null +++ b/storage/browser/blob/blob_data_snapshot.cc @@ -0,0 +1,39 @@ +// Copyright (c) 2015 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 "storage/browser/blob/blob_data_snapshot.h" + +namespace storage { + +BlobDataSnapshot::BlobDataSnapshot( + const std::string& uuid, + const std::string& content_type, + const std::string& content_disposition, + const std::vector>& items) + : uuid_(uuid), + content_type_(content_type), + content_disposition_(content_disposition), + items_(items) { +} + +BlobDataSnapshot::BlobDataSnapshot(const BlobDataSnapshot& other) + : uuid_(other.uuid_), + content_type_(other.content_type_), + content_disposition_(other.content_disposition_), + items_(other.items_) { +} + +BlobDataSnapshot::~BlobDataSnapshot() { +} + +size_t BlobDataSnapshot::GetMemoryUsage() const { + int64 memory = 0; + for (const auto& data_item : items_) { + if (data_item->type() == DataElement::TYPE_BYTES) + memory += data_item->length(); + } + return memory; +} + +} // namespace storage diff --git a/storage/browser/blob/blob_data_snapshot.h b/storage/browser/blob/blob_data_snapshot.h new file mode 100644 index 00000000000000..416c3865f32330 --- /dev/null +++ b/storage/browser/blob/blob_data_snapshot.h @@ -0,0 +1,54 @@ +// Copyright 2015 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 STORAGE_BROWSER_BLOB_BLOB_DATA_SNAPSHOT_H_ +#define STORAGE_BROWSER_BLOB_BLOB_DATA_SNAPSHOT_H_ + +#include +#include + +#include "base/memory/ref_counted.h" +#include "base/supports_user_data.h" +#include "storage/browser/blob/blob_data_item.h" +#include "storage/browser/storage_browser_export.h" + +namespace storage { +class BlobDataBuilder; + +// Snapshot of a Blob. This snapshot holds a refcount of the current +// blob item resources so the backing storage for these items will stick +// around for the lifetime of this object. (The data represented by a blob is +// immutable, but the backing store can change). Keeping this object alive +// guarantees that the resources stay alive, but it does not guarentee that +// the blob stays alive. Use the BlobDataHandle to keep a blob alive. +// This class must be deleted on the IO thread. +class STORAGE_EXPORT BlobDataSnapshot : public base::SupportsUserData::Data { + public: + BlobDataSnapshot(const BlobDataSnapshot& other); + ~BlobDataSnapshot() override; + + const std::vector>& items() const { + return items_; + } + const std::string& content_type() const { return content_type_; } + const std::string& content_disposition() const { + return content_disposition_; + } + size_t GetMemoryUsage() const; + + private: + friend class BlobDataBuilder; + BlobDataSnapshot(const std::string& uuid, + const std::string& content_type, + const std::string& content_disposition, + const std::vector>& items); + + const std::string uuid_; + const std::string content_type_; + const std::string content_disposition_; + const std::vector> items_; +}; + +} // namespace storage +#endif // STORAGE_BROWSER_BLOB_BLOB_DATA_SNAPSHOT_H_ diff --git a/storage/browser/blob/blob_storage_context.cc b/storage/browser/blob/blob_storage_context.cc index 9680e4d4413f88..1577b6bd9b9594 100644 --- a/storage/browser/blob/blob_storage_context.cc +++ b/storage/browser/blob/blob_storage_context.cc @@ -9,8 +9,8 @@ #include "base/logging.h" #include "base/message_loop/message_loop_proxy.h" #include "base/metrics/histogram.h" -#include "storage/browser/blob/blob_data_handle.h" -#include "storage/common/blob/blob_data.h" +#include "base/stl_util.h" +#include "storage/browser/blob/blob_data_builder.h" #include "url/gurl.h" namespace storage { @@ -43,19 +43,24 @@ BlobStorageContext::BlobMapEntry::BlobMapEntry() : refcount(0), flags(0) { } -BlobStorageContext::BlobMapEntry::BlobMapEntry( - int refcount, int flags, BlobData* data) - : refcount(refcount), flags(flags), data(data) { +BlobStorageContext::BlobMapEntry::BlobMapEntry(int refcount, + BlobDataBuilder* data) + : refcount(refcount), flags(0), data_builder(data) { } BlobStorageContext::BlobMapEntry::~BlobMapEntry() { } +bool BlobStorageContext::BlobMapEntry::IsBeingBuilt() { + return data_builder; +} + BlobStorageContext::BlobStorageContext() : memory_usage_(0) { } BlobStorageContext::~BlobStorageContext() { + STLDeleteContainerPairSecondPointers(blob_map_.begin(), blob_map_.end()); } scoped_ptr BlobStorageContext::GetBlobDataFromUUID( @@ -64,11 +69,12 @@ scoped_ptr BlobStorageContext::GetBlobDataFromUUID( BlobMap::iterator found = blob_map_.find(uuid); if (found == blob_map_.end()) return result.Pass(); - if (found->second.flags & EXCEEDED_MEMORY) + auto* entry = found->second; + if (entry->flags & EXCEEDED_MEMORY) return result.Pass(); - DCHECK(!(found->second.flags & BEING_BUILT)); - result.reset(new BlobDataHandle( - found->second.data.get(), this, base::MessageLoopProxy::current().get())); + DCHECK(!entry->IsBeingBuilt()); + result.reset( + new BlobDataHandle(uuid, this, base::MessageLoopProxy::current().get())); return result.Pass(); } @@ -82,16 +88,13 @@ scoped_ptr BlobStorageContext::GetBlobDataFromPublicURL( } scoped_ptr BlobStorageContext::AddFinishedBlob( - const BlobData* data) { - StartBuildingBlob(data->uuid()); - for (std::vector::const_iterator iter = - data->items().begin(); - iter != data->items().end(); ++iter) { - AppendBlobDataItem(data->uuid(), *iter); - } - FinishBuildingBlob(data->uuid(), data->content_type()); - scoped_ptr handle = GetBlobDataFromUUID(data->uuid()); - DecrementBlobRefCount(data->uuid()); + const BlobDataBuilder& data) { + StartBuildingBlob(data.uuid_); + for (const auto& blob_item : data.items_) + AppendBlobDataItem(data.uuid_, *(blob_item->item_)); + FinishBuildingBlob(data.uuid_, data.content_type_); + scoped_ptr handle = GetBlobDataFromUUID(data.uuid_); + DecrementBlobRefCount(data.uuid_); return handle.Pass(); } @@ -115,20 +118,33 @@ void BlobStorageContext::RevokePublicBlobURL(const GURL& blob_url) { public_blob_urls_.erase(blob_url); } +scoped_ptr BlobStorageContext::CreateSnapshot( + const std::string& uuid) { + scoped_ptr result; + auto found = blob_map_.find(uuid); + DCHECK(found != blob_map_.end()) + << "Blob should be in map, as the handle is still around"; + BlobMapEntry* entry = found->second; + DCHECK(!entry->IsBeingBuilt()); + result.reset(new BlobDataSnapshot(*entry->data)); + return result.Pass(); +} + void BlobStorageContext::StartBuildingBlob(const std::string& uuid) { DCHECK(!IsInUse(uuid) && !uuid.empty()); - blob_map_[uuid] = BlobMapEntry(1, BEING_BUILT, new BlobData(uuid)); + blob_map_[uuid] = new BlobMapEntry(1, new BlobDataBuilder(uuid)); } -void BlobStorageContext::AppendBlobDataItem( - const std::string& uuid, const BlobData::Item& item) { +void BlobStorageContext::AppendBlobDataItem(const std::string& uuid, + const DataElement& item) { DCHECK(IsBeingBuilt(uuid)); BlobMap::iterator found = blob_map_.find(uuid); if (found == blob_map_.end()) return; - if (found->second.flags & EXCEEDED_MEMORY) + BlobMapEntry* entry = found->second; + if (entry->flags & EXCEEDED_MEMORY) return; - BlobData* target_blob_data = found->second.data.get(); + BlobDataBuilder* target_blob_data = entry->data_builder.get(); DCHECK(target_blob_data); bool exceeded_memory = false; @@ -149,31 +165,33 @@ void BlobStorageContext::AppendBlobDataItem( UMA_HISTOGRAM_COUNTS("Storage.Blob.StorageSizeBeforeAppend", memory_usage_ / 1024); switch (item.type()) { - case BlobData::Item::TYPE_BYTES: + case DataElement::TYPE_BYTES: UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.Bytes", length / 1024); DCHECK(!item.offset()); exceeded_memory = !AppendBytesItem(target_blob_data, item.bytes(), static_cast(length)); break; - case BlobData::Item::TYPE_FILE: + case DataElement::TYPE_FILE: UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.File", length / 1024); - AppendFileItem(target_blob_data, item.path(), item.offset(), length, - item.expected_modification_time()); + AppendFileItem(target_blob_data, item.path(), item.offset(), + item.length(), item.expected_modification_time()); break; - case BlobData::Item::TYPE_FILE_FILESYSTEM: + case DataElement::TYPE_FILE_FILESYSTEM: UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.FileSystem", length / 1024); AppendFileSystemFileItem(target_blob_data, item.filesystem_url(), - item.offset(), length, + item.offset(), item.length(), item.expected_modification_time()); break; - case BlobData::Item::TYPE_BLOB: { + case DataElement::TYPE_BLOB: { UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.Blob", length / 1024); + // We grab the handle to ensure it stays around while we copy it. scoped_ptr src = GetBlobDataFromUUID(item.blob_uuid()); - if (src) - exceeded_memory = !ExpandStorageItems(target_blob_data, - src->data(), - item.offset(), - item.length()); + if (src) { + BlobMapEntry* entry = blob_map_.find(item.blob_uuid())->second; + DCHECK(entry->data); + exceeded_memory = !ExpandStorageItems(target_blob_data, *entry->data, + item.offset(), item.length()); + } break; } default: @@ -188,8 +206,8 @@ void BlobStorageContext::AppendBlobDataItem( // as a stop gap, we'll prevent memory usage over a max amount. if (exceeded_memory) { memory_usage_ -= target_blob_data->GetMemoryUsage(); - found->second.flags |= EXCEEDED_MEMORY; - found->second.data = new BlobData(uuid); + entry->flags |= EXCEEDED_MEMORY; + entry->data_builder.reset(new BlobDataBuilder(uuid)); return; } } @@ -200,13 +218,13 @@ void BlobStorageContext::FinishBuildingBlob( BlobMap::iterator found = blob_map_.find(uuid); if (found == blob_map_.end()) return; - found->second.data->set_content_type(content_type); - found->second.flags &= ~BEING_BUILT; - UMA_HISTOGRAM_COUNTS("Storage.Blob.ItemCount", - found->second.data->items().size()); - UMA_HISTOGRAM_BOOLEAN( - "Storage.Blob.ExceededMemory", - (found->second.flags & EXCEEDED_MEMORY) == EXCEEDED_MEMORY); + BlobMapEntry* entry = found->second; + entry->data_builder->set_content_type(content_type); + entry->data = entry->data_builder->BuildSnapshot().Pass(); + entry->data_builder.reset(); + UMA_HISTOGRAM_COUNTS("Storage.Blob.ItemCount", entry->data->items().size()); + UMA_HISTOGRAM_BOOLEAN("Storage.Blob.ExceededMemory", + (entry->flags & EXCEEDED_MEMORY) == EXCEEDED_MEMORY); } void BlobStorageContext::CancelBuildingBlob(const std::string& uuid) { @@ -220,60 +238,63 @@ void BlobStorageContext::IncrementBlobRefCount(const std::string& uuid) { DCHECK(false); return; } - ++(found->second.refcount); + ++(found->second->refcount); } void BlobStorageContext::DecrementBlobRefCount(const std::string& uuid) { BlobMap::iterator found = blob_map_.find(uuid); if (found == blob_map_.end()) return; - DCHECK_EQ(found->second.data->uuid(), uuid); - if (--(found->second.refcount) == 0) { - memory_usage_ -= found->second.data->GetMemoryUsage(); + auto* entry = found->second; + if (--(entry->refcount) == 0) { + if (entry->IsBeingBuilt()) { + memory_usage_ -= entry->data_builder->GetMemoryUsage(); + } else { + memory_usage_ -= entry->data->GetMemoryUsage(); + } + delete entry; blob_map_.erase(found); } } bool BlobStorageContext::ExpandStorageItems( - BlobData* target_blob_data, BlobData* src_blob_data, - uint64 offset, uint64 length) { - DCHECK(target_blob_data && src_blob_data && - length != static_cast(-1)); - - std::vector::const_iterator iter = - src_blob_data->items().begin(); + BlobDataBuilder* target_blob_data, + const BlobDataSnapshot& src_blob_data, + uint64 offset, + uint64 length) { + DCHECK(target_blob_data && length != static_cast(-1)); + + const std::vector>& items = src_blob_data.items(); + auto iter = items.begin(); if (offset) { - for (; iter != src_blob_data->items().end(); ++iter) { - if (offset >= iter->length()) - offset -= iter->length(); + for (; iter != items.end(); ++iter) { + const BlobDataItem& item = *(iter->get()); + if (offset >= item.length()) + offset -= item.length(); else break; } } - for (; iter != src_blob_data->items().end() && length > 0; ++iter) { - uint64 current_length = iter->length() - offset; + for (; iter != items.end() && length > 0; ++iter) { + const BlobDataItem& item = *(iter->get()); + uint64 current_length = item.length() - offset; uint64 new_length = current_length > length ? length : current_length; - if (iter->type() == BlobData::Item::TYPE_BYTES) { + if (iter->get()->type() == DataElement::TYPE_BYTES) { if (!AppendBytesItem( target_blob_data, - iter->bytes() + static_cast(iter->offset() + offset), + item.bytes() + static_cast(item.offset() + offset), static_cast(new_length))) { return false; // exceeded memory } - } else if (iter->type() == BlobData::Item::TYPE_FILE) { - AppendFileItem(target_blob_data, - iter->path(), - iter->offset() + offset, - new_length, - iter->expected_modification_time()); + } else if (item.type() == DataElement::TYPE_FILE) { + AppendFileItem(target_blob_data, item.path(), item.offset() + offset, + new_length, item.expected_modification_time()); } else { - DCHECK(iter->type() == BlobData::Item::TYPE_FILE_FILESYSTEM); - AppendFileSystemFileItem(target_blob_data, - iter->filesystem_url(), - iter->offset() + offset, - new_length, - iter->expected_modification_time()); + DCHECK(item.type() == DataElement::TYPE_FILE_FILESYSTEM); + AppendFileSystemFileItem(target_blob_data, item.filesystem_url(), + item.offset() + offset, new_length, + item.expected_modification_time()); } length -= new_length; offset = 0; @@ -281,36 +302,40 @@ bool BlobStorageContext::ExpandStorageItems( return true; } -bool BlobStorageContext::AppendBytesItem( - BlobData* target_blob_data, const char* bytes, int64 length) { +bool BlobStorageContext::AppendBytesItem(BlobDataBuilder* target_blob_data, + const char* bytes, + int64 length) { if (length < 0) { DCHECK(false); return false; } - if (memory_usage_ + length > kMaxMemoryUsage) + if (memory_usage_ + length > kMaxMemoryUsage) { return false; + } target_blob_data->AppendData(bytes, static_cast(length)); memory_usage_ += length; return true; } void BlobStorageContext::AppendFileItem( - BlobData* target_blob_data, - const base::FilePath& file_path, uint64 offset, uint64 length, + BlobDataBuilder* target_blob_data, + const base::FilePath& file_path, + uint64 offset, + uint64 length, const base::Time& expected_modification_time) { - target_blob_data->AppendFile(file_path, offset, length, - expected_modification_time); - // It may be a temporary file that should be deleted when no longer needed. scoped_refptr shareable_file = ShareableFileReference::Get(file_path); - if (shareable_file.get()) - target_blob_data->AttachShareableFileReference(shareable_file.get()); + + target_blob_data->AppendFile(file_path, offset, length, + expected_modification_time, shareable_file); } void BlobStorageContext::AppendFileSystemFileItem( - BlobData* target_blob_data, - const GURL& filesystem_url, uint64 offset, uint64 length, + BlobDataBuilder* target_blob_data, + const GURL& filesystem_url, + uint64 offset, + uint64 length, const base::Time& expected_modification_time) { target_blob_data->AppendFileSystemFile(filesystem_url, offset, length, expected_modification_time); @@ -324,7 +349,7 @@ bool BlobStorageContext::IsBeingBuilt(const std::string& uuid) { BlobMap::iterator found = blob_map_.find(uuid); if (found == blob_map_.end()) return false; - return found->second.flags & BEING_BUILT; + return found->second->IsBeingBuilt(); } bool BlobStorageContext::IsUrlRegistered(const GURL& blob_url) { diff --git a/storage/browser/blob/blob_storage_context.h b/storage/browser/blob/blob_storage_context.h index 7ccc133626505c..322a4c62c1bf1c 100644 --- a/storage/browser/blob/blob_storage_context.h +++ b/storage/browser/blob/blob_storage_context.h @@ -12,8 +12,9 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "storage/browser/blob/blob_data_handle.h" +#include "storage/browser/blob/blob_data_snapshot.h" #include "storage/browser/storage_browser_export.h" -#include "storage/common/blob/blob_data.h" +#include "storage/common/data_element.h" class GURL; @@ -29,6 +30,7 @@ class BlobStorageHost; namespace storage { class BlobDataHandle; +class BlobDataBuilder; // This class handles the logistics of blob Storage within the browser process, // and maintains a mapping from blob uuid to the data. The class is single @@ -45,7 +47,7 @@ class STORAGE_EXPORT BlobStorageContext // Useful for coining blobs from within the browser process. If the // blob cannot be added due to memory consumption, returns NULL. - scoped_ptr AddFinishedBlob(const BlobData* blob_data); + scoped_ptr AddFinishedBlob(const BlobDataBuilder& blob_data); // Useful for coining blob urls from within the browser process. bool RegisterPublicBlobURL(const GURL& url, const std::string& uuid); @@ -57,46 +59,54 @@ class STORAGE_EXPORT BlobStorageContext friend class ViewBlobInternalsJob; enum EntryFlags { - BEING_BUILT = 1 << 0, EXCEEDED_MEMORY = 1 << 1, }; struct BlobMapEntry { int refcount; int flags; - scoped_refptr data; + // data and data_builder are mutually exclusive. + scoped_ptr data; + scoped_ptr data_builder; BlobMapEntry(); - BlobMapEntry(int refcount, int flags, BlobData* data); + BlobMapEntry(int refcount, BlobDataBuilder* data); ~BlobMapEntry(); + + bool IsBeingBuilt(); }; - typedef std::map - BlobMap; + typedef std::map BlobMap; typedef std::map BlobURLMap; + // Called by BlobDataHandle. + scoped_ptr CreateSnapshot(const std::string& uuid); + void StartBuildingBlob(const std::string& uuid); void AppendBlobDataItem(const std::string& uuid, - const BlobData::Item& data_item); + const DataElement& data_item); void FinishBuildingBlob(const std::string& uuid, const std::string& type); void CancelBuildingBlob(const std::string& uuid); void IncrementBlobRefCount(const std::string& uuid); void DecrementBlobRefCount(const std::string& uuid); - bool ExpandStorageItems(BlobData* target_blob_data, - BlobData* src_blob_data, + bool ExpandStorageItems(BlobDataBuilder* target_blob_data, + const BlobDataSnapshot& src_blob_data, uint64 offset, uint64 length); - bool AppendBytesItem(BlobData* target_blob_data, - const char* data, int64 length); - void AppendFileItem(BlobData* target_blob_data, + bool AppendBytesItem(BlobDataBuilder* target_blob_data, + const char* data, + int64 length); + void AppendFileItem(BlobDataBuilder* target_blob_data, const base::FilePath& file_path, - uint64 offset, uint64 length, + uint64 offset, + uint64 length, const base::Time& expected_modification_time); - void AppendFileSystemFileItem( - BlobData* target_blob_data, - const GURL& url, uint64 offset, uint64 length, - const base::Time& expected_modification_time); + void AppendFileSystemFileItem(BlobDataBuilder* target_blob_data, + const GURL& url, + uint64 offset, + uint64 length, + const base::Time& expected_modification_time); bool IsInUse(const std::string& uuid); bool IsBeingBuilt(const std::string& uuid); diff --git a/storage/browser/blob/blob_url_request_job.cc b/storage/browser/blob/blob_url_request_job.cc index 41e79429b241a6..068b5c48487a2f 100644 --- a/storage/browser/blob/blob_url_request_job.cc +++ b/storage/browser/blob/blob_url_request_job.cc @@ -34,15 +34,16 @@ #include "storage/browser/blob/file_stream_reader.h" #include "storage/browser/fileapi/file_system_context.h" #include "storage/browser/fileapi/file_system_url.h" +#include "storage/common/data_element.h" namespace storage { namespace { -bool IsFileType(BlobData::Item::Type type) { +bool IsFileType(DataElement::Type type) { switch (type) { - case BlobData::Item::TYPE_FILE: - case BlobData::Item::TYPE_FILE_FILESYSTEM: + case DataElement::TYPE_FILE: + case DataElement::TYPE_FILE_FILESYSTEM: return true; default: return false; @@ -54,11 +55,11 @@ bool IsFileType(BlobData::Item::Type type) { BlobURLRequestJob::BlobURLRequestJob( net::URLRequest* request, net::NetworkDelegate* network_delegate, - const scoped_refptr& blob_data, + scoped_ptr blob_data, storage::FileSystemContext* file_system_context, base::MessageLoopProxy* file_thread_proxy) : net::URLRequestJob(request, network_delegate), - blob_data_(blob_data), + blob_data_(blob_data.Pass()), file_system_context_(file_system_context), file_thread_proxy_(file_thread_proxy), total_size_(0), @@ -174,7 +175,7 @@ void BlobURLRequestJob::DidStart() { } // If the blob data is not present, bail out. - if (!blob_data_.get()) { + if (!blob_data_) { NotifyFailure(net::ERR_FILE_NOT_FOUND); return; } @@ -198,10 +199,11 @@ bool BlobURLRequestJob::AddItemLength(size_t index, int64 item_length) { void BlobURLRequestJob::CountSize() { pending_get_file_info_count_ = 0; total_size_ = 0; - item_length_list_.resize(blob_data_->items().size()); + const auto& items = blob_data_->items(); + item_length_list_.resize(items.size()); - for (size_t i = 0; i < blob_data_->items().size(); ++i) { - const BlobData::Item& item = blob_data_->items().at(i); + for (size_t i = 0; i < items.size(); ++i) { + const BlobDataItem& item = *items.at(i); if (IsFileType(item.type())) { ++pending_get_file_info_count_; GetFileStreamReader(i)->GetLength( @@ -257,8 +259,9 @@ void BlobURLRequestJob::DidGetFileItemLength(size_t index, int64 result) { return; } - DCHECK_LT(index, blob_data_->items().size()); - const BlobData::Item& item = blob_data_->items().at(index); + const auto& items = blob_data_->items(); + DCHECK_LT(index, items.size()); + const BlobDataItem& item = *items.at(index); DCHECK(IsFileType(item.type())); uint64 file_length = result; @@ -290,8 +293,9 @@ void BlobURLRequestJob::DidGetFileItemLength(size_t index, int64 result) { void BlobURLRequestJob::Seek(int64 offset) { // Skip the initial items that are not in the range. + const auto& items = blob_data_->items(); for (current_item_index_ = 0; - current_item_index_ < blob_data_->items().size() && + current_item_index_ < items.size() && offset >= item_length_list_[current_item_index_]; ++current_item_index_) { offset -= item_length_list_[current_item_index_]; @@ -304,7 +308,7 @@ void BlobURLRequestJob::Seek(int64 offset) { return; // Adjust the offset of the first stream if it is of file type. - const BlobData::Item& item = blob_data_->items().at(current_item_index_); + const BlobDataItem& item = *items.at(current_item_index_); if (IsFileType(item.type())) { DeleteCurrentFileReader(); CreateFileStreamReader(current_item_index_, offset); @@ -316,9 +320,10 @@ bool BlobURLRequestJob::ReadItem() { if (remaining_bytes_ == 0) return true; + const auto& items = blob_data_->items(); // If we get to the last item but still expect something to read, bail out // since something is wrong. - if (current_item_index_ >= blob_data_->items().size()) { + if (current_item_index_ >= items.size()) { NotifyFailure(net::ERR_FAILED); return false; } @@ -333,8 +338,8 @@ bool BlobURLRequestJob::ReadItem() { } // Do the reading. - const BlobData::Item& item = blob_data_->items().at(current_item_index_); - if (item.type() == BlobData::Item::TYPE_BYTES) + const BlobDataItem& item = *items.at(current_item_index_); + if (item.type() == DataElement::TYPE_BYTES) return ReadBytesItem(item, bytes_to_read); if (IsFileType(item.type())) { return ReadFileItem(GetFileStreamReader(current_item_index_), @@ -370,7 +375,7 @@ void BlobURLRequestJob::AdvanceBytesRead(int result) { DCHECK_GE(read_buf_->BytesRemaining(), 0); } -bool BlobURLRequestJob::ReadBytesItem(const BlobData::Item& item, +bool BlobURLRequestJob::ReadBytesItem(const BlobDataItem& item, int bytes_to_read) { DCHECK_GE(read_buf_->BytesRemaining(), bytes_to_read); @@ -555,8 +560,9 @@ void BlobURLRequestJob::HeadersCompleted(net::HttpStatusCode status_code) { } FileStreamReader* BlobURLRequestJob::GetFileStreamReader(size_t index) { - DCHECK_LT(index, blob_data_->items().size()); - const BlobData::Item& item = blob_data_->items().at(index); + const auto& items = blob_data_->items(); + DCHECK_LT(index, items.size()); + const BlobDataItem& item = *items.at(index); if (!IsFileType(item.type())) return NULL; if (index_to_reader_.find(index) == index_to_reader_.end()) @@ -567,21 +573,22 @@ FileStreamReader* BlobURLRequestJob::GetFileStreamReader(size_t index) { void BlobURLRequestJob::CreateFileStreamReader(size_t index, int64 additional_offset) { - DCHECK_LT(index, blob_data_->items().size()); - const BlobData::Item& item = blob_data_->items().at(index); + const auto& items = blob_data_->items(); + DCHECK_LT(index, items.size()); + const BlobDataItem& item = *items.at(index); DCHECK(IsFileType(item.type())); DCHECK_EQ(0U, index_to_reader_.count(index)); FileStreamReader* reader = NULL; switch (item.type()) { - case BlobData::Item::TYPE_FILE: + case DataElement::TYPE_FILE: reader = FileStreamReader::CreateForLocalFile( file_thread_proxy_.get(), item.path(), item.offset() + additional_offset, item.expected_modification_time()); break; - case BlobData::Item::TYPE_FILE_FILESYSTEM: + case DataElement::TYPE_FILE_FILESYSTEM: reader = file_system_context_ ->CreateFileStreamReader( storage::FileSystemURL(file_system_context_->CrackURL( diff --git a/storage/browser/blob/blob_url_request_job.h b/storage/browser/blob/blob_url_request_job.h index dab61dc7759d12..cf296b64cad118 100644 --- a/storage/browser/blob/blob_url_request_job.h +++ b/storage/browser/blob/blob_url_request_job.h @@ -12,8 +12,8 @@ #include "net/http/http_byte_range.h" #include "net/http/http_status_code.h" #include "net/url_request/url_request_job.h" +#include "storage/browser/blob/blob_data_snapshot.h" #include "storage/browser/storage_browser_export.h" -#include "storage/common/blob/blob_data.h" namespace base { class MessageLoopProxy; @@ -38,7 +38,7 @@ class STORAGE_EXPORT BlobURLRequestJob public: BlobURLRequestJob(net::URLRequest* request, net::NetworkDelegate* network_delegate, - const scoped_refptr& blob_data, + scoped_ptr blob_data, storage::FileSystemContext* file_system_context, base::MessageLoopProxy* resolving_message_loop_proxy); @@ -70,7 +70,7 @@ class STORAGE_EXPORT BlobURLRequestJob bool ReadItem(); void AdvanceItem(); void AdvanceBytesRead(int result); - bool ReadBytesItem(const BlobData::Item& item, int bytes_to_read); + bool ReadBytesItem(const BlobDataItem& item, int bytes_to_read); bool ReadFileItem(FileStreamReader* reader, int bytes_to_read); void DidReadFile(int result); @@ -92,7 +92,7 @@ class STORAGE_EXPORT BlobURLRequestJob // Creates a FileStreamReader for the item at |index| with additional_offset. void CreateFileStreamReader(size_t index, int64 additional_offset); - scoped_refptr blob_data_; + scoped_ptr blob_data_; // Variables for controlling read from |blob_data_|. scoped_refptr file_system_context_; diff --git a/storage/browser/blob/blob_url_request_job_factory.cc b/storage/browser/blob/blob_url_request_job_factory.cc index 60f9c738b9e742..fe193afbeb8abd 100644 --- a/storage/browser/blob/blob_url_request_job_factory.cc +++ b/storage/browser/blob/blob_url_request_job_factory.cc @@ -68,11 +68,11 @@ net::URLRequestJob* BlobProtocolHandler::MaybeCreateJob( file_loop_proxy_.get()); } -scoped_refptr BlobProtocolHandler::LookupBlobData( +scoped_ptr BlobProtocolHandler::LookupBlobData( net::URLRequest* request) const { BlobDataHandle* blob_data_handle = GetRequestedBlobDataHandle(request); if (blob_data_handle) - return blob_data_handle->data(); + return blob_data_handle->CreateSnapshot().Pass(); if (!context_.get()) return NULL; @@ -84,7 +84,12 @@ scoped_refptr BlobProtocolHandler::LookupBlobData( return NULL; std::string uuid = request->url().spec().substr(kPrefix.length()); scoped_ptr handle = context_->GetBlobDataFromUUID(uuid); - return handle.get() ? handle->data() : NULL; + scoped_ptr snapshot; + if (handle) { + snapshot = handle->CreateSnapshot().Pass(); + SetRequestedBlobDataHandle(request, handle.Pass()); + } + return snapshot.Pass(); } } // namespace storage diff --git a/storage/browser/blob/blob_url_request_job_factory.h b/storage/browser/blob/blob_url_request_job_factory.h index c3e34e38b6777e..381a95fce895bd 100644 --- a/storage/browser/blob/blob_url_request_job_factory.h +++ b/storage/browser/blob/blob_url_request_job_factory.h @@ -26,7 +26,7 @@ class URLRequestContext; namespace storage { -class BlobData; +class BlobDataSnapshot; class BlobDataHandle; class BlobStorageContext; @@ -56,8 +56,7 @@ class STORAGE_EXPORT BlobProtocolHandler net::NetworkDelegate* network_delegate) const override; private: - scoped_refptr LookupBlobData( - net::URLRequest* request) const; + scoped_ptr LookupBlobData(net::URLRequest* request) const; base::WeakPtr context_; const scoped_refptr file_system_context_; diff --git a/storage/common/blob/scoped_file.cc b/storage/browser/blob/scoped_file.cc similarity index 98% rename from storage/common/blob/scoped_file.cc rename to storage/browser/blob/scoped_file.cc index b54444948c1da6..cdf4cb88550f61 100644 --- a/storage/common/blob/scoped_file.cc +++ b/storage/browser/blob/scoped_file.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "storage/common/blob/scoped_file.h" +#include "storage/browser/blob/scoped_file.h" #include "base/bind.h" #include "base/callback.h" diff --git a/storage/common/blob/scoped_file.h b/storage/browser/blob/scoped_file.h similarity index 92% rename from storage/common/blob/scoped_file.h rename to storage/browser/blob/scoped_file.h index 4a51a465ce3d81..a8fd730efce630 100644 --- a/storage/common/blob/scoped_file.h +++ b/storage/browser/blob/scoped_file.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef STORAGE_COMMON_BLOB_SCOPED_FILE_H_ -#define STORAGE_COMMON_BLOB_SCOPED_FILE_H_ +#ifndef STORAGE_BROWSER_BLOB_SCOPED_FILE_H_ +#define STORAGE_BROWSER_BLOB_SCOPED_FILE_H_ #include @@ -11,7 +11,7 @@ #include "base/files/file_path.h" #include "base/memory/ref_counted.h" #include "base/move.h" -#include "storage/common/storage_common_export.h" +#include "storage/browser/storage_browser_export.h" namespace base { class TaskRunner; @@ -26,7 +26,7 @@ namespace storage { // // TODO(kinuko): Probably this can be moved under base or somewhere more // common place. -class STORAGE_COMMON_EXPORT ScopedFile { +class STORAGE_EXPORT ScopedFile { // To support destructive assignment from an l-value assignment. // This provides Pass() method which creates an r-value for the current // instance. (See base/move.h for details) @@ -91,4 +91,4 @@ class STORAGE_COMMON_EXPORT ScopedFile { } // namespace storage -#endif // STORAGE_COMMON_BLOB_SCOPED_FILE_H_ +#endif // STORAGE_BROWSER_BLOB_SCOPED_FILE_H_ diff --git a/storage/common/blob/shareable_file_reference.cc b/storage/browser/blob/shareable_file_reference.cc similarity index 98% rename from storage/common/blob/shareable_file_reference.cc rename to storage/browser/blob/shareable_file_reference.cc index c2ec839637e7a9..02a5be4481af13 100644 --- a/storage/common/blob/shareable_file_reference.cc +++ b/storage/browser/blob/shareable_file_reference.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "storage/common/blob/shareable_file_reference.h" +#include "storage/browser/blob/shareable_file_reference.h" #include diff --git a/storage/common/blob/shareable_file_reference.h b/storage/browser/blob/shareable_file_reference.h similarity index 89% rename from storage/common/blob/shareable_file_reference.h rename to storage/browser/blob/shareable_file_reference.h index bd9d050374925b..e2739dcf860465 100644 --- a/storage/common/blob/shareable_file_reference.h +++ b/storage/browser/blob/shareable_file_reference.h @@ -2,12 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef STORAGE_COMMON_BLOB_SHAREABLE_FILE_REFERENCE_H_ -#define STORAGE_COMMON_BLOB_SHAREABLE_FILE_REFERENCE_H_ +#ifndef STORAGE_BROWSER_BLOB_SHAREABLE_FILE_REFERENCE_H_ +#define STORAGE_BROWSER_BLOB_SHAREABLE_FILE_REFERENCE_H_ #include -#include "storage/common/blob/scoped_file.h" +#include "storage/browser/blob/scoped_file.h" +#include "storage/browser/storage_browser_export.h" namespace storage { @@ -15,7 +16,7 @@ namespace storage { // same path if it already exists in its internal map. // This class is non-thread-safe and all methods must be called on a single // thread. -class STORAGE_COMMON_EXPORT ShareableFileReference +class STORAGE_EXPORT ShareableFileReference : public base::RefCounted { public: typedef ScopedFile::ScopeOutCallback FinalReleaseCallback; @@ -71,4 +72,4 @@ class STORAGE_COMMON_EXPORT ShareableFileReference } // namespace storage -#endif // STORAGE_COMMON_BLOB_SHAREABLE_FILE_REFERENCE_H_ +#endif // STORAGE_BROWSER_BLOB_SHAREABLE_FILE_REFERENCE_H_ diff --git a/storage/browser/blob/view_blob_internals_job.cc b/storage/browser/blob/view_blob_internals_job.cc index 2065a310f83ee3..3f5cc41dcd037e 100644 --- a/storage/browser/blob/view_blob_internals_job.cc +++ b/storage/browser/blob/view_blob_internals_job.cc @@ -18,8 +18,8 @@ #include "net/base/escape.h" #include "net/base/net_errors.h" #include "net/url_request/url_request.h" +#include "storage/browser/blob/blob_data_snapshot.h" #include "storage/browser/blob/blob_storage_context.h" -#include "storage/common/blob/blob_data.h" namespace { @@ -150,8 +150,7 @@ void ViewBlobInternalsJob::GenerateHTML(std::string* out) const { iter != blob_storage_context_->blob_map_.end(); ++iter) { AddHTMLBoldText(iter->first, out); - GenerateHTMLForBlobData(*(iter->second.data.get()), - iter->second.refcount, + GenerateHTMLForBlobData(*(iter->second->data.get()), iter->second->refcount, out); } if (!blob_storage_context_->public_blob_urls_.empty()) { @@ -168,9 +167,10 @@ void ViewBlobInternalsJob::GenerateHTML(std::string* out) const { } } -void ViewBlobInternalsJob::GenerateHTMLForBlobData(const BlobData& blob_data, - int refcount, - std::string* out) { +void ViewBlobInternalsJob::GenerateHTMLForBlobData( + const BlobDataSnapshot& blob_data, + int refcount, + std::string* out) { StartHTMLList(out); AddHTMLListItem(kRefcount, base::IntToString(refcount), out); @@ -190,13 +190,13 @@ void ViewBlobInternalsJob::GenerateHTMLForBlobData(const BlobData& blob_data, AddHTMLListItem(kIndex, base::UTF16ToUTF8(base::FormatNumber(i)), out); StartHTMLList(out); } - const BlobData::Item& item = blob_data.items().at(i); + const BlobDataItem& item = *(blob_data.items().at(i)); switch (item.type()) { - case BlobData::Item::TYPE_BYTES: + case DataElement::TYPE_BYTES: AddHTMLListItem(kType, "data", out); break; - case BlobData::Item::TYPE_FILE: + case DataElement::TYPE_FILE: AddHTMLListItem(kType, "file", out); AddHTMLListItem(kPath, net::EscapeForHTML(item.path().AsUTF8Unsafe()), @@ -207,10 +207,10 @@ void ViewBlobInternalsJob::GenerateHTMLForBlobData(const BlobData& blob_data, out); } break; - case BlobData::Item::TYPE_BLOB: + case DataElement::TYPE_BLOB: NOTREACHED(); // Should be flattened in the storage context. break; - case BlobData::Item::TYPE_FILE_FILESYSTEM: + case DataElement::TYPE_FILE_FILESYSTEM: AddHTMLListItem(kType, "filesystem", out); AddHTMLListItem(kURL, item.filesystem_url().spec(), out); if (!item.expected_modification_time().is_null()) { @@ -219,7 +219,7 @@ void ViewBlobInternalsJob::GenerateHTMLForBlobData(const BlobData& blob_data, out); } break; - case BlobData::Item::TYPE_UNKNOWN: + case DataElement::TYPE_UNKNOWN: NOTREACHED(); break; } diff --git a/storage/browser/blob/view_blob_internals_job.h b/storage/browser/blob/view_blob_internals_job.h index 4ab1e30cc8601e..2abb1d4f8ffcc8 100644 --- a/storage/browser/blob/view_blob_internals_job.h +++ b/storage/browser/blob/view_blob_internals_job.h @@ -17,7 +17,7 @@ class URLRequest; namespace storage { -class BlobData; +class BlobDataSnapshot; class BlobStorageContext; // A job subclass that implements a protocol to inspect the internal @@ -41,7 +41,7 @@ class STORAGE_EXPORT ViewBlobInternalsJob ~ViewBlobInternalsJob() override; void GenerateHTML(std::string* out) const; - static void GenerateHTMLForBlobData(const BlobData& blob_data, + static void GenerateHTMLForBlobData(const BlobDataSnapshot& blob_data, int refcount, std::string* out); diff --git a/storage/browser/fileapi/async_file_util_adapter.cc b/storage/browser/fileapi/async_file_util_adapter.cc index 3bb20f9bc1f488..7d324c006f8abb 100644 --- a/storage/browser/fileapi/async_file_util_adapter.cc +++ b/storage/browser/fileapi/async_file_util_adapter.cc @@ -10,11 +10,11 @@ #include "base/sequenced_task_runner.h" #include "base/task_runner_util.h" #include "base/thread_task_runner_handle.h" +#include "storage/browser/blob/shareable_file_reference.h" #include "storage/browser/fileapi/file_system_context.h" #include "storage/browser/fileapi/file_system_file_util.h" #include "storage/browser/fileapi/file_system_operation_context.h" #include "storage/browser/fileapi/file_system_url.h" -#include "storage/common/blob/shareable_file_reference.h" #include "storage/common/fileapi/file_system_util.h" using base::Bind; diff --git a/storage/browser/fileapi/copy_or_move_operation_delegate.cc b/storage/browser/fileapi/copy_or_move_operation_delegate.cc index 1b95f79daac14a..baa93db438eb93 100644 --- a/storage/browser/fileapi/copy_or_move_operation_delegate.cc +++ b/storage/browser/fileapi/copy_or_move_operation_delegate.cc @@ -9,6 +9,7 @@ #include "net/base/io_buffer.h" #include "net/base/net_errors.h" #include "storage/browser/blob/file_stream_reader.h" +#include "storage/browser/blob/shareable_file_reference.h" #include "storage/browser/fileapi/copy_or_move_file_validator.h" #include "storage/browser/fileapi/file_observers.h" #include "storage/browser/fileapi/file_stream_writer.h" @@ -16,7 +17,6 @@ #include "storage/browser/fileapi/file_system_operation_runner.h" #include "storage/browser/fileapi/file_system_url.h" #include "storage/browser/fileapi/recursive_operation_delegate.h" -#include "storage/common/blob/shareable_file_reference.h" #include "storage/common/fileapi/file_system_util.h" namespace storage { diff --git a/storage/browser/fileapi/dragged_file_util.cc b/storage/browser/fileapi/dragged_file_util.cc index 9a5b66ee8d4d68..ff581fe326f046 100644 --- a/storage/browser/fileapi/dragged_file_util.cc +++ b/storage/browser/fileapi/dragged_file_util.cc @@ -8,12 +8,12 @@ #include #include "base/files/file_util.h" +#include "storage/browser/blob/shareable_file_reference.h" #include "storage/browser/fileapi/file_system_context.h" #include "storage/browser/fileapi/file_system_operation_context.h" #include "storage/browser/fileapi/file_system_url.h" #include "storage/browser/fileapi/isolated_context.h" #include "storage/browser/fileapi/native_file_util.h" -#include "storage/common/blob/shareable_file_reference.h" namespace storage { diff --git a/storage/browser/fileapi/file_system_file_stream_reader.h b/storage/browser/fileapi/file_system_file_stream_reader.h index b0a718a304e172..c0cdeb1c937985 100644 --- a/storage/browser/fileapi/file_system_file_stream_reader.h +++ b/storage/browser/fileapi/file_system_file_stream_reader.h @@ -10,9 +10,9 @@ #include "base/memory/ref_counted.h" #include "base/time/time.h" #include "storage/browser/blob/file_stream_reader.h" +#include "storage/browser/blob/shareable_file_reference.h" #include "storage/browser/fileapi/file_system_url.h" #include "storage/browser/storage_browser_export.h" -#include "storage/common/blob/shareable_file_reference.h" namespace base { class FilePath; diff --git a/storage/browser/fileapi/file_system_file_util.h b/storage/browser/fileapi/file_system_file_util.h index c649c3107f11bd..48a127a6a0029f 100644 --- a/storage/browser/fileapi/file_system_file_util.h +++ b/storage/browser/fileapi/file_system_file_util.h @@ -8,9 +8,9 @@ #include "base/files/file.h" #include "base/files/file_path.h" #include "base/memory/scoped_ptr.h" +#include "storage/browser/blob/scoped_file.h" #include "storage/browser/fileapi/file_system_operation.h" #include "storage/browser/storage_browser_export.h" -#include "storage/common/blob/scoped_file.h" namespace base { class Time; diff --git a/storage/browser/fileapi/file_system_operation_impl.cc b/storage/browser/fileapi/file_system_operation_impl.cc index 25613dd3c09df0..dbca3d6af96adc 100644 --- a/storage/browser/fileapi/file_system_operation_impl.cc +++ b/storage/browser/fileapi/file_system_operation_impl.cc @@ -10,6 +10,7 @@ #include "base/time/time.h" #include "net/base/escape.h" #include "net/url_request/url_request.h" +#include "storage/browser/blob/shareable_file_reference.h" #include "storage/browser/fileapi/async_file_util.h" #include "storage/browser/fileapi/copy_or_move_operation_delegate.h" #include "storage/browser/fileapi/file_observers.h" @@ -22,7 +23,6 @@ #include "storage/browser/fileapi/remove_operation_delegate.h" #include "storage/browser/fileapi/sandbox_file_system_backend.h" #include "storage/browser/quota/quota_manager_proxy.h" -#include "storage/common/blob/shareable_file_reference.h" #include "storage/common/fileapi/file_system_types.h" #include "storage/common/fileapi/file_system_util.h" #include "storage/common/quota/quota_types.h" diff --git a/storage/browser/fileapi/file_system_operation_impl.h b/storage/browser/fileapi/file_system_operation_impl.h index add6b7c41bd96a..dbf6e3a781c419 100644 --- a/storage/browser/fileapi/file_system_operation_impl.h +++ b/storage/browser/fileapi/file_system_operation_impl.h @@ -10,12 +10,12 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" +#include "storage/browser/blob/scoped_file.h" #include "storage/browser/fileapi/file_system_operation.h" #include "storage/browser/fileapi/file_system_operation_context.h" #include "storage/browser/fileapi/file_system_url.h" #include "storage/browser/fileapi/file_writer_delegate.h" #include "storage/browser/storage_browser_export.h" -#include "storage/common/blob/scoped_file.h" #include "storage/common/quota/quota_types.h" namespace storage { diff --git a/storage/browser/fileapi/file_system_operation_runner.cc b/storage/browser/fileapi/file_system_operation_runner.cc index 9c1e4a6c08390c..848929f38cdb95 100644 --- a/storage/browser/fileapi/file_system_operation_runner.cc +++ b/storage/browser/fileapi/file_system_operation_runner.cc @@ -9,12 +9,12 @@ #include "base/stl_util.h" #include "net/url_request/url_request_context.h" #include "storage/browser/blob/blob_url_request_job_factory.h" +#include "storage/browser/blob/shareable_file_reference.h" #include "storage/browser/fileapi/file_observers.h" #include "storage/browser/fileapi/file_stream_writer.h" #include "storage/browser/fileapi/file_system_context.h" #include "storage/browser/fileapi/file_system_operation.h" #include "storage/browser/fileapi/file_writer_delegate.h" -#include "storage/common/blob/shareable_file_reference.h" namespace storage { diff --git a/storage/browser/fileapi/obfuscated_file_util.h b/storage/browser/fileapi/obfuscated_file_util.h index 090e55e3b49f8f..b8fab48c29568f 100644 --- a/storage/browser/fileapi/obfuscated_file_util.h +++ b/storage/browser/fileapi/obfuscated_file_util.h @@ -16,12 +16,12 @@ #include "base/files/file_util_proxy.h" #include "base/gtest_prod_util.h" #include "base/memory/scoped_ptr.h" +#include "storage/browser/blob/shareable_file_reference.h" #include "storage/browser/fileapi/file_system_file_util.h" #include "storage/browser/fileapi/file_system_url.h" #include "storage/browser/fileapi/sandbox_directory_database.h" #include "storage/browser/fileapi/sandbox_file_system_backend_delegate.h" #include "storage/browser/storage_browser_export.h" -#include "storage/common/blob/shareable_file_reference.h" #include "storage/common/fileapi/file_system_types.h" namespace base { diff --git a/storage/browser/fileapi/sandbox_file_stream_writer.h b/storage/browser/fileapi/sandbox_file_stream_writer.h index 69b31369fab692..61375b11b37e00 100644 --- a/storage/browser/fileapi/sandbox_file_stream_writer.h +++ b/storage/browser/fileapi/sandbox_file_stream_writer.h @@ -8,11 +8,11 @@ #include "base/files/file.h" #include "base/files/file_path.h" #include "base/memory/scoped_ptr.h" +#include "storage/browser/blob/shareable_file_reference.h" #include "storage/browser/fileapi/file_stream_writer.h" #include "storage/browser/fileapi/file_system_url.h" #include "storage/browser/fileapi/task_runner_bound_observer_list.h" #include "storage/browser/storage_browser_export.h" -#include "storage/common/blob/shareable_file_reference.h" #include "storage/common/fileapi/file_system_types.h" #include "storage/common/quota/quota_types.h" #include "url/gurl.h" diff --git a/storage/common/BUILD.gn b/storage/common/BUILD.gn index 5212a92eb2492f..00679727aabd8a 100644 --- a/storage/common/BUILD.gn +++ b/storage/common/BUILD.gn @@ -9,12 +9,6 @@ component("common") { "data_element.cc", "data_element.h", "storage_common_export.h", - "blob/blob_data.cc", - "blob/blob_data.h", - "blob/scoped_file.cc", - "blob/scoped_file.h", - "blob/shareable_file_reference.cc", - "blob/shareable_file_reference.h", "database/database_connections.cc", "database/database_connections.h", "database/database_identifier.cc", diff --git a/storage/common/blob/blob_data.cc b/storage/common/blob/blob_data.cc deleted file mode 100644 index 23f73e3f0ffcb4..00000000000000 --- a/storage/common/blob/blob_data.cc +++ /dev/null @@ -1,63 +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 "storage/common/blob/blob_data.h" - -#include "base/logging.h" -#include "base/strings/sys_string_conversions.h" -#include "base/strings/utf_string_conversions.h" -#include "base/time/time.h" - -namespace storage { - -BlobData::BlobData() {} -BlobData::BlobData(const std::string& uuid) - : uuid_(uuid) { -} - -BlobData::~BlobData() {} - -void BlobData::AppendData(const char* data, size_t length) { - DCHECK(length > 0); - items_.push_back(Item()); - items_.back().SetToBytes(data, length); -} - -void BlobData::AppendFile(const base::FilePath& file_path, - uint64 offset, uint64 length, - const base::Time& expected_modification_time) { - DCHECK(length > 0); - items_.push_back(Item()); - items_.back().SetToFilePathRange(file_path, offset, length, - expected_modification_time); -} - -void BlobData::AppendBlob(const std::string& uuid, - uint64 offset, uint64 length) { - DCHECK_GT(length, 0ul); - items_.push_back(Item()); - items_.back().SetToBlobRange(uuid, offset, length); -} - -void BlobData::AppendFileSystemFile( - const GURL& url, uint64 offset, - uint64 length, - const base::Time& expected_modification_time) { - DCHECK(length > 0); - items_.push_back(Item()); - items_.back().SetToFileSystemUrlRange(url, offset, length, - expected_modification_time); -} - -int64 BlobData::GetMemoryUsage() const { - int64 memory = 0; - for (std::vector::const_iterator iter = items_.begin(); - iter != items_.end(); ++iter) { - if (iter->type() == Item::TYPE_BYTES) - memory += iter->length(); - } - return memory; -} - -} // namespace storage diff --git a/storage/common/blob/blob_data.h b/storage/common/blob/blob_data.h deleted file mode 100644 index 2f48546585b302..00000000000000 --- a/storage/common/blob/blob_data.h +++ /dev/null @@ -1,98 +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 STORAGE_COMMON_BLOB_BLOB_DATA_H_ -#define STORAGE_COMMON_BLOB_BLOB_DATA_H_ - -#include -#include - -#include "base/basictypes.h" -#include "base/files/file_path.h" -#include "base/memory/ref_counted.h" -#include "base/time/time.h" -#include "storage/common/blob/shareable_file_reference.h" -#include "storage/common/data_element.h" -#include "storage/common/storage_common_export.h" -#include "url/gurl.h" - -namespace storage { - -class STORAGE_COMMON_EXPORT BlobData - : public base::RefCounted { - public: - typedef storage::DataElement Item; - - // TODO(michaeln): remove the empty ctor when we fully transition to uuids. - BlobData(); - explicit BlobData(const std::string& uuid); - - void AppendData(const std::string& data) { - AppendData(data.c_str(), data.size()); - } - - void AppendData(const char* data, size_t length); - - void AppendFile(const base::FilePath& file_path, uint64 offset, uint64 length, - const base::Time& expected_modification_time); - void AppendBlob(const std::string& uuid, uint64 offset, uint64 length); - void AppendFileSystemFile(const GURL& url, uint64 offset, uint64 length, - const base::Time& expected_modification_time); - - void AttachShareableFileReference(ShareableFileReference* reference) { - shareable_files_.push_back(reference); - } - - const std::string& uuid() const { return uuid_; } - const std::vector& items() const { return items_; } - const std::string& content_type() const { return content_type_; } - void set_content_type(const std::string& content_type) { - content_type_ = content_type; - } - - const std::string& content_disposition() const { - return content_disposition_; - } - void set_content_disposition(const std::string& content_disposition) { - content_disposition_ = content_disposition; - } - - int64 GetMemoryUsage() const; - - private: - friend class base::RefCounted; - virtual ~BlobData(); - - std::string uuid_; - std::string content_type_; - std::string content_disposition_; - std::vector items_; - std::vector > shareable_files_; - - DISALLOW_COPY_AND_ASSIGN(BlobData); -}; - -#if defined(UNIT_TEST) -inline bool operator==(const BlobData& a, const BlobData& b) { - if (a.content_type() != b.content_type()) - return false; - if (a.content_disposition() != b.content_disposition()) - return false; - if (a.items().size() != b.items().size()) - return false; - for (size_t i = 0; i < a.items().size(); ++i) { - if (a.items()[i] != b.items()[i]) - return false; - } - return true; -} - -inline bool operator!=(const BlobData& a, const BlobData& b) { - return !(a == b); -} -#endif // defined(UNIT_TEST) - -} // namespace storage - -#endif // STORAGE_COMMON_BLOB_BLOB_DATA_H_ diff --git a/storage/storage_browser.gyp b/storage/storage_browser.gyp index 2ec504f5052ca2..5f93ecf78eb888 100644 --- a/storage/storage_browser.gyp +++ b/storage/storage_browser.gyp @@ -25,8 +25,14 @@ ], 'defines': ['STORAGE_BROWSER_IMPLEMENTATION'], 'sources': [ + 'browser/blob/blob_data_builder.cc', + 'browser/blob/blob_data_builder.h', 'browser/blob/blob_data_handle.cc', 'browser/blob/blob_data_handle.h', + 'browser/blob/blob_data_item.cc', + 'browser/blob/blob_data_item.h', + 'browser/blob/blob_data_snapshot.cc', + 'browser/blob/blob_data_snapshot.h', 'browser/blob/blob_storage_context.cc', 'browser/blob/blob_storage_context.h', 'browser/blob/blob_url_request_job.cc', @@ -37,6 +43,10 @@ 'browser/blob/file_stream_reader.h', 'browser/blob/local_file_stream_reader.cc', 'browser/blob/local_file_stream_reader.h', + 'browser/blob/scoped_file.cc', + 'browser/blob/scoped_file.h', + 'browser/blob/shareable_file_reference.cc', + 'browser/blob/shareable_file_reference.h', 'browser/blob/view_blob_internals_job.cc', 'browser/blob/view_blob_internals_job.h', 'browser/database/database_quota_client.cc', diff --git a/storage/storage_common.gyp b/storage/storage_common.gyp index 87d34b94d54b84..74b913913038ba 100644 --- a/storage/storage_common.gyp +++ b/storage/storage_common.gyp @@ -22,12 +22,6 @@ 'sources': [ 'common/data_element.cc', 'common/data_element.h', - 'common/blob/blob_data.cc', - 'common/blob/blob_data.h', - 'common/blob/scoped_file.cc', - 'common/blob/scoped_file.h', - 'common/blob/shareable_file_reference.cc', - 'common/blob/shareable_file_reference.h', 'common/database/database_connections.cc', 'common/database/database_connections.h', 'common/database/database_identifier.cc',