diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-01-23 17:21:03 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-01-23 16:25:15 +0000 |
commit | c551f43206405019121bd2b2c93714319a0a3300 (patch) | |
tree | 1f48c30631c421fd4bbb3c36da20183c8a2ed7d7 /chromium/storage | |
parent | 7961cea6d1041e3e454dae6a1da660b453efd238 (diff) | |
download | qtwebengine-chromium-c551f43206405019121bd2b2c93714319a0a3300.tar.gz |
BASELINE: Update Chromium to 79.0.3945.139
Change-Id: I336b7182fab9bca80b709682489c07db112eaca5
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/storage')
56 files changed, 564 insertions, 572 deletions
diff --git a/chromium/storage/browser/BUILD.gn b/chromium/storage/browser/BUILD.gn index 1a7f5e4d654..59614d042a1 100644 --- a/chromium/storage/browser/BUILD.gn +++ b/chromium/storage/browser/BUILD.gn @@ -83,8 +83,6 @@ jumbo_component("browser") { "fileapi/file_system_backend.h", "fileapi/file_system_context.cc", "fileapi/file_system_context.h", - "fileapi/file_system_features.cc", - "fileapi/file_system_features.h", "fileapi/file_system_file_stream_reader.cc", "fileapi/file_system_file_stream_reader.h", "fileapi/file_system_file_util.cc", diff --git a/chromium/storage/browser/blob/blob_builder_from_stream.cc b/chromium/storage/browser/blob/blob_builder_from_stream.cc index 4dd25aa5c25..6a6758a8d2a 100644 --- a/chromium/storage/browser/blob/blob_builder_from_stream.cc +++ b/chromium/storage/browser/blob/blob_builder_from_stream.cc @@ -495,8 +495,7 @@ void BlobBuilderFromStream::AllocateMoreFileSpace( items_.back()->item()->length() < kMaxFileSize) { auto item = items_.back()->item(); uint64_t old_file_size = item->length(); - scoped_refptr<ShareableFileReference> file_reference = - static_cast<ShareableFileReference*>(item->data_handle()); + scoped_refptr<ShareableFileReference> file_reference = item->file_ref_; DCHECK(file_reference); auto file_size_delta = std::min(kMaxFileSize - old_file_size, length_hint); context_->mutable_memory_controller()->GrowFileAllocation( @@ -618,7 +617,7 @@ void BlobBuilderFromStream::DidWriteToExtendedFile( DCHECK(!items_.empty()); auto item = items_.back()->item(); DCHECK_EQ(item->type(), BlobDataItem::Type::kFile); - DCHECK_EQ(item->data_handle(), file_reference.get()); + DCHECK_EQ(item->file_ref_, file_reference.get()); item->SetFileModificationTime(modification_time); current_total_size_ += bytes_written; diff --git a/chromium/storage/browser/blob/blob_data_builder.cc b/chromium/storage/browser/blob/blob_data_builder.cc index fec479c3719..bd8caad32df 100644 --- a/chromium/storage/browser/blob/blob_data_builder.cc +++ b/chromium/storage/browser/blob/blob_data_builder.cc @@ -281,8 +281,7 @@ void BlobDataBuilder::SliceBlob(const BlobEntry* source, case BlobDataItem::Type::kFile: { data_item = BlobDataItem::CreateFile( source_item->path(), source_item->offset() + item_offset, read_size, - source_item->expected_modification_time(), - source_item->data_handle_); + source_item->expected_modification_time(), source_item->file_ref_); if (source_item->IsFutureFileItem()) { // The source file isn't a real file yet (path is fake), so store the diff --git a/chromium/storage/browser/blob/blob_data_item.cc b/chromium/storage/browser/blob/blob_data_item.cc index 22582a9a0fc..0a98e09ac23 100644 --- a/chromium/storage/browser/blob/blob_data_item.cc +++ b/chromium/storage/browser/blob/blob_data_item.cc @@ -78,12 +78,12 @@ scoped_refptr<BlobDataItem> BlobDataItem::CreateFile( uint64_t offset, uint64_t length, base::Time expected_modification_time, - scoped_refptr<DataHandle> data_handle) { + scoped_refptr<ShareableFileReference> file_ref) { auto item = base::WrapRefCounted(new BlobDataItem(Type::kFile, offset, length)); item->path_ = std::move(path); item->expected_modification_time_ = std::move(expected_modification_time); - item->data_handle_ = std::move(data_handle); + item->file_ref_ = std::move(file_ref); // TODO(mek): DCHECK(!item->IsFutureFileItem()) when BlobDataBuilder has some // other way of slicing a future file. return item; @@ -171,14 +171,15 @@ void BlobDataItem::ShrinkBytes(size_t new_length) { bytes_.resize(length_); } -void BlobDataItem::PopulateFile(base::FilePath path, - base::Time expected_modification_time, - scoped_refptr<DataHandle> data_handle) { +void BlobDataItem::PopulateFile( + base::FilePath path, + base::Time expected_modification_time, + scoped_refptr<ShareableFileReference> file_ref) { DCHECK_EQ(type_, Type::kFile); DCHECK(IsFutureFileItem()); path_ = std::move(path); expected_modification_time_ = std::move(expected_modification_time); - data_handle_ = std::move(data_handle); + file_ref_ = std::move(file_ref); } void BlobDataItem::ShrinkFile(uint64_t new_length) { diff --git a/chromium/storage/browser/blob/blob_data_item.h b/chromium/storage/browser/blob/blob_data_item.h index bec072f1485..4b559ed244f 100644 --- a/chromium/storage/browser/blob/blob_data_item.h +++ b/chromium/storage/browser/blob/blob_data_item.h @@ -16,6 +16,7 @@ #include "base/files/file_path.h" #include "base/memory/ref_counted.h" #include "net/base/io_buffer.h" +#include "storage/browser/blob/shareable_file_reference.h" #include "url/gurl.h" namespace storage { @@ -102,7 +103,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobDataItem uint64_t offset, uint64_t length, base::Time expected_modification_time = base::Time(), - scoped_refptr<DataHandle> data_handle = nullptr); + scoped_refptr<ShareableFileReference> file_ref = nullptr); static scoped_refptr<BlobDataItem> CreateFutureFile(uint64_t offset, uint64_t length, uint64_t file_id); @@ -148,8 +149,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobDataItem } DataHandle* data_handle() const { - DCHECK(type_ == Type::kFile || type_ == Type::kReadableDataHandle) - << static_cast<int>(type_); + DCHECK_EQ(type_, Type::kReadableDataHandle) << static_cast<int>(type_); return data_handle_.get(); } @@ -180,7 +180,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobDataItem void PopulateFile(base::FilePath path, base::Time expected_modification_time, - scoped_refptr<DataHandle> data_handle); + scoped_refptr<ShareableFileReference> file_ref); void ShrinkFile(uint64_t new_length); void GrowFile(uint64_t new_length); void SetFileModificationTime(base::Time time) { @@ -198,8 +198,8 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobDataItem base::Time expected_modification_time_; // For Type::kFile and kFileFilesystem. - scoped_refptr<DataHandle> - data_handle_; // For Type::kFile and kReadableDataHandle. + scoped_refptr<DataHandle> data_handle_; // For kReadableDataHandle. + scoped_refptr<ShareableFileReference> file_ref_; // For Type::kFile scoped_refptr<FileSystemContext> file_system_context_; // For Type::kFileFilesystem. diff --git a/chromium/storage/browser/blob/blob_flattener_unittest.cc b/chromium/storage/browser/blob/blob_flattener_unittest.cc index 9af353d3b84..6909afe384b 100644 --- a/chromium/storage/browser/blob/blob_flattener_unittest.cc +++ b/chromium/storage/browser/blob/blob_flattener_unittest.cc @@ -117,7 +117,7 @@ class BlobFlattenerTest : public testing::Test { base::ScopedTempDir temp_dir_; scoped_refptr<TestSimpleTaskRunner> file_runner_ = new TestSimpleTaskRunner(); - base::test::TaskEnvironment task_environment; + base::test::SingleThreadTaskEnvironment task_environment; std::unique_ptr<BlobStorageContext> context_; }; diff --git a/chromium/storage/browser/blob/blob_handle.cc b/chromium/storage/browser/blob/blob_handle.cc index 1d6db680282..31129332e10 100644 --- a/chromium/storage/browser/blob/blob_handle.cc +++ b/chromium/storage/browser/blob/blob_handle.cc @@ -6,13 +6,14 @@ namespace storage { -BlobHandle::BlobHandle(blink::mojom::BlobPtr blob) : blob_(std::move(blob)) { +BlobHandle::BlobHandle(mojo::PendingRemote<blink::mojom::Blob> blob) + : blob_(std::move(blob)) { DCHECK(blob_); } -blink::mojom::BlobPtr BlobHandle::Clone() const { - blink::mojom::BlobPtr clone; - blob_->Clone(MakeRequest(&clone)); +mojo::PendingRemote<blink::mojom::Blob> BlobHandle::Clone() const { + mojo::PendingRemote<blink::mojom::Blob> clone; + blob_->Clone(clone.InitWithNewPipeAndPassReceiver()); return clone; } diff --git a/chromium/storage/browser/blob/blob_handle.h b/chromium/storage/browser/blob/blob_handle.h index 9b3e7de8f1e..4050dff54b0 100644 --- a/chromium/storage/browser/blob/blob_handle.h +++ b/chromium/storage/browser/blob/blob_handle.h @@ -7,29 +7,30 @@ #include "base/component_export.h" #include "base/memory/ref_counted.h" +#include "mojo/public/cpp/bindings/pending_remote.h" +#include "mojo/public/cpp/bindings/remote.h" #include "third_party/blink/public/mojom/blob/blob.mojom.h" namespace storage { -// Refcounted wrapper around a mojom::BlobPtr. +// Refcounted wrapper around a mojom::Blob. class COMPONENT_EXPORT(STORAGE_BROWSER) BlobHandle : public base::RefCounted<BlobHandle> { public: - explicit BlobHandle(blink::mojom::BlobPtr blob); + explicit BlobHandle(mojo::PendingRemote<blink::mojom::Blob> blob); bool is_bound() const { return blob_.is_bound(); } blink::mojom::Blob* get() const { return blob_.get(); } blink::mojom::Blob* operator->() const { return get(); } blink::mojom::Blob& operator*() const { return *get(); } - blink::mojom::BlobPtr Clone() const; - blink::mojom::BlobPtr&& TakeBlobPtr() { return std::move(blob_); } + mojo::PendingRemote<blink::mojom::Blob> Clone() const; private: friend class base::RefCounted<BlobHandle>; ~BlobHandle(); - blink::mojom::BlobPtr blob_; + mojo::Remote<blink::mojom::Blob> blob_; }; } // namespace storage diff --git a/chromium/storage/browser/blob/blob_impl.cc b/chromium/storage/browser/blob/blob_impl.cc index dc27eaa5992..d403498207b 100644 --- a/chromium/storage/browser/blob/blob_impl.cc +++ b/chromium/storage/browser/blob/blob_impl.cc @@ -92,8 +92,9 @@ void BlobImpl::Clone(mojo::PendingReceiver<blink::mojom::Blob> receiver) { receivers_.Add(this, std::move(receiver)); } -void BlobImpl::AsDataPipeGetter(network::mojom::DataPipeGetterRequest request) { - data_pipe_getter_bindings_.AddBinding(this, std::move(request)); +void BlobImpl::AsDataPipeGetter( + mojo::PendingReceiver<network::mojom::DataPipeGetter> receiver) { + data_pipe_getter_receivers_.Add(this, std::move(receiver)); } void BlobImpl::ReadRange( @@ -175,8 +176,9 @@ void BlobImpl::GetInternalUUID(GetInternalUUIDCallback callback) { std::move(callback).Run(handle_->uuid()); } -void BlobImpl::Clone(network::mojom::DataPipeGetterRequest request) { - data_pipe_getter_bindings_.AddBinding(this, std::move(request)); +void BlobImpl::Clone( + mojo::PendingReceiver<network::mojom::DataPipeGetter> receiver) { + data_pipe_getter_receivers_.Add(this, std::move(receiver)); } void BlobImpl::Read(mojo::ScopedDataPipeProducerHandle handle, @@ -192,10 +194,10 @@ void BlobImpl::FlushForTesting() { receivers_.FlushForTesting(); if (!weak_self) return; - data_pipe_getter_bindings_.FlushForTesting(); + data_pipe_getter_receivers_.FlushForTesting(); if (!weak_self) return; - if (receivers_.empty() && data_pipe_getter_bindings_.empty()) + if (receivers_.empty() && data_pipe_getter_receivers_.empty()) delete this; } @@ -206,7 +208,7 @@ BlobImpl::BlobImpl(std::unique_ptr<BlobDataHandle> handle, receivers_.Add(this, std::move(receiver)); receivers_.set_disconnect_handler( base::BindRepeating(&BlobImpl::OnMojoDisconnect, base::Unretained(this))); - data_pipe_getter_bindings_.set_connection_error_handler( + data_pipe_getter_receivers_.set_disconnect_handler( base::BindRepeating(&BlobImpl::OnMojoDisconnect, base::Unretained(this))); } @@ -215,7 +217,7 @@ BlobImpl::~BlobImpl() = default; void BlobImpl::OnMojoDisconnect() { if (!receivers_.empty()) return; - if (!data_pipe_getter_bindings_.empty()) + if (!data_pipe_getter_receivers_.empty()) return; delete this; } diff --git a/chromium/storage/browser/blob/blob_impl.h b/chromium/storage/browser/blob/blob_impl.h index df0ae9a7c48..c0006248e79 100644 --- a/chromium/storage/browser/blob/blob_impl.h +++ b/chromium/storage/browser/blob/blob_impl.h @@ -6,7 +6,7 @@ #define STORAGE_BROWSER_BLOB_BLOB_IMPL_H_ #include "base/component_export.h" -#include "mojo/public/cpp/bindings/binding_set.h" +#include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/receiver_set.h" #include "services/network/public/mojom/data_pipe_getter.mojom.h" #include "third_party/blink/public/mojom/blob/blob.mojom.h" @@ -26,7 +26,8 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobImpl // blink::mojom::Blob: void Clone(mojo::PendingReceiver<blink::mojom::Blob> receiver) override; - void AsDataPipeGetter(network::mojom::DataPipeGetterRequest request) override; + void AsDataPipeGetter( + mojo::PendingReceiver<network::mojom::DataPipeGetter> receiver) override; void ReadRange( uint64_t offset, uint64_t length, @@ -39,7 +40,8 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobImpl void GetInternalUUID(GetInternalUUIDCallback callback) override; // network::mojom::DataPipeGetter: - void Clone(network::mojom::DataPipeGetterRequest request) override; + void Clone( + mojo::PendingReceiver<network::mojom::DataPipeGetter> receiver) override; void Read(mojo::ScopedDataPipeProducerHandle pipe, ReadCallback callback) override; @@ -54,7 +56,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobImpl std::unique_ptr<BlobDataHandle> handle_; mojo::ReceiverSet<blink::mojom::Blob> receivers_; - mojo::BindingSet<network::mojom::DataPipeGetter> data_pipe_getter_bindings_; + mojo::ReceiverSet<network::mojom::DataPipeGetter> data_pipe_getter_receivers_; base::WeakPtrFactory<BlobImpl> weak_ptr_factory_{this}; diff --git a/chromium/storage/browser/blob/blob_impl_unittest.cc b/chromium/storage/browser/blob/blob_impl_unittest.cc index c6d75d92904..460a0cb0fa3 100644 --- a/chromium/storage/browser/blob/blob_impl_unittest.cc +++ b/chromium/storage/browser/blob/blob_impl_unittest.cc @@ -13,7 +13,9 @@ #include "base/run_loop.h" #include "base/task/post_task.h" #include "base/test/task_environment.h" +#include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/receiver.h" +#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/system/data_pipe_drainer.h" #include "net/base/net_errors.h" #include "storage/browser/blob/blob_data_builder.h" @@ -111,30 +113,32 @@ TEST_F(BlobImplTest, GetInternalUUID) { const std::string kId = "id"; auto handle = CreateBlobFromString(kId, "hello world"); - blink::mojom::BlobPtr ptr; - auto blob = BlobImpl::Create(std::move(handle), MakeRequest(&ptr)); + mojo::Remote<blink::mojom::Blob> remote; + auto blob = + BlobImpl::Create(std::move(handle), remote.BindNewPipeAndPassReceiver()); EXPECT_EQ(kId, UUIDFromBlob(blob.get())); - EXPECT_EQ(kId, UUIDFromBlob(ptr.get())); + EXPECT_EQ(kId, UUIDFromBlob(remote.get())); } TEST_F(BlobImplTest, CloneAndLifetime) { const std::string kId = "id"; auto handle = CreateBlobFromString(kId, "hello world"); - blink::mojom::BlobPtr ptr; - auto blob = BlobImpl::Create(std::move(handle), MakeRequest(&ptr)); - EXPECT_EQ(kId, UUIDFromBlob(ptr.get())); + mojo::Remote<blink::mojom::Blob> remote; + auto blob = + BlobImpl::Create(std::move(handle), remote.BindNewPipeAndPassReceiver()); + EXPECT_EQ(kId, UUIDFromBlob(remote.get())); // Blob should exist in registry as long as connection is alive. EXPECT_TRUE(context_->registry().HasEntry(kId)); EXPECT_TRUE(blob); - blink::mojom::BlobPtr clone; - blob->Clone(MakeRequest(&clone)); + mojo::Remote<blink::mojom::Blob> clone; + blob->Clone(clone.BindNewPipeAndPassReceiver()); EXPECT_EQ(kId, UUIDFromBlob(clone.get())); clone.FlushForTesting(); - ptr.reset(); + remote.reset(); blob->FlushForTesting(); EXPECT_TRUE(context_->registry().HasEntry(kId)); EXPECT_TRUE(blob); @@ -150,15 +154,15 @@ TEST_F(BlobImplTest, ReadAll) { const std::string kContents = "hello world"; auto handle = CreateBlobFromString(kId, kContents); - blink::mojom::BlobPtr ptr; - BlobImpl::Create(std::move(handle), MakeRequest(&ptr)); + mojo::Remote<blink::mojom::Blob> remote; + BlobImpl::Create(std::move(handle), remote.BindNewPipeAndPassReceiver()); MockBlobReaderClient client; mojo::Receiver<blink::mojom::BlobReaderClient> client_receiver(&client); mojo::DataPipe pipe; - ptr->ReadAll(std::move(pipe.producer_handle), - client_receiver.BindNewPipeAndPassRemote()); + remote->ReadAll(std::move(pipe.producer_handle), + client_receiver.BindNewPipeAndPassRemote()); std::string received = ReadDataPipe(std::move(pipe.consumer_handle)); EXPECT_EQ(kContents, received); @@ -177,11 +181,11 @@ TEST_F(BlobImplTest, ReadAll_WithoutClient) { const std::string kContents = "hello world"; auto handle = CreateBlobFromString(kId, kContents); - blink::mojom::BlobPtr ptr; - BlobImpl::Create(std::move(handle), MakeRequest(&ptr)); + mojo::Remote<blink::mojom::Blob> remote; + BlobImpl::Create(std::move(handle), remote.BindNewPipeAndPassReceiver()); mojo::DataPipe pipe; - ptr->ReadAll(std::move(pipe.producer_handle), mojo::NullRemote()); + remote->ReadAll(std::move(pipe.producer_handle), mojo::NullRemote()); std::string received = ReadDataPipe(std::move(pipe.consumer_handle)); EXPECT_EQ(kContents, received); } @@ -191,15 +195,15 @@ TEST_F(BlobImplTest, ReadAll_BrokenBlob) { auto handle = context_->AddBrokenBlob( kId, "", "", BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS); - blink::mojom::BlobPtr ptr; - BlobImpl::Create(std::move(handle), MakeRequest(&ptr)); + mojo::Remote<blink::mojom::Blob> remote; + BlobImpl::Create(std::move(handle), remote.BindNewPipeAndPassReceiver()); MockBlobReaderClient client; mojo::Receiver<blink::mojom::BlobReaderClient> client_receiver(&client); mojo::DataPipe pipe; - ptr->ReadAll(std::move(pipe.producer_handle), - client_receiver.BindNewPipeAndPassRemote()); + remote->ReadAll(std::move(pipe.producer_handle), + client_receiver.BindNewPipeAndPassRemote()); std::string received = ReadDataPipe(std::move(pipe.consumer_handle)); EXPECT_EQ("", received); @@ -216,15 +220,15 @@ TEST_F(BlobImplTest, ReadRange) { const std::string kContents = "hello world"; auto handle = CreateBlobFromString(kId, kContents); - blink::mojom::BlobPtr ptr; - BlobImpl::Create(std::move(handle), MakeRequest(&ptr)); + mojo::Remote<blink::mojom::Blob> remote; + BlobImpl::Create(std::move(handle), remote.BindNewPipeAndPassReceiver()); MockBlobReaderClient client; mojo::Receiver<blink::mojom::BlobReaderClient> client_receiver(&client); mojo::DataPipe pipe; - ptr->ReadRange(2, 5, std::move(pipe.producer_handle), - client_receiver.BindNewPipeAndPassRemote()); + remote->ReadRange(2, 5, std::move(pipe.producer_handle), + client_receiver.BindNewPipeAndPassRemote()); std::string received = ReadDataPipe(std::move(pipe.consumer_handle)); EXPECT_EQ(kContents.substr(2, 5), received); @@ -244,11 +248,11 @@ TEST_F(BlobImplTest, ReadRange_WithoutClient) { const std::string kContents = "hello world"; auto handle = CreateBlobFromString(kId, kContents); - blink::mojom::BlobPtr ptr; - BlobImpl::Create(std::move(handle), MakeRequest(&ptr)); + mojo::Remote<blink::mojom::Blob> remote; + BlobImpl::Create(std::move(handle), remote.BindNewPipeAndPassReceiver()); mojo::DataPipe pipe; - ptr->ReadRange(2, 5, std::move(pipe.producer_handle), mojo::NullRemote()); + remote->ReadRange(2, 5, std::move(pipe.producer_handle), mojo::NullRemote()); std::string received = ReadDataPipe(std::move(pipe.consumer_handle)); EXPECT_EQ(kContents.substr(2, 5), received); @@ -259,15 +263,15 @@ TEST_F(BlobImplTest, ReadRange_TooLargeLength) { const std::string kContents = "hello world"; auto handle = CreateBlobFromString(kId, kContents); - blink::mojom::BlobPtr ptr; - BlobImpl::Create(std::move(handle), MakeRequest(&ptr)); + mojo::Remote<blink::mojom::Blob> remote; + BlobImpl::Create(std::move(handle), remote.BindNewPipeAndPassReceiver()); MockBlobReaderClient client; mojo::Receiver<blink::mojom::BlobReaderClient> client_receiver(&client); mojo::DataPipe pipe; - ptr->ReadRange(2, 15, std::move(pipe.producer_handle), - client_receiver.BindNewPipeAndPassRemote()); + remote->ReadRange(2, 15, std::move(pipe.producer_handle), + client_receiver.BindNewPipeAndPassRemote()); std::string received = ReadDataPipe(std::move(pipe.consumer_handle)); EXPECT_EQ(kContents.substr(2, 15), received); @@ -287,16 +291,16 @@ TEST_F(BlobImplTest, ReadRange_UnboundedLength) { const std::string kContents = "hello world"; auto handle = CreateBlobFromString(kId, kContents); - blink::mojom::BlobPtr ptr; - BlobImpl::Create(std::move(handle), MakeRequest(&ptr)); + mojo::Remote<blink::mojom::Blob> remote; + BlobImpl::Create(std::move(handle), remote.BindNewPipeAndPassReceiver()); MockBlobReaderClient client; mojo::Receiver<blink::mojom::BlobReaderClient> client_receiver(&client); mojo::DataPipe pipe; - ptr->ReadRange(2, std::numeric_limits<uint64_t>::max(), - std::move(pipe.producer_handle), - client_receiver.BindNewPipeAndPassRemote()); + remote->ReadRange(2, std::numeric_limits<uint64_t>::max(), + std::move(pipe.producer_handle), + client_receiver.BindNewPipeAndPassRemote()); std::string received = ReadDataPipe(std::move(pipe.consumer_handle)); EXPECT_EQ(kContents.substr(2, kContents.size()), received); @@ -316,15 +320,15 @@ TEST_F(BlobImplTest, ReadRange_BrokenBlob) { auto handle = context_->AddBrokenBlob( kId, "", "", BlobStatus::ERR_INVALID_CONSTRUCTION_ARGUMENTS); - blink::mojom::BlobPtr ptr; - BlobImpl::Create(std::move(handle), MakeRequest(&ptr)); + mojo::Remote<blink::mojom::Blob> remote; + BlobImpl::Create(std::move(handle), remote.BindNewPipeAndPassReceiver()); MockBlobReaderClient client; mojo::Receiver<blink::mojom::BlobReaderClient> client_receiver(&client); mojo::DataPipe pipe; - ptr->ReadRange(2, 5, std::move(pipe.producer_handle), - client_receiver.BindNewPipeAndPassRemote()); + remote->ReadRange(2, 5, std::move(pipe.producer_handle), + client_receiver.BindNewPipeAndPassRemote()); std::string received = ReadDataPipe(std::move(pipe.consumer_handle)); EXPECT_EQ("", received); @@ -341,16 +345,16 @@ TEST_F(BlobImplTest, ReadRange_InvalidRange) { const std::string kContents = "hello world"; auto handle = CreateBlobFromString(kId, kContents); - blink::mojom::BlobPtr ptr; - BlobImpl::Create(std::move(handle), MakeRequest(&ptr)); + mojo::Remote<blink::mojom::Blob> remote; + BlobImpl::Create(std::move(handle), remote.BindNewPipeAndPassReceiver()); MockBlobReaderClient client; mojo::Receiver<blink::mojom::BlobReaderClient> client_receiver(&client); base::RunLoop loop; mojo::DataPipe pipe; - ptr->ReadRange(15, 4, std::move(pipe.producer_handle), - client_receiver.BindNewPipeAndPassRemote()); + remote->ReadRange(15, 4, std::move(pipe.producer_handle), + client_receiver.BindNewPipeAndPassRemote()); std::string received = ReadDataPipe(std::move(pipe.consumer_handle)); EXPECT_EQ("", received); diff --git a/chromium/storage/browser/blob/blob_memory_controller_unittest.cc b/chromium/storage/browser/blob/blob_memory_controller_unittest.cc index e5d5599c7d4..87f56200dae 100644 --- a/chromium/storage/browser/blob/blob_memory_controller_unittest.cc +++ b/chromium/storage/browser/blob/blob_memory_controller_unittest.cc @@ -165,7 +165,7 @@ class BlobMemoryControllerTest : public testing::Test { scoped_refptr<TestSimpleTaskRunner> file_runner_ = new TestSimpleTaskRunner(); - base::test::TaskEnvironment task_environment_; + base::test::SingleThreadTaskEnvironment task_environment_; }; TEST_F(BlobMemoryControllerTest, Strategy) { diff --git a/chromium/storage/browser/blob/blob_reader.cc b/chromium/storage/browser/blob/blob_reader.cc index 1179a0e38a9..66e73006b77 100644 --- a/chromium/storage/browser/blob/blob_reader.cc +++ b/chromium/storage/browser/blob/blob_reader.cc @@ -644,8 +644,7 @@ int BlobReader::ComputeBytesToRead() const { uint64_t max_int_value = std::numeric_limits<int>::max(); // Here we make sure we don't overflow 'max int'. uint64_t min = std::min( - std::min(std::min(item_remaining, buf_remaining), remaining_bytes_), - max_int_value); + {item_remaining, buf_remaining, remaining_bytes_, max_int_value}); return static_cast<int>(min); } diff --git a/chromium/storage/browser/blob/blob_reader.h b/chromium/storage/browser/blob/blob_reader.h index aa89fcb3f3b..fb8f1f31c49 100644 --- a/chromium/storage/browser/blob/blob_reader.h +++ b/chromium/storage/browser/blob/blob_reader.h @@ -48,7 +48,7 @@ class FileStreamReader; // Use a BlobDataHandle to create an instance. // // For more information on how to read Blobs in your specific situation, see: -// https://chromium.googlesource.com/chromium/src/+/HEAD/storage/browser/blob/README.md#accessing-reading +// https://chromium.googlesource.com/chromium/src/+/HEAD/storage/browser/blob/README.md#how-to-use-blobs-browser_side-accessing-reading class COMPONENT_EXPORT(STORAGE_BROWSER) BlobReader { public: class COMPONENT_EXPORT(STORAGE_BROWSER) FileStreamReaderProvider { diff --git a/chromium/storage/browser/blob/blob_registry_impl.cc b/chromium/storage/browser/blob/blob_registry_impl.cc index f3ae0c6a942..1cc34f91e01 100644 --- a/chromium/storage/browser/blob/blob_registry_impl.cc +++ b/chromium/storage/browser/blob/blob_registry_impl.cc @@ -58,8 +58,9 @@ class BlobRegistryImpl::BlobUnderConstruction { private: // Holds onto a blink::mojom::DataElement struct and optionally a bound - // mojo::Remote<blink::mojom::BytesProvider> or blink::mojom::BlobPtr, if the - // element encapsulates a large byte array or a blob. + // mojo::Remote<blink::mojom::BytesProvider> or + // mojo::Remote<blink::mojom::Blob>, if the element encapsulates a large byte + // array or a blob. struct ElementEntry { explicit ElementEntry(blink::mojom::DataElementPtr e) : element(std::move(e)) { @@ -76,7 +77,7 @@ class BlobRegistryImpl::BlobUnderConstruction { blink::mojom::DataElementPtr element; mojo::Remote<blink::mojom::BytesProvider> bytes_provider; - blink::mojom::BlobPtr blob; + mojo::Remote<blink::mojom::Blob> blob; }; BlobStorageContext* context() const { return blob_registry_->context_.get(); } @@ -220,7 +221,7 @@ void BlobRegistryImpl::BlobUnderConstruction::StartTransportation() { // If connection to blob is broken, something bad happened, so mark this // new blob as broken, which will delete |this| and keep it from doing // unneeded extra work. - entry.blob.set_connection_error_handler(base::BindOnce( + entry.blob.set_disconnect_handler(base::BindOnce( &BlobUnderConstruction::MarkAsBroken, weak_ptr_factory_.GetWeakPtr(), BlobStatus::ERR_REFERENCED_BLOB_BROKEN, "")); @@ -237,7 +238,8 @@ void BlobRegistryImpl::BlobUnderConstruction::StartTransportation() { // TODO(mek): Do we need some kind of timeout for fetching the UUIDs? // Without it a blob could forever remaing pending if a renderer sends us - // a BlobPtr connected to a (malicious) non-responding implementation. + // a mojo::Remote<Blob> connected to a (malicious) non-responding + // implementation. // Do some basic validation of bytes to transport, and determine memory // transport strategy to use later. @@ -633,8 +635,10 @@ void BlobRegistryImpl::StreamingBlobDone( if (result) { DCHECK_EQ(BlobStatus::DONE, result->GetBlobStatus()); blob = blink::mojom::SerializedBlob::New( - result->uuid(), result->content_type(), result->size(), nullptr); - BlobImpl::Create(std::move(result), MakeRequest(&blob->blob)); + result->uuid(), result->content_type(), result->size(), + mojo::NullRemote()); + BlobImpl::Create(std::move(result), + blob->blob.InitWithNewPipeAndPassReceiver()); } std::move(callback).Run(std::move(blob)); } diff --git a/chromium/storage/browser/blob/blob_registry_impl_unittest.cc b/chromium/storage/browser/blob/blob_registry_impl_unittest.cc index 62a8b5664b0..3182e7af08b 100644 --- a/chromium/storage/browser/blob/blob_registry_impl_unittest.cc +++ b/chromium/storage/browser/blob/blob_registry_impl_unittest.cc @@ -23,7 +23,6 @@ #include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/self_owned_receiver.h" -#include "mojo/public/cpp/bindings/strong_binding.h" #include "mojo/public/cpp/system/data_pipe_utils.h" #include "storage/browser/blob/blob_data_builder.h" #include "storage/browser/blob/blob_data_handle.h" @@ -206,26 +205,26 @@ TEST_F(BlobRegistryImplTest, GetBlobFromUUID) { CreateBlobFromString(kId, "hello world"); { - blink::mojom::BlobPtr blob; - registry_->GetBlobFromUUID(MakeRequest(&blob), kId); + mojo::Remote<blink::mojom::Blob> blob; + registry_->GetBlobFromUUID(blob.BindNewPipeAndPassReceiver(), kId); EXPECT_EQ(kId, UUIDFromBlob(blob.get())); - EXPECT_FALSE(blob.encountered_error()); + EXPECT_TRUE(blob.is_connected()); } { - blink::mojom::BlobPtr blob; - registry_->GetBlobFromUUID(MakeRequest(&blob), "invalid id"); + mojo::Remote<blink::mojom::Blob> blob; + registry_->GetBlobFromUUID(blob.BindNewPipeAndPassReceiver(), "invalid id"); blob.FlushForTesting(); - EXPECT_TRUE(blob.encountered_error()); + EXPECT_FALSE(blob.is_connected()); } } TEST_F(BlobRegistryImplTest, GetBlobFromEmptyUUID) { - blink::mojom::BlobPtr blob; - registry_->GetBlobFromUUID(MakeRequest(&blob), ""); + mojo::Remote<blink::mojom::Blob> blob; + registry_->GetBlobFromUUID(blob.BindNewPipeAndPassReceiver(), ""); blob.FlushForTesting(); EXPECT_EQ(1u, bad_messages_.size()); - EXPECT_TRUE(blob.encountered_error()); + EXPECT_FALSE(blob.is_connected()); } TEST_F(BlobRegistryImplTest, Register_EmptyUUID) { @@ -294,11 +293,11 @@ TEST_F(BlobRegistryImplTest, Register_ReferencedBlobClosedPipe) { const std::string kId = "id"; std::vector<blink::mojom::DataElementPtr> elements; - blink::mojom::BlobPtrInfo referenced_blob_info; - MakeRequest(&referenced_blob_info); + mojo::PendingRemote<blink::mojom::Blob> referenced_blob_remote; + ignore_result(referenced_blob_remote.InitWithNewPipeAndPassReceiver()); elements.push_back( blink::mojom::DataElement::NewBlob(blink::mojom::DataElementBlob::New( - std::move(referenced_blob_info), 0, 16))); + std::move(referenced_blob_remote), 0, 16))); mojo::PendingRemote<blink::mojom::Blob> blob; EXPECT_TRUE(registry_->Register(blob.InitWithNewPipeAndPassReceiver(), kId, @@ -415,12 +414,13 @@ TEST_F(BlobRegistryImplTest, Register_NonExistentBlob) { const std::string kId = "id"; std::vector<blink::mojom::DataElementPtr> elements; - blink::mojom::BlobPtrInfo referenced_blob_info; - mojo::MakeStrongBinding(std::make_unique<FakeBlob>("mock blob"), - MakeRequest(&referenced_blob_info)); + mojo::PendingRemote<blink::mojom::Blob> referenced_blob_remote; + mojo::MakeSelfOwnedReceiver( + std::make_unique<FakeBlob>("mock blob"), + referenced_blob_remote.InitWithNewPipeAndPassReceiver()); elements.push_back( blink::mojom::DataElement::NewBlob(blink::mojom::DataElementBlob::New( - std::move(referenced_blob_info), 0, 16))); + std::move(referenced_blob_remote), 0, 16))); mojo::PendingRemote<blink::mojom::Blob> blob; EXPECT_TRUE(registry_->Register(blob.InitWithNewPipeAndPassReceiver(), kId, @@ -445,9 +445,9 @@ TEST_F(BlobRegistryImplTest, Register_ValidBlobReferences) { const std::string kId1 = "id1"; std::unique_ptr<BlobDataHandle> handle = CreateBlobFromString(kId1, "hello world"); - blink::mojom::BlobPtrInfo blob1_info; - mojo::MakeStrongBinding(std::make_unique<FakeBlob>(kId1), - MakeRequest(&blob1_info)); + mojo::PendingRemote<blink::mojom::Blob> blob1_remote; + mojo::MakeSelfOwnedReceiver(std::make_unique<FakeBlob>(kId1), + blob1_remote.InitWithNewPipeAndPassReceiver()); const std::string kId2 = "id2"; mojo::PendingRemote<blink::mojom::Blob> blob2_remote; @@ -456,7 +456,7 @@ TEST_F(BlobRegistryImplTest, Register_ValidBlobReferences) { std::vector<blink::mojom::DataElementPtr> elements1; elements1.push_back(blink::mojom::DataElement::NewBlob( - blink::mojom::DataElementBlob::New(std::move(blob1_info), 0, 8))); + blink::mojom::DataElementBlob::New(std::move(blob1_remote), 0, 8))); std::vector<blink::mojom::DataElementPtr> elements2; elements2.push_back(blink::mojom::DataElement::NewBlob( @@ -916,15 +916,16 @@ TEST_F(BlobRegistryImplTest, // Create future blob. auto blob_handle = context_->AddFutureBlob( kDepId, "", "", BlobStorageContext::BuildAbortedCallback()); - blink::mojom::BlobPtrInfo referenced_blob_info; - mojo::MakeStrongBinding(std::make_unique<FakeBlob>(kDepId), - MakeRequest(&referenced_blob_info)); + mojo::PendingRemote<blink::mojom::Blob> referenced_blob_remote; + mojo::MakeSelfOwnedReceiver( + std::make_unique<FakeBlob>(kDepId), + referenced_blob_remote.InitWithNewPipeAndPassReceiver()); // Create mojo blob depending on future blob. std::vector<blink::mojom::DataElementPtr> elements; elements.push_back( blink::mojom::DataElement::NewBlob(blink::mojom::DataElementBlob::New( - std::move(referenced_blob_info), 0, kData.size()))); + std::move(referenced_blob_remote), 0, kData.size()))); mojo::PendingRemote<blink::mojom::Blob> blob; EXPECT_TRUE(registry_->Register(blob.InitWithNewPipeAndPassReceiver(), kId, diff --git a/chromium/storage/browser/blob/blob_storage_context.cc b/chromium/storage/browser/blob/blob_storage_context.cc index 18c9f9c618b..ccbbda618d9 100644 --- a/chromium/storage/browser/blob/blob_storage_context.cc +++ b/chromium/storage/browser/blob/blob_storage_context.cc @@ -29,6 +29,7 @@ #include "storage/browser/blob/blob_data_builder.h" #include "storage/browser/blob/blob_data_item.h" #include "storage/browser/blob/blob_data_snapshot.h" +#include "storage/browser/blob/blob_impl.h" #include "storage/browser/blob/shareable_blob_data_item.h" #include "third_party/blink/public/common/blob/blob_utils.h" #include "url/gurl.h" @@ -66,13 +67,9 @@ std::unique_ptr<BlobDataHandle> BlobStorageContext::GetBlobDataFromUUID( return CreateHandle(uuid, entry); } -std::unique_ptr<BlobDataHandle> BlobStorageContext::GetBlobDataFromPublicURL( - const GURL& url) { - std::string uuid; - BlobEntry* entry = registry_.GetEntryFromURL(url, &uuid); - if (!entry) - return nullptr; - return CreateHandle(uuid, entry); +mojo::PendingRemote<blink::mojom::Blob> +BlobStorageContext::GetBlobFromPublicURL(const GURL& url) { + return registry_.GetBlobFromURL(url); } void BlobStorageContext::GetBlobDataFromBlobRemote( @@ -142,19 +139,14 @@ std::unique_ptr<BlobDataHandle> BlobStorageContext::AddBrokenBlob( return CreateHandle(uuid, entry); } -bool BlobStorageContext::RegisterPublicBlobURL(const GURL& blob_url, - const std::string& uuid) { - if (!registry_.CreateUrlMapping(blob_url, uuid)) - return false; - IncrementBlobRefCount(uuid); - return true; +bool BlobStorageContext::RegisterPublicBlobURL( + const GURL& blob_url, + mojo::PendingRemote<blink::mojom::Blob> blob) { + return registry_.CreateUrlMapping(blob_url, std::move(blob)); } void BlobStorageContext::RevokePublicBlobURL(const GURL& blob_url) { - std::string uuid; - if (!registry_.DeleteURLMapping(blob_url, &uuid)) - return; - DecrementBlobRefCount(uuid); + registry_.DeleteURLMapping(blob_url); } std::unique_ptr<BlobDataHandle> BlobStorageContext::AddFutureBlob( @@ -528,7 +520,7 @@ void BlobStorageContext::FinishBuilding(BlobEntry* entry) { source_item->path(), source_item->offset() + copy.source_item_offset, dest_size, source_item->expected_modification_time(), - source_item->data_handle_); + source_item->file_ref_); copy.dest_item->set_item(std::move(new_item)); break; } diff --git a/chromium/storage/browser/blob/blob_storage_context.h b/chromium/storage/browser/blob/blob_storage_context.h index 6f5338036cb..c4fdee53af2 100644 --- a/chromium/storage/browser/blob/blob_storage_context.h +++ b/chromium/storage/browser/blob/blob_storage_context.h @@ -61,7 +61,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobStorageContext // The following three methods all lookup a BlobDataHandle based on some // input. If no blob matching the input exists these methods return null. std::unique_ptr<BlobDataHandle> GetBlobDataFromUUID(const std::string& uuid); - std::unique_ptr<BlobDataHandle> GetBlobDataFromPublicURL(const GURL& url); + mojo::PendingRemote<blink::mojom::Blob> GetBlobFromPublicURL(const GURL& url); // If this BlobStorageContext is deleted before this method finishes, the // callback will still be called with null. void GetBlobDataFromBlobRemote( @@ -87,7 +87,8 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobStorageContext BlobStatus reason); // Useful for coining blob urls from within the browser process. - bool RegisterPublicBlobURL(const GURL& url, const std::string& uuid); + bool RegisterPublicBlobURL(const GURL& url, + mojo::PendingRemote<blink::mojom::Blob> blob); void RevokePublicBlobURL(const GURL& url); size_t blob_count() const { return registry_.blob_count(); } diff --git a/chromium/storage/browser/blob/blob_storage_context_unittest.cc b/chromium/storage/browser/blob/blob_storage_context_unittest.cc index 6e80f438511..2188c6e85ca 100644 --- a/chromium/storage/browser/blob/blob_storage_context_unittest.cc +++ b/chromium/storage/browser/blob/blob_storage_context_unittest.cc @@ -28,6 +28,7 @@ #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_impl.h" #include "storage/browser/test/fake_blob_data_handle.h" #include "testing/gtest/include/gtest/gtest.h" @@ -111,11 +112,25 @@ class BlobStorageContextTest : public testing::Test { context_->DecrementBlobRefCount(uuid); } + std::string UUIDFromBlob(blink::mojom::Blob* blob) { + base::RunLoop loop; + std::string received_uuid; + blob->GetInternalUUID(base::BindOnce( + [](base::OnceClosure quit_closure, std::string* uuid_out, + const std::string& uuid) { + *uuid_out = uuid; + std::move(quit_closure).Run(); + }, + loop.QuitClosure(), &received_uuid)); + loop.Run(); + return received_uuid; + } + std::vector<FileCreationInfo> files_; base::ScopedTempDir temp_dir_; scoped_refptr<TestSimpleTaskRunner> file_runner_ = new TestSimpleTaskRunner(); - base::test::TaskEnvironment task_environment_; + base::test::SingleThreadTaskEnvironment task_environment_; std::unique_ptr<BlobStorageContext> context_; }; @@ -606,31 +621,33 @@ TEST_F(BlobStorageContextTest, CompoundBlobs) { TEST_F(BlobStorageContextTest, PublicBlobUrls) { // Build up a basic blob. const std::string kId("id"); - std::unique_ptr<BlobDataHandle> first_handle = SetupBasicBlob(kId); + mojo::PendingRemote<blink::mojom::Blob> pending_blob_remote; + BlobImpl::Create(SetupBasicBlob(kId), + pending_blob_remote.InitWithNewPipeAndPassReceiver()); // Now register a url for that blob. GURL kUrl("blob:id"); - context_->RegisterPublicBlobURL(kUrl, kId); - std::unique_ptr<BlobDataHandle> blob_data_handle = - context_->GetBlobDataFromPublicURL(kUrl); - ASSERT_TRUE(blob_data_handle.get()); - EXPECT_EQ(kId, blob_data_handle->uuid()); - std::unique_ptr<BlobDataSnapshot> data = blob_data_handle->CreateSnapshot(); - blob_data_handle.reset(); - first_handle.reset(); + context_->RegisterPublicBlobURL(kUrl, std::move(pending_blob_remote)); + pending_blob_remote = context_->GetBlobFromPublicURL(kUrl); + ASSERT_TRUE(pending_blob_remote); + mojo::Remote<blink::mojom::Blob> blob_remote(std::move(pending_blob_remote)); + EXPECT_EQ(kId, UUIDFromBlob(blob_remote.get())); + blob_remote.reset(); base::RunLoop().RunUntilIdle(); // The url registration should keep the blob alive even after // explicit references are dropped. - blob_data_handle = context_->GetBlobDataFromPublicURL(kUrl); - EXPECT_TRUE(blob_data_handle); - blob_data_handle.reset(); + pending_blob_remote = context_->GetBlobFromPublicURL(kUrl); + EXPECT_TRUE(pending_blob_remote); + pending_blob_remote.reset(); base::RunLoop().RunUntilIdle(); // Finally get rid of the url registration and the blob. context_->RevokePublicBlobURL(kUrl); - blob_data_handle = context_->GetBlobDataFromPublicURL(kUrl); - EXPECT_FALSE(blob_data_handle.get()); + pending_blob_remote = context_->GetBlobFromPublicURL(kUrl); + EXPECT_FALSE(pending_blob_remote); + base::RunLoop().RunUntilIdle(); + EXPECT_FALSE(context_->registry().HasEntry(kId)); } diff --git a/chromium/storage/browser/blob/blob_storage_registry.cc b/chromium/storage/browser/blob/blob_storage_registry.cc index 0ad1eccbf2e..b282a4393c0 100644 --- a/chromium/storage/browser/blob/blob_storage_registry.cc +++ b/chromium/storage/browser/blob/blob_storage_registry.cc @@ -56,63 +56,64 @@ const BlobEntry* BlobStorageRegistry::GetEntry(const std::string& uuid) const { return const_cast<BlobStorageRegistry*>(this)->GetEntry(uuid); } -bool BlobStorageRegistry::CreateUrlMapping(const GURL& blob_url, - const std::string& uuid) { +bool BlobStorageRegistry::CreateUrlMapping( + const GURL& blob_url, + mojo::PendingRemote<blink::mojom::Blob> blob) { DCHECK(!BlobUrlUtils::UrlHasFragment(blob_url)); - if (blob_map_.find(uuid) == blob_map_.end() || IsURLMapped(blob_url)) + if (IsURLMapped(blob_url)) return false; - url_to_uuid_[blob_url] = uuid; + url_to_blob_[blob_url] = mojo::Remote<blink::mojom::Blob>(std::move(blob)); return true; } -bool BlobStorageRegistry::DeleteURLMapping(const GURL& blob_url, - std::string* uuid) { +bool BlobStorageRegistry::DeleteURLMapping(const GURL& blob_url) { DCHECK(!BlobUrlUtils::UrlHasFragment(blob_url)); - auto found = url_to_uuid_.find(blob_url); - if (found == url_to_uuid_.end()) + auto found = url_to_blob_.find(blob_url); + if (found == url_to_blob_.end()) return false; - if (uuid) - uuid->assign(found->second); - url_to_uuid_.erase(found); + url_to_blob_.erase(found); return true; } bool BlobStorageRegistry::IsURLMapped(const GURL& blob_url) const { - return url_to_uuid_.find(blob_url) != url_to_uuid_.end(); + return url_to_blob_.find(blob_url) != url_to_blob_.end(); } -BlobEntry* BlobStorageRegistry::GetEntryFromURL(const GURL& url, - std::string* uuid) { - auto found = url_to_uuid_.find(BlobUrlUtils::ClearUrlFragment(url)); - if (found == url_to_uuid_.end()) - return nullptr; - BlobEntry* entry = GetEntry(found->second); - if (entry && uuid) - uuid->assign(found->second); - return entry; +mojo::PendingRemote<blink::mojom::Blob> BlobStorageRegistry::GetBlobFromURL( + const GURL& url) { + auto found = url_to_blob_.find(BlobUrlUtils::ClearUrlFragment(url)); + if (found == url_to_blob_.end()) + return mojo::NullRemote(); + mojo::PendingRemote<blink::mojom::Blob> result; + found->second->Clone(result.InitWithNewPipeAndPassReceiver()); + return result; } -void BlobStorageRegistry::AddTokenMapping(const base::UnguessableToken& token, - const GURL& url, - const std::string& uuid) { - DCHECK(token_to_url_and_uuid_.find(token) == token_to_url_and_uuid_.end()); - token_to_url_and_uuid_.emplace(token, std::make_pair(url, uuid)); +void BlobStorageRegistry::AddTokenMapping( + const base::UnguessableToken& token, + const GURL& url, + mojo::PendingRemote<blink::mojom::Blob> blob) { + DCHECK(token_to_url_and_blob_.find(token) == token_to_url_and_blob_.end()); + token_to_url_and_blob_.emplace( + token, + std::make_pair(url, mojo::Remote<blink::mojom::Blob>(std::move(blob)))); } void BlobStorageRegistry::RemoveTokenMapping( const base::UnguessableToken& token) { - DCHECK(token_to_url_and_uuid_.find(token) != token_to_url_and_uuid_.end()); - token_to_url_and_uuid_.erase(token); + DCHECK(token_to_url_and_blob_.find(token) != token_to_url_and_blob_.end()); + token_to_url_and_blob_.erase(token); } -bool BlobStorageRegistry::GetTokenMapping(const base::UnguessableToken& token, - GURL* url, - std::string* uuid) const { - auto it = token_to_url_and_uuid_.find(token); - if (it == token_to_url_and_uuid_.end()) +bool BlobStorageRegistry::GetTokenMapping( + const base::UnguessableToken& token, + GURL* url, + mojo::PendingRemote<blink::mojom::Blob>* blob) const { + auto it = token_to_url_and_blob_.find(token); + if (it == token_to_url_and_blob_.end()) return false; *url = it->second.first; - *uuid = it->second.second; + it->second.second->Clone(blob->InitWithNewPipeAndPassReceiver()); return true; } diff --git a/chromium/storage/browser/blob/blob_storage_registry.h b/chromium/storage/browser/blob/blob_storage_registry.h index 7bb79e7014d..9127899b9a3 100644 --- a/chromium/storage/browser/blob/blob_storage_registry.h +++ b/chromium/storage/browser/blob/blob_storage_registry.h @@ -17,7 +17,10 @@ #include "base/component_export.h" #include "base/macros.h" #include "base/unguessable_token.h" +#include "mojo/public/cpp/bindings/pending_remote.h" +#include "mojo/public/cpp/bindings/remote.h" #include "storage/browser/blob/blob_storage_constants.h" +#include "third_party/blink/public/mojom/blob/blob.mojom.h" class GURL; @@ -51,39 +54,40 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobStorageRegistry { BlobEntry* GetEntry(const std::string& uuid); const BlobEntry* GetEntry(const std::string& uuid) const; - // Creates a url mapping from blob uuid to the given url. Returns false if - // the uuid isn't mapped to an entry or if there already is a map for the URL. - bool CreateUrlMapping(const GURL& url, const std::string& uuid); + // Creates a url mapping from blob to the given url. Returns false if + // there already is a map for the URL. + bool CreateUrlMapping(const GURL& url, + mojo::PendingRemote<blink::mojom::Blob> blob); - // Removes the given URL mapping. Optionally populates a uuid string of the - // removed entry uuid. Returns false if the url isn't mapped. - bool DeleteURLMapping(const GURL& url, std::string* uuid); + // Removes the given URL mapping. Returns false if the url wasn't mapped. + bool DeleteURLMapping(const GURL& url); - // Returns if the url is mapped to a blob uuid. + // Returns if the url is mapped to a blob. bool IsURLMapped(const GURL& blob_url) const; - // Returns the entry from the given url, and optionally populates the uuid for - // that entry. Returns a nullptr if the mapping or entry doesn't exist. - BlobEntry* GetEntryFromURL(const GURL& url, std::string* uuid); + // Returns the blob from the given url. Returns a null remote if the mapping + // doesn't exist. + mojo::PendingRemote<blink::mojom::Blob> GetBlobFromURL(const GURL& url); size_t blob_count() const { return blob_map_.size(); } - size_t url_count() const { return url_to_uuid_.size(); } + size_t url_count() const { return url_to_blob_.size(); } void AddTokenMapping(const base::UnguessableToken& token, const GURL& url, - const std::string& uuid); + mojo::PendingRemote<blink::mojom::Blob> blob); void RemoveTokenMapping(const base::UnguessableToken& token); bool GetTokenMapping(const base::UnguessableToken& token, GURL* url, - std::string* uuid) const; + mojo::PendingRemote<blink::mojom::Blob>* blob) const; private: friend class ViewBlobInternalsJob; std::unordered_map<std::string, std::unique_ptr<BlobEntry>> blob_map_; - std::map<GURL, std::string> url_to_uuid_; - std::map<base::UnguessableToken, std::pair<GURL, std::string>> - token_to_url_and_uuid_; + std::map<GURL, mojo::Remote<blink::mojom::Blob>> url_to_blob_; + std::map<base::UnguessableToken, + std::pair<GURL, mojo::Remote<blink::mojom::Blob>>> + token_to_url_and_blob_; DISALLOW_COPY_AND_ASSIGN(BlobStorageRegistry); }; diff --git a/chromium/storage/browser/blob/blob_storage_registry_unittest.cc b/chromium/storage/browser/blob/blob_storage_registry_unittest.cc index 9cb2285f11f..d9c12c9fe0f 100644 --- a/chromium/storage/browser/blob/blob_storage_registry_unittest.cc +++ b/chromium/storage/browser/blob/blob_storage_registry_unittest.cc @@ -5,7 +5,10 @@ #include "storage/browser/blob/blob_storage_registry.h" #include "base/callback.h" +#include "base/run_loop.h" +#include "base/test/task_environment.h" #include "storage/browser/blob/blob_entry.h" +#include "storage/browser/test/fake_blob.h" #include "testing/gtest/include/gtest/gtest.h" #include "url/gurl.h" @@ -35,46 +38,57 @@ TEST(BlobStorageRegistry, UUIDRegistration) { EXPECT_EQ(1u, registry.blob_count()); } +std::string UUIDFromBlob(mojo::PendingRemote<blink::mojom::Blob> pending_blob) { + mojo::Remote<blink::mojom::Blob> blob(std::move(pending_blob)); + + base::RunLoop loop; + std::string received_uuid; + blob->GetInternalUUID(base::BindOnce( + [](base::OnceClosure quit_closure, std::string* uuid_out, + const std::string& uuid) { + *uuid_out = uuid; + std::move(quit_closure).Run(); + }, + loop.QuitClosure(), &received_uuid)); + loop.Run(); + return received_uuid; +} + TEST(BlobStorageRegistry, URLRegistration) { - const std::string kBlob = "Blob1"; + const std::string kBlobId1 = "Blob1"; const std::string kType = "type1"; const std::string kDisposition = "disp1"; - const std::string kBlob2 = "Blob2"; + const std::string kBlobId2 = "Blob2"; const GURL kURL = GURL("blob://Blob1"); const GURL kURL2 = GURL("blob://Blob2"); - BlobStorageRegistry registry; + base::test::SingleThreadTaskEnvironment task_environment_; + + FakeBlob blob1(kBlobId1); + FakeBlob blob2(kBlobId2); + + BlobStorageRegistry registry; EXPECT_FALSE(registry.IsURLMapped(kURL)); - EXPECT_EQ(nullptr, registry.GetEntryFromURL(kURL, nullptr)); - EXPECT_FALSE(registry.DeleteURLMapping(kURL, nullptr)); - EXPECT_FALSE(registry.CreateUrlMapping(kURL, kBlob)); + EXPECT_FALSE(registry.GetBlobFromURL(kURL)); + EXPECT_FALSE(registry.DeleteURLMapping(kURL)); EXPECT_EQ(0u, registry.url_count()); - BlobEntry* entry = registry.CreateEntry(kBlob, kType, kDisposition); - EXPECT_FALSE(registry.IsURLMapped(kURL)); - EXPECT_TRUE(registry.CreateUrlMapping(kURL, kBlob)); - EXPECT_FALSE(registry.CreateUrlMapping(kURL, kBlob2)); + EXPECT_TRUE(registry.CreateUrlMapping(kURL, blob1.Clone())); + EXPECT_FALSE(registry.CreateUrlMapping(kURL, blob2.Clone())); EXPECT_TRUE(registry.IsURLMapped(kURL)); - EXPECT_EQ(entry, registry.GetEntryFromURL(kURL, nullptr)); - std::string uuid; - EXPECT_EQ(entry, registry.GetEntryFromURL(kURL, &uuid)); - EXPECT_EQ(kBlob, uuid); + EXPECT_EQ(kBlobId1, UUIDFromBlob(registry.GetBlobFromURL(kURL))); EXPECT_EQ(1u, registry.url_count()); - registry.CreateEntry(kBlob2, kType, kDisposition); - EXPECT_TRUE(registry.CreateUrlMapping(kURL2, kBlob2)); + EXPECT_TRUE(registry.CreateUrlMapping(kURL2, blob2.Clone())); EXPECT_EQ(2u, registry.url_count()); - EXPECT_TRUE(registry.DeleteURLMapping(kURL2, &uuid)); - EXPECT_EQ(kBlob2, uuid); + EXPECT_TRUE(registry.DeleteURLMapping(kURL2)); EXPECT_FALSE(registry.IsURLMapped(kURL2)); // Both urls point to the same blob. - EXPECT_TRUE(registry.CreateUrlMapping(kURL2, kBlob)); - std::string uuid2; - EXPECT_EQ(registry.GetEntryFromURL(kURL, &uuid), - registry.GetEntryFromURL(kURL2, &uuid2)); - EXPECT_EQ(uuid, uuid2); + EXPECT_TRUE(registry.CreateUrlMapping(kURL2, blob1.Clone())); + EXPECT_EQ(UUIDFromBlob(registry.GetBlobFromURL(kURL)), + UUIDFromBlob(registry.GetBlobFromURL(kURL2))); } } // namespace diff --git a/chromium/storage/browser/blob/blob_url_loader_factory.cc b/chromium/storage/browser/blob/blob_url_loader_factory.cc index 5119a09b460..85058b4281a 100644 --- a/chromium/storage/browser/blob/blob_url_loader_factory.cc +++ b/chromium/storage/browser/blob/blob_url_loader_factory.cc @@ -18,44 +18,67 @@ namespace { // The mojo::Remote<BlobURLToken> parameter is passed in to make sure the // connection stays alive until this method is called, it is not otherwise used // by this method. -void CreateFactoryForToken(mojo::Remote<blink::mojom::BlobURLToken>, - const base::WeakPtr<BlobStorageContext>& context, - network::mojom::URLLoaderFactoryRequest request, - const base::UnguessableToken& token) { - std::unique_ptr<BlobDataHandle> handle; +void CreateFactoryForToken( + mojo::Remote<blink::mojom::BlobURLToken>, + const base::WeakPtr<BlobStorageContext>& context, + mojo::PendingReceiver<network::mojom::URLLoaderFactory> receiver, + const base::UnguessableToken& token) { + mojo::PendingRemote<blink::mojom::Blob> blob; GURL blob_url; - if (context) { - std::string uuid; - if (context->registry().GetTokenMapping(token, &blob_url, &uuid)) - handle = context->GetBlobDataFromUUID(uuid); - } - BlobURLLoaderFactory::Create(std::move(handle), blob_url, std::move(request)); + if (context) + context->registry().GetTokenMapping(token, &blob_url, &blob); + BlobURLLoaderFactory::Create(std::move(blob), blob_url, context, + std::move(receiver)); } } // namespace // static void BlobURLLoaderFactory::Create( - std::unique_ptr<BlobDataHandle> handle, + mojo::PendingRemote<blink::mojom::Blob> pending_blob, const GURL& blob_url, - network::mojom::URLLoaderFactoryRequest request) { - new BlobURLLoaderFactory(std::move(handle), blob_url, std::move(request)); + base::WeakPtr<BlobStorageContext> context, + mojo::PendingReceiver<network::mojom::URLLoaderFactory> receiver) { + if (!pending_blob) { + new BlobURLLoaderFactory(nullptr, blob_url, std::move(receiver)); + return; + } + // Not every URLLoaderFactory user deals with the URLLoaderFactory simply + // disconnecting very well, so make sure we always at least bind the receiver + // to some factory that can then fail with a network error. Hence the callback + // is wrapped in WrapCallbackWithDefaultInvokeIfNotRun. + mojo::Remote<blink::mojom::Blob> blob(std::move(pending_blob)); + blink::mojom::Blob* raw_blob = blob.get(); + raw_blob->GetInternalUUID(mojo::WrapCallbackWithDefaultInvokeIfNotRun( + base::BindOnce( + [](mojo::Remote<blink::mojom::Blob>, + base::WeakPtr<BlobStorageContext> context, const GURL& blob_url, + mojo::PendingReceiver<network::mojom::URLLoaderFactory> receiver, + const std::string& uuid) { + std::unique_ptr<BlobDataHandle> blob; + if (context) + blob = context->GetBlobDataFromUUID(uuid); + new BlobURLLoaderFactory(std::move(blob), blob_url, + std::move(receiver)); + }, + std::move(blob), std::move(context), blob_url, std::move(receiver)), + "")); } // static void BlobURLLoaderFactory::Create( mojo::PendingRemote<blink::mojom::BlobURLToken> token, base::WeakPtr<BlobStorageContext> context, - network::mojom::URLLoaderFactoryRequest request) { + mojo::PendingReceiver<network::mojom::URLLoaderFactory> receiver) { // Not every URLLoaderFactory user deals with the URLLoaderFactory simply - // disconnecting very well, so make sure we always at least bind the request + // disconnecting very well, so make sure we always at least bind the receiver // to some factory that can then fail with a network error. Hence the callback // is wrapped in WrapCallbackWithDefaultInvokeIfNotRun. mojo::Remote<blink::mojom::BlobURLToken> token_remote(std::move(token)); auto* raw_token = token_remote.get(); raw_token->GetToken(mojo::WrapCallbackWithDefaultInvokeIfNotRun( base::BindOnce(&CreateFactoryForToken, std::move(token_remote), - std::move(context), std::move(request)), + std::move(context), std::move(receiver)), base::UnguessableToken())); } @@ -68,7 +91,7 @@ void BlobURLLoaderFactory::CreateLoaderAndStart( network::mojom::URLLoaderClientPtr client, const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) { if (url_.is_valid() && request.url != url_) { - bindings_.ReportBadMessage("Invalid URL when attempting to fetch Blob"); + receivers_.ReportBadMessage("Invalid URL when attempting to fetch Blob"); client->OnComplete( network::URLLoaderCompletionStatus(net::ERR_INVALID_URL)); return; @@ -79,24 +102,24 @@ void BlobURLLoaderFactory::CreateLoaderAndStart( } void BlobURLLoaderFactory::Clone( - network::mojom::URLLoaderFactoryRequest request) { - bindings_.AddBinding(this, std::move(request)); + mojo::PendingReceiver<network::mojom::URLLoaderFactory> receiver) { + receivers_.Add(this, std::move(receiver)); } BlobURLLoaderFactory::BlobURLLoaderFactory( std::unique_ptr<BlobDataHandle> handle, const GURL& blob_url, - network::mojom::URLLoaderFactoryRequest request) + mojo::PendingReceiver<network::mojom::URLLoaderFactory> receiver) : handle_(std::move(handle)), url_(blob_url) { - bindings_.AddBinding(this, std::move(request)); - bindings_.set_connection_error_handler(base::BindRepeating( + receivers_.Add(this, std::move(receiver)); + receivers_.set_disconnect_handler(base::BindRepeating( &BlobURLLoaderFactory::OnConnectionError, base::Unretained(this))); } BlobURLLoaderFactory::~BlobURLLoaderFactory() = default; void BlobURLLoaderFactory::OnConnectionError() { - if (!bindings_.empty()) + if (!receivers_.empty()) return; delete this; } diff --git a/chromium/storage/browser/blob/blob_url_loader_factory.h b/chromium/storage/browser/blob/blob_url_loader_factory.h index 9f796ca1b38..c4ac5c2dc98 100644 --- a/chromium/storage/browser/blob/blob_url_loader_factory.h +++ b/chromium/storage/browser/blob/blob_url_loader_factory.h @@ -6,7 +6,8 @@ #define STORAGE_BROWSER_BLOB_BLOB_URL_LOADER_FACTORY_H_ #include "base/component_export.h" -#include "mojo/public/cpp/bindings/binding_set.h" +#include "mojo/public/cpp/bindings/pending_receiver.h" +#include "mojo/public/cpp/bindings/receiver_set.h" #include "services/network/public/mojom/url_loader_factory.mojom.h" #include "third_party/blink/public/mojom/blob/blob_url_store.mojom.h" @@ -21,16 +22,19 @@ class BlobStorageContext; class COMPONENT_EXPORT(STORAGE_BROWSER) BlobURLLoaderFactory : public network::mojom::URLLoaderFactory { public: - static void Create(std::unique_ptr<BlobDataHandle> handle, - const GURL& blob_url, - network::mojom::URLLoaderFactoryRequest request); + static void Create( + mojo::PendingRemote<blink::mojom::Blob> blob, + const GURL& blob_url, + base::WeakPtr<BlobStorageContext> context, + mojo::PendingReceiver<network::mojom::URLLoaderFactory> receiver); // Creates a factory for a BlobURLToken. The token is used to look up the blob // and blob URL in the (browser side) BlobStorageRegistry, to ensure you can't // use a blob URL to load the contents of an unrelated blob. - static void Create(mojo::PendingRemote<blink::mojom::BlobURLToken> token, - base::WeakPtr<BlobStorageContext> context, - network::mojom::URLLoaderFactoryRequest request); + static void Create( + mojo::PendingRemote<blink::mojom::BlobURLToken> token, + base::WeakPtr<BlobStorageContext> context, + mojo::PendingReceiver<network::mojom::URLLoaderFactory> receiver); // URLLoaderFactory: void CreateLoaderAndStart(network::mojom::URLLoaderRequest loader, @@ -41,19 +45,21 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobURLLoaderFactory network::mojom::URLLoaderClientPtr client, const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) override; - void Clone(network::mojom::URLLoaderFactoryRequest request) override; + void Clone(mojo::PendingReceiver<network::mojom::URLLoaderFactory> receiver) + override; private: - BlobURLLoaderFactory(std::unique_ptr<BlobDataHandle> handle, - const GURL& blob_url, - network::mojom::URLLoaderFactoryRequest request); + BlobURLLoaderFactory( + std::unique_ptr<BlobDataHandle> handle, + const GURL& blob_url, + mojo::PendingReceiver<network::mojom::URLLoaderFactory> receiver); ~BlobURLLoaderFactory() override; void OnConnectionError(); std::unique_ptr<BlobDataHandle> handle_; GURL url_; - mojo::BindingSet<network::mojom::URLLoaderFactory> bindings_; + mojo::ReceiverSet<network::mojom::URLLoaderFactory> receivers_; DISALLOW_COPY_AND_ASSIGN(BlobURLLoaderFactory); }; diff --git a/chromium/storage/browser/blob/blob_url_store_impl.cc b/chromium/storage/browser/blob/blob_url_store_impl.cc index 0d1b5b7f54a..a79f0b0bd7d 100644 --- a/chromium/storage/browser/blob/blob_url_store_impl.cc +++ b/chromium/storage/browser/blob/blob_url_store_impl.cc @@ -18,18 +18,17 @@ class BlobURLTokenImpl : public blink::mojom::BlobURLToken { public: BlobURLTokenImpl(base::WeakPtr<BlobStorageContext> context, const GURL& url, - std::unique_ptr<BlobDataHandle> blob, + mojo::PendingRemote<blink::mojom::Blob> blob, mojo::PendingReceiver<blink::mojom::BlobURLToken> receiver) : context_(std::move(context)), url_(url), - blob_(std::move(blob)), token_(base::UnguessableToken::Create()) { receivers_.Add(this, std::move(receiver)); receivers_.set_disconnect_handler(base::BindRepeating( &BlobURLTokenImpl::OnConnectionError, base::Unretained(this))); if (context_) { context_->mutable_registry()->AddTokenMapping(token_, url_, - blob_->uuid()); + std::move(blob)); } } @@ -57,7 +56,6 @@ class BlobURLTokenImpl : public blink::mojom::BlobURLToken { base::WeakPtr<BlobStorageContext> context_; mojo::ReceiverSet<blink::mojom::BlobURLToken> receivers_; const GURL url_; - const std::unique_ptr<BlobDataHandle> blob_; const base::UnguessableToken token_; }; @@ -98,11 +96,10 @@ void BlobURLStoreImpl::Register(mojo::PendingRemote<blink::mojom::Blob> blob, return; } - mojo::Remote<blink::mojom::Blob> blob_remote(std::move(blob)); - blink::mojom::Blob* blob_ptr = blob_remote.get(); - blob_ptr->GetInternalUUID(base::BindOnce( - &BlobURLStoreImpl::RegisterWithUUID, weak_ptr_factory_.GetWeakPtr(), - std::move(blob_remote), url, std::move(callback))); + if (context_) + context_->RegisterPublicBlobURL(url, std::move(blob)); + urls_.insert(url); + std::move(callback).Run(); } void BlobURLStoreImpl::Revoke(const GURL& url) { @@ -132,23 +129,20 @@ void BlobURLStoreImpl::Revoke(const GURL& url) { void BlobURLStoreImpl::Resolve(const GURL& url, ResolveCallback callback) { if (!context_) { - std::move(callback).Run(nullptr); + std::move(callback).Run(mojo::NullRemote()); return; } - blink::mojom::BlobPtr blob; - std::unique_ptr<BlobDataHandle> blob_handle = - context_->GetBlobDataFromPublicURL(url); - if (blob_handle) - BlobImpl::Create(std::move(blob_handle), MakeRequest(&blob)); + mojo::PendingRemote<blink::mojom::Blob> blob = + context_->GetBlobFromPublicURL(url); std::move(callback).Run(std::move(blob)); } void BlobURLStoreImpl::ResolveAsURLLoaderFactory( const GURL& url, - network::mojom::URLLoaderFactoryRequest request) { + mojo::PendingReceiver<network::mojom::URLLoaderFactory> receiver) { BlobURLLoaderFactory::Create( - context_ ? context_->GetBlobDataFromPublicURL(url) : nullptr, url, - std::move(request)); + context_ ? context_->GetBlobFromPublicURL(url) : mojo::NullRemote(), url, + context_, std::move(receiver)); } void BlobURLStoreImpl::ResolveForNavigation( @@ -156,23 +150,11 @@ void BlobURLStoreImpl::ResolveForNavigation( mojo::PendingReceiver<blink::mojom::BlobURLToken> token) { if (!context_) return; - std::unique_ptr<BlobDataHandle> blob_handle = - context_->GetBlobDataFromPublicURL(url); - if (!blob_handle) + mojo::PendingRemote<blink::mojom::Blob> blob = + context_->GetBlobFromPublicURL(url); + if (!blob) return; - new BlobURLTokenImpl(context_, url, std::move(blob_handle), std::move(token)); -} - -void BlobURLStoreImpl::RegisterWithUUID(mojo::Remote<blink::mojom::Blob> blob, - const GURL& url, - RegisterCallback callback, - const std::string& uuid) { - // |blob| is unused, but is passed here to be kept alive until - // RegisterPublicBlobURL increments the refcount of it via the uuid. - if (context_) - context_->RegisterPublicBlobURL(url, uuid); - urls_.insert(url); - std::move(callback).Run(); + new BlobURLTokenImpl(context_, url, std::move(blob), std::move(token)); } } // namespace storage diff --git a/chromium/storage/browser/blob/blob_url_store_impl.h b/chromium/storage/browser/blob/blob_url_store_impl.h index 910b5a6301f..90223c75229 100644 --- a/chromium/storage/browser/blob/blob_url_store_impl.h +++ b/chromium/storage/browser/blob/blob_url_store_impl.h @@ -8,6 +8,7 @@ #include <memory> #include "base/component_export.h" +#include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/remote.h" #include "storage/browser/blob/blob_registry_impl.h" @@ -31,17 +32,13 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobURLStoreImpl void Resolve(const GURL& url, ResolveCallback callback) override; void ResolveAsURLLoaderFactory( const GURL& url, - network::mojom::URLLoaderFactoryRequest request) override; + mojo::PendingReceiver<network::mojom::URLLoaderFactory> receiver) + override; void ResolveForNavigation( const GURL& url, mojo::PendingReceiver<blink::mojom::BlobURLToken> token) override; private: - void RegisterWithUUID(mojo::Remote<blink::mojom::Blob> blob, - const GURL& url, - RegisterCallback callback, - const std::string& uuid); - base::WeakPtr<BlobStorageContext> context_; BlobRegistryImpl::Delegate* delegate_; diff --git a/chromium/storage/browser/blob/blob_url_store_impl_unittest.cc b/chromium/storage/browser/blob/blob_url_store_impl_unittest.cc index 79655172229..06a6e8befd1 100644 --- a/chromium/storage/browser/blob/blob_url_store_impl_unittest.cc +++ b/chromium/storage/browser/blob/blob_url_store_impl_unittest.cc @@ -8,6 +8,7 @@ #include "base/test/bind_test_util.h" #include "base/test/task_environment.h" #include "mojo/core/embedder/embedder.h" +#include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/self_owned_receiver.h" #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" @@ -19,7 +20,6 @@ #include "storage/browser/test/mock_blob_registry_delegate.h" #include "testing/gtest/include/gtest/gtest.h" -using blink::mojom::BlobPtr; using blink::mojom::BlobURLStore; namespace storage { @@ -42,14 +42,15 @@ class BlobURLStoreImplTest : public testing::Test { bad_messages_.push_back(error); } - BlobPtr CreateBlobFromString(const std::string& uuid, - const std::string& contents) { + mojo::PendingRemote<blink::mojom::Blob> CreateBlobFromString( + const std::string& uuid, + const std::string& contents) { auto builder = std::make_unique<BlobDataBuilder>(uuid); builder->set_content_type("text/plain"); builder->AppendData(contents); - BlobPtr blob; + mojo::PendingRemote<blink::mojom::Blob> blob; BlobImpl::Create(context_->AddFinishedBlob(std::move(builder)), - MakeRequest(&blob)); + blob.InitWithNewPipeAndPassReceiver()); return blob; } @@ -75,22 +76,27 @@ class BlobURLStoreImplTest : public testing::Test { return result; } - void RegisterURL(BlobURLStore* store, BlobPtr blob, const GURL& url) { + void RegisterURL(BlobURLStore* store, + mojo::PendingRemote<blink::mojom::Blob> blob, + const GURL& url) { base::RunLoop loop; - store->Register(blob.PassInterface(), url, loop.QuitClosure()); + store->Register(std::move(blob), url, loop.QuitClosure()); loop.Run(); } - BlobPtr ResolveURL(BlobURLStore* store, const GURL& url) { - BlobPtr result; + mojo::PendingRemote<blink::mojom::Blob> ResolveURL(BlobURLStore* store, + const GURL& url) { + mojo::PendingRemote<blink::mojom::Blob> result; base::RunLoop loop; - store->Resolve(kValidUrl, base::BindOnce( - [](base::OnceClosure done, BlobPtr* blob_out, - BlobPtr blob) { - *blob_out = std::move(blob); - std::move(done).Run(); - }, - loop.QuitClosure(), &result)); + store->Resolve(kValidUrl, + base::BindOnce( + [](base::OnceClosure done, + mojo::PendingRemote<blink::mojom::Blob>* blob_out, + mojo::PendingRemote<blink::mojom::Blob> blob) { + *blob_out = std::move(blob); + std::move(done).Run(); + }, + loop.QuitClosure(), &result)); loop.Run(); return result; } @@ -108,86 +114,92 @@ class BlobURLStoreImplTest : public testing::Test { }; TEST_F(BlobURLStoreImplTest, BasicRegisterRevoke) { - BlobPtr blob = CreateBlobFromString(kId, "hello world"); + mojo::PendingRemote<blink::mojom::Blob> blob = + CreateBlobFromString(kId, "hello world"); // Register a URL and make sure the URL keeps the blob alive. BlobURLStoreImpl url_store(context_->AsWeakPtr(), &delegate_); RegisterURL(&url_store, std::move(blob), kValidUrl); - std::unique_ptr<BlobDataHandle> blob_data_handle = - context_->GetBlobDataFromPublicURL(kValidUrl); - ASSERT_TRUE(blob_data_handle); - EXPECT_EQ(kId, blob_data_handle->uuid()); - blob_data_handle = nullptr; + blob = context_->GetBlobFromPublicURL(kValidUrl); + ASSERT_TRUE(blob); + mojo::Remote<blink::mojom::Blob> blob_remote(std::move(blob)); + EXPECT_EQ(kId, UUIDFromBlob(blob_remote.get())); + blob_remote.reset(); // Revoke the URL. url_store.Revoke(kValidUrl); - blob_data_handle = context_->GetBlobDataFromPublicURL(kValidUrl); - EXPECT_FALSE(blob_data_handle); + blob = context_->GetBlobFromPublicURL(kValidUrl); + EXPECT_FALSE(blob); base::RunLoop().RunUntilIdle(); EXPECT_FALSE(context_->registry().HasEntry(kId)); } TEST_F(BlobURLStoreImplTest, RegisterInvalidScheme) { - BlobPtr blob = CreateBlobFromString(kId, "hello world"); + mojo::PendingRemote<blink::mojom::Blob> blob = + CreateBlobFromString(kId, "hello world"); mojo::Remote<BlobURLStore> url_store(CreateURLStore()); RegisterURL(url_store.get(), std::move(blob), kInvalidUrl); - EXPECT_FALSE(context_->GetBlobDataFromPublicURL(kInvalidUrl)); + EXPECT_FALSE(context_->GetBlobFromPublicURL(kInvalidUrl)); EXPECT_EQ(1u, bad_messages_.size()); } TEST_F(BlobURLStoreImplTest, RegisterCantCommit) { - BlobPtr blob = CreateBlobFromString(kId, "hello world"); + mojo::PendingRemote<blink::mojom::Blob> blob = + CreateBlobFromString(kId, "hello world"); delegate_.can_commit_url_result = false; mojo::Remote<BlobURLStore> url_store(CreateURLStore()); RegisterURL(url_store.get(), std::move(blob), kValidUrl); - EXPECT_FALSE(context_->GetBlobDataFromPublicURL(kValidUrl)); + EXPECT_FALSE(context_->GetBlobFromPublicURL(kValidUrl)); EXPECT_EQ(1u, bad_messages_.size()); } TEST_F(BlobURLStoreImplTest, RegisterUrlFragment) { - BlobPtr blob = CreateBlobFromString(kId, "hello world"); + mojo::PendingRemote<blink::mojom::Blob> blob = + CreateBlobFromString(kId, "hello world"); mojo::Remote<BlobURLStore> url_store(CreateURLStore()); RegisterURL(url_store.get(), std::move(blob), kFragmentUrl); - EXPECT_FALSE(context_->GetBlobDataFromPublicURL(kFragmentUrl)); + EXPECT_FALSE(context_->GetBlobFromPublicURL(kFragmentUrl)); EXPECT_EQ(1u, bad_messages_.size()); } TEST_F(BlobURLStoreImplTest, ImplicitRevoke) { const GURL kValidUrl2("blob:id2"); - BlobPtr blob = CreateBlobFromString(kId, "hello world"); - BlobPtr blob2; - blob->Clone(MakeRequest(&blob2)); + mojo::Remote<blink::mojom::Blob> blob( + CreateBlobFromString(kId, "hello world")); + mojo::PendingRemote<blink::mojom::Blob> blob2; + blob->Clone(blob2.InitWithNewPipeAndPassReceiver()); auto url_store = std::make_unique<BlobURLStoreImpl>(context_->AsWeakPtr(), &delegate_); - RegisterURL(url_store.get(), std::move(blob), kValidUrl); - EXPECT_TRUE(context_->GetBlobDataFromPublicURL(kValidUrl)); + RegisterURL(url_store.get(), blob.Unbind(), kValidUrl); + EXPECT_TRUE(context_->GetBlobFromPublicURL(kValidUrl)); RegisterURL(url_store.get(), std::move(blob2), kValidUrl2); - EXPECT_TRUE(context_->GetBlobDataFromPublicURL(kValidUrl2)); + EXPECT_TRUE(context_->GetBlobFromPublicURL(kValidUrl2)); // Destroy URL Store, should revoke URLs. url_store = nullptr; - EXPECT_FALSE(context_->GetBlobDataFromPublicURL(kValidUrl)); - EXPECT_FALSE(context_->GetBlobDataFromPublicURL(kValidUrl2)); + EXPECT_FALSE(context_->GetBlobFromPublicURL(kValidUrl)); + EXPECT_FALSE(context_->GetBlobFromPublicURL(kValidUrl2)); } TEST_F(BlobURLStoreImplTest, RevokeThroughDifferentURLStore) { - BlobPtr blob = CreateBlobFromString(kId, "hello world"); + mojo::PendingRemote<blink::mojom::Blob> blob = + CreateBlobFromString(kId, "hello world"); BlobURLStoreImpl url_store1(context_->AsWeakPtr(), &delegate_); BlobURLStoreImpl url_store2(context_->AsWeakPtr(), &delegate_); RegisterURL(&url_store1, std::move(blob), kValidUrl); - EXPECT_TRUE(context_->GetBlobDataFromPublicURL(kValidUrl)); + EXPECT_TRUE(context_->GetBlobFromPublicURL(kValidUrl)); url_store2.Revoke(kValidUrl); - EXPECT_FALSE(context_->GetBlobDataFromPublicURL(kValidUrl)); + EXPECT_FALSE(context_->GetBlobFromPublicURL(kValidUrl)); } TEST_F(BlobURLStoreImplTest, RevokeInvalidScheme) { @@ -214,7 +226,7 @@ TEST_F(BlobURLStoreImplTest, RevokeCantCommit_ProcessNotValid) { url_store->Revoke(kValidUrl); url_store.FlushForTesting(); EXPECT_TRUE(bad_messages_.empty()); - EXPECT_FALSE(context_->GetBlobDataFromPublicURL(kValidUrl)); + EXPECT_FALSE(context_->GetBlobFromPublicURL(kValidUrl)); } TEST_F(BlobURLStoreImplTest, RevokeURLWithFragment) { @@ -225,23 +237,28 @@ TEST_F(BlobURLStoreImplTest, RevokeURLWithFragment) { } TEST_F(BlobURLStoreImplTest, Resolve) { - BlobPtr blob = CreateBlobFromString(kId, "hello world"); + mojo::PendingRemote<blink::mojom::Blob> blob = + CreateBlobFromString(kId, "hello world"); BlobURLStoreImpl url_store(context_->AsWeakPtr(), &delegate_); RegisterURL(&url_store, std::move(blob), kValidUrl); blob = ResolveURL(&url_store, kValidUrl); ASSERT_TRUE(blob); - EXPECT_EQ(kId, UUIDFromBlob(blob.get())); + mojo::Remote<blink::mojom::Blob> blob_remote(std::move(blob)); + EXPECT_EQ(kId, UUIDFromBlob(blob_remote.get())); blob = ResolveURL(&url_store, kFragmentUrl); ASSERT_TRUE(blob); - EXPECT_EQ(kId, UUIDFromBlob(blob.get())); + blob_remote.reset(); + blob_remote.Bind(std::move(blob)); + EXPECT_EQ(kId, UUIDFromBlob(blob_remote.get())); } TEST_F(BlobURLStoreImplTest, ResolveNonExistentURL) { BlobURLStoreImpl url_store(context_->AsWeakPtr(), &delegate_); - BlobPtr blob = ResolveURL(&url_store, kValidUrl); + mojo::PendingRemote<blink::mojom::Blob> blob = + ResolveURL(&url_store, kValidUrl); EXPECT_FALSE(blob); blob = ResolveURL(&url_store, kFragmentUrl); EXPECT_FALSE(blob); @@ -250,12 +267,14 @@ TEST_F(BlobURLStoreImplTest, ResolveNonExistentURL) { TEST_F(BlobURLStoreImplTest, ResolveInvalidURL) { BlobURLStoreImpl url_store(context_->AsWeakPtr(), &delegate_); - BlobPtr blob = ResolveURL(&url_store, kInvalidUrl); + mojo::PendingRemote<blink::mojom::Blob> blob = + ResolveURL(&url_store, kInvalidUrl); EXPECT_FALSE(blob); } TEST_F(BlobURLStoreImplTest, ResolveAsURLLoaderFactory) { - BlobPtr blob = CreateBlobFromString(kId, "hello world"); + mojo::PendingRemote<blink::mojom::Blob> blob = + CreateBlobFromString(kId, "hello world"); BlobURLStoreImpl url_store(context_->AsWeakPtr(), &delegate_); RegisterURL(&url_store, std::move(blob), kValidUrl); @@ -279,7 +298,8 @@ TEST_F(BlobURLStoreImplTest, ResolveAsURLLoaderFactory) { } TEST_F(BlobURLStoreImplTest, ResolveForNavigation) { - BlobPtr blob = CreateBlobFromString(kId, "hello world"); + mojo::PendingRemote<blink::mojom::Blob> blob = + CreateBlobFromString(kId, "hello world"); BlobURLStoreImpl url_store(context_->AsWeakPtr(), &delegate_); RegisterURL(&url_store, std::move(blob), kValidUrl); @@ -298,11 +318,10 @@ TEST_F(BlobURLStoreImplTest, ResolveForNavigation) { loop.Run(); GURL blob_url; - std::string blob_uuid; - EXPECT_TRUE( - context_->registry().GetTokenMapping(token, &blob_url, &blob_uuid)); + EXPECT_TRUE(context_->registry().GetTokenMapping(token, &blob_url, &blob)); EXPECT_EQ(kValidUrl, blob_url); - EXPECT_EQ(kId, blob_uuid); + mojo::Remote<blink::mojom::Blob> blob_remote(std::move(blob)); + EXPECT_EQ(kId, UUIDFromBlob(blob_remote.get())); } } // namespace storage diff --git a/chromium/storage/browser/blob/shareable_file_reference.h b/chromium/storage/browser/blob/shareable_file_reference.h index c009c70890f..d6f30a853d8 100644 --- a/chromium/storage/browser/blob/shareable_file_reference.h +++ b/chromium/storage/browser/blob/shareable_file_reference.h @@ -7,7 +7,6 @@ #include "base/component_export.h" #include "base/macros.h" -#include "storage/browser/blob/blob_data_item.h" #include "storage/browser/blob/scoped_file.h" namespace storage { @@ -17,7 +16,7 @@ namespace storage { // This class is non-thread-safe and all methods must be called on a single // thread. class COMPONENT_EXPORT(STORAGE_BROWSER) ShareableFileReference - : public BlobDataItem::DataHandle { + : public base::RefCounted<ShareableFileReference> { public: using FinalReleaseCallback = ScopedFile::ScopeOutCallback; @@ -64,8 +63,10 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) ShareableFileReference void AddFinalReleaseCallback(FinalReleaseCallback callback); private: + friend class base::RefCounted<ShareableFileReference>; + ShareableFileReference(ScopedFile scoped_file); - ~ShareableFileReference() override; + ~ShareableFileReference(); ScopedFile scoped_file_; diff --git a/chromium/storage/browser/blob/view_blob_internals_job.cc b/chromium/storage/browser/blob/view_blob_internals_job.cc index bb0fe8688df..d6dca3e2a48 100644 --- a/chromium/storage/browser/blob/view_blob_internals_job.cc +++ b/chromium/storage/browser/blob/view_blob_internals_job.cc @@ -44,7 +44,6 @@ const char kURL[] = "URL: "; const char kModificationTime[] = "Modification Time: "; const char kOffset[] = "Offset: "; const char kLength[] = "Length: "; -const char kUUID[] = "Uuid: "; const char kRefcount[] = "Refcount: "; const char kStatus[] = "Status: "; @@ -156,14 +155,13 @@ std::string ViewBlobInternalsJob::GenerateHTML( entry->content_disposition(), entry->refcount(), &out); } - if (!blob_storage_context->registry().url_to_uuid_.empty()) { + if (!blob_storage_context->registry().url_to_blob_.empty()) { AddHorizontalRule(&out); for (const auto& url_uuid_pair : - blob_storage_context->registry().url_to_uuid_) { + blob_storage_context->registry().url_to_blob_) { AddHTMLBoldText(url_uuid_pair.first.spec(), &out); - StartHTMLList(&out); - AddHTMLListItem(kUUID, url_uuid_pair.second, &out); - EndHTMLList(&out); + // TODO(mek): Somehow include information on the blob the URL is mapped + // to. } } } diff --git a/chromium/storage/browser/fileapi/copy_or_move_operation_delegate_unittest.cc b/chromium/storage/browser/fileapi/copy_or_move_operation_delegate_unittest.cc index 82d88317a0b..cd0c8c9469f 100644 --- a/chromium/storage/browser/fileapi/copy_or_move_operation_delegate_unittest.cc +++ b/chromium/storage/browser/fileapi/copy_or_move_operation_delegate_unittest.cc @@ -736,8 +736,8 @@ TEST(LocalFileSystemCopyOrMoveOperationTest, StreamCopyHelper) { base::WriteFile(source_path, kTestData, base::size(kTestData) - 1); // Exclude trailing '\0'. - base::test::TaskEnvironment task_environment( - base::test::TaskEnvironment::MainThreadType::IO); + base::test::SingleThreadTaskEnvironment task_environment( + base::test::SingleThreadTaskEnvironment::MainThreadType::IO); base::Thread file_thread("file_thread"); ASSERT_TRUE(file_thread.Start()); ScopedThreadStopper thread_stopper(&file_thread); @@ -794,8 +794,8 @@ TEST(LocalFileSystemCopyOrMoveOperationTest, StreamCopyHelperWithFlush) { base::WriteFile(source_path, kTestData, base::size(kTestData) - 1); // Exclude trailing '\0'. - base::test::TaskEnvironment task_environment( - base::test::TaskEnvironment::MainThreadType::IO); + base::test::SingleThreadTaskEnvironment task_environment( + base::test::SingleThreadTaskEnvironment::MainThreadType::IO); base::Thread file_thread("file_thread"); ASSERT_TRUE(file_thread.Start()); ScopedThreadStopper thread_stopper(&file_thread); @@ -848,8 +848,8 @@ TEST(LocalFileSystemCopyOrMoveOperationTest, StreamCopyHelper_Cancel) { base::WriteFile(source_path, kTestData, base::size(kTestData) - 1); // Exclude trailing '\0'. - base::test::TaskEnvironment task_environment( - base::test::TaskEnvironment::MainThreadType::IO); + base::test::SingleThreadTaskEnvironment task_environment( + base::test::SingleThreadTaskEnvironment::MainThreadType::IO); base::Thread file_thread("file_thread"); ASSERT_TRUE(file_thread.Start()); ScopedThreadStopper thread_stopper(&file_thread); diff --git a/chromium/storage/browser/fileapi/dragged_file_util_unittest.cc b/chromium/storage/browser/fileapi/dragged_file_util_unittest.cc index 8911dc028a5..751e36f20e6 100644 --- a/chromium/storage/browser/fileapi/dragged_file_util_unittest.cc +++ b/chromium/storage/browser/fileapi/dragged_file_util_unittest.cc @@ -281,8 +281,8 @@ class DraggedFileUtilTest : public testing::Test { base::ScopedTempDir data_dir_; base::ScopedTempDir partition_dir_; - base::test::TaskEnvironment task_environment_{ - base::test::TaskEnvironment::MainThreadType::IO}; + base::test::SingleThreadTaskEnvironment task_environment_{ + base::test::SingleThreadTaskEnvironment::MainThreadType::IO}; std::string filesystem_id_; scoped_refptr<FileSystemContext> file_system_context_; std::map<base::FilePath, base::FilePath> toplevel_root_map_; diff --git a/chromium/storage/browser/fileapi/file_system_context.cc b/chromium/storage/browser/fileapi/file_system_context.cc index e34edd52b31..955887674fb 100644 --- a/chromium/storage/browser/fileapi/file_system_context.cc +++ b/chromium/storage/browser/fileapi/file_system_context.cc @@ -17,6 +17,7 @@ #include "base/stl_util.h" #include "base/task_runner_util.h" #include "base/threading/thread_task_runner_handle.h" +#include "base/util/type_safety/pass_key.h" #include "net/url_request/url_request.h" #include "storage/browser/fileapi/copy_or_move_file_validator.h" #include "storage/browser/fileapi/external_mount_points.h" @@ -172,7 +173,9 @@ FileSystemContext::FileSystemContext( external_mount_points_(external_mount_points), partition_path_(partition_path), is_incognito_(options.is_incognito()), - operation_runner_(new FileSystemOperationRunner(this)) { + operation_runner_( + new FileSystemOperationRunner(util::PassKey<FileSystemContext>(), + this)) { RegisterBackend(sandbox_backend_.get()); RegisterBackend(plugin_private_backend_.get()); @@ -459,7 +462,15 @@ std::unique_ptr<FileStreamWriter> FileSystemContext::CreateFileStreamWriter( std::unique_ptr<FileSystemOperationRunner> FileSystemContext::CreateFileSystemOperationRunner() { - return base::WrapUnique(new FileSystemOperationRunner(this)); + return std::make_unique<FileSystemOperationRunner>( + util::PassKey<FileSystemContext>(), this); +} + +base::SequenceBound<FileSystemOperationRunner> +FileSystemContext::CreateSequenceBoundFileSystemOperationRunner() { + return base::SequenceBound<FileSystemOperationRunner>( + io_task_runner_, util::PassKey<FileSystemContext>(), + base::WrapRefCounted(this)); } FileSystemURL FileSystemContext::CrackURL(const GURL& url) const { @@ -474,20 +485,12 @@ FileSystemURL FileSystemContext::CreateCrackedFileSystemURL( FileSystemURL(url::Origin::Create(origin), type, path)); } -#if defined(OS_CHROMEOS) -void FileSystemContext::EnableTemporaryFileSystemInIncognito() { - sandbox_backend_->set_enable_temporary_file_system_in_incognito(true); -} -#endif - bool FileSystemContext::CanServeURLRequest(const FileSystemURL& url) const { // We never support accessing files in isolated filesystems via an URL. if (url.mount_type() == kFileSystemTypeIsolated) return false; - if (url.type() == kFileSystemTypeTemporary && - sandbox_backend_->enable_temporary_file_system_in_incognito()) { + if (url.type() == kFileSystemTypeTemporary) return true; - } return !is_incognito_ || !FileSystemContext::IsSandboxFileSystem(url.type()); } diff --git a/chromium/storage/browser/fileapi/file_system_context.h b/chromium/storage/browser/fileapi/file_system_context.h index b49512b98df..c609cd8cfa2 100644 --- a/chromium/storage/browser/fileapi/file_system_context.h +++ b/chromium/storage/browser/fileapi/file_system_context.h @@ -18,6 +18,7 @@ #include "base/macros.h" #include "base/memory/ref_counted_delete_on_sequence.h" #include "base/sequenced_task_runner_helpers.h" +#include "base/threading/sequence_bound.h" #include "build/build_config.h" #include "storage/browser/fileapi/file_system_url.h" #include "storage/browser/fileapi/open_file_system_mode.h" @@ -259,8 +260,13 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemContext // Creates a new FileSystemOperationRunner. Callers have to make sure that // this FileSystemContext outlives the returned FileSystemOperationRunner. + // This must be called on the IO thread. std::unique_ptr<FileSystemOperationRunner> CreateFileSystemOperationRunner(); + // Similar to above, but this method can be called on any thread. + base::SequenceBound<FileSystemOperationRunner> + CreateSequenceBoundFileSystemOperationRunner(); + base::SequencedTaskRunner* default_file_task_runner() { return default_file_task_runner_.get(); } @@ -279,12 +285,6 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemContext FileSystemType type, const base::FilePath& path) const; -#if defined(OS_CHROMEOS) - // Used only on ChromeOS for now. It can be removed when - // kEnableFilesystemInIncognito feature flag is removed. - void EnableTemporaryFileSystemInIncognito(); -#endif - SandboxFileSystemBackendDelegate* sandbox_delegate() { return sandbox_delegate_.get(); } diff --git a/chromium/storage/browser/fileapi/file_system_features.cc b/chromium/storage/browser/fileapi/file_system_features.cc deleted file mode 100644 index fb35cfed777..00000000000 --- a/chromium/storage/browser/fileapi/file_system_features.cc +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2019 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/fileapi/file_system_features.h" - -namespace storage { - -namespace features { - -// Enables Filesystem API in incognito mode. -const base::Feature kEnableFilesystemInIncognito{ - "EnableFilesystemInIncognito", base::FEATURE_ENABLED_BY_DEFAULT}; -} // namespace features - -} // namespace storage diff --git a/chromium/storage/browser/fileapi/file_system_features.h b/chromium/storage/browser/fileapi/file_system_features.h deleted file mode 100644 index 7c5861b3789..00000000000 --- a/chromium/storage/browser/fileapi/file_system_features.h +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2019 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_FILEAPI_FILE_SYSTEM_FEATURES_H_ -#define STORAGE_BROWSER_FILEAPI_FILE_SYSTEM_FEATURES_H_ - -#include "base/component_export.h" -#include "base/feature_list.h" - -namespace storage { - -namespace features { - -COMPONENT_EXPORT(STORAGE_BROWSER) -extern const base::Feature kEnableFilesystemInIncognito; - -} // namespace features - -} // namespace storage - -#endif // STORAGE_BROWSER_FILEAPI_FILE_SYSTEM_FEATURES_H_
\ No newline at end of file diff --git a/chromium/storage/browser/fileapi/file_system_file_stream_reader.cc b/chromium/storage/browser/fileapi/file_system_file_stream_reader.cc index dffd4b9e5c6..8657f568510 100644 --- a/chromium/storage/browser/fileapi/file_system_file_stream_reader.cc +++ b/chromium/storage/browser/fileapi/file_system_file_stream_reader.cc @@ -15,7 +15,6 @@ #include "net/base/io_buffer.h" #include "net/base/net_errors.h" #include "storage/browser/fileapi/file_system_context.h" -#include "storage/browser/fileapi/file_system_features.h" #include "storage/browser/fileapi/file_system_operation_runner.h" #include "storage/browser/fileapi/obfuscated_file_util_memory_delegate.h" #include "storage/browser/fileapi/plugin_private_file_system_backend.h" @@ -102,8 +101,7 @@ void FileSystemFileStreamReader::DidCreateSnapshot( // Keep the reference (if it's non-null) so that the file won't go away. snapshot_ref_ = std::move(file_ref); - if (file_system_context_->is_incognito() && - base::FeatureList::IsEnabled(features::kEnableFilesystemInIncognito)) { + if (file_system_context_->is_incognito()) { base::WeakPtr<ObfuscatedFileUtilMemoryDelegate> memory_file_util_delegate; if (url_.type() == kFileSystemTypePluginPrivate) { auto* backend = static_cast<PluginPrivateFileSystemBackend*>( diff --git a/chromium/storage/browser/fileapi/file_system_file_stream_reader_unittest.cc b/chromium/storage/browser/fileapi/file_system_file_stream_reader_unittest.cc index 7df61e45735..0020d60f64e 100644 --- a/chromium/storage/browser/fileapi/file_system_file_stream_reader_unittest.cc +++ b/chromium/storage/browser/fileapi/file_system_file_stream_reader_unittest.cc @@ -116,8 +116,8 @@ class FileSystemFileStreamReaderTest : public testing::Test { base::FilePath().AppendASCII(file_name)); } - base::test::TaskEnvironment task_environment_{ - base::test::TaskEnvironment::MainThreadType::IO}; + base::test::SingleThreadTaskEnvironment task_environment_{ + base::test::SingleThreadTaskEnvironment::MainThreadType::IO}; base::ScopedTempDir temp_dir_; scoped_refptr<FileSystemContext> file_system_context_; base::Time test_file_modification_time_; diff --git a/chromium/storage/browser/fileapi/file_system_operation_runner.cc b/chromium/storage/browser/fileapi/file_system_operation_runner.cc index 79f2b6b69ab..fb4ae7b4458 100644 --- a/chromium/storage/browser/fileapi/file_system_operation_runner.cc +++ b/chromium/storage/browser/fileapi/file_system_operation_runner.cc @@ -27,6 +27,16 @@ namespace storage { using OperationID = FileSystemOperationRunner::OperationID; +FileSystemOperationRunner::FileSystemOperationRunner( + util::PassKey<FileSystemContext>, + const scoped_refptr<FileSystemContext>& file_system_context) + : FileSystemOperationRunner(file_system_context.get()) {} + +FileSystemOperationRunner::FileSystemOperationRunner( + util::PassKey<FileSystemContext>, + FileSystemContext* file_system_context) + : FileSystemOperationRunner(file_system_context) {} + FileSystemOperationRunner::~FileSystemOperationRunner() = default; void FileSystemOperationRunner::Shutdown() { @@ -272,7 +282,7 @@ OperationID FileSystemOperationRunner::Write( return id; } -OperationID FileSystemOperationRunner::Write( +OperationID FileSystemOperationRunner::WriteStream( const FileSystemURL& url, mojo::ScopedDataPipeConsumerHandle data_pipe, int64_t offset, diff --git a/chromium/storage/browser/fileapi/file_system_operation_runner.h b/chromium/storage/browser/fileapi/file_system_operation_runner.h index 3b9bebd28c5..c221ef52f5c 100644 --- a/chromium/storage/browser/fileapi/file_system_operation_runner.h +++ b/chromium/storage/browser/fileapi/file_system_operation_runner.h @@ -16,6 +16,7 @@ #include "base/containers/id_map.h" #include "base/macros.h" #include "base/memory/weak_ptr.h" +#include "base/util/type_safety/pass_key.h" #include "components/services/filesystem/public/mojom/types.mojom.h" #include "storage/browser/blob/blob_data_handle.h" #include "storage/browser/fileapi/file_system_operation.h" @@ -50,6 +51,13 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemOperationRunner { using OperationID = uint64_t; + // |file_system_context| is stored as a raw pointer. The caller must ensure + // that |file_system_context| outlives the new instance. + FileSystemOperationRunner( + util::PassKey<FileSystemContext>, + const scoped_refptr<FileSystemContext>& file_system_context); + FileSystemOperationRunner(util::PassKey<FileSystemContext>, + FileSystemContext* file_system_context); virtual ~FileSystemOperationRunner(); // Cancels all inflight operations. @@ -116,10 +124,10 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemOperationRunner { const WriteCallback& callback); // Writes contents of |data_pipe| to |url| at |offset|. - OperationID Write(const FileSystemURL& url, - mojo::ScopedDataPipeConsumerHandle data_pipe, - int64_t offset, - const WriteCallback& callback); + OperationID WriteStream(const FileSystemURL& url, + mojo::ScopedDataPipeConsumerHandle data_pipe, + int64_t offset, + const WriteCallback& callback); // Truncates a file at |url| to |length|. If |length| is larger than // the original file size, the file will be extended, and the extended @@ -244,7 +252,6 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemOperationRunner { base::FilePath* platform_path); private: - friend class FileSystemContext; explicit FileSystemOperationRunner(FileSystemContext* file_system_context); void DidFinish(const OperationID id, diff --git a/chromium/storage/browser/fileapi/file_system_usage_cache_unittest.cc b/chromium/storage/browser/fileapi/file_system_usage_cache_unittest.cc index dd87d686902..6144fee0a8b 100644 --- a/chromium/storage/browser/fileapi/file_system_usage_cache_unittest.cc +++ b/chromium/storage/browser/fileapi/file_system_usage_cache_unittest.cc @@ -11,9 +11,7 @@ #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" #include "base/macros.h" -#include "base/test/scoped_feature_list.h" #include "base/test/task_environment.h" -#include "storage/browser/fileapi/file_system_features.h" #include "testing/gtest/include/gtest/gtest.h" using storage::FileSystemUsageCache; @@ -23,12 +21,7 @@ namespace content { class FileSystemUsageCacheTest : public testing::Test, public ::testing::WithParamInterface<bool> { public: - FileSystemUsageCacheTest() : usage_cache_(is_incognito()) { - if (is_incognito()) { - feature_list_.InitAndEnableFeature( - storage::features::kEnableFilesystemInIncognito); - } - } + FileSystemUsageCacheTest() : usage_cache_(is_incognito()) {} void SetUp() override { ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); } @@ -42,8 +35,7 @@ class FileSystemUsageCacheTest : public testing::Test, FileSystemUsageCache* usage_cache() { return &usage_cache_; } private: - base::test::ScopedFeatureList feature_list_; - base::test::TaskEnvironment task_environment_; + base::test::SingleThreadTaskEnvironment task_environment_; base::ScopedTempDir data_dir_; FileSystemUsageCache usage_cache_; diff --git a/chromium/storage/browser/fileapi/local_file_stream_reader_unittest.cc b/chromium/storage/browser/fileapi/local_file_stream_reader_unittest.cc index 7881a62e3b6..55d30507e02 100644 --- a/chromium/storage/browser/fileapi/local_file_stream_reader_unittest.cc +++ b/chromium/storage/browser/fileapi/local_file_stream_reader_unittest.cc @@ -105,8 +105,8 @@ class LocalFileStreamReaderTest : public testing::Test { } private: - base::test::TaskEnvironment task_environment_{ - base::test::TaskEnvironment::MainThreadType::IO}; + base::test::SingleThreadTaskEnvironment task_environment_{ + base::test::SingleThreadTaskEnvironment::MainThreadType::IO}; base::Thread file_thread_; base::ScopedTempDir dir_; base::Time test_file_modification_time_; diff --git a/chromium/storage/browser/fileapi/local_file_stream_writer_unittest.cc b/chromium/storage/browser/fileapi/local_file_stream_writer_unittest.cc index fd9902a064b..5eb2afca6a3 100644 --- a/chromium/storage/browser/fileapi/local_file_stream_writer_unittest.cc +++ b/chromium/storage/browser/fileapi/local_file_stream_writer_unittest.cc @@ -73,8 +73,8 @@ class LocalFileStreamWriterTest : public testing::Test { } private: - base::test::TaskEnvironment task_environment_{ - base::test::TaskEnvironment::MainThreadType::IO}; + base::test::SingleThreadTaskEnvironment task_environment_{ + base::test::SingleThreadTaskEnvironment::MainThreadType::IO}; base::Thread file_thread_; base::ScopedTempDir temp_dir_; }; diff --git a/chromium/storage/browser/fileapi/obfuscated_file_util.cc b/chromium/storage/browser/fileapi/obfuscated_file_util.cc index bdb9c54fb62..fe268d70f41 100644 --- a/chromium/storage/browser/fileapi/obfuscated_file_util.cc +++ b/chromium/storage/browser/fileapi/obfuscated_file_util.cc @@ -24,7 +24,6 @@ #include "base/time/time.h" #include "storage/browser/fileapi/file_observers.h" #include "storage/browser/fileapi/file_system_context.h" -#include "storage/browser/fileapi/file_system_features.h" #include "storage/browser/fileapi/file_system_operation_context.h" #include "storage/browser/fileapi/obfuscated_file_util_disk_delegate.h" #include "storage/browser/fileapi/obfuscated_file_util_memory_delegate.h" @@ -280,8 +279,7 @@ ObfuscatedFileUtil::ObfuscatedFileUtil( DCHECK(!is_incognito_ || (env_override && leveldb_chrome::IsMemEnv(env_override))); - if (is_incognito_ && - base::FeatureList::IsEnabled(features::kEnableFilesystemInIncognito)) { + if (is_incognito_) { delegate_ = std::make_unique<ObfuscatedFileUtilMemoryDelegate>( file_system_directory_); } else { @@ -955,8 +953,7 @@ ObfuscatedFileUtil::CreateOriginEnumerator() { InitOriginDatabase(GURL(), false); base::WeakPtr<ObfuscatedFileUtilMemoryDelegate> file_util_delegate; - if (is_incognito() && - base::FeatureList::IsEnabled(features::kEnableFilesystemInIncognito)) { + if (is_incognito()) { file_util_delegate = static_cast<ObfuscatedFileUtilMemoryDelegate*>(delegate()) ->GetWeakPtr(); diff --git a/chromium/storage/browser/fileapi/obfuscated_file_util_unittest.cc b/chromium/storage/browser/fileapi/obfuscated_file_util_unittest.cc index f4889aeecba..1c4e70e5311 100644 --- a/chromium/storage/browser/fileapi/obfuscated_file_util_unittest.cc +++ b/chromium/storage/browser/fileapi/obfuscated_file_util_unittest.cc @@ -29,7 +29,6 @@ #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_features.h" #include "storage/browser/fileapi/file_system_operation_context.h" #include "storage/browser/fileapi/file_system_usage_cache.h" #include "storage/browser/fileapi/obfuscated_file_util.h" @@ -71,7 +70,7 @@ namespace content { namespace { -enum TestMode { kRegular, kIncognitoDisabled, kIncognitoEnabled }; +enum TestMode { kRegular, kIncognito }; bool FileExists(const base::FilePath& path) { return base::PathExists(path) && !base::DirectoryExists(path); @@ -174,22 +173,9 @@ class ObfuscatedFileUtilTest : public testing::Test, type_(storage::kFileSystemTypeTemporary), sandbox_file_system_(origin_, type_), quota_status_(blink::mojom::QuotaStatusCode::kUnknown), - usage_(-1) { - if (GetParam() == TestMode::kRegular) { - is_incognito_ = false; - return; - } - is_incognito_ = true; - if (GetParam() == TestMode::kIncognitoDisabled) { - feature_list_.InitAndDisableFeature( - storage::features::kEnableFilesystemInIncognito); - } else { - feature_list_.InitAndEnableFeature( - storage::features::kEnableFilesystemInIncognito); - } - } + usage_(-1) {} - bool in_memory_test() { return GetParam() == TestMode::kIncognitoEnabled; } + bool is_incognito() { return GetParam() == TestMode::kIncognito; } void SetUp() override { ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); @@ -197,7 +183,7 @@ class ObfuscatedFileUtilTest : public testing::Test, storage_policy_ = new MockSpecialStoragePolicy(); quota_manager_ = new storage::QuotaManager( - is_incognito_, data_dir_.GetPath(), + is_incognito(), data_dir_.GetPath(), base::ThreadTaskRunnerHandle::Get().get(), storage_policy_.get(), storage::GetQuotaSettingsFunc()); storage::QuotaSettings settings; @@ -212,24 +198,24 @@ class ObfuscatedFileUtilTest : public testing::Test, // another sandbox_backend, and another OFU. // We need to pass in the context to skip all that. file_system_context_ = - in_memory_test() ? CreateIncognitoFileSystemContextForTesting( - base::ThreadTaskRunnerHandle::Get(), - base::ThreadTaskRunnerHandle::Get(), - quota_manager_->proxy(), data_dir_.GetPath()) - : CreateFileSystemContextForTesting( - quota_manager_->proxy(), data_dir_.GetPath()); + is_incognito() ? CreateIncognitoFileSystemContextForTesting( + base::ThreadTaskRunnerHandle::Get(), + base::ThreadTaskRunnerHandle::Get(), + quota_manager_->proxy(), data_dir_.GetPath()) + : CreateFileSystemContextForTesting( + quota_manager_->proxy(), data_dir_.GetPath()); sandbox_file_system_.SetUp(file_system_context_.get()); change_observers_ = storage::MockFileChangeObserver::CreateList(&change_observer_); - if (is_incognito_) + if (is_incognito()) incognito_leveldb_environment_ = leveldb_chrome::NewMemEnv("FileSystem"); } void TearDown() override { - if (in_memory_test()) + if (is_incognito()) ASSERT_TRUE(IsDirectoryEmpty(data_dir_.GetPath())); quota_manager_ = nullptr; @@ -289,8 +275,8 @@ class ObfuscatedFileUtilTest : public testing::Test, return std::unique_ptr<ObfuscatedFileUtil>( ObfuscatedFileUtil::CreateForTesting( storage_policy, data_dir_path(), - is_incognito_ ? incognito_leveldb_environment_.get() : nullptr, - is_incognito_)); + is_incognito() ? incognito_leveldb_environment_.get() : nullptr, + is_incognito())); } ObfuscatedFileUtil* ofu() { @@ -390,14 +376,14 @@ class ObfuscatedFileUtilTest : public testing::Test, EXPECT_EQ(base::File::FILE_OK, ofu()->GetFileInfo(context.get(), url, &file_info0, &data_path)); EXPECT_EQ(data_path, local_path); - EXPECT_EQ(!in_memory_test(), FileExists(data_path)); + EXPECT_EQ(!is_incognito(), FileExists(data_path)); const char data[] = "test data"; const int length = base::size(data) - 1; base::File file = ofu()->CreateOrOpen( context.get(), url, base::File::FLAG_WRITE | base::File::FLAG_OPEN); - if (in_memory_test()) { + if (is_incognito()) { ASSERT_FALSE(file.IsValid()); auto* memory_delegate = static_cast<storage::ObfuscatedFileUtilMemoryDelegate*>( @@ -414,7 +400,7 @@ class ObfuscatedFileUtilTest : public testing::Test, } base::File::Info file_info1; - if (!in_memory_test()) + if (!is_incognito()) EXPECT_EQ(length, GetLocalFileSize(data_path)); EXPECT_EQ(length, GetPathSize(url)); context.reset(NewContext(nullptr)); @@ -825,13 +811,12 @@ class ObfuscatedFileUtilTest : public testing::Test, void CheckFileSize(FileSystemURL& url, base::FilePath& local_path, int64_t expected_size) { - if (!in_memory_test()) + if (!is_incognito()) EXPECT_EQ(expected_size, GetLocalFileSize(local_path)); EXPECT_EQ(expected_size, GetPathSize(url)); } protected: - bool is_incognito_; base::test::ScopedFeatureList feature_list_; std::unique_ptr<leveldb::Env> incognito_leveldb_environment_; base::test::TaskEnvironment task_environment_; @@ -855,8 +840,7 @@ class ObfuscatedFileUtilTest : public testing::Test, INSTANTIATE_TEST_SUITE_P(, ObfuscatedFileUtilTest, testing::Values(TestMode::kRegular, - TestMode::kIncognitoDisabled, - TestMode::kIncognitoEnabled)); + TestMode::kIncognito)); TEST_P(ObfuscatedFileUtilTest, TestCreateAndDeleteFile) { FileSystemURL url = CreateURLFromUTF8("fake/file"); @@ -897,7 +881,7 @@ TEST_P(ObfuscatedFileUtilTest, TestCreateAndDeleteFile) { base::FilePath local_path; EXPECT_EQ(base::File::FILE_OK, ofu()->GetLocalFilePath(context.get(), url, &local_path)); - EXPECT_EQ(!in_memory_test(), base::PathExists(local_path)); + EXPECT_NE(is_incognito(), base::PathExists(local_path)); EXPECT_TRUE(PathExists(url)); // Verify that deleting a file isn't stopped by zero quota, and that it frees @@ -934,7 +918,7 @@ TEST_P(ObfuscatedFileUtilTest, TestCreateAndDeleteFile) { context.reset(NewContext(nullptr)); EXPECT_EQ(base::File::FILE_OK, ofu()->GetLocalFilePath(context.get(), url, &local_path)); - EXPECT_EQ(!in_memory_test(), base::PathExists(local_path)); + EXPECT_NE(is_incognito(), base::PathExists(local_path)); EXPECT_TRUE(PathExists(url)); context.reset(NewContext(nullptr)); @@ -1025,7 +1009,7 @@ TEST_P(ObfuscatedFileUtilTest, MAYBE_TestQuotaOnTruncation) { ASSERT_EQ(1019, ComputeTotalFileSize()); } - if (!in_memory_test()) { + if (!is_incognito()) { // Delete backing file to make following truncation fail. base::FilePath local_path; ASSERT_EQ( @@ -2395,7 +2379,7 @@ TEST_P(ObfuscatedFileUtilTest, TestQuotaOnOpen) { // TODO(https://crbug.com/936722): After CreateOrOpen is modified to return // file error instead of file, the in-memory test can proceed through the next // steps. - if (in_memory_test()) + if (is_incognito()) return; // Opening it with CREATE_ALWAYS flag, which should truncate the file size. diff --git a/chromium/storage/browser/fileapi/plugin_private_file_system_backend_unittest.cc b/chromium/storage/browser/fileapi/plugin_private_file_system_backend_unittest.cc index b95275b1549..7ea42e2ccd5 100644 --- a/chromium/storage/browser/fileapi/plugin_private_file_system_backend_unittest.cc +++ b/chromium/storage/browser/fileapi/plugin_private_file_system_backend_unittest.cc @@ -69,7 +69,7 @@ class PluginPrivateFileSystemBackendTest : public testing::Test { const base::FilePath& base_path() const { return backend()->base_path(); } base::ScopedTempDir data_dir_; - base::test::TaskEnvironment task_environment_; + base::test::SingleThreadTaskEnvironment task_environment_; scoped_refptr<FileSystemContext> context_; }; diff --git a/chromium/storage/browser/fileapi/quota/quota_backend_impl_unittest.cc b/chromium/storage/browser/fileapi/quota/quota_backend_impl_unittest.cc index c83184506ea..285b50de27d 100644 --- a/chromium/storage/browser/fileapi/quota/quota_backend_impl_unittest.cc +++ b/chromium/storage/browser/fileapi/quota/quota_backend_impl_unittest.cc @@ -16,7 +16,6 @@ #include "base/test/scoped_feature_list.h" #include "base/test/task_environment.h" #include "base/threading/thread_task_runner_handle.h" -#include "storage/browser/fileapi/file_system_features.h" #include "storage/browser/fileapi/file_system_usage_cache.h" #include "storage/browser/fileapi/obfuscated_file_util.h" #include "storage/browser/quota/quota_manager_proxy.h" @@ -101,12 +100,7 @@ class QuotaBackendImplTest : public testing::Test, public: QuotaBackendImplTest() : file_system_usage_cache_(is_incognito()), - quota_manager_proxy_(new MockQuotaManagerProxy) { - if (is_incognito()) { - feature_list_.InitAndEnableFeature( - storage::features::kEnableFilesystemInIncognito); - } - } + quota_manager_proxy_(new MockQuotaManagerProxy) {} void SetUp() override { ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); @@ -159,7 +153,7 @@ class QuotaBackendImplTest : public testing::Test, } base::test::ScopedFeatureList feature_list_; - base::test::TaskEnvironment task_environment_; + base::test::SingleThreadTaskEnvironment task_environment_; base::ScopedTempDir data_dir_; std::unique_ptr<leveldb::Env> in_memory_env_; std::unique_ptr<ObfuscatedFileUtil> file_util_; diff --git a/chromium/storage/browser/fileapi/quota/quota_reservation_manager_unittest.cc b/chromium/storage/browser/fileapi/quota/quota_reservation_manager_unittest.cc index dadb30b0732..c4a930b0c47 100644 --- a/chromium/storage/browser/fileapi/quota/quota_reservation_manager_unittest.cc +++ b/chromium/storage/browser/fileapi/quota/quota_reservation_manager_unittest.cc @@ -211,7 +211,7 @@ class QuotaReservationManagerTest : public testing::Test { const base::FilePath& file_path() const { return file_path_; } private: - base::test::TaskEnvironment task_environment_; + base::test::SingleThreadTaskEnvironment task_environment_; base::ScopedTempDir work_dir_; base::FilePath file_path_; std::unique_ptr<QuotaReservationManager> reservation_manager_; diff --git a/chromium/storage/browser/fileapi/sandbox_file_stream_writer.cc b/chromium/storage/browser/fileapi/sandbox_file_stream_writer.cc index fd018c9c477..10257d30275 100644 --- a/chromium/storage/browser/fileapi/sandbox_file_stream_writer.cc +++ b/chromium/storage/browser/fileapi/sandbox_file_stream_writer.cc @@ -18,7 +18,6 @@ #include "storage/browser/fileapi/file_observers.h" #include "storage/browser/fileapi/file_stream_reader.h" #include "storage/browser/fileapi/file_system_context.h" -#include "storage/browser/fileapi/file_system_features.h" #include "storage/browser/fileapi/file_system_operation_runner.h" #include "storage/browser/fileapi/obfuscated_file_util_memory_delegate.h" #include "storage/browser/fileapi/plugin_private_file_system_backend.h" @@ -143,8 +142,7 @@ void SandboxFileStreamWriter::DidCreateSnapshotFile( } DCHECK(!file_writer_.get()); - if (file_system_context_->is_incognito() && - base::FeatureList::IsEnabled(features::kEnableFilesystemInIncognito)) { + if (file_system_context_->is_incognito()) { base::WeakPtr<ObfuscatedFileUtilMemoryDelegate> memory_file_util_delegate; if (url_.type() == kFileSystemTypePluginPrivate) { auto* backend = static_cast<PluginPrivateFileSystemBackend*>( diff --git a/chromium/storage/browser/fileapi/sandbox_file_system_backend.cc b/chromium/storage/browser/fileapi/sandbox_file_system_backend.cc index b1a073e0673..e6e5833763d 100644 --- a/chromium/storage/browser/fileapi/sandbox_file_system_backend.cc +++ b/chromium/storage/browser/fileapi/sandbox_file_system_backend.cc @@ -19,7 +19,6 @@ #include "storage/browser/fileapi/file_stream_reader.h" #include "storage/browser/fileapi/file_stream_writer.h" #include "storage/browser/fileapi/file_system_context.h" -#include "storage/browser/fileapi/file_system_features.h" #include "storage/browser/fileapi/file_system_operation.h" #include "storage/browser/fileapi/file_system_operation_context.h" #include "storage/browser/fileapi/file_system_options.h" @@ -38,9 +37,7 @@ namespace storage { SandboxFileSystemBackend::SandboxFileSystemBackend( SandboxFileSystemBackendDelegate* delegate) - : delegate_(delegate), - enable_temporary_file_system_in_incognito_(base::FeatureList::IsEnabled( - features::kEnableFilesystemInIncognito)) {} + : delegate_(delegate) {} SandboxFileSystemBackend::~SandboxFileSystemBackend() = default; @@ -68,8 +65,7 @@ void SandboxFileSystemBackend::ResolveURL(const FileSystemURL& url, DCHECK(CanHandleType(url.type())); DCHECK(delegate_); if (delegate_->file_system_options().is_incognito() && - !(url.type() == kFileSystemTypeTemporary && - enable_temporary_file_system_in_incognito_)) { + url.type() != kFileSystemTypeTemporary) { // TODO(kinuko): return an isolated temporary directory. std::move(callback).Run(GURL(), std::string(), base::File::FILE_ERROR_SECURITY); diff --git a/chromium/storage/browser/fileapi/sandbox_file_system_backend.h b/chromium/storage/browser/fileapi/sandbox_file_system_backend.h index 921ccfe7473..b5acfdb9ebd 100644 --- a/chromium/storage/browser/fileapi/sandbox_file_system_backend.h +++ b/chromium/storage/browser/fileapi/sandbox_file_system_backend.h @@ -74,19 +74,9 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) SandboxFileSystemBackend // This method can only be called on the file thread. SandboxFileSystemBackendDelegate::OriginEnumerator* CreateOriginEnumerator(); - void set_enable_temporary_file_system_in_incognito(bool enable) { - enable_temporary_file_system_in_incognito_ = enable; - } - bool enable_temporary_file_system_in_incognito() const { - return enable_temporary_file_system_in_incognito_; - } - - private: SandboxFileSystemBackendDelegate* delegate_; // Not owned. - bool enable_temporary_file_system_in_incognito_; - DISALLOW_COPY_AND_ASSIGN(SandboxFileSystemBackend); }; diff --git a/chromium/storage/browser/fileapi/sandbox_file_system_backend_unittest.cc b/chromium/storage/browser/fileapi/sandbox_file_system_backend_unittest.cc index 11a487d6f02..2a353dd8f9c 100644 --- a/chromium/storage/browser/fileapi/sandbox_file_system_backend_unittest.cc +++ b/chromium/storage/browser/fileapi/sandbox_file_system_backend_unittest.cc @@ -15,11 +15,9 @@ #include "base/macros.h" #include "base/run_loop.h" #include "base/stl_util.h" -#include "base/test/scoped_feature_list.h" #include "base/test/task_environment.h" #include "base/threading/thread_task_runner_handle.h" #include "storage/browser/fileapi/file_system_backend.h" -#include "storage/browser/fileapi/file_system_features.h" #include "storage/browser/fileapi/file_system_url.h" #include "storage/browser/fileapi/sandbox_file_system_backend_delegate.h" #include "storage/browser/test/test_file_system_options.h" @@ -75,18 +73,9 @@ void DidOpenFileSystem(base::File::Error* error_out, } // namespace -class SandboxFileSystemBackendTest - : public testing::Test, - public ::testing::WithParamInterface<bool> { +class SandboxFileSystemBackendTest : public testing::Test { protected: void SetUp() override { - if (IsIncognitoEnabled()) { - feature_list_.InitAndEnableFeature( - storage::features::kEnableFilesystemInIncognito); - } else { - feature_list_.InitAndDisableFeature( - storage::features::kEnableFilesystemInIncognito); - } ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); SetUpNewDelegate(CreateAllowFileAccessOptions()); } @@ -105,8 +94,6 @@ class SandboxFileSystemBackendTest backend_.reset(new SandboxFileSystemBackend(delegate_.get())); } - bool IsIncognitoEnabled() { return GetParam(); } - storage::SandboxFileSystemBackendDelegate::OriginEnumerator* CreateOriginEnumerator() const { return backend_->CreateOriginEnumerator(); @@ -150,19 +137,16 @@ class SandboxFileSystemBackendTest base::test::TaskEnvironment task_environment_; std::unique_ptr<storage::SandboxFileSystemBackendDelegate> delegate_; std::unique_ptr<storage::SandboxFileSystemBackend> backend_; - base::test::ScopedFeatureList feature_list_; }; -INSTANTIATE_TEST_SUITE_P(, SandboxFileSystemBackendTest, ::testing::Bool()); - -TEST_P(SandboxFileSystemBackendTest, Empty) { +TEST_F(SandboxFileSystemBackendTest, Empty) { SetUpNewBackend(CreateAllowFileAccessOptions()); std::unique_ptr<SandboxFileSystemBackendDelegate::OriginEnumerator> enumerator(CreateOriginEnumerator()); ASSERT_TRUE(enumerator->Next().is_empty()); } -TEST_P(SandboxFileSystemBackendTest, EnumerateOrigins) { +TEST_F(SandboxFileSystemBackendTest, EnumerateOrigins) { SetUpNewBackend(CreateAllowFileAccessOptions()); const char* temporary_origins[] = { "http://www.bar.com/", @@ -211,7 +195,7 @@ TEST_P(SandboxFileSystemBackendTest, EnumerateOrigins) { EXPECT_EQ(persistent_size, persistent_actual_size); } -TEST_P(SandboxFileSystemBackendTest, GetRootPathCreateAndExamine) { +TEST_F(SandboxFileSystemBackendTest, GetRootPathCreateAndExamine) { std::vector<base::FilePath> returned_root_path( base::size(kRootPathTestCases)); SetUpNewBackend(CreateAllowFileAccessOptions()); @@ -251,7 +235,7 @@ TEST_P(SandboxFileSystemBackendTest, GetRootPathCreateAndExamine) { } } -TEST_P(SandboxFileSystemBackendTest, +TEST_F(SandboxFileSystemBackendTest, GetRootPathCreateAndExamineWithNewBackend) { std::vector<base::FilePath> returned_root_path( base::size(kRootPathTestCases)); @@ -275,7 +259,7 @@ TEST_P(SandboxFileSystemBackendTest, EXPECT_EQ(root_path1.value(), root_path2.value()); } -TEST_P(SandboxFileSystemBackendTest, GetRootPathGetWithoutCreate) { +TEST_F(SandboxFileSystemBackendTest, GetRootPathGetWithoutCreate) { SetUpNewBackend(CreateDisallowFileAccessOptions()); // Try to get a root directory without creating. @@ -288,7 +272,7 @@ TEST_P(SandboxFileSystemBackendTest, GetRootPathGetWithoutCreate) { } } -TEST_P(SandboxFileSystemBackendTest, GetRootPathInIncognito) { +TEST_F(SandboxFileSystemBackendTest, GetRootPathInIncognito) { SetUpNewBackend(CreateIncognitoFileSystemOptions()); // Try to get a root directory. @@ -296,15 +280,14 @@ TEST_P(SandboxFileSystemBackendTest, GetRootPathInIncognito) { SCOPED_TRACE(testing::Message() << "RootPath (incognito) #" << i << " " << kRootPathTestCases[i].expected_path); EXPECT_EQ( - IsIncognitoEnabled() && - kRootPathTestCases[i].type == storage::kFileSystemTypeTemporary, + kRootPathTestCases[i].type == storage::kFileSystemTypeTemporary, GetRootPath(GURL(kRootPathTestCases[i].origin_url), kRootPathTestCases[i].type, storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, nullptr)); } } -TEST_P(SandboxFileSystemBackendTest, GetRootPathFileURI) { +TEST_F(SandboxFileSystemBackendTest, GetRootPathFileURI) { SetUpNewBackend(CreateDisallowFileAccessOptions()); for (size_t i = 0; i < base::size(kRootPathFileURITestCases); ++i) { SCOPED_TRACE(testing::Message() << "RootPathFileURI (disallow) #" @@ -316,7 +299,7 @@ TEST_P(SandboxFileSystemBackendTest, GetRootPathFileURI) { } } -TEST_P(SandboxFileSystemBackendTest, GetRootPathFileURIWithAllowFlag) { +TEST_F(SandboxFileSystemBackendTest, GetRootPathFileURIWithAllowFlag) { SetUpNewBackend(CreateAllowFileAccessOptions()); for (size_t i = 0; i < base::size(kRootPathFileURITestCases); ++i) { SCOPED_TRACE(testing::Message() << "RootPathFileURI (allow) #" diff --git a/chromium/storage/browser/quota/OWNERS b/chromium/storage/browser/quota/OWNERS index f62a608ec7a..148302e8cb4 100644 --- a/chromium/storage/browser/quota/OWNERS +++ b/chromium/storage/browser/quota/OWNERS @@ -1,8 +1,11 @@ +# Primary +jarrydg@chromium.org + +# Secondary jsbell@chromium.org kinuko@chromium.org nhiroki@chromium.org pwnall@chromium.org -tzik@chromium.org # TEAM: storage-dev@chromium.org # COMPONENT: Blink>Storage>Quota diff --git a/chromium/storage/browser/quota/quota_database_unittest.cc b/chromium/storage/browser/quota/quota_database_unittest.cc index b3d5466946a..31a54d03955 100644 --- a/chromium/storage/browser/quota/quota_database_unittest.cc +++ b/chromium/storage/browser/quota/quota_database_unittest.cc @@ -575,7 +575,7 @@ class QuotaDatabaseTest : public testing::Test { db->CommitTransaction(); } - base::test::TaskEnvironment task_environment_; + base::test::SingleThreadTaskEnvironment task_environment_; }; TEST_F(QuotaDatabaseTest, LazyOpen) { diff --git a/chromium/storage/browser/quota/quota_features.cc b/chromium/storage/browser/quota/quota_features.cc index 6acac112f71..771e905dfc5 100644 --- a/chromium/storage/browser/quota/quota_features.cc +++ b/chromium/storage/browser/quota/quota_features.cc @@ -8,25 +8,14 @@ namespace storage { namespace features { -#if defined(OS_CHROMEOS) -// Chrome OS is given a larger fraction, as web content is the considered -// the primary use of the platform. Chrome OS itself maintains free space by -// starting to evict data (old profiles) when less than 1GB remains, -// stopping eviction once 2GB is free. -// Prior to M66 this was 1/3, same as other platforms. -const constexpr double kTemporaryPoolSizeRatioThirds = 2.0 / 3.0; // 66% -#else -const constexpr double kTemporaryPoolSizeRatioThirds = 1.0 / 3.0; // 33% -#endif - const base::Feature kQuotaExpandPoolSize{"QuotaExpandPoolSize", - base::FEATURE_DISABLED_BY_DEFAULT}; + base::FEATURE_ENABLED_BY_DEFAULT}; constexpr base::FeatureParam<double> kExperimentalPoolSizeRatio{ - &kQuotaExpandPoolSize, "PoolSizeRatio", kTemporaryPoolSizeRatioThirds}; + &kQuotaExpandPoolSize, "PoolSizeRatio", 0.8}; constexpr base::FeatureParam<double> kPerHostRatio{&kQuotaExpandPoolSize, - "PerHostRatio", 0.2}; + "PerHostRatio", 0.75}; // StaticHostQuota enables a simpler per-host quota model, where the quota is // only based on disk capacity (partition size). When the flag is disabled, the diff --git a/chromium/storage/browser/quota/quota_settings.h b/chromium/storage/browser/quota/quota_settings.h index a68445342b7..72561a91626 100644 --- a/chromium/storage/browser/quota/quota_settings.h +++ b/chromium/storage/browser/quota/quota_settings.h @@ -100,4 +100,4 @@ COMPONENT_EXPORT(STORAGE_BROWSER) QuotaDiskInfoHelper* GetDefaultDiskInfoHelper(); } // namespace storage -#endif // STORAGE_BROWSER_QUOTA_QUOTA_MANAGER_H_ +#endif // STORAGE_BROWSER_QUOTA_QUOTA_SETTINGS_H_ diff --git a/chromium/storage/browser/quota/quota_settings_unittest.cc b/chromium/storage/browser/quota/quota_settings_unittest.cc index 022463a35c5..55a4990c4e2 100644 --- a/chromium/storage/browser/quota/quota_settings_unittest.cc +++ b/chromium/storage/browser/quota/quota_settings_unittest.cc @@ -42,6 +42,26 @@ class QuotaSettingsTest : public testing::Test { DISALLOW_COPY_AND_ASSIGN(QuotaSettingsTest); }; +TEST_F(QuotaSettingsTest, Default) { + MockQuotaDiskInfoHelper disk_info_helper; + ON_CALL(disk_info_helper, AmountOfTotalDiskSpace(_)) + .WillByDefault(::testing::Return(2000)); + + bool callback_executed = false; + GetNominalDynamicSettings( + profile_path(), false, &disk_info_helper, + base::BindLambdaForTesting([&](base::Optional<QuotaSettings> settings) { + callback_executed = true; + ASSERT_NE(settings, base::nullopt); + // 1600 = 2000 * default PoolSizeRatio (0.8) + EXPECT_EQ(settings->pool_size, 1600); + // 1200 = 1600 * default PerHostRatio (.75) + EXPECT_EQ(settings->per_host_quota, 1200); + })); + task_environment_.RunUntilIdle(); + EXPECT_TRUE(callback_executed); +} + TEST_F(QuotaSettingsTest, ExpandedTempPool) { MockQuotaDiskInfoHelper disk_info_helper; ON_CALL(disk_info_helper, AmountOfTotalDiskSpace(_)) |