diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2022-02-04 17:20:24 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2022-02-12 08:15:25 +0000 |
commit | 8fa0776f1f79e91fc9c0b9c1ba11a0a29c05196b (patch) | |
tree | 788d8d7549712682703a0310ca4a0f0860d4802b /chromium/storage | |
parent | 606d85f2a5386472314d39923da28c70c60dc8e7 (diff) | |
download | qtwebengine-chromium-8fa0776f1f79e91fc9c0b9c1ba11a0a29c05196b.tar.gz |
BASELINE: Update Chromium to 98.0.4758.90
Change-Id: Ib7c41539bf8a8e0376bd639f27d68294de90f3c8
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/storage')
168 files changed, 1698 insertions, 1008 deletions
diff --git a/chromium/storage/browser/BUILD.gn b/chromium/storage/browser/BUILD.gn index bead925f060..bd02958142c 100644 --- a/chromium/storage/browser/BUILD.gn +++ b/chromium/storage/browser/BUILD.gn @@ -105,6 +105,8 @@ component("browser") { "file_system/file_system_quota_client.cc", "file_system/file_system_quota_client.h", "file_system/file_system_quota_util.h", + "file_system/file_system_request_info.cc", + "file_system/file_system_request_info.h", "file_system/file_system_url.cc", "file_system/file_system_url.h", "file_system/file_system_usage_cache.cc", diff --git a/chromium/storage/browser/blob/blob_data_builder.h b/chromium/storage/browser/blob/blob_data_builder.h index 4d6838d3e8c..120ffa1cb33 100644 --- a/chromium/storage/browser/blob/blob_data_builder.h +++ b/chromium/storage/browser/blob/blob_data_builder.h @@ -13,7 +13,6 @@ #include "base/component_export.h" #include "base/files/file_path.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/numerics/checked_math.h" #include "components/services/storage/public/mojom/blob_storage_context.mojom.h" diff --git a/chromium/storage/browser/blob/blob_data_handle.cc b/chromium/storage/browser/blob/blob_data_handle.cc index 8252545442a..fa93ea6fd03 100644 --- a/chromium/storage/browser/blob/blob_data_handle.cc +++ b/chromium/storage/browser/blob/blob_data_handle.cc @@ -12,10 +12,9 @@ #include "base/callback.h" #include "base/check.h" #include "base/location.h" -#include "base/macros.h" #include "base/memory/ptr_util.h" -#include "base/sequenced_task_runner.h" -#include "base/task_runner.h" +#include "base/task/sequenced_task_runner.h" +#include "base/task/task_runner.h" #include "base/time/time.h" #include "storage/browser/blob/blob_data_snapshot.h" #include "storage/browser/blob/blob_reader.h" diff --git a/chromium/storage/browser/blob/blob_data_handle.h b/chromium/storage/browser/blob/blob_data_handle.h index 1db1d45c3f2..bf36ffee6af 100644 --- a/chromium/storage/browser/blob/blob_data_handle.h +++ b/chromium/storage/browser/blob/blob_data_handle.h @@ -11,11 +11,10 @@ #include "base/callback_forward.h" #include "base/component_export.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" -#include "base/sequenced_task_runner_helpers.h" #include "base/supports_user_data.h" +#include "base/task/sequenced_task_runner_helpers.h" #include "storage/browser/blob/blob_storage_constants.h" namespace base { @@ -112,6 +111,9 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobDataHandle uint64_t size, BlobStorageContext* context); + BlobDataHandleShared(const BlobDataHandleShared&) = delete; + BlobDataHandleShared& operator=(const BlobDataHandleShared&) = delete; + private: friend class base::DeleteHelper<BlobDataHandleShared>; friend class base::RefCountedThreadSafe<BlobDataHandleShared>; @@ -124,8 +126,6 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobDataHandle const std::string content_disposition_; const uint64_t size_; base::WeakPtr<BlobStorageContext> context_; - - DISALLOW_COPY_AND_ASSIGN(BlobDataHandleShared); }; friend class BlobStorageContext; diff --git a/chromium/storage/browser/blob/blob_entry.h b/chromium/storage/browser/blob/blob_entry.h index 9e8f72e5773..44cd73b2b19 100644 --- a/chromium/storage/browser/blob/blob_entry.h +++ b/chromium/storage/browser/blob/blob_entry.h @@ -13,7 +13,6 @@ #include "base/callback_forward.h" #include "base/component_export.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" #include "storage/browser/blob/blob_memory_controller.h" diff --git a/chromium/storage/browser/blob/blob_impl.cc b/chromium/storage/browser/blob/blob_impl.cc index 141fcd8722f..d46565ac953 100644 --- a/chromium/storage/browser/blob/blob_impl.cc +++ b/chromium/storage/browser/blob/blob_impl.cc @@ -30,6 +30,9 @@ class ReaderDelegate : public MojoBlobReader::Delegate { ReaderDelegate(mojo::PendingRemote<blink::mojom::BlobReaderClient> client) : client_(std::move(client)) {} + ReaderDelegate(const ReaderDelegate&) = delete; + ReaderDelegate& operator=(const ReaderDelegate&) = delete; + MojoBlobReader::Delegate::RequestSideData DidCalculateSize( uint64_t total_size, uint64_t content_size) override { @@ -45,8 +48,6 @@ class ReaderDelegate : public MojoBlobReader::Delegate { private: mojo::Remote<blink::mojom::BlobReaderClient> client_; - - DISALLOW_COPY_AND_ASSIGN(ReaderDelegate); }; class DataPipeGetterReaderDelegate : public MojoBlobReader::Delegate { @@ -55,6 +56,10 @@ class DataPipeGetterReaderDelegate : public MojoBlobReader::Delegate { network::mojom::DataPipeGetter::ReadCallback callback) : callback_(std::move(callback)) {} + DataPipeGetterReaderDelegate(const DataPipeGetterReaderDelegate&) = delete; + DataPipeGetterReaderDelegate& operator=(const DataPipeGetterReaderDelegate&) = + delete; + MojoBlobReader::Delegate::RequestSideData DidCalculateSize( uint64_t total_size, uint64_t content_size) override { @@ -78,8 +83,6 @@ class DataPipeGetterReaderDelegate : public MojoBlobReader::Delegate { private: network::mojom::DataPipeGetter::ReadCallback callback_; - - DISALLOW_COPY_AND_ASSIGN(DataPipeGetterReaderDelegate); }; } // namespace diff --git a/chromium/storage/browser/blob/blob_impl.h b/chromium/storage/browser/blob/blob_impl.h index ee72f6ee285..b93c906aa17 100644 --- a/chromium/storage/browser/blob/blob_impl.h +++ b/chromium/storage/browser/blob/blob_impl.h @@ -24,6 +24,9 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobImpl std::unique_ptr<BlobDataHandle> handle, mojo::PendingReceiver<blink::mojom::Blob> receiver); + BlobImpl(const BlobImpl&) = delete; + BlobImpl& operator=(const BlobImpl&) = delete; + // Can be used to update the BlobDataHandle this BlobImpl refers to, for // example to update it from one that doesn't have a valid size (when the // BlobImpl was created) to one that has a valid size (after construction of @@ -71,8 +74,6 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobImpl mojo::ReceiverSet<network::mojom::DataPipeGetter> data_pipe_getter_receivers_; base::WeakPtrFactory<BlobImpl> weak_ptr_factory_{this}; - - DISALLOW_COPY_AND_ASSIGN(BlobImpl); }; } // namespace storage diff --git a/chromium/storage/browser/blob/blob_impl_unittest.cc b/chromium/storage/browser/blob/blob_impl_unittest.cc index fcb524760b3..3b88a924b7d 100644 --- a/chromium/storage/browser/blob/blob_impl_unittest.cc +++ b/chromium/storage/browser/blob/blob_impl_unittest.cc @@ -10,6 +10,7 @@ #include <utility> #include "base/bind.h" +#include "base/memory/raw_ptr.h" #include "base/run_loop.h" #include "base/task/post_task.h" #include "base/test/task_environment.h" @@ -39,7 +40,7 @@ class DataPipeReader : public mojo::DataPipeDrainer::Client { void OnDataComplete() override { std::move(done_callback_).Run(); } private: - std::string* data_out_; + raw_ptr<std::string> data_out_; base::OnceClosure done_callback_; }; diff --git a/chromium/storage/browser/blob/blob_memory_controller.cc b/chromium/storage/browser/blob/blob_memory_controller.cc index f841876f22b..40123a3c62f 100644 --- a/chromium/storage/browser/blob/blob_memory_controller.cc +++ b/chromium/storage/browser/blob/blob_memory_controller.cc @@ -18,15 +18,16 @@ #include "base/guid.h" #include "base/location.h" #include "base/memory/ptr_util.h" +#include "base/memory/raw_ptr.h" #include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_macros.h" #include "base/numerics/safe_conversions.h" #include "base/numerics/safe_math.h" -#include "base/single_thread_task_runner.h" #include "base/strings/string_number_conversions.h" #include "base/system/sys_info.h" -#include "base/task_runner.h" -#include "base/task_runner_util.h" +#include "base/task/single_thread_task_runner.h" +#include "base/task/task_runner.h" +#include "base/task/task_runner_util.h" #include "base/threading/scoped_blocking_call.h" #include "base/time/time.h" #include "base/trace_event/trace_event.h" @@ -371,7 +372,7 @@ class BlobMemoryController::MemoryQuotaAllocationTask size_t allocation_size() const { return allocation_size_; } private: - BlobMemoryController* controller_; + raw_ptr<BlobMemoryController> controller_; std::vector<scoped_refptr<ShareableBlobDataItem>> pending_items_; MemoryQuotaRequestCallback done_callback_; @@ -530,7 +531,7 @@ class BlobMemoryController::FileQuotaAllocationTask size_t allocation_size() const { return allocation_size_; } private: - BlobMemoryController* controller_; + raw_ptr<BlobMemoryController> controller_; std::vector<uint64_t> file_sizes_; std::vector<scoped_refptr<ShareableBlobDataItem>> pending_items_; FileQuotaRequestCallback done_callback_; @@ -549,7 +550,7 @@ BlobMemoryController::BlobMemoryController( file_runner_(std::move(file_runner)), disk_space_function_(&base::SysInfo::AmountOfFreeDiskSpace), populated_memory_items_( - base::MRUCache<uint64_t, ShareableBlobDataItem*>::NO_AUTO_EVICT), + base::LRUCache<uint64_t, ShareableBlobDataItem*>::NO_AUTO_EVICT), memory_pressure_listener_( FROM_HERE, base::BindRepeating(&BlobMemoryController::OnMemoryPressure, diff --git a/chromium/storage/browser/blob/blob_memory_controller.h b/chromium/storage/browser/blob/blob_memory_controller.h index 3e5db532356..b002bbe41b4 100644 --- a/chromium/storage/browser/blob/blob_memory_controller.h +++ b/chromium/storage/browser/blob/blob_memory_controller.h @@ -18,12 +18,11 @@ #include "base/callback_forward.h" #include "base/callback_helpers.h" #include "base/component_export.h" -#include "base/containers/mru_cache.h" +#include "base/containers/lru_cache.h" #include "base/feature_list.h" #include "base/files/file.h" #include "base/files/file_path.h" #include "base/gtest_prod_util.h" -#include "base/macros.h" #include "base/memory/memory_pressure_listener.h" #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" @@ -121,6 +120,10 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobMemoryController { // We enable file paging if |file_runner| isn't a nullptr. BlobMemoryController(const base::FilePath& storage_directory, scoped_refptr<base::TaskRunner> file_runner); + + BlobMemoryController(const BlobMemoryController&) = delete; + BlobMemoryController& operator=(const BlobMemoryController&) = delete; + ~BlobMemoryController(); // Disables file paging. This cancels all pending file creations and paging @@ -312,7 +315,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobMemoryController { // Lifetime of the ShareableBlobDataItem objects is handled externally in the // BlobStorageContext class. - base::MRUCache<uint64_t, ShareableBlobDataItem*> populated_memory_items_; + base::LRUCache<uint64_t, ShareableBlobDataItem*> populated_memory_items_; size_t populated_memory_items_bytes_ = 0; // We need to keep track of items currently being paged to disk so that if // another blob successfully grabs a ref, we can prevent it from adding the @@ -322,8 +325,6 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobMemoryController { base::MemoryPressureListener memory_pressure_listener_; base::WeakPtrFactory<BlobMemoryController> weak_factory_{this}; - - DISALLOW_COPY_AND_ASSIGN(BlobMemoryController); }; } // namespace storage #endif // STORAGE_BROWSER_BLOB_BLOB_MEMORY_CONTROLLER_H_ diff --git a/chromium/storage/browser/blob/blob_reader.h b/chromium/storage/browser/blob/blob_reader.h index 5145ecfd7be..fa32571e908 100644 --- a/chromium/storage/browser/blob/blob_reader.h +++ b/chromium/storage/browser/blob/blob_reader.h @@ -14,7 +14,6 @@ #include "base/component_export.h" #include "base/gtest_prod_util.h" -#include "base/macros.h" #include "base/memory/weak_ptr.h" #include "base/sequence_checker.h" #include "mojo/public/cpp/base/big_buffer.h" diff --git a/chromium/storage/browser/blob/blob_reader_unittest.cc b/chromium/storage/browser/blob/blob_reader_unittest.cc index 3a6c52eacd7..e259f00388d 100644 --- a/chromium/storage/browser/blob/blob_reader_unittest.cc +++ b/chromium/storage/browser/blob/blob_reader_unittest.cc @@ -17,11 +17,11 @@ #include "base/callback_helpers.h" #include "base/files/file_path.h" #include "base/location.h" -#include "base/macros.h" #include "base/memory/ptr_util.h" +#include "base/memory/raw_ptr.h" #include "base/run_loop.h" #include "base/strings/stringprintf.h" -#include "base/task_runner.h" +#include "base/task/task_runner.h" #include "base/test/bind.h" #include "base/test/task_environment.h" #include "base/threading/thread_task_runner_handle.h" @@ -230,7 +230,7 @@ class BlobReaderTest : public ::testing::Test { builder ? context_.AddFinishedBlob(std::move(builder)) : nullptr; provider_ = new MockFileStreamReaderProvider(); reader_.reset(new BlobReader(blob_handle_.get())); - reader_->SetFileStreamProviderForTesting(base::WrapUnique(provider_)); + reader_->SetFileStreamProviderForTesting(base::WrapUnique(provider_.get())); } // Takes ownership of the file reader (the blob reader takes ownership). @@ -289,7 +289,7 @@ class BlobReaderTest : public ::testing::Test { BlobStorageContext context_; std::unique_ptr<BlobDataHandle> blob_handle_; - MockFileStreamReaderProvider* provider_ = nullptr; + raw_ptr<MockFileStreamReaderProvider> provider_ = nullptr; std::unique_ptr<BlobReader> reader_; scoped_refptr<FileSystemContext> file_system_context_; }; @@ -1159,7 +1159,7 @@ TEST_F(BlobReaderTest, HandleBeforeAsyncCancel) { EXPECT_EQ(BlobStatus::PENDING_TRANSPORT, can_populate_status); provider_ = new MockFileStreamReaderProvider(); reader_.reset(new BlobReader(blob_handle_.get())); - reader_->SetFileStreamProviderForTesting(base::WrapUnique(provider_)); + reader_->SetFileStreamProviderForTesting(base::WrapUnique(provider_.get())); int size_result = -1; EXPECT_EQ( BlobReader::Status::IO_PENDING, @@ -1187,7 +1187,7 @@ TEST_F(BlobReaderTest, ReadFromIncompleteBlob) { EXPECT_EQ(BlobStatus::PENDING_TRANSPORT, can_populate_status); provider_ = new MockFileStreamReaderProvider(); reader_.reset(new BlobReader(blob_handle_.get())); - reader_->SetFileStreamProviderForTesting(base::WrapUnique(provider_)); + reader_->SetFileStreamProviderForTesting(base::WrapUnique(provider_.get())); int size_result = -1; EXPECT_EQ( BlobReader::Status::IO_PENDING, diff --git a/chromium/storage/browser/blob/blob_registry_impl.cc b/chromium/storage/browser/blob/blob_registry_impl.cc index f5e6ef4cf36..3d565c5aa08 100644 --- a/chromium/storage/browser/blob/blob_registry_impl.cc +++ b/chromium/storage/browser/blob/blob_registry_impl.cc @@ -9,6 +9,7 @@ #include "base/barrier_closure.h" #include "base/bind.h" #include "base/callback_helpers.h" +#include "base/memory/raw_ptr.h" #include "storage/browser/blob/blob_builder_from_stream.h" #include "storage/browser/blob/blob_data_builder.h" #include "storage/browser/blob/blob_impl.h" @@ -178,7 +179,7 @@ class BlobRegistryImpl::BlobUnderConstruction { #endif // BlobRegistryImpl we belong to. - BlobRegistryImpl* blob_registry_; + raw_ptr<BlobRegistryImpl> blob_registry_; // UUID of the blob being built. std::string uuid_; @@ -644,7 +645,7 @@ void BlobRegistryImpl::URLStoreForOrigin( mojo::PendingAssociatedReceiver<blink::mojom::BlobURLStore> receiver) { Delegate* delegate = receivers_.current_context().get(); DCHECK(delegate); - if (!origin.opaque() && !delegate->CanCommitURL(origin.GetURL())) { + if (!origin.opaque() && !delegate->CanAccessDataForOrigin(origin)) { mojo::ReportBadMessage( "Cannot access data for origin passed to " "BlobRegistryImpl::URLStoreForOrigin"); diff --git a/chromium/storage/browser/blob/blob_registry_impl.h b/chromium/storage/browser/blob/blob_registry_impl.h index 09631b0929e..35ae9b60213 100644 --- a/chromium/storage/browser/blob/blob_registry_impl.h +++ b/chromium/storage/browser/blob/blob_registry_impl.h @@ -14,6 +14,7 @@ #include "storage/browser/blob/blob_url_registry.h" #include "storage/browser/file_system/file_system_context.h" #include "third_party/blink/public/mojom/blob/blob_registry.mojom.h" +#include "url/origin.h" namespace storage { @@ -32,7 +33,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobRegistryImpl virtual ~Delegate() {} virtual bool CanReadFile(const base::FilePath& file) = 0; virtual bool CanReadFileSystemFile(const FileSystemURL& url) = 0; - virtual bool CanCommitURL(const GURL& url) = 0; + virtual bool CanAccessDataForOrigin(const url::Origin& origin) = 0; }; BlobRegistryImpl(base::WeakPtr<BlobStorageContext> context, diff --git a/chromium/storage/browser/blob/blob_registry_impl_unittest.cc b/chromium/storage/browser/blob/blob_registry_impl_unittest.cc index 76af9d4c0e3..e7de3b85352 100644 --- a/chromium/storage/browser/blob/blob_registry_impl_unittest.cc +++ b/chromium/storage/browser/blob/blob_registry_impl_unittest.cc @@ -13,10 +13,12 @@ #include "base/bind.h" #include "base/callback_helpers.h" #include "base/files/scoped_temp_dir.h" +#include "base/ignore_result.h" +#include "base/memory/raw_ptr.h" #include "base/rand_util.h" #include "base/run_loop.h" -#include "base/sequenced_task_runner.h" #include "base/task/post_task.h" +#include "base/task/sequenced_task_runner.h" #include "base/task/thread_pool.h" #include "base/test/bind.h" #include "base/test/task_environment.h" @@ -196,7 +198,7 @@ class BlobRegistryImplTest : public testing::Test { BlobUrlRegistry url_registry_; std::unique_ptr<BlobRegistryImpl> registry_impl_; mojo::Remote<blink::mojom::BlobRegistry> registry_; - MockBlobRegistryDelegate* delegate_ptr_; + raw_ptr<MockBlobRegistryDelegate> delegate_ptr_; scoped_refptr<base::SequencedTaskRunner> bytes_provider_runner_; size_t reply_request_count_ = 0; diff --git a/chromium/storage/browser/blob/blob_storage_context.cc b/chromium/storage/browser/blob/blob_storage_context.cc index 7c0cd2d3006..f69576532bb 100644 --- a/chromium/storage/browser/blob/blob_storage_context.cc +++ b/chromium/storage/browser/blob/blob_storage_context.cc @@ -22,8 +22,8 @@ #include "base/numerics/safe_math.h" #include "base/strings/stringprintf.h" #include "base/task/post_task.h" +#include "base/task/task_runner.h" #include "base/task/thread_pool.h" -#include "base/task_runner.h" #include "base/threading/thread_task_runner_handle.h" #include "base/trace_event/memory_dump_manager.h" #include "base/trace_event/trace_event.h" diff --git a/chromium/storage/browser/blob/blob_storage_context.h b/chromium/storage/browser/blob/blob_storage_context.h index 8e5440d79dc..8f59c3abb8a 100644 --- a/chromium/storage/browser/blob/blob_storage_context.h +++ b/chromium/storage/browser/blob/blob_storage_context.h @@ -17,7 +17,6 @@ #include "base/component_export.h" #include "base/files/file_path.h" #include "base/gtest_prod_util.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" #include "base/trace_event/memory_dump_provider.h" diff --git a/chromium/storage/browser/blob/blob_storage_context_mojo_unittest.cc b/chromium/storage/browser/blob/blob_storage_context_mojo_unittest.cc index 8afd979d45b..f2b5409b815 100644 --- a/chromium/storage/browser/blob/blob_storage_context_mojo_unittest.cc +++ b/chromium/storage/browser/blob/blob_storage_context_mojo_unittest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/memory/raw_ptr.h" #include "storage/browser/blob/blob_storage_context.h" #include <memory> @@ -46,7 +47,7 @@ class DataPipeReader : public mojo::DataPipeDrainer::Client { void OnDataComplete() override { std::move(done_callback_).Run(); } private: - std::string* data_out_; + raw_ptr<std::string> data_out_; base::OnceClosure done_callback_; }; diff --git a/chromium/storage/browser/blob/blob_storage_registry.h b/chromium/storage/browser/blob/blob_storage_registry.h index 6a7656ad1d1..7b840005589 100644 --- a/chromium/storage/browser/blob/blob_storage_registry.h +++ b/chromium/storage/browser/blob/blob_storage_registry.h @@ -14,7 +14,6 @@ #include <vector> #include "base/component_export.h" -#include "base/macros.h" #include "storage/browser/blob/blob_storage_constants.h" namespace storage { diff --git a/chromium/storage/browser/blob/blob_transport_strategy.cc b/chromium/storage/browser/blob/blob_transport_strategy.cc index c86c700fd0f..0b62ea31fd4 100644 --- a/chromium/storage/browser/blob/blob_transport_strategy.cc +++ b/chromium/storage/browser/blob/blob_transport_strategy.cc @@ -8,6 +8,7 @@ #include "base/bind.h" #include "base/containers/circular_deque.h" +#include "base/memory/raw_ptr.h" #include "mojo/public/cpp/system/data_pipe.h" #include "storage/browser/blob/blob_data_builder.h" #include "third_party/blink/public/mojom/blob/data_element.mojom.h" @@ -346,7 +347,7 @@ class FileTransportStrategy : public BlobTransportStrategy { struct Request { // The BytesProvider to request this particular bit of data from. - blink::mojom::BytesProvider* provider; + raw_ptr<blink::mojom::BytesProvider> provider; // Offset into the BytesProvider of the data to request. uint64_t source_offset; // Size of the bytes to request. diff --git a/chromium/storage/browser/blob/blob_transport_strategy.h b/chromium/storage/browser/blob/blob_transport_strategy.h index aa5746d9669..1985be83ce3 100644 --- a/chromium/storage/browser/blob/blob_transport_strategy.h +++ b/chromium/storage/browser/blob/blob_transport_strategy.h @@ -7,6 +7,7 @@ #include "base/callback.h" #include "base/component_export.h" +#include "base/memory/raw_ptr.h" #include "mojo/public/cpp/bindings/remote.h" #include "storage/browser/blob/blob_memory_controller.h" #include "third_party/blink/public/mojom/blob/blob_registry.mojom.h" @@ -50,7 +51,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobTransportStrategy { BlobTransportStrategy(BlobDataBuilder* builder, ResultCallback result_callback); - BlobDataBuilder* builder_; + raw_ptr<BlobDataBuilder> builder_; ResultCallback result_callback_; }; diff --git a/chromium/storage/browser/blob/blob_transport_strategy_unittest.cc b/chromium/storage/browser/blob/blob_transport_strategy_unittest.cc index e29f1048d9b..0f24c79baf3 100644 --- a/chromium/storage/browser/blob/blob_transport_strategy_unittest.cc +++ b/chromium/storage/browser/blob/blob_transport_strategy_unittest.cc @@ -16,8 +16,8 @@ #include "base/files/scoped_temp_dir.h" #include "base/rand_util.h" #include "base/run_loop.h" -#include "base/sequenced_task_runner.h" #include "base/task/post_task.h" +#include "base/task/sequenced_task_runner.h" #include "base/task/thread_pool.h" #include "base/test/task_environment.h" #include "base/threading/thread_restrictions.h" diff --git a/chromium/storage/browser/blob/blob_url_loader.h b/chromium/storage/browser/blob/blob_url_loader.h index 0fed3de09ec..484d4cc345e 100644 --- a/chromium/storage/browser/blob/blob_url_loader.h +++ b/chromium/storage/browser/blob/blob_url_loader.h @@ -10,7 +10,6 @@ #include <vector> #include "base/component_export.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_remote.h" diff --git a/chromium/storage/browser/blob/blob_url_loader_factory.h b/chromium/storage/browser/blob/blob_url_loader_factory.h index 76ba963d9dc..fc615281e70 100644 --- a/chromium/storage/browser/blob/blob_url_loader_factory.h +++ b/chromium/storage/browser/blob/blob_url_loader_factory.h @@ -36,6 +36,9 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobURLLoaderFactory base::WeakPtr<BlobUrlRegistry> url_registry, mojo::PendingReceiver<network::mojom::URLLoaderFactory> receiver); + BlobURLLoaderFactory(const BlobURLLoaderFactory&) = delete; + BlobURLLoaderFactory& operator=(const BlobURLLoaderFactory&) = delete; + // URLLoaderFactory: void CreateLoaderAndStart( mojo::PendingReceiver<network::mojom::URLLoader> loader, @@ -60,8 +63,6 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) BlobURLLoaderFactory GURL url_; mojo::ReceiverSet<network::mojom::URLLoaderFactory> receivers_; - - DISALLOW_COPY_AND_ASSIGN(BlobURLLoaderFactory); }; } // namespace storage diff --git a/chromium/storage/browser/blob/blob_url_registry.h b/chromium/storage/browser/blob/blob_url_registry.h index b30100bfa37..b2b7a3156d2 100644 --- a/chromium/storage/browser/blob/blob_url_registry.h +++ b/chromium/storage/browser/blob/blob_url_registry.h @@ -8,7 +8,6 @@ #include <map> #include "base/component_export.h" -#include "base/macros.h" #include "base/sequence_checker.h" #include "base/unguessable_token.h" #include "mojo/public/cpp/bindings/pending_remote.h" diff --git a/chromium/storage/browser/blob/mojo_blob_reader.h b/chromium/storage/browser/blob/mojo_blob_reader.h index f2c88b4b4b9..a1e0b8c32d3 100644 --- a/chromium/storage/browser/blob/mojo_blob_reader.h +++ b/chromium/storage/browser/blob/mojo_blob_reader.h @@ -75,6 +75,9 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) MojoBlobReader { std::unique_ptr<Delegate> delegate, mojo::ScopedDataPipeProducerHandle response_body_stream); + MojoBlobReader(const MojoBlobReader&) = delete; + MojoBlobReader& operator=(const MojoBlobReader&) = delete; + private: MojoBlobReader(const BlobDataHandle* handle, const net::HttpByteRange& range, @@ -130,8 +133,6 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) MojoBlobReader { SEQUENCE_CHECKER(sequence_checker_); base::WeakPtrFactory<MojoBlobReader> weak_factory_{this}; - - DISALLOW_COPY_AND_ASSIGN(MojoBlobReader); }; } // namespace storage diff --git a/chromium/storage/browser/blob/scoped_file.cc b/chromium/storage/browser/blob/scoped_file.cc index b1a01a1e23f..9a9a2f9121c 100644 --- a/chromium/storage/browser/blob/scoped_file.cc +++ b/chromium/storage/browser/blob/scoped_file.cc @@ -9,7 +9,7 @@ #include "base/files/file_util.h" #include "base/location.h" #include "base/logging.h" -#include "base/task_runner.h" +#include "base/task/task_runner.h" #include "base/threading/thread_task_runner_handle.h" namespace storage { diff --git a/chromium/storage/browser/blob/scoped_file.h b/chromium/storage/browser/blob/scoped_file.h index 35c0adbdbb4..6798ebbb0e9 100644 --- a/chromium/storage/browser/blob/scoped_file.h +++ b/chromium/storage/browser/blob/scoped_file.h @@ -10,7 +10,6 @@ #include "base/callback_forward.h" #include "base/component_export.h" #include "base/files/file_path.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" namespace base { diff --git a/chromium/storage/browser/blob/shareable_blob_data_item.h b/chromium/storage/browser/blob/shareable_blob_data_item.h index f16df2aafa8..8e4853b1689 100644 --- a/chromium/storage/browser/blob/shareable_blob_data_item.h +++ b/chromium/storage/browser/blob/shareable_blob_data_item.h @@ -10,7 +10,6 @@ #include "base/callback_helpers.h" #include "base/component_export.h" #include "base/hash/hash.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "storage/browser/blob/blob_memory_controller.h" @@ -43,6 +42,9 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) ShareableBlobDataItem ShareableBlobDataItem(scoped_refptr<BlobDataItem> item, State state); + ShareableBlobDataItem(const ShareableBlobDataItem&) = delete; + ShareableBlobDataItem& operator=(const ShareableBlobDataItem&) = delete; + const scoped_refptr<BlobDataItem>& item() const { return item_; } void set_item(scoped_refptr<BlobDataItem> item); @@ -86,8 +88,6 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) ShareableBlobDataItem State state_; scoped_refptr<BlobDataItem> item_; std::unique_ptr<BlobMemoryController::MemoryAllocation> memory_allocation_; - - DISALLOW_COPY_AND_ASSIGN(ShareableBlobDataItem); }; COMPONENT_EXPORT(STORAGE_BROWSER) diff --git a/chromium/storage/browser/blob/shareable_file_reference.cc b/chromium/storage/browser/blob/shareable_file_reference.cc index 9179c241c87..1d97a45ccb6 100644 --- a/chromium/storage/browser/blob/shareable_file_reference.cc +++ b/chromium/storage/browser/blob/shareable_file_reference.cc @@ -9,9 +9,8 @@ #include "base/lazy_instance.h" #include "base/logging.h" -#include "base/macros.h" #include "base/sequence_checker.h" -#include "base/task_runner.h" +#include "base/task/task_runner.h" namespace storage { diff --git a/chromium/storage/browser/blob/shareable_file_reference.h b/chromium/storage/browser/blob/shareable_file_reference.h index d6f30a853d8..107ee717087 100644 --- a/chromium/storage/browser/blob/shareable_file_reference.h +++ b/chromium/storage/browser/blob/shareable_file_reference.h @@ -6,7 +6,6 @@ #define STORAGE_BROWSER_BLOB_SHAREABLE_FILE_REFERENCE_H_ #include "base/component_export.h" -#include "base/macros.h" #include "storage/browser/blob/scoped_file.h" namespace storage { @@ -50,6 +49,9 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) ShareableFileReference static scoped_refptr<ShareableFileReference> GetOrCreate( ScopedFile scoped_file); + ShareableFileReference(const ShareableFileReference&) = delete; + ShareableFileReference& operator=(const ShareableFileReference&) = delete; + // The full file path. const base::FilePath& path() const { return scoped_file_.path(); } @@ -69,8 +71,6 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) ShareableFileReference ~ShareableFileReference(); ScopedFile scoped_file_; - - DISALLOW_COPY_AND_ASSIGN(ShareableFileReference); }; } // namespace storage diff --git a/chromium/storage/browser/blob/view_blob_internals_job.cc b/chromium/storage/browser/blob/view_blob_internals_job.cc index 2849cd6bfa2..34dc003e671 100644 --- a/chromium/storage/browser/blob/view_blob_internals_job.cc +++ b/chromium/storage/browser/blob/view_blob_internals_job.cc @@ -15,10 +15,10 @@ #include "base/i18n/time_formatting.h" #include "base/location.h" #include "base/notreached.h" -#include "base/single_thread_task_runner.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" +#include "base/task/single_thread_task_runner.h" #include "base/threading/thread_task_runner_handle.h" #include "net/base/escape.h" #include "net/base/net_errors.h" diff --git a/chromium/storage/browser/blob/view_blob_internals_job.h b/chromium/storage/browser/blob/view_blob_internals_job.h index 4e651f78d3f..6f437fbbdef 100644 --- a/chromium/storage/browser/blob/view_blob_internals_job.h +++ b/chromium/storage/browser/blob/view_blob_internals_job.h @@ -8,7 +8,6 @@ #include <string> #include "base/component_export.h" -#include "base/macros.h" #include "base/memory/weak_ptr.h" namespace storage { @@ -20,6 +19,9 @@ class BlobStorageContext; // state of blob registry. class COMPONENT_EXPORT(STORAGE_BROWSER) ViewBlobInternalsJob { public: + ViewBlobInternalsJob(const ViewBlobInternalsJob&) = delete; + ViewBlobInternalsJob& operator=(const ViewBlobInternalsJob&) = delete; + static std::string GenerateHTML(BlobStorageContext* blob_storage_context); private: @@ -28,8 +30,6 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) ViewBlobInternalsJob { const std::string& content_disposition, size_t refcount, std::string* out); - - DISALLOW_COPY_AND_ASSIGN(ViewBlobInternalsJob); }; } // namespace storage diff --git a/chromium/storage/browser/database/database_quota_client.cc b/chromium/storage/browser/database/database_quota_client.cc index da8579fead9..8240da802da 100644 --- a/chromium/storage/browser/database/database_quota_client.cc +++ b/chromium/storage/browser/database/database_quota_client.cc @@ -15,8 +15,8 @@ #include "base/callback_helpers.h" #include "base/location.h" #include "base/sequence_checker.h" -#include "base/sequenced_task_runner.h" -#include "base/task_runner_util.h" +#include "base/task/sequenced_task_runner.h" +#include "base/task/task_runner_util.h" #include "base/threading/sequenced_task_runner_handle.h" #include "net/base/completion_once_callback.h" #include "net/base/net_errors.h" diff --git a/chromium/storage/browser/database/database_quota_client.h b/chromium/storage/browser/database/database_quota_client.h index 2a43801d2a2..d4c9b427314 100644 --- a/chromium/storage/browser/database/database_quota_client.h +++ b/chromium/storage/browser/database/database_quota_client.h @@ -9,10 +9,9 @@ #include <string> #include "base/component_export.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/sequence_checker.h" -#include "base/single_thread_task_runner.h" +#include "base/task/single_thread_task_runner.h" #include "base/thread_annotations.h" #include "components/services/storage/public/cpp/storage_key_quota_client.h" #include "storage/browser/quota/quota_client_type.h" diff --git a/chromium/storage/browser/database/database_quota_client_unittest.cc b/chromium/storage/browser/database/database_quota_client_unittest.cc index 88fa9575363..06f0483ca51 100644 --- a/chromium/storage/browser/database/database_quota_client_unittest.cc +++ b/chromium/storage/browser/database/database_quota_client_unittest.cc @@ -16,8 +16,8 @@ #include "base/location.h" #include "base/memory/scoped_refptr.h" #include "base/run_loop.h" -#include "base/single_thread_task_runner.h" #include "base/strings/utf_string_conversions.h" +#include "base/task/single_thread_task_runner.h" #include "base/test/bind.h" #include "base/test/task_environment.h" #include "base/threading/sequenced_task_runner_handle.h" diff --git a/chromium/storage/browser/database/database_tracker.cc b/chromium/storage/browser/database/database_tracker.cc index c96e3fad1a7..842886e2fce 100644 --- a/chromium/storage/browser/database/database_tracker.cc +++ b/chromium/storage/browser/database/database_tracker.cc @@ -947,7 +947,7 @@ void DatabaseTracker::ClearSessionOnlyOrigins() { for (const auto& database : databases) { base::File file( GetFullDBFilePath(origin, database), - base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_SHARE_DELETE | + base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_WIN_SHARE_DELETE | base::File::FLAG_DELETE_ON_CLOSE | base::File::FLAG_READ); } DeleteOrigin(origin, true); diff --git a/chromium/storage/browser/database/database_tracker.h b/chromium/storage/browser/database/database_tracker.h index eb52fa940e1..63d2c3acc86 100644 --- a/chromium/storage/browser/database/database_tracker.h +++ b/chromium/storage/browser/database/database_tracker.h @@ -21,8 +21,8 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_refptr.h" #include "base/observer_list.h" -#include "base/sequenced_task_runner.h" #include "base/strings/string_util.h" +#include "base/task/sequenced_task_runner.h" #include "base/time/time.h" #include "base/types/pass_key.h" #include "components/services/storage/public/mojom/quota_client.mojom.h" diff --git a/chromium/storage/browser/database/database_tracker_unittest.cc b/chromium/storage/browser/database/database_tracker_unittest.cc index 86c10742c59..9a83aca64f4 100644 --- a/chromium/storage/browser/database/database_tracker_unittest.cc +++ b/chromium/storage/browser/database/database_tracker_unittest.cc @@ -18,7 +18,7 @@ #include "base/memory/ptr_util.h" #include "base/memory/scoped_refptr.h" #include "base/run_loop.h" -#include "base/sequenced_task_runner.h" +#include "base/task/sequenced_task_runner.h" #include "base/test/bind.h" #include "base/test/task_environment.h" #include "base/threading/sequenced_task_runner_handle.h" diff --git a/chromium/storage/browser/database/databases_table.h b/chromium/storage/browser/database/databases_table.h index fc7bc701a41..21f9c852833 100644 --- a/chromium/storage/browser/database/databases_table.h +++ b/chromium/storage/browser/database/databases_table.h @@ -11,6 +11,7 @@ #include <vector> #include "base/component_export.h" +#include "base/memory/raw_ptr.h" namespace sql { class Database; @@ -48,7 +49,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) DatabasesTable { std::vector<DatabaseDetails>* details); bool DeleteOriginIdentifier(const std::string& origin_identifier); private: - sql::Database* db_; + raw_ptr<sql::Database> db_; }; } // namespace storage diff --git a/chromium/storage/browser/database/vfs_backend.cc b/chromium/storage/browser/database/vfs_backend.cc index 98bb007fdc9..beb7d59db2a 100644 --- a/chromium/storage/browser/database/vfs_backend.cc +++ b/chromium/storage/browser/database/vfs_backend.cc @@ -79,7 +79,8 @@ base::File VfsBackend::OpenFile(const base::FilePath& file_path, flags |= base::File::FLAG_WRITE; if (!(desired_flags & SQLITE_OPEN_MAIN_DB)) - flags |= base::File::FLAG_EXCLUSIVE_READ | base::File::FLAG_EXCLUSIVE_WRITE; + flags |= base::File::FLAG_WIN_EXCLUSIVE_READ | + base::File::FLAG_WIN_EXCLUSIVE_WRITE; if (desired_flags & SQLITE_OPEN_CREATE) { flags |= (desired_flags & SQLITE_OPEN_EXCLUSIVE) @@ -90,13 +91,13 @@ base::File VfsBackend::OpenFile(const base::FilePath& file_path, } if (desired_flags & SQLITE_OPEN_DELETEONCLOSE) { - flags |= base::File::FLAG_TEMPORARY | base::File::FLAG_HIDDEN | + flags |= base::File::FLAG_WIN_TEMPORARY | base::File::FLAG_WIN_HIDDEN | base::File::FLAG_DELETE_ON_CLOSE; } // This flag will allow us to delete the file later on from the browser // process. - flags |= base::File::FLAG_SHARE_DELETE; + flags |= base::File::FLAG_WIN_SHARE_DELETE; // Try to open/create the DB file. return base::File(file_path, flags); diff --git a/chromium/storage/browser/file_system/async_file_util.h b/chromium/storage/browser/file_system/async_file_util.h index 2d89171abad..3f1b41a5f62 100644 --- a/chromium/storage/browser/file_system/async_file_util.h +++ b/chromium/storage/browser/file_system/async_file_util.h @@ -75,7 +75,7 @@ class AsyncFileUtil { using CopyFileProgressCallback = base::RepeatingCallback<void(int64_t size)>; - using CopyOrMoveOption = FileSystemOperation::CopyOrMoveOption; + using CopyOrMoveOptionSet = FileSystemOperation::CopyOrMoveOptionSet; using GetMetadataField = FileSystemOperation::GetMetadataField; // Creates an AsyncFileUtil instance which performs file operations on local @@ -227,7 +227,7 @@ class AsyncFileUtil { std::unique_ptr<FileSystemOperationContext> context, const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, CopyFileProgressCallback progress_callback, StatusCallback callback) = 0; @@ -250,7 +250,7 @@ class AsyncFileUtil { std::unique_ptr<FileSystemOperationContext> context, const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, StatusCallback callback) = 0; // Copies in a single file from a different filesystem. diff --git a/chromium/storage/browser/file_system/async_file_util_adapter.cc b/chromium/storage/browser/file_system/async_file_util_adapter.cc index a28d6f5760f..d1f31d8149f 100644 --- a/chromium/storage/browser/file_system/async_file_util_adapter.cc +++ b/chromium/storage/browser/file_system/async_file_util_adapter.cc @@ -12,9 +12,8 @@ #include <vector> #include "base/bind.h" -#include "base/macros.h" -#include "base/sequenced_task_runner.h" -#include "base/task_runner_util.h" +#include "base/task/sequenced_task_runner.h" +#include "base/task/task_runner_util.h" #include "base/threading/thread_task_runner_handle.h" #include "components/services/filesystem/public/mojom/types.mojom.h" #include "storage/browser/blob/shareable_file_reference.h" @@ -35,6 +34,9 @@ class EnsureFileExistsHelper { public: EnsureFileExistsHelper() : error_(base::File::FILE_OK), created_(false) {} + EnsureFileExistsHelper(const EnsureFileExistsHelper&) = delete; + EnsureFileExistsHelper& operator=(const EnsureFileExistsHelper&) = delete; + void RunWork(FileSystemFileUtil* file_util, FileSystemOperationContext* context, const FileSystemURL& url) { @@ -48,13 +50,15 @@ class EnsureFileExistsHelper { private: base::File::Error error_; bool created_; - DISALLOW_COPY_AND_ASSIGN(EnsureFileExistsHelper); }; class GetFileInfoHelper { public: GetFileInfoHelper() : error_(base::File::FILE_OK) {} + GetFileInfoHelper(const GetFileInfoHelper&) = delete; + GetFileInfoHelper& operator=(const GetFileInfoHelper&) = delete; + void GetFileInfo(FileSystemFileUtil* file_util, FileSystemOperationContext* context, const FileSystemURL& url, @@ -96,7 +100,6 @@ class GetFileInfoHelper { base::File::Info file_info_; base::FilePath platform_path_; ScopedFile scoped_file_; - DISALLOW_COPY_AND_ASSIGN(GetFileInfoHelper); }; void ReadDirectoryHelper(FileSystemFileUtil* file_util, @@ -283,7 +286,7 @@ void AsyncFileUtilAdapter::CopyFileLocal( std::unique_ptr<FileSystemOperationContext> context, const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, CopyFileProgressCallback progress_callback, StatusCallback callback) { // TODO(hidehiko): Support progress_callback. @@ -292,7 +295,7 @@ void AsyncFileUtilAdapter::CopyFileLocal( context_ptr->task_runner(), FROM_HERE, base::BindOnce(&FileSystemFileUtil::CopyOrMoveFile, Unretained(sync_file_util_.get()), - base::Owned(context_ptr), src_url, dest_url, option, + base::Owned(context_ptr), src_url, dest_url, options, true /* copy */), std::move(callback)); DCHECK(success); @@ -302,14 +305,14 @@ void AsyncFileUtilAdapter::MoveFileLocal( std::unique_ptr<FileSystemOperationContext> context, const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, StatusCallback callback) { FileSystemOperationContext* context_ptr = context.release(); const bool success = base::PostTaskAndReplyWithResult( context_ptr->task_runner(), FROM_HERE, base::BindOnce(&FileSystemFileUtil::CopyOrMoveFile, Unretained(sync_file_util_.get()), - base::Owned(context_ptr), src_url, dest_url, option, + base::Owned(context_ptr), src_url, dest_url, options, false /* copy */), std::move(callback)); DCHECK(success); diff --git a/chromium/storage/browser/file_system/async_file_util_adapter.h b/chromium/storage/browser/file_system/async_file_util_adapter.h index c04e9b23b26..bb9cb2e8d13 100644 --- a/chromium/storage/browser/file_system/async_file_util_adapter.h +++ b/chromium/storage/browser/file_system/async_file_util_adapter.h @@ -10,7 +10,6 @@ #include <memory> #include "base/component_export.h" -#include "base/macros.h" #include "base/memory/ptr_util.h" #include "storage/browser/file_system/async_file_util.h" @@ -73,13 +72,13 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) AsyncFileUtilAdapter void CopyFileLocal(std::unique_ptr<FileSystemOperationContext> context, const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, CopyFileProgressCallback progress_callback, StatusCallback callback) override; void MoveFileLocal(std::unique_ptr<FileSystemOperationContext> context, const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, StatusCallback callback) override; void CopyInForeignFile(std::unique_ptr<FileSystemOperationContext> context, const base::FilePath& src_file_path, diff --git a/chromium/storage/browser/file_system/copy_or_move_file_validator_unittest.cc b/chromium/storage/browser/file_system/copy_or_move_file_validator_unittest.cc index 6442b318ecd..b09f6497a44 100644 --- a/chromium/storage/browser/file_system/copy_or_move_file_validator_unittest.cc +++ b/chromium/storage/browser/file_system/copy_or_move_file_validator_unittest.cc @@ -13,9 +13,8 @@ #include "base/files/file_path.h" #include "base/files/scoped_temp_dir.h" #include "base/location.h" -#include "base/macros.h" #include "base/run_loop.h" -#include "base/single_thread_task_runner.h" +#include "base/task/single_thread_task_runner.h" #include "base/test/task_environment.h" #include "base/threading/thread_task_runner_handle.h" #include "storage/browser/blob/shareable_file_reference.h" diff --git a/chromium/storage/browser/file_system/copy_or_move_operation_delegate.cc b/chromium/storage/browser/file_system/copy_or_move_operation_delegate.cc index d77fcad8211..05a61084e32 100644 --- a/chromium/storage/browser/file_system/copy_or_move_operation_delegate.cc +++ b/chromium/storage/browser/file_system/copy_or_move_operation_delegate.cc @@ -13,7 +13,7 @@ #include "base/bind.h" #include "base/callback_helpers.h" #include "base/files/file_path.h" -#include "base/macros.h" +#include "base/memory/raw_ptr.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" #include "storage/browser/blob/shareable_file_reference.h" @@ -39,19 +39,23 @@ class CopyOrMoveOperationDelegate::CopyOrMoveImpl { virtual void Run(CopyOrMoveOperationDelegate::StatusCallback callback) = 0; virtual void Cancel() = 0; + // Force any file copy to result in an error. This affects copies or + // cross-filesystem moves. + void ForceCopyErrorForTest() { force_error_for_test_ = true; } + protected: CopyOrMoveImpl( FileSystemOperationRunner* operation_runner, const CopyOrMoveOperationDelegate::OperationType operation_type, const FileSystemURL& src_url, const FileSystemURL& dest_url, - const CopyOrMoveOperationDelegate::CopyOrMoveOption option, + const CopyOrMoveOperationDelegate::CopyOrMoveOptionSet options, FileSystemOperation::CopyOrMoveProgressCallback progress_callback) : operation_runner_(operation_runner), operation_type_(operation_type), src_url_(src_url), dest_url_(dest_url), - option_(option), + options_(options), progress_callback_(std::move(progress_callback)) {} // Callback for sending progress events with the current number of processed @@ -80,6 +84,19 @@ class CopyOrMoveOperationDelegate::CopyOrMoveImpl { } } + if (options_.Has(FileSystemOperation::CopyOrMoveOption:: + kRemovePartiallyCopiedFilesOnError) && + error != base::File::FILE_OK && + error != base::File::FILE_ERROR_NOT_A_FILE) { + // On error, remove the destination file. + operation_runner_->Remove( + dest_url_, /*recursive=*/false, + base::BindOnce(&CopyOrMoveImpl::DidRemoveDestOnError, + weak_factory_.GetWeakPtr(), error, + std::move(callback))); + return; + } + // The callback should be called in case of copy or error. The callback is // null if the operation type is OPERATION_MOVE (implemented as copy + // delete) and no error occurred. @@ -124,14 +141,32 @@ class CopyOrMoveOperationDelegate::CopyOrMoveImpl { std::move(callback).Run(error); } - FileSystemOperationRunner* const operation_runner_; + void DidRemoveDestOnError( + base::File::Error prior_error, + CopyOrMoveOperationDelegate::StatusCallback callback, + base::File::Error error) { + if (error != base::File::FILE_OK) { + VLOG(1) << "Error removing destination file after copy error or " + "cancellation: " + << error; + } + // The callback is null if the operation type is OPERATION_MOVE (implemented + // as copy + delete) and no error occurred. + if (!callback.is_null()) { + std::move(callback).Run(prior_error); + } + } + + const raw_ptr<FileSystemOperationRunner> operation_runner_; const CopyOrMoveOperationDelegate::OperationType operation_type_; const FileSystemURL src_url_; const FileSystemURL dest_url_; - const CopyOrMoveOperationDelegate::CopyOrMoveOption option_; + const CopyOrMoveOperationDelegate::CopyOrMoveOptionSet options_; + bool force_error_for_test_ = false; private: const FileSystemOperation::CopyOrMoveProgressCallback progress_callback_; + base::WeakPtrFactory<CopyOrMoveImpl> weak_factory_{this}; }; namespace { @@ -146,24 +181,29 @@ class CopyOrMoveOnSameFileSystemImpl const CopyOrMoveOperationDelegate::OperationType operation_type, const FileSystemURL& src_url, const FileSystemURL& dest_url, - const CopyOrMoveOperationDelegate::CopyOrMoveOption option, + const CopyOrMoveOperationDelegate::CopyOrMoveOptionSet options, FileSystemOperation::CopyOrMoveProgressCallback progress_callback) : CopyOrMoveImpl(operation_runner, operation_type, src_url, dest_url, - option, + options, progress_callback) {} + CopyOrMoveOnSameFileSystemImpl(const CopyOrMoveOnSameFileSystemImpl&) = + delete; + CopyOrMoveOnSameFileSystemImpl& operator=( + const CopyOrMoveOnSameFileSystemImpl&) = delete; + void Run(CopyOrMoveOperationDelegate::StatusCallback callback) override { if (operation_type_ == CopyOrMoveOperationDelegate::OPERATION_MOVE) { operation_runner_->MoveFileLocal( - src_url_, dest_url_, option_, + src_url_, dest_url_, options_, base::BindOnce(&CopyOrMoveOnSameFileSystemImpl::DidEndMove, weak_factory_.GetWeakPtr(), std::move(callback))); } else { operation_runner_->CopyFileLocal( - src_url_, dest_url_, option_, + src_url_, dest_url_, options_, base::BindRepeating( &CopyOrMoveOnSameFileSystemImpl::OnCopyOrMoveFileProgress, weak_factory_.GetWeakPtr()), @@ -180,7 +220,6 @@ class CopyOrMoveOnSameFileSystemImpl private: base::WeakPtrFactory<CopyOrMoveOnSameFileSystemImpl> weak_factory_{this}; - DISALLOW_COPY_AND_ASSIGN(CopyOrMoveOnSameFileSystemImpl); }; // Specifically for cross file system copy/move operation, this class creates @@ -195,19 +234,22 @@ class SnapshotCopyOrMoveImpl CopyOrMoveOperationDelegate::OperationType operation_type, const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOperationDelegate::CopyOrMoveOption option, + CopyOrMoveOperationDelegate::CopyOrMoveOptionSet options, CopyOrMoveFileValidatorFactory* validator_factory, FileSystemOperation::CopyOrMoveProgressCallback progress_callback) : CopyOrMoveImpl(operation_runner, operation_type, src_url, dest_url, - option, + options, progress_callback), validator_factory_(validator_factory), cancel_requested_(false) {} + SnapshotCopyOrMoveImpl(const SnapshotCopyOrMoveImpl&) = delete; + SnapshotCopyOrMoveImpl& operator=(const SnapshotCopyOrMoveImpl&) = delete; + void Run(CopyOrMoveOperationDelegate::StatusCallback callback) override { OnCopyOrMoveFileProgress(0); operation_runner_->CreateSnapshotFile( @@ -290,7 +332,7 @@ class SnapshotCopyOrMoveImpl OnCopyOrMoveFileProgress(file_info.size); - if (option_ == FileSystemOperation::OPTION_NONE) { + if (options_.Empty()) { RunAfterTouchFile(std::move(callback), base::File::FILE_OK); return; } @@ -326,6 +368,9 @@ class SnapshotCopyOrMoveImpl void RunAfterPostWriteValidation( CopyOrMoveOperationDelegate::StatusCallback callback, base::File::Error error) { + if (force_error_for_test_) { + error = base::File::FILE_ERROR_FAILED; + } if (cancel_requested_) { DidEndCopy(std::move(callback), base::File::FILE_ERROR_ABORT); return; @@ -433,11 +478,10 @@ class SnapshotCopyOrMoveImpl std::move(callback).Run(error); } - CopyOrMoveFileValidatorFactory* validator_factory_; + raw_ptr<CopyOrMoveFileValidatorFactory> validator_factory_; std::unique_ptr<CopyOrMoveFileValidator> validator_; bool cancel_requested_; base::WeakPtrFactory<SnapshotCopyOrMoveImpl> weak_factory_{this}; - DISALLOW_COPY_AND_ASSIGN(SnapshotCopyOrMoveImpl); }; // The size of buffer for StreamCopyHelper. @@ -459,7 +503,7 @@ class StreamCopyOrMoveImpl CopyOrMoveOperationDelegate::OperationType operation_type, const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOperationDelegate::CopyOrMoveOption option, + CopyOrMoveOperationDelegate::CopyOrMoveOptionSet options, std::unique_ptr<FileStreamReader> reader, std::unique_ptr<FileStreamWriter> writer, FileSystemOperation::CopyOrMoveProgressCallback progress_callback) @@ -467,13 +511,16 @@ class StreamCopyOrMoveImpl operation_type, src_url, dest_url, - option, + options, progress_callback), file_system_context_(file_system_context), reader_(std::move(reader)), writer_(std::move(writer)), cancel_requested_(false) {} + StreamCopyOrMoveImpl(const StreamCopyOrMoveImpl&) = delete; + StreamCopyOrMoveImpl& operator=(const StreamCopyOrMoveImpl&) = delete; + void Run(CopyOrMoveOperationDelegate::StatusCallback callback) override { // Reader can be created even if the entry does not exist or the entry is // a directory. To check errors before destination file creation, @@ -607,6 +654,9 @@ class StreamCopyOrMoveImpl NotifyOnModifyFile(dest_url_); NotifyOnEndUpdate(dest_url_); + if (force_error_for_test_) { + error = base::File::FILE_ERROR_FAILED; + } if (cancel_requested_) error = base::File::FILE_ERROR_ABORT; @@ -615,7 +665,7 @@ class StreamCopyOrMoveImpl return; } - if (option_ == FileSystemOperation::OPTION_NONE) { + if (options_.Empty()) { RunAfterTouchFile(std::move(callback), base::File::FILE_OK); return; } @@ -668,7 +718,6 @@ class StreamCopyOrMoveImpl std::unique_ptr<CopyOrMoveOperationDelegate::StreamCopyHelper> copy_helper_; bool cancel_requested_; base::WeakPtrFactory<StreamCopyOrMoveImpl> weak_factory_{this}; - DISALLOW_COPY_AND_ASSIGN(StreamCopyOrMoveImpl); }; } // namespace @@ -815,7 +864,7 @@ CopyOrMoveOperationDelegate::CopyOrMoveOperationDelegate( const FileSystemURL& src_root, const FileSystemURL& dest_root, OperationType operation_type, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, ErrorBehavior error_behavior, const CopyOrMoveProgressCallback& progress_callback, StatusCallback callback) @@ -823,11 +872,15 @@ CopyOrMoveOperationDelegate::CopyOrMoveOperationDelegate( src_root_(src_root), dest_root_(dest_root), operation_type_(operation_type), - option_(option), + options_(options), error_behavior_(error_behavior), progress_callback_(progress_callback), callback_(std::move(callback)) { - same_file_system_ = src_root_.IsInSameFileSystem(dest_root_); + // Force same_file_system_ = false if options include kForceCrossFilesystem. + same_file_system_ = + !options.Has( + FileSystemOperation::CopyOrMoveOption::kForceCrossFilesystem) && + src_root_.IsInSameFileSystem(dest_root_); } CopyOrMoveOperationDelegate::~CopyOrMoveOperationDelegate() = default; @@ -881,7 +934,7 @@ void CopyOrMoveOperationDelegate::ProcessFile(const FileSystemURL& src_url, ->HasInplaceCopyImplementation(src_url.type()) || operation_type_ == OPERATION_MOVE)) { impl = std::make_unique<CopyOrMoveOnSameFileSystemImpl>( - operation_runner(), operation_type_, src_url, dest_url, option_, + operation_runner(), operation_type_, src_url, dest_url, options_, progress_callback_); } else { // Cross filesystem case. @@ -908,22 +961,24 @@ void CopyOrMoveOperationDelegate::ProcessFile(const FileSystemURL& src_url, if (reader && writer) { impl = std::make_unique<StreamCopyOrMoveImpl>( operation_runner(), file_system_context(), operation_type_, src_url, - dest_url, option_, std::move(reader), std::move(writer), + dest_url, options_, std::move(reader), std::move(writer), progress_callback_); } } if (!impl) { impl = std::make_unique<SnapshotCopyOrMoveImpl>( - operation_runner(), operation_type_, src_url, dest_url, option_, + operation_runner(), operation_type_, src_url, dest_url, options_, validator_factory, progress_callback_); } } // Register the running task. - CopyOrMoveImpl* impl_ptr = impl.get(); running_copy_set_[impl_ptr] = std::move(impl); + if (src_url == error_url_for_test_) { + impl_ptr->ForceCopyErrorForTest(); // IN-TEST + } impl_ptr->Run(base::BindOnce(&CopyOrMoveOperationDelegate::DidCopyOrMoveFile, weak_factory_.GetWeakPtr(), std::move(callback), impl_ptr)); @@ -957,7 +1012,7 @@ void CopyOrMoveOperationDelegate::ProcessDirectory(const FileSystemURL& src_url, void CopyOrMoveOperationDelegate::PostProcessDirectory( const FileSystemURL& src_url, StatusCallback callback) { - if (option_ == FileSystemOperation::OPTION_NONE) { + if (options_.Empty()) { PostProcessDirectoryAfterTouchFile(src_url, std::move(callback), base::File::FILE_OK); return; diff --git a/chromium/storage/browser/file_system/copy_or_move_operation_delegate.h b/chromium/storage/browser/file_system/copy_or_move_operation_delegate.h index e2501b032c7..ec3a3db7965 100644 --- a/chromium/storage/browser/file_system/copy_or_move_operation_delegate.h +++ b/chromium/storage/browser/file_system/copy_or_move_operation_delegate.h @@ -11,7 +11,6 @@ #include <memory> #include "base/component_export.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/time/time.h" #include "storage/browser/file_system/recursive_operation_delegate.h" @@ -28,12 +27,13 @@ class FileStreamWriter; enum class FlushPolicy; // A delegate class for recursive copy or move operations. -class CopyOrMoveOperationDelegate : public RecursiveOperationDelegate { +class COMPONENT_EXPORT(STORAGE_BROWSER) CopyOrMoveOperationDelegate + : public RecursiveOperationDelegate { public: class CopyOrMoveImpl; using CopyOrMoveProgressCallback = FileSystemOperation::CopyOrMoveProgressCallback; - using CopyOrMoveOption = FileSystemOperation::CopyOrMoveOption; + using CopyOrMoveOptionSet = FileSystemOperation::CopyOrMoveOptionSet; using ErrorBehavior = FileSystemOperation::ErrorBehavior; enum OperationType { OPERATION_COPY, OPERATION_MOVE }; @@ -93,10 +93,15 @@ class CopyOrMoveOperationDelegate : public RecursiveOperationDelegate { const FileSystemURL& src_root, const FileSystemURL& dest_root, OperationType operation_type, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, ErrorBehavior error_behavior, const CopyOrMoveProgressCallback& progress_callback, StatusCallback callback); + + CopyOrMoveOperationDelegate(const CopyOrMoveOperationDelegate&) = delete; + CopyOrMoveOperationDelegate& operator=(const CopyOrMoveOperationDelegate&) = + delete; + ~CopyOrMoveOperationDelegate() override; // RecursiveOperationDelegate overrides: @@ -107,6 +112,11 @@ class CopyOrMoveOperationDelegate : public RecursiveOperationDelegate { StatusCallback callback) override; void PostProcessDirectory(const FileSystemURL& url, StatusCallback callback) override; + // Force a given source URL to produce an error for a copy or a + // cross-filesystem move. + void SetErrorUrlForTest(const FileSystemURL& url) { + error_url_for_test_ = url; + } protected: void OnCancel() override; @@ -144,15 +154,14 @@ class CopyOrMoveOperationDelegate : public RecursiveOperationDelegate { const FileSystemURL dest_root_; bool same_file_system_; const OperationType operation_type_; - const CopyOrMoveOption option_; + const CopyOrMoveOptionSet options_; const ErrorBehavior error_behavior_; const CopyOrMoveProgressCallback progress_callback_; StatusCallback callback_; + FileSystemURL error_url_for_test_; std::map<CopyOrMoveImpl*, std::unique_ptr<CopyOrMoveImpl>> running_copy_set_; base::WeakPtrFactory<CopyOrMoveOperationDelegate> weak_factory_{this}; - - DISALLOW_COPY_AND_ASSIGN(CopyOrMoveOperationDelegate); }; } // namespace storage diff --git a/chromium/storage/browser/file_system/copy_or_move_operation_delegate_unittest.cc b/chromium/storage/browser/file_system/copy_or_move_operation_delegate_unittest.cc index 0bfe16eeaa7..a5c5349b6a5 100644 --- a/chromium/storage/browser/file_system/copy_or_move_operation_delegate_unittest.cc +++ b/chromium/storage/browser/file_system/copy_or_move_operation_delegate_unittest.cc @@ -17,10 +17,10 @@ #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" #include "base/location.h" -#include "base/macros.h" +#include "base/memory/raw_ptr.h" #include "base/memory/scoped_refptr.h" #include "base/run_loop.h" -#include "base/single_thread_task_runner.h" +#include "base/task/single_thread_task_runner.h" #include "base/test/task_environment.h" #include "base/threading/thread_task_runner_handle.h" #include "components/services/filesystem/public/mojom/types.mojom.h" @@ -53,6 +53,8 @@ using FileEntryList = FileSystemOperation::FileEntryList; namespace { +constexpr int64_t kDefaultFileSize = 10; + void ExpectOk(const GURL& origin_url, const std::string& name, base::File::Error error) { @@ -168,7 +170,7 @@ class ScopedThreadStopper { bool is_valid() const { return thread_; } private: - base::Thread* thread_; + raw_ptr<base::Thread> thread_; }; } // namespace @@ -1023,4 +1025,259 @@ TEST(LocalFileSystemCopyOrMoveOperationTest, StreamCopyHelper_Cancel) { EXPECT_EQ(base::File::FILE_ERROR_ABORT, error); } +class CopyOrMoveOperationDelegateTestHelper { + public: + CopyOrMoveOperationDelegateTestHelper( + const std::string& origin, + FileSystemType src_type, + FileSystemType dest_type, + FileSystemOperation::CopyOrMoveOptionSet options) + : origin_(url::Origin::Create(GURL(origin))), + src_type_(src_type), + dest_type_(dest_type), + options_(options), + task_environment_(base::test::TaskEnvironment::MainThreadType::IO) {} + + CopyOrMoveOperationDelegateTestHelper( + const CopyOrMoveOperationDelegateTestHelper&) = delete; + CopyOrMoveOperationDelegateTestHelper& operator=( + const CopyOrMoveOperationDelegateTestHelper&) = delete; + + ~CopyOrMoveOperationDelegateTestHelper() { + file_system_context_ = nullptr; + task_environment_.RunUntilIdle(); + } + + void SetUp() { + ASSERT_TRUE(base_.CreateUniqueTempDir()); + base::FilePath base_dir = base_.GetPath(); + file_system_context_ = + storage::CreateFileSystemContextForTesting(nullptr, base_dir); + + // Prepare the origin's root directory. + FileSystemBackend* backend = + file_system_context_->GetFileSystemBackend(src_type_); + backend->ResolveURL( + FileSystemURL::CreateForTest(blink::StorageKey(url::Origin(origin_)), + src_type_, base::FilePath()), + OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, base::BindOnce(&ExpectOk)); + backend = file_system_context_->GetFileSystemBackend(dest_type_); + backend->ResolveURL( + FileSystemURL::CreateForTest(blink::StorageKey(url::Origin(origin_)), + dest_type_, base::FilePath()), + OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, base::BindOnce(&ExpectOk)); + task_environment_.RunUntilIdle(); + } + + FileSystemURL GenerateSourceUrlFromPath(const std::string& path) { + return file_system_context_->CreateCrackedFileSystemURL( + blink::StorageKey(origin_), src_type_, + base::FilePath::FromUTF8Unsafe(path)); + } + + FileSystemURL GenerateDestinationUrlFromPath(const std::string& path) { + return file_system_context_->CreateCrackedFileSystemURL( + blink::StorageKey(origin_), dest_type_, + base::FilePath::FromUTF8Unsafe(path)); + } + + base::File::Error CreateFile(const FileSystemURL& url, size_t size) { + base::File::Error result = + AsyncFileTestHelper::CreateFile(file_system_context_.get(), url); + if (result != base::File::FILE_OK) + return result; + return AsyncFileTestHelper::TruncateFile(file_system_context_.get(), url, + size); + } + + base::File::Error CreateDirectory(const FileSystemURL& url) { + return AsyncFileTestHelper::CreateDirectory(file_system_context_.get(), + url); + } + + bool FileExists(const FileSystemURL& url, int64_t expected_size) { + return AsyncFileTestHelper::FileExists(file_system_context_.get(), url, + expected_size); + } + + bool DirectoryExists(const FileSystemURL& url) { + return AsyncFileTestHelper::DirectoryExists(file_system_context_.get(), + url); + } + + // Force Copy or Move error when a given URL is encountered. + void SetErrorUrl(const FileSystemURL& url) { error_url_ = url; } + + base::File::Error Copy(const FileSystemURL& src, const FileSystemURL& dest) { + base::RunLoop run_loop; + base::File::Error result = base::File::FILE_ERROR_FAILED; + + CopyOrMoveOperationDelegate copy_or_move_operation_delegate( + file_system_context_.get(), src, dest, + CopyOrMoveOperationDelegate::OPERATION_COPY, options_, + FileSystemOperation::ERROR_BEHAVIOR_ABORT, + FileSystemOperation::CopyOrMoveProgressCallback(), + base::BindOnce(&AssignAndQuit, &run_loop, base::Unretained(&result))); + if (error_url_.is_valid()) { + copy_or_move_operation_delegate.SetErrorUrlForTest(error_url_); + } + copy_or_move_operation_delegate.RunRecursively(); + run_loop.Run(); + return result; + } + + base::File::Error Move(const FileSystemURL& src, const FileSystemURL& dest) { + base::RunLoop run_loop; + base::File::Error result = base::File::FILE_ERROR_FAILED; + + CopyOrMoveOperationDelegate copy_or_move_operation_delegate( + file_system_context_.get(), src, dest, + CopyOrMoveOperationDelegate::OPERATION_MOVE, options_, + FileSystemOperation::ERROR_BEHAVIOR_ABORT, + FileSystemOperation::CopyOrMoveProgressCallback(), + base::BindOnce(&AssignAndQuit, &run_loop, base::Unretained(&result))); + if (error_url_.is_valid()) { + copy_or_move_operation_delegate.SetErrorUrlForTest(error_url_); + } + copy_or_move_operation_delegate.RunRecursively(); + run_loop.Run(); + return result; + } + + private: + base::ScopedTempDir base_; + + const url::Origin origin_; + const FileSystemType src_type_; + const FileSystemType dest_type_; + FileSystemOperation::CopyOrMoveOptionSet options_; + + FileSystemURL error_url_; + + base::test::TaskEnvironment task_environment_; + scoped_refptr<FileSystemContext> file_system_context_; +}; + +TEST(CopyOrMoveOperationDelegateTest, StopRecursionOnCopyError) { + FileSystemOperation::CopyOrMoveOptionSet options; + CopyOrMoveOperationDelegateTestHelper helper( + "http://foo", kFileSystemTypePersistent, kFileSystemTypePersistent, + options); + helper.SetUp(); + + FileSystemURL src = helper.GenerateSourceUrlFromPath("a"); + FileSystemURL src_file_1 = helper.GenerateSourceUrlFromPath("a/file 1"); + FileSystemURL src_file_2 = helper.GenerateSourceUrlFromPath("a/file 2"); + FileSystemURL dest = helper.GenerateDestinationUrlFromPath("b"); + FileSystemURL dest_file_1 = helper.GenerateDestinationUrlFromPath("b/file 1"); + FileSystemURL dest_file_2 = helper.GenerateDestinationUrlFromPath("b/file 2"); + + // Set up source files. + ASSERT_EQ(base::File::FILE_OK, helper.CreateDirectory(src)); + ASSERT_EQ(base::File::FILE_OK, + helper.CreateFile(src_file_1, kDefaultFileSize)); + ASSERT_EQ(base::File::FILE_OK, + helper.CreateFile(src_file_2, kDefaultFileSize)); + + // [file 1, file 2] are processed as a LIFO. An error is returned after + // copying file 2. + helper.SetErrorUrl(src_file_2); + ASSERT_EQ(base::File::FILE_ERROR_FAILED, helper.Copy(src, dest)); + + EXPECT_TRUE(helper.DirectoryExists(src)); + EXPECT_TRUE(helper.DirectoryExists(dest)); + // Check: file 2 is copied, even though the copy results in an error. + EXPECT_TRUE(helper.FileExists(src_file_2, kDefaultFileSize)); + EXPECT_TRUE( + helper.FileExists(dest_file_2, AsyncFileTestHelper::kDontCheckSize)); + // Check: the recursion has been interrupted after the error, so file 1 hasn't + // been copied. + EXPECT_TRUE(helper.FileExists(src_file_1, kDefaultFileSize)); + EXPECT_FALSE( + helper.FileExists(dest_file_1, AsyncFileTestHelper::kDontCheckSize)); +} + +TEST(CopyOrMoveOperationDelegateTest, RemoveDestFileOnCopyError) { + FileSystemOperation::CopyOrMoveOptionSet options( + storage::FileSystemOperation::CopyOrMoveOption:: + kRemovePartiallyCopiedFilesOnError); + CopyOrMoveOperationDelegateTestHelper helper( + "http://foo", kFileSystemTypePersistent, kFileSystemTypePersistent, + options); + helper.SetUp(); + + FileSystemURL src = helper.GenerateSourceUrlFromPath("a"); + FileSystemURL src_file_1 = helper.GenerateSourceUrlFromPath("a/file 1"); + FileSystemURL src_file_2 = helper.GenerateSourceUrlFromPath("a/file 2"); + FileSystemURL dest = helper.GenerateDestinationUrlFromPath("b"); + FileSystemURL dest_file_1 = helper.GenerateDestinationUrlFromPath("b/file 1"); + FileSystemURL dest_file_2 = helper.GenerateDestinationUrlFromPath("b/file 2"); + + // Set up source files. + ASSERT_EQ(base::File::FILE_OK, helper.CreateDirectory(src)); + ASSERT_EQ(base::File::FILE_OK, + helper.CreateFile(src_file_1, kDefaultFileSize)); + ASSERT_EQ(base::File::FILE_OK, + helper.CreateFile(src_file_2, kDefaultFileSize)); + + // [file 1, file 2] are processed as a LIFO. An error is returned after + // copying file 1. + helper.SetErrorUrl(src_file_1); + ASSERT_EQ(base::File::FILE_ERROR_FAILED, helper.Copy(src, dest)); + + EXPECT_TRUE(helper.DirectoryExists(src)); + EXPECT_TRUE(helper.DirectoryExists(dest)); + // Check: file 2 is properly copied. + EXPECT_TRUE(helper.FileExists(src_file_2, kDefaultFileSize)); + EXPECT_TRUE(helper.FileExists(dest_file_2, kDefaultFileSize)); + // Check: file 1 has been removed on error after being copied. + EXPECT_TRUE(helper.FileExists(src_file_1, kDefaultFileSize)); + EXPECT_FALSE( + helper.FileExists(dest_file_1, AsyncFileTestHelper::kDontCheckSize)); +} + +TEST(CopyOrMoveOperationDelegateTest, + RemoveDestFileOnCrossFilesystemMoveError) { + FileSystemOperation::CopyOrMoveOptionSet options( + storage::FileSystemOperation::CopyOrMoveOption:: + kRemovePartiallyCopiedFilesOnError); + // Removing destination files on Move errors applies only to cross-filesystem + // moves. + CopyOrMoveOperationDelegateTestHelper helper( + "http://foo", kFileSystemTypeTemporary, kFileSystemTypePersistent, + options); + helper.SetUp(); + + FileSystemURL src = helper.GenerateSourceUrlFromPath("a"); + FileSystemURL src_file_1 = helper.GenerateSourceUrlFromPath("a/file 1"); + FileSystemURL src_file_2 = helper.GenerateSourceUrlFromPath("a/file 2"); + FileSystemURL dest = helper.GenerateDestinationUrlFromPath("b"); + FileSystemURL dest_file_1 = helper.GenerateDestinationUrlFromPath("b/file 1"); + FileSystemURL dest_file_2 = helper.GenerateDestinationUrlFromPath("b/file 2"); + + // Set up source files. + ASSERT_EQ(base::File::FILE_OK, helper.CreateDirectory(src)); + ASSERT_EQ(base::File::FILE_OK, + helper.CreateFile(src_file_1, kDefaultFileSize)); + ASSERT_EQ(base::File::FILE_OK, + helper.CreateFile(src_file_2, kDefaultFileSize)); + + // [file 1, file 2] are processed as a LIFO. An error is returned after + // copying file 1. + helper.SetErrorUrl(src_file_1); + ASSERT_EQ(base::File::FILE_ERROR_FAILED, helper.Move(src, dest)); + + EXPECT_TRUE(helper.DirectoryExists(src)); + EXPECT_TRUE(helper.DirectoryExists(dest)); + // Check: file 2 is moved. + EXPECT_FALSE( + helper.FileExists(src_file_2, AsyncFileTestHelper::kDontCheckSize)); + EXPECT_TRUE(helper.FileExists(dest_file_2, kDefaultFileSize)); + // Check: destination file 1 has been removed on error, and its source still + // exists. + EXPECT_TRUE(helper.FileExists(src_file_1, kDefaultFileSize)); + EXPECT_FALSE( + helper.FileExists(dest_file_1, AsyncFileTestHelper::kDontCheckSize)); +} + } // namespace storage diff --git a/chromium/storage/browser/file_system/dragged_file_util.h b/chromium/storage/browser/file_system/dragged_file_util.h index 9440c077a9b..4c9c0993adf 100644 --- a/chromium/storage/browser/file_system/dragged_file_util.h +++ b/chromium/storage/browser/file_system/dragged_file_util.h @@ -8,7 +8,6 @@ #include <memory> #include "base/component_export.h" -#include "base/macros.h" #include "storage/browser/file_system/local_file_util.h" namespace storage { diff --git a/chromium/storage/browser/file_system/dragged_file_util_unittest.cc b/chromium/storage/browser/file_system/dragged_file_util_unittest.cc index 0db456a531d..20c902e9612 100644 --- a/chromium/storage/browser/file_system/dragged_file_util_unittest.cc +++ b/chromium/storage/browser/file_system/dragged_file_util_unittest.cc @@ -16,7 +16,6 @@ #include "base/files/file_enumerator.h" #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" -#include "base/macros.h" #include "base/test/task_environment.h" #include "base/time/time.h" #include "build/build_config.h" @@ -98,6 +97,9 @@ class DraggedFileUtilTest : public testing::Test { public: DraggedFileUtilTest() = default; + DraggedFileUtilTest(const DraggedFileUtilTest&) = delete; + DraggedFileUtilTest& operator=(const DraggedFileUtilTest&) = delete; + void SetUp() override { ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); ASSERT_TRUE(partition_dir_.CreateUniqueTempDir()); @@ -280,7 +282,6 @@ class DraggedFileUtilTest : public testing::Test { scoped_refptr<FileSystemContext> file_system_context_; std::map<base::FilePath, base::FilePath> toplevel_root_map_; std::unique_ptr<DraggedFileUtil> file_util_; - DISALLOW_COPY_AND_ASSIGN(DraggedFileUtilTest); }; TEST_F(DraggedFileUtilTest, BasicTest) { diff --git a/chromium/storage/browser/file_system/external_mount_points.cc b/chromium/storage/browser/file_system/external_mount_points.cc index 2426477fb66..6ee8f8aa5f5 100644 --- a/chromium/storage/browser/file_system/external_mount_points.cc +++ b/chromium/storage/browser/file_system/external_mount_points.cc @@ -9,7 +9,6 @@ #include "base/files/file_path.h" #include "base/lazy_instance.h" -#include "base/macros.h" #include "build/chromeos_buildflags.h" #include "storage/browser/file_system/file_system_url.h" #include "third_party/blink/public/common/storage_key/storage_key.h" diff --git a/chromium/storage/browser/file_system/external_mount_points.h b/chromium/storage/browser/file_system/external_mount_points.h index 660a7c550b5..fe832b831ff 100644 --- a/chromium/storage/browser/file_system/external_mount_points.h +++ b/chromium/storage/browser/file_system/external_mount_points.h @@ -11,7 +11,6 @@ #include <vector> #include "base/component_export.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/synchronization/lock.h" #include "storage/browser/file_system/mount_points.h" @@ -45,6 +44,9 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) ExternalMountPoints static ExternalMountPoints* GetSystemInstance(); static scoped_refptr<ExternalMountPoints> CreateRefCounted(); + ExternalMountPoints(const ExternalMountPoints&) = delete; + ExternalMountPoints& operator=(const ExternalMountPoints&) = delete; + // Registers a new named external filesystem. // The |path| is registered as the root path of the mount point which // is identified by a URL "filesystem:.../external/mount_name". @@ -156,8 +158,6 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) ExternalMountPoints // Reverse map from registered path to its corresponding mount name. std::map<base::FilePath, std::string> path_to_name_map_; - - DISALLOW_COPY_AND_ASSIGN(ExternalMountPoints); }; } // namespace storage diff --git a/chromium/storage/browser/file_system/external_mount_points_unittest.cc b/chromium/storage/browser/file_system/external_mount_points_unittest.cc index 5a72caae4b9..c4f0b7fe4e9 100644 --- a/chromium/storage/browser/file_system/external_mount_points_unittest.cc +++ b/chromium/storage/browser/file_system/external_mount_points_unittest.cc @@ -10,7 +10,6 @@ #include "base/cxx17_backports.h" #include "base/files/file_path.h" -#include "base/macros.h" #include "storage/browser/file_system/file_system_url.h" #include "storage/common/file_system/file_system_mount_option.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/chromium/storage/browser/file_system/file_stream_reader_test.h b/chromium/storage/browser/file_system/file_stream_reader_test.h index d1877e8ff0e..4517ced6992 100644 --- a/chromium/storage/browser/file_system/file_stream_reader_test.h +++ b/chromium/storage/browser/file_system/file_stream_reader_test.h @@ -7,7 +7,7 @@ #include "base/callback_helpers.h" #include "base/files/scoped_temp_dir.h" -#include "base/single_thread_task_runner.h" +#include "base/task/single_thread_task_runner.h" #include "base/test/task_environment.h" #include "base/threading/thread.h" #include "net/base/io_buffer.h" @@ -53,8 +53,11 @@ class FileStreamReaderTest : public testing::Test { static void NeverCalled(int unused) { ADD_FAILURE(); } private: - base::test::SingleThreadTaskEnvironment task_environment_{ - base::test::SingleThreadTaskEnvironment::MainThreadType::IO}; + // FileSystemContext queries QuotaDatabase, and even with MockQuotaManager + // (which really fakes parts of QuotaManagerImpl), a thread pool is created + // that requires TaskEnvironment. + base::test::TaskEnvironment task_environment_{ + base::test::TaskEnvironment::MainThreadType::IO}; base::Time test_file_modification_time_; }; diff --git a/chromium/storage/browser/file_system/file_stream_writer_test.h b/chromium/storage/browser/file_system/file_stream_writer_test.h index 1b5b67deeb2..9f4fcbdd3c6 100644 --- a/chromium/storage/browser/file_system/file_stream_writer_test.h +++ b/chromium/storage/browser/file_system/file_stream_writer_test.h @@ -9,7 +9,7 @@ #include "base/callback_helpers.h" #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" -#include "base/single_thread_task_runner.h" +#include "base/task/single_thread_task_runner.h" #include "base/test/task_environment.h" #include "base/threading/thread.h" #include "net/base/io_buffer.h" diff --git a/chromium/storage/browser/file_system/file_system_context.cc b/chromium/storage/browser/file_system/file_system_context.cc index f6362869e4f..0b2c0fa920b 100644 --- a/chromium/storage/browser/file_system/file_system_context.cc +++ b/chromium/storage/browser/file_system/file_system_context.cc @@ -14,13 +14,14 @@ #include "base/callback_helpers.h" #include "base/containers/contains.h" #include "base/feature_list.h" -#include "base/macros.h" #include "base/memory/ptr_util.h" #include "base/memory/scoped_refptr.h" -#include "base/single_thread_task_runner.h" -#include "base/task_runner_util.h" +#include "base/task/single_thread_task_runner.h" +#include "base/task/task_runner_util.h" #include "base/threading/thread_task_runner_handle.h" #include "base/types/pass_key.h" +#include "components/services/storage/public/cpp/buckets/bucket_info.h" +#include "components/services/storage/public/cpp/buckets/constants.h" #include "components/services/storage/public/cpp/quota_client_callback_wrapper.h" #include "components/services/storage/public/mojom/quota_client.mojom.h" #include "mojo/public/cpp/bindings/pending_receiver.h" @@ -38,6 +39,7 @@ #include "storage/browser/file_system/file_system_operation_runner.h" #include "storage/browser/file_system/file_system_options.h" #include "storage/browser/file_system/file_system_quota_client.h" +#include "storage/browser/file_system/file_system_request_info.h" #include "storage/browser/file_system/file_system_util.h" #include "storage/browser/file_system/isolated_context.h" #include "storage/browser/file_system/isolated_file_system_backend.h" @@ -56,7 +58,6 @@ #include "url/origin.h" namespace storage { - namespace { void DidGetMetadataForResolveURL(const base::FilePath& path, @@ -423,6 +424,42 @@ void FileSystemContext::OpenFileSystem(const blink::StorageKey& storage_key, return; } + // Quota manager isn't provided by all tests. + if (quota_manager_proxy()) { + // Ensure default bucket for `storage_key` exists so that Quota API + // is aware of the usage. Bucket type 'temporary' is used even though the + // actual storage type of the file system being opened may be different. + quota_manager_proxy()->GetOrCreateBucket( + storage_key, kDefaultBucketName, io_task_runner_.get(), + base::BindOnce(&FileSystemContext::OnGetOrCreateBucket, + weak_factory_.GetWeakPtr(), storage_key, type, mode, + std::move(callback))); + } else { + ResolveURLOnOpenFileSystem(storage_key, type, mode, std::move(callback)); + } +} + +void FileSystemContext::OnGetOrCreateBucket( + const blink::StorageKey& storage_key, + FileSystemType type, + OpenFileSystemMode mode, + OpenFileSystemCallback callback, + QuotaErrorOr<BucketInfo> result) { + if (!result.ok()) { + std::move(callback).Run(GURL(), std::string(), + base::File::FILE_ERROR_FAILED); + return; + } + ResolveURLOnOpenFileSystem(storage_key, type, mode, std::move(callback)); +} + +void FileSystemContext::ResolveURLOnOpenFileSystem( + const blink::StorageKey& storage_key, + FileSystemType type, + OpenFileSystemMode mode, + OpenFileSystemCallback callback) { + DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); + FileSystemBackend* backend = GetFileSystemBackend(type); if (!backend) { std::move(callback).Run(GURL(), std::string(), @@ -467,11 +504,8 @@ void FileSystemContext::ResolveURL(const FileSystemURL& url, void FileSystemContext::AttemptAutoMountForURLRequest( const FileSystemRequestInfo& request_info, StatusCallback callback) { - // TODO(https://crbug.com/1221308): function will use StorageKey for the - // receiver frame/worker in future CL - const FileSystemURL filesystem_url( - request_info.url, - blink::StorageKey(url::Origin::Create(request_info.url))); + const FileSystemURL filesystem_url(request_info.url, + request_info.storage_key); if (filesystem_url.type() == kFileSystemTypeExternal) { for (auto& handler : auto_mount_handlers_) { auto split_callback = base::SplitOnceCallback(std::move(callback)); @@ -719,7 +753,7 @@ void FileSystemContext::DidOpenFileSystemForResolveURL( FileSystemInfo info(filesystem_name, filesystem_root, url.mount_type()); - // Extract the virtual path not containing a filesystem type part from |url|. + // Extract the virtual path not containing a filesystem type part from `url`. base::FilePath parent = CrackURLInFirstPartyContext(filesystem_root).virtual_path(); base::FilePath child = url.virtual_path(); diff --git a/chromium/storage/browser/file_system/file_system_context.h b/chromium/storage/browser/file_system/file_system_context.h index 99699365e0a..d92761afb80 100644 --- a/chromium/storage/browser/file_system/file_system_context.h +++ b/chromium/storage/browser/file_system/file_system_context.h @@ -15,15 +15,17 @@ #include "base/callback.h" #include "base/component_export.h" #include "base/files/file.h" -#include "base/macros.h" #include "base/memory/ref_counted_delete_on_sequence.h" #include "base/memory/scoped_refptr.h" -#include "base/sequenced_task_runner_helpers.h" +#include "base/memory/weak_ptr.h" +#include "base/task/sequenced_task_runner_helpers.h" #include "base/threading/sequence_bound.h" #include "base/types/pass_key.h" #include "build/build_config.h" +#include "components/services/storage/public/cpp/quota_error_or.h" #include "components/services/storage/public/mojom/quota_client.mojom.h" #include "mojo/public/cpp/bindings/receiver.h" +#include "storage/browser/file_system/file_system_request_info.h" #include "storage/browser/file_system/file_system_url.h" #include "storage/browser/file_system/open_file_system_mode.h" #include "storage/browser/file_system/plugin_private_file_system_backend.h" @@ -71,17 +73,9 @@ class QuotaReservation; class SandboxFileSystemBackend; class SpecialStoragePolicy; +struct BucketInfo; struct FileSystemInfo; -struct FileSystemRequestInfo { - // The original request URL (always set). - const GURL url; - // The storage domain (always set). - const std::string storage_domain; - // Set by the network service for use by callbacks. - int content_id = 0; -}; - // An auto mount handler will attempt to mount the file system requested in // `request_info`. If the URL is for this auto mount handler, it returns true // and calls `callback` when the attempt is complete. If the auto mounter @@ -99,6 +93,10 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemContext public: REQUIRE_ADOPTION_FOR_REFCOUNTED_TYPE(); + FileSystemContext() = delete; + FileSystemContext(const FileSystemContext&) = delete; + FileSystemContext& operator=(const FileSystemContext&) = delete; + // Returns file permission policy we should apply for the given `type`. // The return value must be bitwise-or'd of FilePermissionPolicy. // @@ -254,7 +252,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemContext void ResolveURL(const FileSystemURL& url, ResolveURLCallback callback); // Attempts to mount the filesystem needed to satisfy `request_info` made from - // `request_info.storage_domain`. If an appropriate file system is not found, + // `request_info.storage_domain_`. If an appropriate file system is not found, // callback will return an error. void AttemptAutoMountForURLRequest(const FileSystemRequestInfo& request_info, StatusCallback callback); @@ -402,6 +400,21 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemContext const std::string& filesystem_name, base::File::Error error); + // OnGetOrCreateBucket is the callback for calling + // QuotaManagerProxy::GetOrCreateDefault. + void OnGetOrCreateBucket(const blink::StorageKey& storage_key, + FileSystemType type, + OpenFileSystemMode mode, + OpenFileSystemCallback callback, + QuotaErrorOr<BucketInfo> result); + // ResolveURLOnOpenFileSystem is called, either by OnGetOrCreateBucket + // on successful bucket creation, or (tests onlyh) by OpenFileSystem + // directly in the absence of a quota manager. + void ResolveURLOnOpenFileSystem(const blink::StorageKey& storage_key, + FileSystemType type, + OpenFileSystemMode mode, + OpenFileSystemCallback callback); + // Returns a FileSystemBackend, used only by test code. SandboxFileSystemBackend* sandbox_backend() const { return sandbox_backend_.get(); @@ -459,7 +472,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemContext std::unique_ptr<mojo::Receiver<mojom::QuotaClient>> quota_client_receiver_; - DISALLOW_IMPLICIT_CONSTRUCTORS(FileSystemContext); + base::WeakPtrFactory<FileSystemContext> weak_factory_{this}; }; } // namespace storage diff --git a/chromium/storage/browser/file_system/file_system_context_unittest.cc b/chromium/storage/browser/file_system/file_system_context_unittest.cc index 036e96dc591..339ba57520b 100644 --- a/chromium/storage/browser/file_system/file_system_context_unittest.cc +++ b/chromium/storage/browser/file_system/file_system_context_unittest.cc @@ -8,7 +8,6 @@ #include "base/cxx17_backports.h" #include "base/files/scoped_temp_dir.h" -#include "base/macros.h" #include "base/memory/scoped_refptr.h" #include "base/strings/stringprintf.h" #include "base/test/task_environment.h" diff --git a/chromium/storage/browser/file_system/file_system_file_util.h b/chromium/storage/browser/file_system/file_system_file_util.h index fbd0ee83d65..71a5bf72eaa 100644 --- a/chromium/storage/browser/file_system/file_system_file_util.h +++ b/chromium/storage/browser/file_system/file_system_file_util.h @@ -31,7 +31,7 @@ class FileSystemURL; // See http://crbug.com/128136 if you need it. class COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemFileUtil { public: - using CopyOrMoveOption = FileSystemOperation::CopyOrMoveOption; + using CopyOrMoveOptionSet = FileSystemOperation::CopyOrMoveOptionSet; // It will be implemented by each subclass such as FileSystemFileEnumerator. class COMPONENT_EXPORT(STORAGE_BROWSER) AbstractFileEnumerator { @@ -144,7 +144,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemFileUtil { virtual base::File::Error CopyOrMoveFile(FileSystemOperationContext* context, const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, bool copy) = 0; // Copies in a single file from a different filesystem. diff --git a/chromium/storage/browser/file_system/file_system_operation.h b/chromium/storage/browser/file_system/file_system_operation.h index 5762713d569..5dc9c635da3 100644 --- a/chromium/storage/browser/file_system/file_system_operation.h +++ b/chromium/storage/browser/file_system/file_system_operation.h @@ -12,6 +12,7 @@ #include "base/callback.h" #include "base/component_export.h" +#include "base/containers/enum_set.h" #include "base/files/file.h" #include "base/files/file_path.h" #include "base/process/process.h" @@ -242,24 +243,45 @@ class FileSystemOperation { // set to the copied file size. using CopyFileProgressCallback = base::RepeatingCallback<void(int64_t size)>; - // The option for copy or move operation. - enum CopyOrMoveOption { - // No additional operation. - OPTION_NONE, - + // The possible options for copy or move operations. Used as an EnumSet to + // allow multiple options to be specified. + enum class CopyOrMoveOption { // Preserves last modified time if possible. If the operation to update // last modified time is not supported on the file system for the // destination file, this option would be simply ignored (i.e. Copy would // be successfully done without preserving last modified time). - OPTION_PRESERVE_LAST_MODIFIED, + kPreserveLastModified, - // Preserve permissions of the destination file. If the operation to update + // Preserves permissions of the destination file. If the operation to update // permissions is not supported on the file system for the destination file, // this option will simply be ignored (i.e. Copy would be successfully done // without preserving permissions of the destination file). - OPTION_PRESERVE_DESTINATION_PERMISSIONS, + kPreserveDestinationPermissions, + + // Forces the copy or move operation to use the cross-filesystem + // implementation. + kForceCrossFilesystem, + + // Removes copied files that result in an error (potentially a + // cancellation), as these files are potentially partial/corrupted. + // Directories are not removed recursively, as it can lead to data loss + // (e.g. user changing the content of the destination folder during a copy + // or a move). Therefore, all successfully copied entries are preserved. + // The removal is best-effort: depending on the origin of the error, + // removing the destination file can fail. + // This option can impact cross-filesystem moves since they are implemented + // as copy + delete (only the copy step is impacted), but not + // same-filesystem moves where the file paths are just renamed. + kRemovePartiallyCopiedFilesOnError, + + kFirst = kPreserveLastModified, + kLast = kRemovePartiallyCopiedFilesOnError }; + using CopyOrMoveOptionSet = base::EnumSet<CopyOrMoveOption, + CopyOrMoveOption::kFirst, + CopyOrMoveOption::kLast>; + // Fields requested for the GetMetadata method. Used as a bitmask. enum GetMetadataField { GET_METADATA_FIELD_NONE = 0, @@ -318,7 +340,7 @@ class FileSystemOperation { // virtual void Copy(const FileSystemURL& src_path, const FileSystemURL& dest_path, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, ErrorBehavior error_behavior, const CopyOrMoveProgressCallback& progress_callback, StatusCallback callback) = 0; @@ -345,7 +367,7 @@ class FileSystemOperation { // operation. virtual void Move(const FileSystemURL& src_path, const FileSystemURL& dest_path, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, ErrorBehavior error_behavior, const CopyOrMoveProgressCallback& progress_callback, StatusCallback callback) = 0; @@ -499,7 +521,7 @@ class FileSystemOperation { // virtual void CopyFileLocal(const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, const CopyFileProgressCallback& progress_callback, StatusCallback callback) = 0; @@ -520,7 +542,7 @@ class FileSystemOperation { // virtual void MoveFileLocal(const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, StatusCallback callback) = 0; // Synchronously gets the platform path for the given |url|. diff --git a/chromium/storage/browser/file_system/file_system_operation_context.cc b/chromium/storage/browser/file_system/file_system_operation_context.cc index 8a1363dbae3..d5444ca0c07 100644 --- a/chromium/storage/browser/file_system/file_system_operation_context.cc +++ b/chromium/storage/browser/file_system/file_system_operation_context.cc @@ -4,7 +4,7 @@ #include "storage/browser/file_system/file_system_operation_context.h" -#include "base/sequenced_task_runner.h" +#include "base/task/sequenced_task_runner.h" #include "storage/browser/file_system/file_system_context.h" #include "storage/browser/file_system/quota/quota_limit_type.h" diff --git a/chromium/storage/browser/file_system/file_system_operation_context.h b/chromium/storage/browser/file_system/file_system_operation_context.h index 2df222e6ba7..1cb8546c9bf 100644 --- a/chromium/storage/browser/file_system/file_system_operation_context.h +++ b/chromium/storage/browser/file_system/file_system_operation_context.h @@ -8,7 +8,6 @@ #include <stdint.h> #include "base/component_export.h" -#include "base/macros.h" #include "base/supports_user_data.h" #include "base/threading/thread_checker.h" #include "storage/browser/file_system/task_runner_bound_observer_list.h" diff --git a/chromium/storage/browser/file_system/file_system_operation_impl.cc b/chromium/storage/browser/file_system/file_system_operation_impl.cc index a3eb8b19e50..14cc1980aba 100644 --- a/chromium/storage/browser/file_system/file_system_operation_impl.cc +++ b/chromium/storage/browser/file_system/file_system_operation_impl.cc @@ -13,7 +13,7 @@ #include "base/bind.h" #include "base/callback_helpers.h" -#include "base/single_thread_task_runner.h" +#include "base/task/single_thread_task_runner.h" #include "base/threading/sequenced_task_runner_handle.h" #include "base/time/time.h" #include "base/types/pass_key.h" @@ -101,7 +101,7 @@ void FileSystemOperationImpl::CreateDirectory(const FileSystemURL& url, void FileSystemOperationImpl::Copy( const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, ErrorBehavior error_behavior, const CopyOrMoveProgressCallback& progress_callback, StatusCallback callback) { @@ -110,7 +110,7 @@ void FileSystemOperationImpl::Copy( recursive_operation_delegate_ = std::make_unique<CopyOrMoveOperationDelegate>( file_system_context(), src_url, dest_url, - CopyOrMoveOperationDelegate::OPERATION_COPY, option, error_behavior, + CopyOrMoveOperationDelegate::OPERATION_COPY, options, error_behavior, progress_callback, base::BindOnce(&FileSystemOperationImpl::DidFinishOperation, weak_factory_.GetWeakPtr(), std::move(callback))); @@ -120,7 +120,7 @@ void FileSystemOperationImpl::Copy( void FileSystemOperationImpl::Move( const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, ErrorBehavior error_behavior, const CopyOrMoveProgressCallback& progress_callback, StatusCallback callback) { @@ -128,7 +128,7 @@ void FileSystemOperationImpl::Move( DCHECK(!recursive_operation_delegate_); recursive_operation_delegate_ = std::make_unique<CopyOrMoveOperationDelegate>( file_system_context(), src_url, dest_url, - CopyOrMoveOperationDelegate::OPERATION_MOVE, option, error_behavior, + CopyOrMoveOperationDelegate::OPERATION_MOVE, options, error_behavior, progress_callback, base::BindOnce(&FileSystemOperationImpl::DidFinishOperation, weak_factory_.GetWeakPtr(), std::move(callback))); @@ -250,7 +250,8 @@ void FileSystemOperationImpl::OpenFile(const FileSystemURL& url, OpenFileCallback callback) { DCHECK(SetPendingOperationType(kOperationOpenFile)); - if (file_flags & (base::File::FLAG_TEMPORARY | base::File::FLAG_HIDDEN)) { + if (file_flags & + (base::File::FLAG_WIN_TEMPORARY | base::File::FLAG_WIN_HIDDEN)) { std::move(callback).Run(base::File(base::File::FILE_ERROR_FAILED), base::OnceClosure()); return; @@ -332,7 +333,7 @@ void FileSystemOperationImpl::RemoveDirectory(const FileSystemURL& url, void FileSystemOperationImpl::CopyFileLocal( const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, const CopyFileProgressCallback& progress_callback, StatusCallback callback) { DCHECK(SetPendingOperationType(kOperationCopy)); @@ -347,7 +348,7 @@ void FileSystemOperationImpl::CopyFileLocal( GetUsageAndQuotaThenRunTask( dest_url, base::BindOnce(&FileSystemOperationImpl::DoCopyFileLocal, - weak_factory_.GetWeakPtr(), src_url, dest_url, option, + weak_factory_.GetWeakPtr(), src_url, dest_url, options, progress_callback, std::move(split_callback.first)), base::BindOnce(std::move(split_callback.second), base::File::FILE_ERROR_FAILED)); @@ -355,7 +356,7 @@ void FileSystemOperationImpl::CopyFileLocal( void FileSystemOperationImpl::MoveFileLocal(const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, StatusCallback callback) { DCHECK(SetPendingOperationType(kOperationMove)); // Don't just DCHECK src_url.IsInSameFileSystem(dest_url). We don't care if @@ -369,7 +370,7 @@ void FileSystemOperationImpl::MoveFileLocal(const FileSystemURL& src_url, GetUsageAndQuotaThenRunTask( dest_url, base::BindOnce(&FileSystemOperationImpl::DoMoveFileLocal, - weak_factory_.GetWeakPtr(), src_url, dest_url, option, + weak_factory_.GetWeakPtr(), src_url, dest_url, options, std::move(split_callback.first)), base::BindOnce(std::move(split_callback.second), base::File::FILE_ERROR_FAILED)); @@ -469,11 +470,11 @@ void FileSystemOperationImpl::DoCreateDirectory(const FileSystemURL& url, void FileSystemOperationImpl::DoCopyFileLocal( const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, const CopyFileProgressCallback& progress_callback, StatusCallback callback) { async_file_util_->CopyFileLocal( - std::move(operation_context_), src_url, dest_url, option, + std::move(operation_context_), src_url, dest_url, options, progress_callback, base::BindOnce(&FileSystemOperationImpl::DidFinishOperation, weak_ptr_, std::move(callback))); @@ -481,10 +482,10 @@ void FileSystemOperationImpl::DoCopyFileLocal( void FileSystemOperationImpl::DoMoveFileLocal(const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, StatusCallback callback) { async_file_util_->MoveFileLocal( - std::move(operation_context_), src_url, dest_url, option, + std::move(operation_context_), src_url, dest_url, options, base::BindOnce(&FileSystemOperationImpl::DidFinishOperation, weak_ptr_, std::move(callback))); } diff --git a/chromium/storage/browser/file_system/file_system_operation_impl.h b/chromium/storage/browser/file_system/file_system_operation_impl.h index 64be697f0d9..419d0b5b3fe 100644 --- a/chromium/storage/browser/file_system/file_system_operation_impl.h +++ b/chromium/storage/browser/file_system/file_system_operation_impl.h @@ -11,7 +11,7 @@ #include <vector> #include "base/component_export.h" -#include "base/macros.h" +#include "base/memory/raw_ptr.h" #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" #include "base/types/pass_key.h" @@ -56,13 +56,13 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemOperationImpl StatusCallback callback) override; void Copy(const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, ErrorBehavior error_behavior, const CopyOrMoveProgressCallback& progress_callback, StatusCallback callback) override; void Move(const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, ErrorBehavior error_behavior, const CopyOrMoveProgressCallback& progress_callback, StatusCallback callback) override; @@ -106,12 +106,12 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemOperationImpl StatusCallback callback) override; void CopyFileLocal(const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, const CopyFileProgressCallback& progress_callback, StatusCallback callback) override; void MoveFileLocal(const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, StatusCallback callback) override; base::File::Error SyncGetPlatformPath(const FileSystemURL& url, base::FilePath* platform_path) override; @@ -151,12 +151,12 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemOperationImpl bool recursive); void DoCopyFileLocal(const FileSystemURL& src, const FileSystemURL& dest, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, const CopyFileProgressCallback& progress_callback, StatusCallback callback); void DoMoveFileLocal(const FileSystemURL& src, const FileSystemURL& dest, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, StatusCallback callback); void DoCopyInForeignFile(const base::FilePath& src_local_disk_file_path, const FileSystemURL& dest, @@ -201,7 +201,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemOperationImpl scoped_refptr<FileSystemContext> file_system_context_; std::unique_ptr<FileSystemOperationContext> operation_context_; - AsyncFileUtil* async_file_util_; // Not owned. + raw_ptr<AsyncFileUtil> async_file_util_; // Not owned. std::unique_ptr<FileWriterDelegate> file_writer_delegate_; std::unique_ptr<RecursiveOperationDelegate> recursive_operation_delegate_; diff --git a/chromium/storage/browser/file_system/file_system_operation_impl_unittest.cc b/chromium/storage/browser/file_system/file_system_operation_impl_unittest.cc index d3c44782632..9cd93ac877b 100644 --- a/chromium/storage/browser/file_system/file_system_operation_impl_unittest.cc +++ b/chromium/storage/browser/file_system/file_system_operation_impl_unittest.cc @@ -15,7 +15,6 @@ #include "base/cxx17_backports.h" #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" -#include "base/macros.h" #include "base/memory/ptr_util.h" #include "base/memory/scoped_refptr.h" #include "base/memory/weak_ptr.h" @@ -50,6 +49,10 @@ class FileSystemOperationImplTest : public testing::Test { FileSystemOperationImplTest() : task_environment_(base::test::TaskEnvironment::MainThreadType::IO) {} + FileSystemOperationImplTest(const FileSystemOperationImplTest&) = delete; + FileSystemOperationImplTest& operator=(const FileSystemOperationImplTest&) = + delete; + protected: void SetUp() override { EXPECT_TRUE(base_.CreateUniqueTempDir()); @@ -277,12 +280,12 @@ class FileSystemOperationImplTest : public testing::Test { base::File::Error Move(const FileSystemURL& src, const FileSystemURL& dest, - FileSystemOperation::CopyOrMoveOption option) { + FileSystemOperation::CopyOrMoveOptionSet options) { base::File::Error status; base::RunLoop run_loop; update_observer_.Enable(); operation_runner()->Move( - src, dest, option, storage::FileSystemOperation::ERROR_BEHAVIOR_ABORT, + src, dest, options, storage::FileSystemOperation::ERROR_BEHAVIOR_ABORT, storage::FileSystemOperation::CopyOrMoveProgressCallback(), RecordStatusCallback(run_loop.QuitClosure(), &status)); run_loop.Run(); @@ -292,12 +295,12 @@ class FileSystemOperationImplTest : public testing::Test { base::File::Error Copy(const FileSystemURL& src, const FileSystemURL& dest, - FileSystemOperation::CopyOrMoveOption option) { + FileSystemOperation::CopyOrMoveOptionSet options) { base::File::Error status; base::RunLoop run_loop; update_observer_.Enable(); operation_runner()->Copy( - src, dest, option, FileSystemOperation::ERROR_BEHAVIOR_ABORT, + src, dest, options, FileSystemOperation::ERROR_BEHAVIOR_ABORT, FileSystemOperation::CopyOrMoveProgressCallback(), RecordStatusCallback(run_loop.QuitClosure(), &status)); run_loop.Run(); @@ -456,15 +459,13 @@ class FileSystemOperationImplTest : public testing::Test { UpdateObserverList update_observers_; base::WeakPtrFactory<FileSystemOperationImplTest> weak_factory_{this}; - - DISALLOW_COPY_AND_ASSIGN(FileSystemOperationImplTest); }; TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcDoesntExist) { change_observer()->ResetCount(); - EXPECT_EQ( - base::File::FILE_ERROR_NOT_FOUND, - Move(URLForPath("a"), URLForPath("b"), FileSystemOperation::OPTION_NONE)); + EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, + Move(URLForPath("a"), URLForPath("b"), + FileSystemOperation::CopyOrMoveOptionSet())); EXPECT_TRUE(change_observer()->HasNoChange()); } @@ -472,8 +473,9 @@ TEST_F(FileSystemOperationImplTest, TestMoveFailureContainsPath) { FileSystemURL src_dir(CreateDirectory("src")); FileSystemURL dest_dir(CreateDirectory("src/dest")); - EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, - Move(src_dir, dest_dir, FileSystemOperation::OPTION_NONE)); + EXPECT_EQ( + base::File::FILE_ERROR_INVALID_OPERATION, + Move(src_dir, dest_dir, FileSystemOperation::CopyOrMoveOptionSet())); EXPECT_TRUE(change_observer()->HasNoChange()); } @@ -483,8 +485,9 @@ TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcDirExistsDestFile) { FileSystemURL dest_dir(CreateDirectory("dest")); FileSystemURL dest_file(CreateFile("dest/file")); - EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, - Move(src_dir, dest_file, FileSystemOperation::OPTION_NONE)); + EXPECT_EQ( + base::File::FILE_ERROR_INVALID_OPERATION, + Move(src_dir, dest_file, FileSystemOperation::CopyOrMoveOptionSet())); EXPECT_TRUE(change_observer()->HasNoChange()); } @@ -495,8 +498,9 @@ TEST_F(FileSystemOperationImplTest, FileSystemURL dest_dir(CreateDirectory("dest")); FileSystemURL dest_file(CreateFile("dest/file")); - EXPECT_EQ(base::File::FILE_ERROR_NOT_EMPTY, - Move(src_dir, dest_dir, FileSystemOperation::OPTION_NONE)); + EXPECT_EQ( + base::File::FILE_ERROR_NOT_EMPTY, + Move(src_dir, dest_dir, FileSystemOperation::CopyOrMoveOptionSet())); EXPECT_TRUE(change_observer()->HasNoChange()); } @@ -506,8 +510,9 @@ TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcFileExistsDestDir) { FileSystemURL src_file(CreateFile("src/file")); FileSystemURL dest_dir(CreateDirectory("dest")); - EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, - Move(src_file, dest_dir, FileSystemOperation::OPTION_NONE)); + EXPECT_EQ( + base::File::FILE_ERROR_INVALID_OPERATION, + Move(src_file, dest_dir, FileSystemOperation::CopyOrMoveOptionSet())); EXPECT_TRUE(change_observer()->HasNoChange()); } @@ -516,7 +521,7 @@ TEST_F(FileSystemOperationImplTest, TestMoveFailureDestParentDoesntExist) { FileSystemURL src_dir(CreateDirectory("src")); EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, Move(src_dir, URLForPath("nonexistent/deset"), - FileSystemOperation::OPTION_NONE)); + FileSystemOperation::CopyOrMoveOptionSet())); EXPECT_TRUE(change_observer()->HasNoChange()); } @@ -524,8 +529,9 @@ TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcFileAndOverwrite) { FileSystemURL src_file(CreateFile("src")); FileSystemURL dest_file(CreateFile("dest")); - EXPECT_EQ(base::File::FILE_OK, - Move(src_file, dest_file, FileSystemOperation::OPTION_NONE)); + EXPECT_EQ( + base::File::FILE_OK, + Move(src_file, dest_file, FileSystemOperation::CopyOrMoveOptionSet())); EXPECT_TRUE(FileExists("dest")); EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); @@ -538,8 +544,9 @@ TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcFileAndOverwrite) { TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcFileAndNew) { FileSystemURL src_file(CreateFile("src")); - EXPECT_EQ(base::File::FILE_OK, Move(src_file, URLForPath("new"), - FileSystemOperation::OPTION_NONE)); + EXPECT_EQ(base::File::FILE_OK, + Move(src_file, URLForPath("new"), + FileSystemOperation::CopyOrMoveOptionSet())); EXPECT_TRUE(FileExists("new")); EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); @@ -551,8 +558,9 @@ TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirAndOverwrite) { FileSystemURL src_dir(CreateDirectory("src")); FileSystemURL dest_dir(CreateDirectory("dest")); - EXPECT_EQ(base::File::FILE_OK, - Move(src_dir, dest_dir, FileSystemOperation::OPTION_NONE)); + EXPECT_EQ( + base::File::FILE_OK, + Move(src_dir, dest_dir, FileSystemOperation::CopyOrMoveOptionSet())); EXPECT_FALSE(DirectoryExists("src")); EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); @@ -568,8 +576,9 @@ TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirAndNew) { FileSystemURL src_dir(CreateDirectory("src")); FileSystemURL dest_dir(CreateDirectory("dest")); - EXPECT_EQ(base::File::FILE_OK, Move(src_dir, URLForPath("dest/new"), - FileSystemOperation::OPTION_NONE)); + EXPECT_EQ(base::File::FILE_OK, + Move(src_dir, URLForPath("dest/new"), + FileSystemOperation::CopyOrMoveOptionSet())); EXPECT_FALSE(DirectoryExists("src")); EXPECT_TRUE(DirectoryExists("dest/new")); @@ -585,8 +594,9 @@ TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirRecursive) { FileSystemURL dest_dir(CreateDirectory("dest")); - EXPECT_EQ(base::File::FILE_OK, - Move(src_dir, dest_dir, FileSystemOperation::OPTION_NONE)); + EXPECT_EQ( + base::File::FILE_OK, + Move(src_dir, dest_dir, FileSystemOperation::CopyOrMoveOptionSet())); EXPECT_TRUE(DirectoryExists("dest/dir")); EXPECT_TRUE(FileExists("dest/dir/sub")); @@ -603,7 +613,7 @@ TEST_F(FileSystemOperationImplTest, TestMoveSuccessSamePath) { CreateFile("src/dir/sub"); EXPECT_EQ(base::File::FILE_OK, - Move(src_dir, src_dir, FileSystemOperation::OPTION_NONE)); + Move(src_dir, src_dir, FileSystemOperation::CopyOrMoveOptionSet())); EXPECT_TRUE(DirectoryExists("src/dir")); EXPECT_TRUE(FileExists("src/dir/sub")); @@ -615,9 +625,9 @@ TEST_F(FileSystemOperationImplTest, TestMoveSuccessSamePath) { } TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcDoesntExist) { - EXPECT_EQ( - base::File::FILE_ERROR_NOT_FOUND, - Copy(URLForPath("a"), URLForPath("b"), FileSystemOperation::OPTION_NONE)); + EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, + Copy(URLForPath("a"), URLForPath("b"), + FileSystemOperation::CopyOrMoveOptionSet())); EXPECT_TRUE(change_observer()->HasNoChange()); } @@ -625,8 +635,9 @@ TEST_F(FileSystemOperationImplTest, TestCopyFailureContainsPath) { FileSystemURL src_dir(CreateDirectory("src")); FileSystemURL dest_dir(CreateDirectory("src/dir")); - EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, - Copy(src_dir, dest_dir, FileSystemOperation::OPTION_NONE)); + EXPECT_EQ( + base::File::FILE_ERROR_INVALID_OPERATION, + Copy(src_dir, dest_dir, FileSystemOperation::CopyOrMoveOptionSet())); EXPECT_TRUE(change_observer()->HasNoChange()); } @@ -636,8 +647,9 @@ TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcDirExistsDestFile) { FileSystemURL dest_dir(CreateDirectory("dest")); FileSystemURL dest_file(CreateFile("dest/file")); - EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, - Copy(src_dir, dest_file, FileSystemOperation::OPTION_NONE)); + EXPECT_EQ( + base::File::FILE_ERROR_INVALID_OPERATION, + Copy(src_dir, dest_file, FileSystemOperation::CopyOrMoveOptionSet())); EXPECT_TRUE(change_observer()->HasNoChange()); } @@ -648,8 +660,9 @@ TEST_F(FileSystemOperationImplTest, FileSystemURL dest_dir(CreateDirectory("dest")); FileSystemURL dest_file(CreateFile("dest/file")); - EXPECT_EQ(base::File::FILE_ERROR_NOT_EMPTY, - Copy(src_dir, dest_dir, FileSystemOperation::OPTION_NONE)); + EXPECT_EQ( + base::File::FILE_ERROR_NOT_EMPTY, + Copy(src_dir, dest_dir, FileSystemOperation::CopyOrMoveOptionSet())); EXPECT_TRUE(change_observer()->HasNoChange()); } @@ -658,8 +671,9 @@ TEST_F(FileSystemOperationImplTest, TestCopyFailureSrcFileExistsDestDir) { FileSystemURL src_file(CreateFile("src")); FileSystemURL dest_dir(CreateDirectory("dest")); - EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, - Copy(src_file, dest_dir, FileSystemOperation::OPTION_NONE)); + EXPECT_EQ( + base::File::FILE_ERROR_INVALID_OPERATION, + Copy(src_file, dest_dir, FileSystemOperation::CopyOrMoveOptionSet())); EXPECT_TRUE(change_observer()->HasNoChange()); } @@ -669,7 +683,7 @@ TEST_F(FileSystemOperationImplTest, TestCopyFailureDestParentDoesntExist) { EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, Copy(src_dir, URLForPath("nonexistent/dest"), - FileSystemOperation::OPTION_NONE)); + FileSystemOperation::CopyOrMoveOptionSet())); EXPECT_TRUE(change_observer()->HasNoChange()); } @@ -685,8 +699,9 @@ TEST_F(FileSystemOperationImplTest, TestCopyFailureByQuota) { GrantQuotaForCurrentUsage(); AddQuota(6 + dest_path_cost - 1); - EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, - Copy(src_file, dest_file, FileSystemOperation::OPTION_NONE)); + EXPECT_EQ( + base::File::FILE_ERROR_NO_SPACE, + Copy(src_file, dest_file, FileSystemOperation::CopyOrMoveOptionSet())); EXPECT_FALSE(FileExists("dest/file")); } @@ -694,8 +709,9 @@ TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndOverwrite) { FileSystemURL src_file(CreateFile("src")); FileSystemURL dest_file(CreateFile("dest")); - EXPECT_EQ(base::File::FILE_OK, - Copy(src_file, dest_file, FileSystemOperation::OPTION_NONE)); + EXPECT_EQ( + base::File::FILE_OK, + Copy(src_file, dest_file, FileSystemOperation::CopyOrMoveOptionSet())); EXPECT_TRUE(FileExists("dest")); EXPECT_EQ(4, quota_manager_proxy()->notify_storage_accessed_count()); @@ -707,8 +723,9 @@ TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndOverwrite) { TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndNew) { FileSystemURL src_file(CreateFile("src")); - EXPECT_EQ(base::File::FILE_OK, Copy(src_file, URLForPath("new"), - FileSystemOperation::OPTION_NONE)); + EXPECT_EQ(base::File::FILE_OK, + Copy(src_file, URLForPath("new"), + FileSystemOperation::CopyOrMoveOptionSet())); EXPECT_TRUE(FileExists("new")); EXPECT_EQ(4, quota_manager_proxy()->notify_storage_accessed_count()); @@ -721,8 +738,9 @@ TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndOverwrite) { FileSystemURL src_dir(CreateDirectory("src")); FileSystemURL dest_dir(CreateDirectory("dest")); - EXPECT_EQ(base::File::FILE_OK, - Copy(src_dir, dest_dir, FileSystemOperation::OPTION_NONE)); + EXPECT_EQ( + base::File::FILE_OK, + Copy(src_dir, dest_dir, FileSystemOperation::CopyOrMoveOptionSet())); // Make sure we've overwritten but not copied the source under the |dest_dir|. EXPECT_TRUE(DirectoryExists("dest")); @@ -738,8 +756,9 @@ TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndNew) { FileSystemURL src_dir(CreateDirectory("src")); FileSystemURL dest_dir_new(URLForPath("dest")); - EXPECT_EQ(base::File::FILE_OK, - Copy(src_dir, dest_dir_new, FileSystemOperation::OPTION_NONE)); + EXPECT_EQ( + base::File::FILE_OK, + Copy(src_dir, dest_dir_new, FileSystemOperation::CopyOrMoveOptionSet())); EXPECT_TRUE(DirectoryExists("dest")); EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 2); @@ -754,8 +773,9 @@ TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirRecursive) { FileSystemURL dest_dir(CreateDirectory("dest")); - EXPECT_EQ(base::File::FILE_OK, - Copy(src_dir, dest_dir, FileSystemOperation::OPTION_NONE)); + EXPECT_EQ( + base::File::FILE_OK, + Copy(src_dir, dest_dir, FileSystemOperation::CopyOrMoveOptionSet())); EXPECT_TRUE(DirectoryExists("dest/dir")); EXPECT_TRUE(FileExists("dest/dir/sub")); @@ -776,7 +796,7 @@ TEST_F(FileSystemOperationImplTest, TestCopySuccessSamePath) { CreateFile("src/dir/sub"); EXPECT_EQ(base::File::FILE_OK, - Copy(src_dir, src_dir, FileSystemOperation::OPTION_NONE)); + Copy(src_dir, src_dir, FileSystemOperation::CopyOrMoveOptionSet())); EXPECT_TRUE(DirectoryExists("src/dir")); EXPECT_TRUE(FileExists("src/dir/sub")); @@ -1190,7 +1210,7 @@ TEST_F(FileSystemOperationImplTest, TestMoveSuccessSrcDirRecursiveWithQuota) { EXPECT_EQ(all_file_size + total_path_cost, GetUsage()); EXPECT_EQ(base::File::FILE_OK, - Move(src, dest, FileSystemOperation::OPTION_NONE)); + Move(src, dest, FileSystemOperation::CopyOrMoveOptionSet())); EXPECT_FALSE(DirectoryExists("src/dir")); EXPECT_FALSE(FileExists("src/dir/file2")); @@ -1235,7 +1255,7 @@ TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirRecursiveWithQuota) { EXPECT_EQ(expected_usage, usage); EXPECT_EQ(base::File::FILE_OK, - Copy(src, dest1, FileSystemOperation::OPTION_NONE)); + Copy(src, dest1, FileSystemOperation::CopyOrMoveOptionSet())); expected_usage += all_file_size + child_path_cost + grandchild_path_cost; EXPECT_TRUE(DirectoryExists("src/dir")); @@ -1247,7 +1267,7 @@ TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirRecursiveWithQuota) { EXPECT_EQ(expected_usage, GetUsage()); EXPECT_EQ(base::File::FILE_OK, - Copy(child_dir, dest2, FileSystemOperation::OPTION_NONE)); + Copy(child_dir, dest2, FileSystemOperation::CopyOrMoveOptionSet())); expected_usage += grandchild_file_size + grandchild_path_cost; usage = GetUsage(); @@ -1262,8 +1282,9 @@ TEST_F(FileSystemOperationImplTest, FileSystemURL dest_file(CreateFile("dest")); EXPECT_EQ(base::File::FILE_OK, Truncate(dest_file, 6)); - EXPECT_EQ(base::File::FILE_OK, - Copy(src_file, dest_file, FileSystemOperation::OPTION_NONE)); + EXPECT_EQ( + base::File::FILE_OK, + Copy(src_file, dest_file, FileSystemOperation::CopyOrMoveOptionSet())); EXPECT_EQ(0, GetFileSize("dest")); } diff --git a/chromium/storage/browser/file_system/file_system_operation_impl_write_unittest.cc b/chromium/storage/browser/file_system/file_system_operation_impl_write_unittest.cc index 9186550edf7..55fe648ad22 100644 --- a/chromium/storage/browser/file_system/file_system_operation_impl_write_unittest.cc +++ b/chromium/storage/browser/file_system/file_system_operation_impl_write_unittest.cc @@ -10,7 +10,6 @@ #include "base/bind.h" #include "base/files/scoped_temp_dir.h" -#include "base/macros.h" #include "base/memory/scoped_refptr.h" #include "base/memory/weak_ptr.h" #include "base/run_loop.h" @@ -60,6 +59,11 @@ class FileSystemOperationImplWriteTest : public testing::Test { change_observers_ = MockFileChangeObserver::CreateList(&change_observer_); } + FileSystemOperationImplWriteTest(const FileSystemOperationImplWriteTest&) = + delete; + FileSystemOperationImplWriteTest& operator=( + const FileSystemOperationImplWriteTest&) = delete; + void SetUp() override { ASSERT_TRUE(dir_.CreateUniqueTempDir()); @@ -163,8 +167,6 @@ class FileSystemOperationImplWriteTest : public testing::Test { ChangeObserverList change_observers_; base::WeakPtrFactory<FileSystemOperationImplWriteTest> weak_factory_{this}; - - DISALLOW_COPY_AND_ASSIGN(FileSystemOperationImplWriteTest); }; TEST_F(FileSystemOperationImplWriteTest, TestWriteSuccess) { diff --git a/chromium/storage/browser/file_system/file_system_operation_runner.cc b/chromium/storage/browser/file_system/file_system_operation_runner.cc index bf2fec28c35..c910fe401a9 100644 --- a/chromium/storage/browser/file_system/file_system_operation_runner.cc +++ b/chromium/storage/browser/file_system/file_system_operation_runner.cc @@ -13,7 +13,6 @@ #include "base/auto_reset.h" #include "base/bind.h" #include "base/containers/contains.h" -#include "base/macros.h" #include "base/memory/ptr_util.h" #include "base/threading/thread_task_runner_handle.h" #include "net/url_request/url_request_context.h" @@ -92,7 +91,7 @@ OperationID FileSystemOperationRunner::CreateDirectory( OperationID FileSystemOperationRunner::Copy( const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, ErrorBehavior error_behavior, const CopyOrMoveProgressCallback& progress_callback, StatusCallback callback) { @@ -109,7 +108,7 @@ OperationID FileSystemOperationRunner::Copy( PrepareForWrite(id, dest_url); PrepareForRead(id, src_url); operation_raw->Copy( - src_url, dest_url, option, error_behavior, + src_url, dest_url, options, error_behavior, progress_callback.is_null() ? CopyOrMoveProgressCallback() : base::BindRepeating(&FileSystemOperationRunner::OnCopyProgress, @@ -122,7 +121,7 @@ OperationID FileSystemOperationRunner::Copy( OperationID FileSystemOperationRunner::Move( const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, ErrorBehavior error_behavior, const CopyOrMoveProgressCallback& progress_callback, StatusCallback callback) { @@ -139,7 +138,7 @@ OperationID FileSystemOperationRunner::Move( PrepareForWrite(id, dest_url); PrepareForWrite(id, src_url); operation_raw->Move( - src_url, dest_url, option, error_behavior, + src_url, dest_url, options, error_behavior, progress_callback.is_null() ? CopyOrMoveProgressCallback() : base::BindRepeating(&FileSystemOperationRunner::OnCopyProgress, @@ -400,7 +399,7 @@ OperationID FileSystemOperationRunner::OpenFile(const FileSystemURL& url, if (file_flags & (base::File::FLAG_CREATE | base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_OPEN_TRUNCATED | - base::File::FLAG_WRITE | base::File::FLAG_EXCLUSIVE_WRITE | + base::File::FLAG_WRITE | base::File::FLAG_WIN_EXCLUSIVE_WRITE | base::File::FLAG_DELETE_ON_CLOSE | base::File::FLAG_WRITE_ATTRIBUTES)) { PrepareForWrite(id, url); } else { @@ -498,7 +497,7 @@ OperationID FileSystemOperationRunner::RemoveDirectory( OperationID FileSystemOperationRunner::CopyFileLocal( const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, const CopyFileProgressCallback& progress_callback, StatusCallback callback) { base::File::Error error = base::File::FILE_OK; @@ -514,7 +513,7 @@ OperationID FileSystemOperationRunner::CopyFileLocal( PrepareForRead(id, src_url); PrepareForWrite(id, dest_url); operation_raw->CopyFileLocal( - src_url, dest_url, option, progress_callback, + src_url, dest_url, options, progress_callback, base::BindOnce(&FileSystemOperationRunner::DidFinish, weak_ptr_, id, std::move(callback))); return id; @@ -523,7 +522,7 @@ OperationID FileSystemOperationRunner::CopyFileLocal( OperationID FileSystemOperationRunner::MoveFileLocal( const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, StatusCallback callback) { base::File::Error error = base::File::FILE_OK; std::unique_ptr<FileSystemOperation> operation = @@ -538,7 +537,7 @@ OperationID FileSystemOperationRunner::MoveFileLocal( PrepareForWrite(id, src_url); PrepareForWrite(id, dest_url); operation_raw->MoveFileLocal( - src_url, dest_url, option, + src_url, dest_url, options, base::BindOnce(&FileSystemOperationRunner::DidFinish, weak_ptr_, id, std::move(callback))); return id; @@ -567,7 +566,7 @@ void FileSystemOperationRunner::DidFinish(const OperationID id, // Calling the callback or deleting the |operations_| entry in // |FinishOperation| may release the FileSystemContext which owns this runner, // so take a reference to keep both alive until the end of this call. - scoped_refptr<FileSystemContext> context(file_system_context_); + scoped_refptr<FileSystemContext> context(file_system_context_.get()); if (is_beginning_operation_) { finished_operations_.insert(id); @@ -588,7 +587,7 @@ void FileSystemOperationRunner::DidGetMetadata( // Calling the callback or deleting the |operations_| entry in // |FinishOperation| may release the FileSystemContext which owns this runner, // so take a reference to keep both alive until the end of this call. - scoped_refptr<FileSystemContext> context(file_system_context_); + scoped_refptr<FileSystemContext> context(file_system_context_.get()); if (is_beginning_operation_) { finished_operations_.insert(id); @@ -611,7 +610,7 @@ void FileSystemOperationRunner::DidReadDirectory( // Calling the callback or deleting the |operations_| entry in // |FinishOperation| may release the FileSystemContext which owns this runner, // so take a reference to keep both alive until the end of this call. - scoped_refptr<FileSystemContext> context(file_system_context_); + scoped_refptr<FileSystemContext> context(file_system_context_.get()); if (is_beginning_operation_) { finished_operations_.insert(id); @@ -634,7 +633,7 @@ void FileSystemOperationRunner::DidWrite(const OperationID id, // Calling the callback or deleting the |operations_| entry in // |FinishOperation| may release the FileSystemContext which owns this runner, // so take a reference to keep both alive until the end of this call. - scoped_refptr<FileSystemContext> context(file_system_context_); + scoped_refptr<FileSystemContext> context(file_system_context_.get()); if (is_beginning_operation_) { finished_operations_.insert(id); @@ -657,7 +656,7 @@ void FileSystemOperationRunner::DidOpenFile( // Calling the callback or deleting the |operations_| entry in // |FinishOperation| may release the FileSystemContext which owns this runner, // so take a reference to keep both alive until the end of this call. - scoped_refptr<FileSystemContext> context(file_system_context_); + scoped_refptr<FileSystemContext> context(file_system_context_.get()); if (is_beginning_operation_) { finished_operations_.insert(id); @@ -682,7 +681,7 @@ void FileSystemOperationRunner::DidCreateSnapshot( // Calling the callback or deleting the |operations_| entry in // |FinishOperation| may release the FileSystemContext which owns this runner, // so take a reference to keep both alive until the end of this call. - scoped_refptr<FileSystemContext> context(file_system_context_); + scoped_refptr<FileSystemContext> context(file_system_context_.get()); if (is_beginning_operation_) { finished_operations_.insert(id); diff --git a/chromium/storage/browser/file_system/file_system_operation_runner.h b/chromium/storage/browser/file_system/file_system_operation_runner.h index 0d186cef3ea..290f7b0c5b8 100644 --- a/chromium/storage/browser/file_system/file_system_operation_runner.h +++ b/chromium/storage/browser/file_system/file_system_operation_runner.h @@ -14,7 +14,7 @@ #include "base/component_export.h" #include "base/containers/id_map.h" -#include "base/macros.h" +#include "base/memory/raw_ptr.h" #include "base/memory/weak_ptr.h" #include "base/types/pass_key.h" #include "components/services/filesystem/public/mojom/types.mojom.h" @@ -47,7 +47,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemOperationRunner { FileSystemOperation::CopyOrMoveProgressCallback; using CopyFileProgressCallback = FileSystemOperation::CopyFileProgressCallback; - using CopyOrMoveOption = FileSystemOperation::CopyOrMoveOption; + using CopyOrMoveOptionSet = FileSystemOperation::CopyOrMoveOptionSet; using GetMetadataField = FileSystemOperation::GetMetadataField; using OperationID = uint64_t; @@ -88,7 +88,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemOperationRunner { // details. OperationID Copy(const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, ErrorBehavior error_behavior, const CopyOrMoveProgressCallback& progress_callback, StatusCallback callback); @@ -98,7 +98,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemOperationRunner { // For |option|, see file_system_operation.h for details. OperationID Move(const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, ErrorBehavior error_behavior, const CopyOrMoveProgressCallback& progress_callback, StatusCallback callback); @@ -227,7 +227,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemOperationRunner { // OperationID CopyFileLocal(const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, const CopyFileProgressCallback& progress_callback, StatusCallback callback); @@ -247,7 +247,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemOperationRunner { // OperationID MoveFileLocal(const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, StatusCallback callback); // This is called only by pepper plugin as of writing to synchronously get @@ -304,7 +304,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemOperationRunner { void FinishOperation(OperationID id); // Not owned; whatever owns this has to make sure context outlives this. - FileSystemContext* file_system_context_; + raw_ptr<FileSystemContext> file_system_context_; using Operations = std::map<OperationID, std::unique_ptr<FileSystemOperation>>; diff --git a/chromium/storage/browser/file_system/file_system_quota_client.cc b/chromium/storage/browser/file_system/file_system_quota_client.cc index c2683591b2c..abf6649cd9c 100644 --- a/chromium/storage/browser/file_system/file_system_quota_client.cc +++ b/chromium/storage/browser/file_system/file_system_quota_client.cc @@ -18,7 +18,7 @@ #include "base/files/file.h" #include "base/location.h" #include "base/sequence_checker.h" -#include "base/sequenced_task_runner.h" +#include "base/task/sequenced_task_runner.h" #include "storage/browser/file_system/file_system_backend.h" #include "storage/browser/file_system/file_system_context.h" #include "storage/common/file_system/file_system_types.h" @@ -165,7 +165,7 @@ void FileSystemQuotaClient::GetStorageKeyUsage( base::BindOnce( &FileSystemQuotaUtil::GetStorageKeyUsageOnFileTaskRunner, base::Unretained(quota_util), - base::RetainedRef(file_system_context_), storage_key, type), + base::RetainedRef(file_system_context_.get()), storage_key, type), barrier); } else { barrier.Run(0); @@ -192,7 +192,7 @@ void FileSystemQuotaClient::GetStorageKeysForType( file_task_runner()->PostTaskAndReplyWithResult( FROM_HERE, base::BindOnce(&GetStorageKeysForTypeOnFileTaskRunner, - base::RetainedRef(file_system_context_), type), + base::RetainedRef(file_system_context_.get()), type), barrier); } } @@ -217,7 +217,8 @@ void FileSystemQuotaClient::GetStorageKeysForHost( file_task_runner()->PostTaskAndReplyWithResult( FROM_HERE, base::BindOnce(&GetStorageKeysForHostOnFileTaskRunner, - base::RetainedRef(file_system_context_), type, host), + base::RetainedRef(file_system_context_.get()), type, + host), barrier); } } @@ -248,8 +249,8 @@ void FileSystemQuotaClient::DeleteStorageKeyData( file_task_runner()->PostTaskAndReplyWithResult( FROM_HERE, base::BindOnce(&DeleteStorageKeyOnFileTaskRunner, - base::RetainedRef(file_system_context_), storage_key, - fs_type), + base::RetainedRef(file_system_context_.get()), + storage_key, fs_type), barrier); } } @@ -270,7 +271,7 @@ void FileSystemQuotaClient::PerformStorageCleanup( file_task_runner()->PostTaskAndReply( FROM_HERE, base::BindOnce(&PerformStorageCleanupOnFileTaskRunner, - base::RetainedRef(file_system_context_), fs_type), + base::RetainedRef(file_system_context_.get()), fs_type), barrier); } } diff --git a/chromium/storage/browser/file_system/file_system_quota_client.h b/chromium/storage/browser/file_system/file_system_quota_client.h index f686c0ee10e..3fe518389f2 100644 --- a/chromium/storage/browser/file_system/file_system_quota_client.h +++ b/chromium/storage/browser/file_system/file_system_quota_client.h @@ -8,6 +8,7 @@ #include <string> #include "base/component_export.h" +#include "base/memory/raw_ptr.h" #include "base/memory/ref_counted.h" #include "base/sequence_checker.h" #include "base/thread_annotations.h" @@ -71,7 +72,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemQuotaClient // `file_system_context_` owns this. We could break the cycle in // FileSystemContext::Shutdown(), but then we would have to ensure that // Shutdown() is called by all FileSystemContext users. - FileSystemContext* const file_system_context_ + const raw_ptr<FileSystemContext> file_system_context_ GUARDED_BY_CONTEXT(sequence_checker_); }; diff --git a/chromium/storage/browser/file_system/file_system_quota_client_unittest.cc b/chromium/storage/browser/file_system/file_system_quota_client_unittest.cc index e5c2086ce43..f8c7fee5bb4 100644 --- a/chromium/storage/browser/file_system/file_system_quota_client_unittest.cc +++ b/chromium/storage/browser/file_system/file_system_quota_client_unittest.cc @@ -11,7 +11,6 @@ #include "base/cxx17_backports.h" #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" -#include "base/macros.h" #include "base/run_loop.h" #include "base/test/scoped_feature_list.h" #include "base/test/task_environment.h" diff --git a/chromium/storage/browser/file_system/file_system_request_info.cc b/chromium/storage/browser/file_system/file_system_request_info.cc new file mode 100644 index 00000000000..004ce9b60fe --- /dev/null +++ b/chromium/storage/browser/file_system/file_system_request_info.cc @@ -0,0 +1,21 @@ +// Copyright (c) 2021 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/file_system/file_system_request_info.h" +#include "third_party/blink/public/common/storage_key/storage_key.h" +#include "url/gurl.h" + +namespace storage { + +FileSystemRequestInfo::FileSystemRequestInfo( + const GURL url, + const std::string storage_domain, + int content_id, + const blink::StorageKey storage_key) + : url(url), + storage_domain(storage_domain), + content_id(content_id), + storage_key(storage_key) {} + +} // namespace storage diff --git a/chromium/storage/browser/file_system/file_system_request_info.h b/chromium/storage/browser/file_system/file_system_request_info.h new file mode 100644 index 00000000000..71be1a79a7d --- /dev/null +++ b/chromium/storage/browser/file_system/file_system_request_info.h @@ -0,0 +1,35 @@ +// Copyright (c) 2021 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_FILE_SYSTEM_FILE_SYSTEM_REQUEST_INFO_H_ +#define STORAGE_BROWSER_FILE_SYSTEM_FILE_SYSTEM_REQUEST_INFO_H_ + +#include "base/component_export.h" +#include "third_party/blink/public/common/storage_key/storage_key.h" +#include "url/gurl.h" + +namespace storage { + +// FileSystemRequestInfo is a struct containing the information +// necessary for a FileSystemURLLoaderFactory to mount the +// FileSystem requested by the caller. +struct COMPONENT_EXPORT(STORAGE_BROWSER) FileSystemRequestInfo { + // The original request URL (always set). + GURL url; + // The storage domain (always set). + std::string storage_domain; + // Set by the network service for use by callbacks. + int content_id = 0; + // The original request blink::StorageKey (always set). + blink::StorageKey storage_key; + + FileSystemRequestInfo(const GURL url, + const std::string storage_domain, + int content_id, + const blink::StorageKey storage_key); +}; + +} // namespace storage + +#endif // STORAGE_BROWSER_FILE_SYSTEM_FILE_SYSTEM_REQUEST_INFO_H_ diff --git a/chromium/storage/browser/file_system/file_system_url.cc b/chromium/storage/browser/file_system/file_system_url.cc index 57bfad03653..1c164adb270 100644 --- a/chromium/storage/browser/file_system/file_system_url.cc +++ b/chromium/storage/browser/file_system/file_system_url.cc @@ -67,12 +67,12 @@ FileSystemURL::FileSystemURL(const GURL& url, type_(kFileSystemTypeUnknown), mount_option_(FlushPolicy::NO_FLUSH_ON_COMPLETION) { GURL origin_url; + // URL should be able to be parsed and the parsed origin should match the + // StorageKey's origin member. is_valid_ = - ParseFileSystemSchemeURL(url, &origin_url, &mount_type_, &virtual_path_); - if (is_valid_) { - DCHECK( - storage_key.origin().IsSameOriginWith(url::Origin::Create(origin_url))); - } + ParseFileSystemSchemeURL(url, &origin_url, &mount_type_, + &virtual_path_) && + storage_key.origin().IsSameOriginWith(url::Origin::Create(origin_url)); storage_key_ = storage_key; path_ = virtual_path_; type_ = mount_type_; diff --git a/chromium/storage/browser/file_system/file_system_url_unittest.cc b/chromium/storage/browser/file_system/file_system_url_unittest.cc index 722f8b16437..d0c85a6445e 100644 --- a/chromium/storage/browser/file_system/file_system_url_unittest.cc +++ b/chromium/storage/browser/file_system/file_system_url_unittest.cc @@ -10,7 +10,6 @@ #include "base/cxx17_backports.h" #include "base/files/file_path.h" -#include "base/macros.h" #include "storage/common/file_system/file_system_types.h" #include "storage/common/file_system/file_system_util.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/chromium/storage/browser/file_system/file_system_usage_cache.h b/chromium/storage/browser/file_system/file_system_usage_cache.h index d19a4142e4f..ef048677824 100644 --- a/chromium/storage/browser/file_system/file_system_usage_cache.h +++ b/chromium/storage/browser/file_system/file_system_usage_cache.h @@ -13,7 +13,6 @@ #include "base/component_export.h" #include "base/files/file.h" #include "base/files/file_path.h" -#include "base/macros.h" #include "base/sequence_checker.h" #include "base/timer/timer.h" diff --git a/chromium/storage/browser/file_system/file_system_usage_cache_unittest.cc b/chromium/storage/browser/file_system/file_system_usage_cache_unittest.cc index 2b8ef41ec4f..c8f669f0319 100644 --- a/chromium/storage/browser/file_system/file_system_usage_cache_unittest.cc +++ b/chromium/storage/browser/file_system/file_system_usage_cache_unittest.cc @@ -10,7 +10,6 @@ #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" -#include "base/macros.h" #include "base/test/task_environment.h" #include "testing/gtest/include/gtest/gtest.h" @@ -21,6 +20,9 @@ class FileSystemUsageCacheTest : public testing::Test, public: FileSystemUsageCacheTest() : usage_cache_(is_incognito()) {} + FileSystemUsageCacheTest(const FileSystemUsageCacheTest&) = delete; + FileSystemUsageCacheTest& operator=(const FileSystemUsageCacheTest&) = delete; + void SetUp() override { ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); } bool is_incognito() { return GetParam(); } @@ -36,8 +38,6 @@ class FileSystemUsageCacheTest : public testing::Test, base::test::SingleThreadTaskEnvironment task_environment_; base::ScopedTempDir data_dir_; FileSystemUsageCache usage_cache_; - - DISALLOW_COPY_AND_ASSIGN(FileSystemUsageCacheTest); }; INSTANTIATE_TEST_SUITE_P(All, FileSystemUsageCacheTest, testing::Bool()); diff --git a/chromium/storage/browser/file_system/file_writer_delegate.cc b/chromium/storage/browser/file_system/file_writer_delegate.cc index e28b5f92110..e7c6acdd488 100644 --- a/chromium/storage/browser/file_system/file_writer_delegate.cc +++ b/chromium/storage/browser/file_system/file_writer_delegate.cc @@ -12,8 +12,8 @@ #include "base/bind.h" #include "base/callback.h" #include "base/location.h" -#include "base/sequenced_task_runner.h" -#include "base/single_thread_task_runner.h" +#include "base/task/sequenced_task_runner.h" +#include "base/task/single_thread_task_runner.h" #include "base/threading/thread_restrictions.h" #include "base/threading/thread_task_runner_handle.h" #include "net/base/net_errors.h" diff --git a/chromium/storage/browser/file_system/file_writer_delegate.h b/chromium/storage/browser/file_system/file_writer_delegate.h index d8fa5514e32..3784400c2e0 100644 --- a/chromium/storage/browser/file_system/file_writer_delegate.h +++ b/chromium/storage/browser/file_system/file_writer_delegate.h @@ -11,7 +11,6 @@ #include "base/component_export.h" #include "base/files/file.h" -#include "base/macros.h" #include "base/memory/weak_ptr.h" #include "base/time/time.h" #include "mojo/public/cpp/system/data_pipe.h" diff --git a/chromium/storage/browser/file_system/file_writer_delegate_unittest.cc b/chromium/storage/browser/file_system/file_writer_delegate_unittest.cc index 7dbd161cd7b..6a1d9675e2a 100644 --- a/chromium/storage/browser/file_system/file_writer_delegate_unittest.cc +++ b/chromium/storage/browser/file_system/file_writer_delegate_unittest.cc @@ -13,10 +13,9 @@ #include "base/cxx17_backports.h" #include "base/files/scoped_temp_dir.h" #include "base/location.h" -#include "base/macros.h" #include "base/memory/weak_ptr.h" #include "base/run_loop.h" -#include "base/single_thread_task_runner.h" +#include "base/task/single_thread_task_runner.h" #include "base/test/task_environment.h" #include "base/threading/thread_task_runner_handle.h" #include "net/base/io_buffer.h" diff --git a/chromium/storage/browser/file_system/filesystem_proxy_file_stream_reader.cc b/chromium/storage/browser/file_system/filesystem_proxy_file_stream_reader.cc index 988daa1e14a..594d7ec5f88 100644 --- a/chromium/storage/browser/file_system/filesystem_proxy_file_stream_reader.cc +++ b/chromium/storage/browser/file_system/filesystem_proxy_file_stream_reader.cc @@ -14,8 +14,8 @@ #include "base/location.h" #include "base/memory/ptr_util.h" #include "base/metrics/histogram_macros.h" -#include "base/task_runner.h" -#include "base/task_runner_util.h" +#include "base/task/task_runner.h" +#include "base/task/task_runner_util.h" #include "net/base/file_stream.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" diff --git a/chromium/storage/browser/file_system/filesystem_proxy_file_stream_reader_unittest.cc b/chromium/storage/browser/file_system/filesystem_proxy_file_stream_reader_unittest.cc index e9180f6b2a3..417b141dcc3 100644 --- a/chromium/storage/browser/file_system/filesystem_proxy_file_stream_reader_unittest.cc +++ b/chromium/storage/browser/file_system/filesystem_proxy_file_stream_reader_unittest.cc @@ -17,9 +17,8 @@ #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" #include "base/location.h" -#include "base/macros.h" #include "base/run_loop.h" -#include "base/single_thread_task_runner.h" +#include "base/task/single_thread_task_runner.h" #include "base/test/task_environment.h" #include "base/threading/thread.h" #include "net/base/io_buffer.h" diff --git a/chromium/storage/browser/file_system/isolated_context.cc b/chromium/storage/browser/file_system/isolated_context.cc index 2871e1c6247..2ab691523aa 100644 --- a/chromium/storage/browser/file_system/isolated_context.cc +++ b/chromium/storage/browser/file_system/isolated_context.cc @@ -10,7 +10,6 @@ #include <memory> #include "base/check_op.h" -#include "base/macros.h" #include "base/notreached.h" #include "base/rand_util.h" #include "base/strings/string_number_conversions.h" diff --git a/chromium/storage/browser/file_system/isolated_context.h b/chromium/storage/browser/file_system/isolated_context.h index 1271f4a947d..3b09ee2afcd 100644 --- a/chromium/storage/browser/file_system/isolated_context.h +++ b/chromium/storage/browser/file_system/isolated_context.h @@ -13,8 +13,6 @@ #include "base/component_export.h" #include "base/files/file_path.h" #include "base/lazy_instance.h" -#include "base/macros.h" -#include "base/memory/singleton.h" #include "base/synchronization/lock.h" #include "storage/browser/file_system/mount_points.h" #include "storage/common/file_system/file_system_types.h" @@ -89,6 +87,9 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) IsolatedContext : public MountPoints { // The instance is lazily created per browser process. static IsolatedContext* GetInstance(); + IsolatedContext(const IsolatedContext&) = delete; + IsolatedContext& operator=(const IsolatedContext&) = delete; + // Returns true if the given filesystem type is managed by IsolatedContext // (i.e. if the given |type| is Isolated or External). // TODO(kinuko): needs a better function name. @@ -214,8 +215,6 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) IsolatedContext : public MountPoints { // Reverse map from registered path to IDs. std::map<base::FilePath, std::set<std::string>> path_to_id_map_; - - DISALLOW_COPY_AND_ASSIGN(IsolatedContext); }; } // namespace storage diff --git a/chromium/storage/browser/file_system/isolated_context_unittest.cc b/chromium/storage/browser/file_system/isolated_context_unittest.cc index a68becfb97d..58f5fab2dee 100644 --- a/chromium/storage/browser/file_system/isolated_context_unittest.cc +++ b/chromium/storage/browser/file_system/isolated_context_unittest.cc @@ -7,7 +7,6 @@ #include <string> #include "base/cxx17_backports.h" -#include "base/macros.h" #include "storage/browser/file_system/file_system_url.h" #include "storage/browser/file_system/isolated_context.h" #include "testing/gtest/include/gtest/gtest.h" @@ -51,6 +50,9 @@ class IsolatedContextTest : public testing::Test { fileset_.insert(path.NormalizePathSeparators()); } + IsolatedContextTest(const IsolatedContextTest&) = delete; + IsolatedContextTest& operator=(const IsolatedContextTest&) = delete; + void SetUp() override { IsolatedContext::FileInfoSet files; for (const auto& path : kTestPaths) { @@ -75,9 +77,6 @@ class IsolatedContextTest : public testing::Test { std::string id_; std::multiset<base::FilePath> fileset_; std::vector<std::string> names_; - - private: - DISALLOW_COPY_AND_ASSIGN(IsolatedContextTest); }; TEST_F(IsolatedContextTest, RegisterAndRevokeTest) { diff --git a/chromium/storage/browser/file_system/isolated_file_system_backend.cc b/chromium/storage/browser/file_system/isolated_file_system_backend.cc index ad82ddbb82d..01bea4b9d83 100644 --- a/chromium/storage/browser/file_system/isolated_file_system_backend.cc +++ b/chromium/storage/browser/file_system/isolated_file_system_backend.cc @@ -14,7 +14,7 @@ #include "base/check.h" #include "base/files/file_path.h" #include "base/notreached.h" -#include "base/sequenced_task_runner.h" +#include "base/task/sequenced_task_runner.h" #include "base/threading/thread_task_runner_handle.h" #include "storage/browser/file_system/async_file_util_adapter.h" #include "storage/browser/file_system/copy_or_move_file_validator.h" diff --git a/chromium/storage/browser/file_system/local_file_stream_reader.cc b/chromium/storage/browser/file_system/local_file_stream_reader.cc index 8ede6afb3a1..21e5744d024 100644 --- a/chromium/storage/browser/file_system/local_file_stream_reader.cc +++ b/chromium/storage/browser/file_system/local_file_stream_reader.cc @@ -14,8 +14,8 @@ #include "base/files/file_util.h" #include "base/location.h" #include "base/memory/ptr_util.h" -#include "base/task_runner.h" -#include "base/task_runner_util.h" +#include "base/task/task_runner.h" +#include "base/task/task_runner_util.h" #include "net/base/file_stream.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" diff --git a/chromium/storage/browser/file_system/local_file_stream_reader_unittest.cc b/chromium/storage/browser/file_system/local_file_stream_reader_unittest.cc index aceebc879a3..2e2ff8ead6c 100644 --- a/chromium/storage/browser/file_system/local_file_stream_reader_unittest.cc +++ b/chromium/storage/browser/file_system/local_file_stream_reader_unittest.cc @@ -17,9 +17,8 @@ #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" #include "base/location.h" -#include "base/macros.h" #include "base/run_loop.h" -#include "base/single_thread_task_runner.h" +#include "base/task/single_thread_task_runner.h" #include "base/test/task_environment.h" #include "base/threading/thread.h" #include "net/base/io_buffer.h" diff --git a/chromium/storage/browser/file_system/local_file_stream_writer.h b/chromium/storage/browser/file_system/local_file_stream_writer.h index dc47e710ea3..a4b988434fa 100644 --- a/chromium/storage/browser/file_system/local_file_stream_writer.h +++ b/chromium/storage/browser/file_system/local_file_stream_writer.h @@ -14,9 +14,8 @@ #include "base/compiler_specific.h" #include "base/component_export.h" #include "base/files/file_path.h" -#include "base/macros.h" #include "base/memory/weak_ptr.h" -#include "base/task_runner.h" +#include "base/task/task_runner.h" #include "storage/browser/file_system/file_stream_writer.h" namespace net { diff --git a/chromium/storage/browser/file_system/local_file_util.cc b/chromium/storage/browser/file_system/local_file_util.cc index 771e750b2c7..a64e4247c09 100644 --- a/chromium/storage/browser/file_system/local_file_util.cc +++ b/chromium/storage/browser/file_system/local_file_util.cc @@ -11,6 +11,7 @@ #include "base/files/file_enumerator.h" #include "base/files/file_util.h" #include "base/memory/ptr_util.h" +#include "base/memory/raw_ptr.h" #include "storage/browser/file_system/async_file_util_adapter.h" #include "storage/browser/file_system/file_system_context.h" #include "storage/browser/file_system/file_system_operation_context.h" @@ -65,7 +66,7 @@ class LocalFileUtil::LocalFileEnumerator private: // The |LocalFileUtil| producing |this| is expected to remain valid // through the whole lifetime of the enumerator. - const LocalFileUtil* const file_util_; + const raw_ptr<const LocalFileUtil> file_util_; base::FileEnumerator file_enum_; base::FileEnumerator::FileInfo file_util_info_; base::FilePath platform_root_path_; @@ -182,7 +183,7 @@ base::File::Error LocalFileUtil::CopyOrMoveFile( FileSystemOperationContext* context, const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, bool copy) { base::FilePath src_file_path; base::File::Error error = GetLocalFilePath(context, src_url, &src_file_path); @@ -195,7 +196,7 @@ base::File::Error LocalFileUtil::CopyOrMoveFile( return error; return NativeFileUtil::CopyOrMoveFile( - src_file_path, dest_file_path, option, + src_file_path, dest_file_path, options, NativeFileUtil::CopyOrMoveModeForDestination(dest_url, copy)); } @@ -212,7 +213,7 @@ base::File::Error LocalFileUtil::CopyInForeignFile( if (error != base::File::FILE_OK) return error; return NativeFileUtil::CopyOrMoveFile( - src_file_path, dest_file_path, FileSystemOperation::OPTION_NONE, + src_file_path, dest_file_path, FileSystemOperation::CopyOrMoveOptionSet(), NativeFileUtil::CopyOrMoveModeForDestination(dest_url, true /* copy */)); } diff --git a/chromium/storage/browser/file_system/local_file_util.h b/chromium/storage/browser/file_system/local_file_util.h index 14506422802..6a21057a3c9 100644 --- a/chromium/storage/browser/file_system/local_file_util.h +++ b/chromium/storage/browser/file_system/local_file_util.h @@ -12,7 +12,6 @@ #include "base/compiler_specific.h" #include "base/component_export.h" #include "base/files/file_path.h" -#include "base/macros.h" #include "storage/browser/file_system/file_system_file_util.h" namespace base { @@ -69,7 +68,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) LocalFileUtil base::File::Error CopyOrMoveFile(FileSystemOperationContext* context, const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, bool copy) override; base::File::Error CopyInForeignFile(FileSystemOperationContext* context, const base::FilePath& src_file_path, diff --git a/chromium/storage/browser/file_system/local_file_util_unittest.cc b/chromium/storage/browser/file_system/local_file_util_unittest.cc index 76a8cda48c1..20c6378fe3a 100644 --- a/chromium/storage/browser/file_system/local_file_util_unittest.cc +++ b/chromium/storage/browser/file_system/local_file_util_unittest.cc @@ -11,7 +11,6 @@ #include "base/files/file_path.h" #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" -#include "base/macros.h" #include "base/run_loop.h" #include "base/test/task_environment.h" #include "build/build_config.h" @@ -42,6 +41,9 @@ class LocalFileUtilTest : public testing::Test { public: LocalFileUtilTest() = default; + LocalFileUtilTest(const LocalFileUtilTest&) = delete; + LocalFileUtilTest& operator=(const LocalFileUtilTest&) = delete; + void SetUp() override { ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); file_system_context_ = CreateFileSystemContextForTesting( @@ -119,8 +121,6 @@ class LocalFileUtilTest : public testing::Test { base::test::TaskEnvironment task_environment_; scoped_refptr<FileSystemContext> file_system_context_; base::ScopedTempDir data_dir_; - - DISALLOW_COPY_AND_ASSIGN(LocalFileUtilTest); }; TEST_F(LocalFileUtilTest, CreateAndClose) { diff --git a/chromium/storage/browser/file_system/memory_file_stream_reader.cc b/chromium/storage/browser/file_system/memory_file_stream_reader.cc index 2eba0f5e082..d2686f07cc5 100644 --- a/chromium/storage/browser/file_system/memory_file_stream_reader.cc +++ b/chromium/storage/browser/file_system/memory_file_stream_reader.cc @@ -8,7 +8,7 @@ #include <utility> #include "base/memory/ptr_util.h" -#include "base/task_runner_util.h" +#include "base/task/task_runner_util.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" diff --git a/chromium/storage/browser/file_system/memory_file_stream_reader_unittest.cc b/chromium/storage/browser/file_system/memory_file_stream_reader_unittest.cc index d2a5a5cd706..a05f88ea95f 100644 --- a/chromium/storage/browser/file_system/memory_file_stream_reader_unittest.cc +++ b/chromium/storage/browser/file_system/memory_file_stream_reader_unittest.cc @@ -16,7 +16,6 @@ #include "base/files/file_path.h" #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" -#include "base/macros.h" #include "base/test/task_environment.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" diff --git a/chromium/storage/browser/file_system/memory_file_stream_writer.cc b/chromium/storage/browser/file_system/memory_file_stream_writer.cc index fe9933f8cd9..9863cf04b73 100644 --- a/chromium/storage/browser/file_system/memory_file_stream_writer.cc +++ b/chromium/storage/browser/file_system/memory_file_stream_writer.cc @@ -8,7 +8,7 @@ #include <utility> #include "base/memory/ptr_util.h" -#include "base/task_runner_util.h" +#include "base/task/task_runner_util.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" diff --git a/chromium/storage/browser/file_system/native_file_util.cc b/chromium/storage/browser/file_system/native_file_util.cc index 2fb54be84f2..106a742df16 100644 --- a/chromium/storage/browser/file_system/native_file_util.cc +++ b/chromium/storage/browser/file_system/native_file_util.cc @@ -253,7 +253,7 @@ bool NativeFileUtil::DirectoryExists(const base::FilePath& path) { base::File::Error NativeFileUtil::CopyOrMoveFile( const base::FilePath& src_path, const base::FilePath& dest_path, - FileSystemOperation::CopyOrMoveOption option, + FileSystemOperation::CopyOrMoveOptionSet options, CopyOrMoveMode mode) { base::File::Info info; base::File::Error error = NativeFileUtil::GetFileInfo(src_path, &info); @@ -290,14 +290,16 @@ base::File::Error NativeFileUtil::CopyOrMoveFile( bool should_retain_file_permissions = false; #if defined(OS_POSIX) int dest_mode; - if (option == FileSystemOperation::OPTION_PRESERVE_DESTINATION_PERMISSIONS) { + if (options.Has(FileSystemOperation::CopyOrMoveOption:: + kPreserveDestinationPermissions)) { // Will be false if the destination file doesn't exist. should_retain_file_permissions = base::GetPosixFilePermissions(dest_path, &dest_mode); } #elif defined(OS_WIN) DWORD dest_attributes; - if (option == FileSystemOperation::OPTION_PRESERVE_DESTINATION_PERMISSIONS) { + if (options.Has(FileSystemOperation::CopyOrMoveOption:: + kPreserveDestinationPermissions)) { dest_attributes = ::GetFileAttributes(dest_path.value().c_str()); should_retain_file_permissions = dest_attributes != INVALID_FILE_ATTRIBUTES; } @@ -320,7 +322,8 @@ base::File::Error NativeFileUtil::CopyOrMoveFile( // Preserve the last modified time. Do not return error here even if // the setting is failed, because the copy itself is successfully done. - if (option == FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED) { + if (options.Has( + FileSystemOperation::CopyOrMoveOption::kPreserveLastModified)) { base::TouchFile(dest_path, last_modified, last_modified); } diff --git a/chromium/storage/browser/file_system/native_file_util.h b/chromium/storage/browser/file_system/native_file_util.h index c71349dc082..a83f51eb658 100644 --- a/chromium/storage/browser/file_system/native_file_util.h +++ b/chromium/storage/browser/file_system/native_file_util.h @@ -12,7 +12,6 @@ #include "base/component_export.h" #include "base/files/file.h" #include "base/files/file_path.h" -#include "base/macros.h" #include "storage/browser/file_system/file_system_file_util.h" namespace base { @@ -35,6 +34,10 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) NativeFileUtil { public: enum CopyOrMoveMode { COPY_NOSYNC, COPY_SYNC, MOVE }; + NativeFileUtil() = delete; + NativeFileUtil(const NativeFileUtil&) = delete; + NativeFileUtil& operator=(const NativeFileUtil&) = delete; + static CopyOrMoveMode CopyOrMoveModeForDestination( const FileSystemURL& dest_url, bool copy); @@ -58,13 +61,10 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) NativeFileUtil { static base::File::Error CopyOrMoveFile( const base::FilePath& src_path, const base::FilePath& dest_path, - FileSystemOperation::CopyOrMoveOption option, + FileSystemOperation::CopyOrMoveOptionSet options, CopyOrMoveMode mode); static base::File::Error DeleteFile(const base::FilePath& path); static base::File::Error DeleteDirectory(const base::FilePath& path); - - private: - DISALLOW_IMPLICIT_CONSTRUCTORS(NativeFileUtil); }; } // namespace storage diff --git a/chromium/storage/browser/file_system/native_file_util_unittest.cc b/chromium/storage/browser/file_system/native_file_util_unittest.cc index 9191ab56c37..16a87636fa5 100644 --- a/chromium/storage/browser/file_system/native_file_util_unittest.cc +++ b/chromium/storage/browser/file_system/native_file_util_unittest.cc @@ -11,7 +11,6 @@ #include "base/files/file_path.h" #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" -#include "base/macros.h" #include "build/build_config.h" #include "storage/browser/file_system/native_file_util.h" #include "testing/gtest/include/gtest/gtest.h" @@ -21,11 +20,20 @@ #endif // defined(OS_WIN) namespace storage { +namespace { + +using CopyOrMoveOption = FileSystemOperation::CopyOrMoveOption; +using CopyOrMoveOptionSet = FileSystemOperation::CopyOrMoveOptionSet; + +} // namespace class NativeFileUtilTest : public testing::Test { public: NativeFileUtilTest() = default; + NativeFileUtilTest(const NativeFileUtilTest&) = delete; + NativeFileUtilTest& operator=(const NativeFileUtilTest&) = delete; + void SetUp() override { ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); } protected: @@ -71,8 +79,6 @@ class NativeFileUtilTest : public testing::Test { private: base::ScopedTempDir data_dir_; - - DISALLOW_COPY_AND_ASSIGN(NativeFileUtilTest); }; TEST_F(NativeFileUtilTest, CreateCloseAndDeleteFile) { @@ -242,11 +248,13 @@ TEST_F(NativeFileUtilTest, CopyFile) { ASSERT_EQ(base::File::FILE_OK, NativeFileUtil::CopyOrMoveFile( - from_file, to_file1, FileSystemOperation::OPTION_NONE, nosync)); + from_file, to_file1, FileSystemOperation::CopyOrMoveOptionSet(), + nosync)); ASSERT_EQ(base::File::FILE_OK, NativeFileUtil::CopyOrMoveFile( - from_file, to_file2, FileSystemOperation::OPTION_NONE, sync)); + from_file, to_file2, FileSystemOperation::CopyOrMoveOptionSet(), + sync)); EXPECT_TRUE(FileExists(from_file)); EXPECT_EQ(1020, GetSize(from_file)); @@ -260,37 +268,40 @@ TEST_F(NativeFileUtilTest, CopyFile) { NativeFileUtil::CreateDirectory(dir, false, false)); ASSERT_TRUE(base::DirectoryExists(dir)); base::FilePath to_dir_file = dir.AppendASCII("file"); - ASSERT_EQ(base::File::FILE_OK, NativeFileUtil::CopyOrMoveFile( - from_file, to_dir_file, - FileSystemOperation::OPTION_NONE, nosync)); + ASSERT_EQ(base::File::FILE_OK, + NativeFileUtil::CopyOrMoveFile( + from_file, to_dir_file, + FileSystemOperation::CopyOrMoveOptionSet(), nosync)); EXPECT_TRUE(FileExists(to_dir_file)); EXPECT_EQ(1020, GetSize(to_dir_file)); // Following tests are error checking. // Source doesn't exist. - EXPECT_EQ( - base::File::FILE_ERROR_NOT_FOUND, - NativeFileUtil::CopyOrMoveFile(Path("nonexists"), Path("file"), - FileSystemOperation::OPTION_NONE, nosync)); + EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, + NativeFileUtil::CopyOrMoveFile( + Path("nonexists"), Path("file"), + FileSystemOperation::CopyOrMoveOptionSet(), nosync)); // Source is not a file. EXPECT_EQ(base::File::FILE_ERROR_NOT_A_FILE, NativeFileUtil::CopyOrMoveFile( - dir, Path("file"), FileSystemOperation::OPTION_NONE, nosync)); + dir, Path("file"), FileSystemOperation::CopyOrMoveOptionSet(), + nosync)); // Destination is not a file. - EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, - NativeFileUtil::CopyOrMoveFile( - from_file, dir, FileSystemOperation::OPTION_NONE, nosync)); + EXPECT_EQ( + base::File::FILE_ERROR_INVALID_OPERATION, + NativeFileUtil::CopyOrMoveFile( + from_file, dir, FileSystemOperation::CopyOrMoveOptionSet(), nosync)); // Destination's parent doesn't exist. EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, NativeFileUtil::CopyOrMoveFile( from_file, Path("nodir").AppendASCII("file"), - FileSystemOperation::OPTION_NONE, nosync)); + FileSystemOperation::CopyOrMoveOptionSet(), nosync)); // Destination's parent is a file. EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, NativeFileUtil::CopyOrMoveFile( from_file, Path("tofile1").AppendASCII("file"), - FileSystemOperation::OPTION_NONE, nosync)); + FileSystemOperation::CopyOrMoveOptionSet(), nosync)); } TEST_F(NativeFileUtilTest, MoveFile) { @@ -309,7 +320,8 @@ TEST_F(NativeFileUtilTest, MoveFile) { ASSERT_EQ(base::File::FILE_OK, NativeFileUtil::CopyOrMoveFile( - from_file, to_file, FileSystemOperation::OPTION_NONE, move)); + from_file, to_file, FileSystemOperation::CopyOrMoveOptionSet(), + move)); EXPECT_FALSE(FileExists(from_file)); EXPECT_TRUE(FileExists(to_file)); @@ -325,43 +337,46 @@ TEST_F(NativeFileUtilTest, MoveFile) { NativeFileUtil::CreateDirectory(dir, false, false)); ASSERT_TRUE(base::DirectoryExists(dir)); base::FilePath to_dir_file = dir.AppendASCII("file"); - ASSERT_EQ(base::File::FILE_OK, NativeFileUtil::CopyOrMoveFile( - from_file, to_dir_file, - FileSystemOperation::OPTION_NONE, move)); + ASSERT_EQ(base::File::FILE_OK, + NativeFileUtil::CopyOrMoveFile( + from_file, to_dir_file, + FileSystemOperation::CopyOrMoveOptionSet(), move)); EXPECT_FALSE(FileExists(from_file)); EXPECT_TRUE(FileExists(to_dir_file)); EXPECT_EQ(1020, GetSize(to_dir_file)); // Following is error checking. // Source doesn't exist. - EXPECT_EQ( - base::File::FILE_ERROR_NOT_FOUND, - NativeFileUtil::CopyOrMoveFile(Path("nonexists"), Path("file"), - FileSystemOperation::OPTION_NONE, move)); + EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, + NativeFileUtil::CopyOrMoveFile( + Path("nonexists"), Path("file"), + FileSystemOperation::CopyOrMoveOptionSet(), move)); base::FilePath dir2 = Path("dir2"); ASSERT_EQ(base::File::FILE_OK, NativeFileUtil::CreateDirectory(dir2, false, false)); ASSERT_TRUE(base::DirectoryExists(dir2)); // Source is a directory, destination is a file. - EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, - NativeFileUtil::CopyOrMoveFile( - dir, to_file, FileSystemOperation::OPTION_NONE, move)); + EXPECT_EQ( + base::File::FILE_ERROR_INVALID_OPERATION, + NativeFileUtil::CopyOrMoveFile( + dir, to_file, FileSystemOperation::CopyOrMoveOptionSet(), move)); #if defined(OS_WIN) // Source is a directory, destination is a directory. EXPECT_EQ(base::File::FILE_ERROR_NOT_A_FILE, NativeFileUtil::CopyOrMoveFile( - dir, dir2, FileSystemOperation::OPTION_NONE, move)); + dir, dir2, FileSystemOperation::CopyOrMoveOptionSet(), move)); #endif ASSERT_EQ(base::File::FILE_OK, NativeFileUtil::EnsureFileExists(from_file, &created)); ASSERT_TRUE(FileExists(from_file)); // Destination is not a file. - EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, - NativeFileUtil::CopyOrMoveFile( - from_file, dir, FileSystemOperation::OPTION_NONE, move)); + EXPECT_EQ( + base::File::FILE_ERROR_INVALID_OPERATION, + NativeFileUtil::CopyOrMoveFile( + from_file, dir, FileSystemOperation::CopyOrMoveOptionSet(), move)); ASSERT_EQ(base::File::FILE_OK, NativeFileUtil::EnsureFileExists(from_file, &created)); @@ -370,12 +385,12 @@ TEST_F(NativeFileUtilTest, MoveFile) { EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, NativeFileUtil::CopyOrMoveFile( from_file, Path("nodir").AppendASCII("file"), - FileSystemOperation::OPTION_NONE, move)); + FileSystemOperation::CopyOrMoveOptionSet(), move)); // Destination's parent is a file. EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, NativeFileUtil::CopyOrMoveFile( from_file, Path("tofile1").AppendASCII("file"), - FileSystemOperation::OPTION_NONE, move)); + FileSystemOperation::CopyOrMoveOptionSet(), move)); } TEST_F(NativeFileUtilTest, MoveFile_Directory) { @@ -395,9 +410,10 @@ TEST_F(NativeFileUtilTest, MoveFile_Directory) { EXPECT_TRUE(FileExists(from_file)); EXPECT_EQ(1020, GetSize(from_file)); - ASSERT_EQ(base::File::FILE_OK, NativeFileUtil::CopyOrMoveFile( - from_directory, to_directory, - FileSystemOperation::OPTION_NONE, move)); + ASSERT_EQ(base::File::FILE_OK, + NativeFileUtil::CopyOrMoveFile( + from_directory, to_directory, + FileSystemOperation::CopyOrMoveOptionSet(), move)); EXPECT_FALSE(base::DirectoryExists(from_directory)); EXPECT_FALSE(FileExists(from_file)); @@ -425,9 +441,10 @@ TEST_F(NativeFileUtilTest, MoveFile_OverwriteEmptyDirectory) { EXPECT_TRUE(FileExists(from_file)); EXPECT_EQ(1020, GetSize(from_file)); - ASSERT_EQ(base::File::FILE_OK, NativeFileUtil::CopyOrMoveFile( - from_directory, to_directory, - FileSystemOperation::OPTION_NONE, move)); + ASSERT_EQ(base::File::FILE_OK, + NativeFileUtil::CopyOrMoveFile( + from_directory, to_directory, + FileSystemOperation::CopyOrMoveOptionSet(), move)); EXPECT_FALSE(base::DirectoryExists(from_directory)); EXPECT_FALSE(FileExists(from_file)); @@ -456,7 +473,7 @@ TEST_F(NativeFileUtilTest, PreserveLastModified) { ASSERT_EQ(base::File::FILE_OK, NativeFileUtil::CopyOrMoveFile( from_file, to_file1, - FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED, + CopyOrMoveOptionSet(CopyOrMoveOption::kPreserveLastModified), NativeFileUtil::COPY_NOSYNC)); base::File::Info file_info2; @@ -469,7 +486,7 @@ TEST_F(NativeFileUtilTest, PreserveLastModified) { ASSERT_EQ(base::File::FILE_OK, NativeFileUtil::CopyOrMoveFile( from_file, to_file2, - FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED, + CopyOrMoveOptionSet(CopyOrMoveOption::kPreserveLastModified), NativeFileUtil::COPY_SYNC)); ASSERT_TRUE(FileExists(to_file2)); @@ -481,7 +498,7 @@ TEST_F(NativeFileUtilTest, PreserveLastModified) { ASSERT_EQ(base::File::FILE_OK, NativeFileUtil::CopyOrMoveFile( from_file, to_file3, - FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED, + CopyOrMoveOptionSet(CopyOrMoveOption::kPreserveLastModified), NativeFileUtil::MOVE)); ASSERT_TRUE(FileExists(to_file3)); @@ -530,7 +547,8 @@ TEST_F(NativeFileUtilTest, PreserveDestinationPermissions) { ASSERT_EQ(base::File::FILE_OK, NativeFileUtil::CopyOrMoveFile( from_file, to_file, - FileSystemOperation::OPTION_PRESERVE_DESTINATION_PERMISSIONS, + CopyOrMoveOptionSet( + CopyOrMoveOption::kPreserveDestinationPermissions), NativeFileUtil::COPY_NOSYNC)); #if defined(OS_POSIX) ExpectFileHasPermissionsPosix(to_file, old_dest_mode); @@ -542,7 +560,8 @@ TEST_F(NativeFileUtilTest, PreserveDestinationPermissions) { ASSERT_EQ(base::File::FILE_OK, NativeFileUtil::CopyOrMoveFile( from_file, to_file, - FileSystemOperation::OPTION_PRESERVE_DESTINATION_PERMISSIONS, + CopyOrMoveOptionSet( + CopyOrMoveOption::kPreserveDestinationPermissions), NativeFileUtil::COPY_SYNC)); #if defined(OS_POSIX) ExpectFileHasPermissionsPosix(to_file, old_dest_mode); @@ -554,7 +573,8 @@ TEST_F(NativeFileUtilTest, PreserveDestinationPermissions) { ASSERT_EQ(base::File::FILE_OK, NativeFileUtil::CopyOrMoveFile( from_file, to_file, - FileSystemOperation::OPTION_PRESERVE_DESTINATION_PERMISSIONS, + CopyOrMoveOptionSet( + CopyOrMoveOption::kPreserveDestinationPermissions), NativeFileUtil::MOVE)); #if defined(OS_POSIX) ExpectFileHasPermissionsPosix(to_file, old_dest_mode); @@ -564,4 +584,122 @@ TEST_F(NativeFileUtilTest, PreserveDestinationPermissions) { } #endif // defined(OS_POSIX) || defined(OS_WIN) +#if defined(OS_POSIX) || defined(OS_WIN) +TEST_F(NativeFileUtilTest, PreserveLastModifiedAndDestinationPermissions) { + base::FilePath from_file = Path("fromfile"); + base::FilePath to_file1 = Path("tofile1"); + base::FilePath to_file2 = Path("tofile2"); + base::FilePath to_file3 = Path("tofile3"); + bool created = false; + ASSERT_EQ(base::File::FILE_OK, + NativeFileUtil::EnsureFileExists(from_file, &created)); + ASSERT_TRUE(created); + EXPECT_TRUE(FileExists(from_file)); + + base::File::Info from_file_info; + ASSERT_EQ(base::File::FILE_OK, + NativeFileUtil::GetFileInfo(from_file, &from_file_info)); + + // Create destination files. + ASSERT_EQ(base::File::FILE_OK, + NativeFileUtil::EnsureFileExists(to_file1, &created)); + ASSERT_TRUE(created); + EXPECT_TRUE(FileExists(to_file1)); + + ASSERT_EQ(base::File::FILE_OK, + NativeFileUtil::EnsureFileExists(to_file2, &created)); + ASSERT_TRUE(created); + EXPECT_TRUE(FileExists(to_file2)); + + ASSERT_EQ(base::File::FILE_OK, + NativeFileUtil::EnsureFileExists(to_file3, &created)); + ASSERT_TRUE(created); + EXPECT_TRUE(FileExists(to_file3)); + + // Get initial permissions of the dest files. We can assume that the 3 + // destination files have the same permissions. +#if defined(OS_POSIX) + int dest_initial_mode; + ASSERT_TRUE(base::GetPosixFilePermissions(to_file1, &dest_initial_mode)); +#elif defined(OS_WIN) + DWORD dest_initial_attributes = ::GetFileAttributes(to_file1.value().c_str()); + ASSERT_NE(dest_initial_attributes, INVALID_FILE_ATTRIBUTES); +#endif // defined(OS_POSIX) + + // Give dest files some distinct permissions they didn't have before. +#if defined(OS_POSIX) + int old_dest_mode = dest_initial_mode | S_IRGRP | S_IXOTH; + EXPECT_NE(old_dest_mode, dest_initial_mode); + EXPECT_TRUE(base::SetPosixFilePermissions(to_file1, old_dest_mode)); + EXPECT_TRUE(base::SetPosixFilePermissions(to_file2, old_dest_mode)); + EXPECT_TRUE(base::SetPosixFilePermissions(to_file3, old_dest_mode)); +#elif defined(OS_WIN) + DWORD old_dest_attributes = FILE_ATTRIBUTE_NORMAL; + EXPECT_NE(old_dest_attributes, dest_initial_attributes); + EXPECT_TRUE( + ::SetFileAttributes(to_file1.value().c_str(), old_dest_attributes)); + EXPECT_TRUE( + ::SetFileAttributes(to_file2.value().c_str(), old_dest_attributes)); + EXPECT_TRUE( + ::SetFileAttributes(to_file3.value().c_str(), old_dest_attributes)); +#endif // defined(OS_POSIX) + + // Test for copy (nosync). + ASSERT_EQ(base::File::FILE_OK, + NativeFileUtil::CopyOrMoveFile( + from_file, to_file1, + CopyOrMoveOptionSet( + CopyOrMoveOption::kPreserveLastModified, + CopyOrMoveOption::kPreserveDestinationPermissions), + NativeFileUtil::COPY_NOSYNC)); + base::File::Info to_file_info; + ASSERT_TRUE(FileExists(to_file1)); + ASSERT_EQ(base::File::FILE_OK, + NativeFileUtil::GetFileInfo(to_file1, &to_file_info)); + EXPECT_EQ(from_file_info.last_modified, to_file_info.last_modified); + +#if defined(OS_POSIX) + ExpectFileHasPermissionsPosix(to_file1, old_dest_mode); +#elif defined(OS_WIN) + ExpectFileHasPermissionsWin(to_file1, old_dest_attributes); +#endif // defined(OS_POSIX) + + // Test for copy (sync). + ASSERT_EQ(base::File::FILE_OK, + NativeFileUtil::CopyOrMoveFile( + from_file, to_file2, + CopyOrMoveOptionSet( + CopyOrMoveOption::kPreserveLastModified, + CopyOrMoveOption::kPreserveDestinationPermissions), + NativeFileUtil::COPY_SYNC)); + ASSERT_EQ(base::File::FILE_OK, + NativeFileUtil::GetFileInfo(to_file2, &to_file_info)); + EXPECT_EQ(from_file_info.last_modified, to_file_info.last_modified); + +#if defined(OS_POSIX) + ExpectFileHasPermissionsPosix(to_file2, old_dest_mode); +#elif defined(OS_WIN) + ExpectFileHasPermissionsWin(to_file2, old_dest_attributes); +#endif // defined(OS_POSIX) + + // Test for move. + ASSERT_EQ(base::File::FILE_OK, + NativeFileUtil::CopyOrMoveFile( + from_file, to_file3, + CopyOrMoveOptionSet( + CopyOrMoveOption::kPreserveLastModified, + CopyOrMoveOption::kPreserveDestinationPermissions), + NativeFileUtil::MOVE)); + ASSERT_EQ(base::File::FILE_OK, + NativeFileUtil::GetFileInfo(to_file3, &to_file_info)); + EXPECT_EQ(from_file_info.last_modified, to_file_info.last_modified); + +#if defined(OS_POSIX) + ExpectFileHasPermissionsPosix(to_file3, old_dest_mode); +#elif defined(OS_WIN) + ExpectFileHasPermissionsWin(to_file3, old_dest_attributes); +#endif // defined(OS_POSIX) +} +#endif // defined(OS_POSIX) || defined(OS_WIN) + } // namespace storage diff --git a/chromium/storage/browser/file_system/obfuscated_file_util.cc b/chromium/storage/browser/file_system/obfuscated_file_util.cc index bdf8475d28b..a3840c4b0ba 100644 --- a/chromium/storage/browser/file_system/obfuscated_file_util.cc +++ b/chromium/storage/browser/file_system/obfuscated_file_util.cc @@ -17,6 +17,7 @@ #include "base/format_macros.h" #include "base/logging.h" #include "base/memory/ptr_util.h" +#include "base/memory/raw_ptr.h" #include "base/metrics/histogram.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_util.h" @@ -201,9 +202,9 @@ class ObfuscatedFileEnumerator final } } - SandboxDirectoryDatabase* db_; - FileSystemOperationContext* context_; - ObfuscatedFileUtil* obfuscated_file_util_; + raw_ptr<SandboxDirectoryDatabase> db_; + raw_ptr<FileSystemOperationContext> context_; + raw_ptr<ObfuscatedFileUtil> obfuscated_file_util_; FileSystemURL root_url_; bool recursive_; @@ -518,7 +519,7 @@ base::File::Error ObfuscatedFileUtil::CopyOrMoveFile( FileSystemOperationContext* context, const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, bool copy) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); // Cross-filesystem copies and moves should be handled via CopyInForeignFile. @@ -603,7 +604,7 @@ base::File::Error ObfuscatedFileUtil::CopyOrMoveFile( if (copy) { if (overwrite) { error = delegate_->CopyOrMoveFile( - src_local_path, dest_local_path, option, + src_local_path, dest_local_path, options, delegate_->CopyOrMoveModeForDestination(dest_url, true /* copy */)); } else { // non-overwrite error = CreateFile(context, src_local_path, false /* foreign_source */, @@ -707,7 +708,8 @@ base::File::Error ObfuscatedFileUtil::CopyInForeignFile( base::FilePath dest_local_path = DataPathToLocalPath(dest_url, dest_file_info.data_path); error = delegate_->CopyInForeignFile( - src_file_path, dest_local_path, FileSystemOperation::OPTION_NONE, + src_file_path, dest_local_path, + FileSystemOperation::CopyOrMoveOptionSet(), delegate_->CopyOrMoveModeForDestination(dest_url, true /* copy */)); } else { error = CreateFile(context, src_file_path, true /* foreign_source */, @@ -1129,11 +1131,13 @@ base::File::Error ObfuscatedFileUtil::CreateFile( } else { if (foreign_source) { error = delegate_->CopyInForeignFile( - src_file_path, dest_local_path, FileSystemOperation::OPTION_NONE, + src_file_path, dest_local_path, + FileSystemOperation::CopyOrMoveOptionSet(), delegate_->CopyOrMoveModeForDestination(dest_url, true /* copy */)); } else { error = delegate_->CopyOrMoveFile( - src_file_path, dest_local_path, FileSystemOperation::OPTION_NONE, + src_file_path, dest_local_path, + FileSystemOperation::CopyOrMoveOptionSet(), delegate_->CopyOrMoveModeForDestination(dest_url, true /* copy */)); } created = true; @@ -1364,10 +1368,10 @@ base::File ObfuscatedFileUtil::CreateOrOpenInternal( const FileSystemURL& url, int file_flags) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - DCHECK( - !(file_flags & - (base::File::FLAG_DELETE_ON_CLOSE | base::File::FLAG_HIDDEN | - base::File::FLAG_EXCLUSIVE_READ | base::File::FLAG_EXCLUSIVE_WRITE))); + DCHECK(!(file_flags & + (base::File::FLAG_DELETE_ON_CLOSE | base::File::FLAG_WIN_HIDDEN | + base::File::FLAG_WIN_EXCLUSIVE_READ | + base::File::FLAG_WIN_EXCLUSIVE_WRITE))); SandboxDirectoryDatabase* db = GetDirectoryDatabase(url, true); if (!db) return base::File(base::File::FILE_ERROR_FAILED); diff --git a/chromium/storage/browser/file_system/obfuscated_file_util.h b/chromium/storage/browser/file_system/obfuscated_file_util.h index 89aed25b846..69b70676251 100644 --- a/chromium/storage/browser/file_system/obfuscated_file_util.h +++ b/chromium/storage/browser/file_system/obfuscated_file_util.h @@ -17,7 +17,7 @@ #include "base/component_export.h" #include "base/files/file.h" #include "base/files/file_path.h" -#include "base/macros.h" +#include "base/memory/raw_ptr.h" #include "base/memory/scoped_refptr.h" #include "base/sequence_checker.h" #include "base/timer/timer.h" @@ -154,7 +154,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) ObfuscatedFileUtil base::File::Error CopyOrMoveFile(FileSystemOperationContext* context, const FileSystemURL& src_url, const FileSystemURL& dest_url, - CopyOrMoveOption option, + CopyOrMoveOptionSet options, bool copy) override; base::File::Error CopyInForeignFile(FileSystemOperationContext* context, const base::FilePath& src_file_path, @@ -331,7 +331,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) ObfuscatedFileUtil std::unique_ptr<SandboxOriginDatabaseInterface> origin_database_; scoped_refptr<SpecialStoragePolicy> special_storage_policy_; base::FilePath file_system_directory_; - leveldb::Env* env_override_; + raw_ptr<leveldb::Env> env_override_; bool is_incognito_; // Used to delete database after a certain period of inactivity. @@ -343,7 +343,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) ObfuscatedFileUtil std::set<std::string> known_type_strings_; // Not owned. - SandboxFileSystemBackendDelegate* sandbox_delegate_; + raw_ptr<SandboxFileSystemBackendDelegate> sandbox_delegate_; std::unique_ptr<ObfuscatedFileUtilDelegate> delegate_; }; diff --git a/chromium/storage/browser/file_system/obfuscated_file_util_delegate.h b/chromium/storage/browser/file_system/obfuscated_file_util_delegate.h index dfb81c8a1b3..dd78689c656 100644 --- a/chromium/storage/browser/file_system/obfuscated_file_util_delegate.h +++ b/chromium/storage/browser/file_system/obfuscated_file_util_delegate.h @@ -51,12 +51,12 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) ObfuscatedFileUtilDelegate { virtual base::File::Error CopyOrMoveFile( const base::FilePath& src_path, const base::FilePath& dest_path, - FileSystemOperation::CopyOrMoveOption option, + FileSystemOperation::CopyOrMoveOptionSet options, NativeFileUtil::CopyOrMoveMode mode) = 0; virtual base::File::Error CopyInForeignFile( const base::FilePath& src_path, const base::FilePath& dest_path, - FileSystemOperation::CopyOrMoveOption option, + FileSystemOperation::CopyOrMoveOptionSet options, NativeFileUtil::CopyOrMoveMode mode) = 0; virtual base::File::Error DeleteFile(const base::FilePath& path) = 0; }; diff --git a/chromium/storage/browser/file_system/obfuscated_file_util_disk_delegate.cc b/chromium/storage/browser/file_system/obfuscated_file_util_disk_delegate.cc index ae1cdcf13fe..fe225cbfe26 100644 --- a/chromium/storage/browser/file_system/obfuscated_file_util_disk_delegate.cc +++ b/chromium/storage/browser/file_system/obfuscated_file_util_disk_delegate.cc @@ -85,17 +85,17 @@ base::File::Error ObfuscatedFileUtilDiskDelegate::Truncate( base::File::Error ObfuscatedFileUtilDiskDelegate::CopyOrMoveFile( const base::FilePath& src_path, const base::FilePath& dest_path, - FileSystemOperation::CopyOrMoveOption option, + FileSystemOperation::CopyOrMoveOptionSet options, NativeFileUtil::CopyOrMoveMode mode) { - return NativeFileUtil::CopyOrMoveFile(src_path, dest_path, option, mode); + return NativeFileUtil::CopyOrMoveFile(src_path, dest_path, options, mode); } base::File::Error ObfuscatedFileUtilDiskDelegate::CopyInForeignFile( const base::FilePath& src_path, const base::FilePath& dest_path, - FileSystemOperation::CopyOrMoveOption option, + FileSystemOperation::CopyOrMoveOptionSet options, NativeFileUtil::CopyOrMoveMode mode) { - return NativeFileUtil::CopyOrMoveFile(src_path, dest_path, option, mode); + return NativeFileUtil::CopyOrMoveFile(src_path, dest_path, options, mode); } base::File::Error ObfuscatedFileUtilDiskDelegate::DeleteFile( diff --git a/chromium/storage/browser/file_system/obfuscated_file_util_disk_delegate.h b/chromium/storage/browser/file_system/obfuscated_file_util_disk_delegate.h index c5615c94f08..afd3be78bd3 100644 --- a/chromium/storage/browser/file_system/obfuscated_file_util_disk_delegate.h +++ b/chromium/storage/browser/file_system/obfuscated_file_util_disk_delegate.h @@ -51,12 +51,12 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) ObfuscatedFileUtilDiskDelegate base::File::Error CopyOrMoveFile( const base::FilePath& src_path, const base::FilePath& dest_path, - FileSystemOperation::CopyOrMoveOption option, + FileSystemOperation::CopyOrMoveOptionSet options, NativeFileUtil::CopyOrMoveMode mode) override; base::File::Error CopyInForeignFile( const base::FilePath& src_path, const base::FilePath& dest_path, - FileSystemOperation::CopyOrMoveOption option, + FileSystemOperation::CopyOrMoveOptionSet options, NativeFileUtil::CopyOrMoveMode mode) override; base::File::Error DeleteFile(const base::FilePath& path) override; }; diff --git a/chromium/storage/browser/file_system/obfuscated_file_util_memory_delegate.cc b/chromium/storage/browser/file_system/obfuscated_file_util_memory_delegate.cc index 2948fa56d6f..7074ca38fa7 100644 --- a/chromium/storage/browser/file_system/obfuscated_file_util_memory_delegate.cc +++ b/chromium/storage/browser/file_system/obfuscated_file_util_memory_delegate.cc @@ -53,6 +53,9 @@ struct ObfuscatedFileUtilMemoryDelegate::Entry { last_accessed = last_modified; } + Entry(const Entry&) = delete; + Entry& operator=(const Entry&) = delete; + Entry(Entry&&) = default; ~Entry() = default; @@ -64,8 +67,6 @@ struct ObfuscatedFileUtilMemoryDelegate::Entry { std::map<base::FilePath::StringType, Entry> directory_content; std::vector<uint8_t> file_content; - - DISALLOW_COPY_AND_ASSIGN(Entry); }; // Keeps a decomposed FilePath. @@ -356,7 +357,7 @@ ObfuscatedFileUtilMemoryDelegate::CopyOrMoveModeForDestination( base::File::Error ObfuscatedFileUtilMemoryDelegate::CopyOrMoveFile( const base::FilePath& src_path, const base::FilePath& dest_path, - FileSystemOperation::CopyOrMoveOption option, + FileSystemOperation::CopyOrMoveOptionSet options, NativeFileUtil::CopyOrMoveMode mode) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); absl::optional<DecomposedPath> src_dp = ParsePath(src_path); @@ -409,11 +410,12 @@ base::File::Error ObfuscatedFileUtilMemoryDelegate::CopyOrMoveFile( break; } - if (option == FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED) { + if (options.Has( + FileSystemOperation::CopyOrMoveOption::kPreserveLastModified)) { Touch(dest_path, last_modified, last_modified); } - // Don't bother with the OPTION_PRESERVE_DESTINATION_PERMISSIONS option, since + // Don't bother with the kPreserveDestinationPermissions option, since // this is not relevant to in-memory files. return base::File::FILE_OK; @@ -596,7 +598,7 @@ base::File::Error ObfuscatedFileUtilMemoryDelegate::CreateFileForTesting( base::File::Error ObfuscatedFileUtilMemoryDelegate::CopyInForeignFile( const base::FilePath& src_path, const base::FilePath& dest_path, - FileSystemOperation::CopyOrMoveOption /* option */, + FileSystemOperation::CopyOrMoveOptionSet /* options */, NativeFileUtil::CopyOrMoveMode /* mode */) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); absl::optional<DecomposedPath> dest_dp = ParsePath(dest_path); diff --git a/chromium/storage/browser/file_system/obfuscated_file_util_memory_delegate.h b/chromium/storage/browser/file_system/obfuscated_file_util_memory_delegate.h index 733d3bcec4c..0a0119d22c1 100644 --- a/chromium/storage/browser/file_system/obfuscated_file_util_memory_delegate.h +++ b/chromium/storage/browser/file_system/obfuscated_file_util_memory_delegate.h @@ -13,7 +13,6 @@ #include "base/containers/span.h" #include "base/files/file.h" #include "base/files/file_path.h" -#include "base/macros.h" #include "base/memory/weak_ptr.h" #include "base/time/time.h" #include "storage/browser/file_system/native_file_util.h" @@ -75,12 +74,12 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) ObfuscatedFileUtilMemoryDelegate base::File::Error CopyOrMoveFile( const base::FilePath& src_path, const base::FilePath& dest_path, - FileSystemOperation::CopyOrMoveOption option, + FileSystemOperation::CopyOrMoveOptionSet options, NativeFileUtil::CopyOrMoveMode mode) override; base::File::Error CopyInForeignFile( const base::FilePath& src_path, const base::FilePath& dest_path, - FileSystemOperation::CopyOrMoveOption option, + FileSystemOperation::CopyOrMoveOptionSet options, NativeFileUtil::CopyOrMoveMode mode) override; base::File::Error DeleteFile(const base::FilePath& path) override; diff --git a/chromium/storage/browser/file_system/obfuscated_file_util_memory_delegate_unittest.cc b/chromium/storage/browser/file_system/obfuscated_file_util_memory_delegate_unittest.cc index 711c83b051c..2430d3136fb 100644 --- a/chromium/storage/browser/file_system/obfuscated_file_util_memory_delegate_unittest.cc +++ b/chromium/storage/browser/file_system/obfuscated_file_util_memory_delegate_unittest.cc @@ -11,17 +11,27 @@ #include "base/files/file_path.h" #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" -#include "base/macros.h" #include "build/build_config.h" #include "net/base/io_buffer.h" #include "testing/gtest/include/gtest/gtest.h" namespace storage { +namespace { + +using CopyOrMoveOption = FileSystemOperation::CopyOrMoveOption; +using CopyOrMoveOptionSet = FileSystemOperation::CopyOrMoveOptionSet; + +} // namespace class ObfuscatedFileUtilMemoryDelegateTest : public testing::Test { public: ObfuscatedFileUtilMemoryDelegateTest() = default; + ObfuscatedFileUtilMemoryDelegateTest( + const ObfuscatedFileUtilMemoryDelegateTest&) = delete; + ObfuscatedFileUtilMemoryDelegateTest& operator=( + const ObfuscatedFileUtilMemoryDelegateTest&) = delete; + void SetUp() override { ASSERT_TRUE(file_system_directory_.CreateUniqueTempDir()); file_util_ = std::make_unique<ObfuscatedFileUtilMemoryDelegate>( @@ -56,8 +66,6 @@ class ObfuscatedFileUtilMemoryDelegateTest : public testing::Test { private: base::ScopedTempDir file_system_directory_; std::unique_ptr<ObfuscatedFileUtilMemoryDelegate> file_util_; - - DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileUtilMemoryDelegateTest); }; TEST_F(ObfuscatedFileUtilMemoryDelegateTest, CreateOrOpenFile) { @@ -272,11 +280,13 @@ TEST_F(ObfuscatedFileUtilMemoryDelegateTest, CopyFile) { ASSERT_EQ(base::File::FILE_OK, file_util()->CopyOrMoveFile( - from_file, to_file1, FileSystemOperation::OPTION_NONE, sync)); + from_file, to_file1, FileSystemOperation::CopyOrMoveOptionSet(), + sync)); ASSERT_EQ(base::File::FILE_OK, file_util()->CopyOrMoveFile( - from_file, to_file2, FileSystemOperation::OPTION_NONE, nosync)); + from_file, to_file2, FileSystemOperation::CopyOrMoveOptionSet(), + nosync)); EXPECT_TRUE(FileExists(from_file)); EXPECT_EQ(1020, GetSize(from_file)); @@ -290,9 +300,10 @@ TEST_F(ObfuscatedFileUtilMemoryDelegateTest, CopyFile) { file_util()->CreateDirectory(dir, false, false)); ASSERT_TRUE(file_util()->DirectoryExists(dir)); base::FilePath to_dir_file = dir.AppendASCII("file"); - ASSERT_EQ(base::File::FILE_OK, file_util()->CopyOrMoveFile( - from_file, to_dir_file, - FileSystemOperation::OPTION_NONE, nosync)); + ASSERT_EQ(base::File::FILE_OK, + file_util()->CopyOrMoveFile( + from_file, to_dir_file, + FileSystemOperation::CopyOrMoveOptionSet(), nosync)); EXPECT_TRUE(FileExists(to_dir_file)); EXPECT_EQ(1020, GetSize(to_dir_file)); } @@ -311,25 +322,26 @@ TEST_F(ObfuscatedFileUtilMemoryDelegateTest, CopyForeignFile) { const NativeFileUtil::CopyOrMoveMode sync = NativeFileUtil::COPY_SYNC; // Test copying nonexistent file. - EXPECT_EQ( - base::File::FILE_ERROR_NOT_FOUND, - file_util()->CopyInForeignFile(from_file, valid_to_file, - FileSystemOperation::OPTION_NONE, sync)); + EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, + file_util()->CopyInForeignFile( + from_file, valid_to_file, + FileSystemOperation::CopyOrMoveOptionSet(), sync)); // Create source file. EXPECT_TRUE(base::WriteFile(from_file, test_data)); // Test copying to a nonexistent directory. - EXPECT_EQ( - base::File::FILE_ERROR_NOT_FOUND, - file_util()->CopyInForeignFile(from_file, invalid_to_file, - FileSystemOperation::OPTION_NONE, sync)); + EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, + file_util()->CopyInForeignFile( + from_file, invalid_to_file, + FileSystemOperation::CopyOrMoveOptionSet(), sync)); EXPECT_FALSE(FileExists(invalid_to_file)); // Test copying to a valid path. - EXPECT_EQ(base::File::FILE_OK, file_util()->CopyInForeignFile( - from_file, valid_to_file, - FileSystemOperation::OPTION_NONE, sync)); + EXPECT_EQ(base::File::FILE_OK, + file_util()->CopyInForeignFile( + from_file, valid_to_file, + FileSystemOperation::CopyOrMoveOptionSet(), sync)); EXPECT_TRUE(FileExists(valid_to_file)); EXPECT_EQ(test_data_len, GetSize(valid_to_file)); scoped_refptr<net::IOBuffer> content = @@ -343,10 +355,10 @@ TEST_F(ObfuscatedFileUtilMemoryDelegateTest, CopyForeignFile) { TEST_F(ObfuscatedFileUtilMemoryDelegateTest, CopyFileNonExistingFile) { const NativeFileUtil::CopyOrMoveMode nosync = NativeFileUtil::COPY_NOSYNC; - EXPECT_EQ( - base::File::FILE_ERROR_NOT_FOUND, - file_util()->CopyOrMoveFile(Path("nonexists"), Path("file"), - FileSystemOperation::OPTION_NONE, nosync)); + EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, + file_util()->CopyOrMoveFile( + Path("nonexists"), Path("file"), + FileSystemOperation::CopyOrMoveOptionSet(), nosync)); } TEST_F(ObfuscatedFileUtilMemoryDelegateTest, CopyDirectoryOverFile) { @@ -358,7 +370,8 @@ TEST_F(ObfuscatedFileUtilMemoryDelegateTest, CopyDirectoryOverFile) { EXPECT_EQ(base::File::FILE_ERROR_NOT_A_FILE, file_util()->CopyOrMoveFile( - dir, Path("file"), FileSystemOperation::OPTION_NONE, nosync)); + dir, Path("file"), FileSystemOperation::CopyOrMoveOptionSet(), + nosync)); } TEST_F(ObfuscatedFileUtilMemoryDelegateTest, CopyFileOverDirectory) { @@ -372,9 +385,10 @@ TEST_F(ObfuscatedFileUtilMemoryDelegateTest, CopyFileOverDirectory) { ASSERT_EQ(base::File::FILE_OK, file_util()->CreateDirectory(dir, false, false)); - EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, - file_util()->CopyOrMoveFile( - file_name, dir, FileSystemOperation::OPTION_NONE, nosync)); + EXPECT_EQ( + base::File::FILE_ERROR_INVALID_OPERATION, + file_util()->CopyOrMoveFile( + file_name, dir, FileSystemOperation::CopyOrMoveOptionSet(), nosync)); } TEST_F(ObfuscatedFileUtilMemoryDelegateTest, CopyFileToNonExistingDirectory) { @@ -385,10 +399,10 @@ TEST_F(ObfuscatedFileUtilMemoryDelegateTest, CopyFileToNonExistingDirectory) { ASSERT_EQ(base::File::FILE_OK, file_util()->EnsureFileExists(file_name, &created)); - EXPECT_EQ( - base::File::FILE_ERROR_NOT_FOUND, - file_util()->CopyOrMoveFile(file_name, Path("nodir").AppendASCII("file"), - FileSystemOperation::OPTION_NONE, nosync)); + EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, + file_util()->CopyOrMoveFile( + file_name, Path("nodir").AppendASCII("file"), + FileSystemOperation::CopyOrMoveOptionSet(), nosync)); } TEST_F(ObfuscatedFileUtilMemoryDelegateTest, CopyFileAsChildOfOtherFile) { @@ -402,10 +416,10 @@ TEST_F(ObfuscatedFileUtilMemoryDelegateTest, CopyFileAsChildOfOtherFile) { ASSERT_EQ(base::File::FILE_OK, file_util()->EnsureFileExists(to_file, &created)); - EXPECT_EQ( - base::File::FILE_ERROR_NOT_FOUND, - file_util()->CopyOrMoveFile(from_file, to_file.AppendASCII("file"), - FileSystemOperation::OPTION_NONE, nosync)); + EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, + file_util()->CopyOrMoveFile( + from_file, to_file.AppendASCII("file"), + FileSystemOperation::CopyOrMoveOptionSet(), nosync)); } TEST_F(ObfuscatedFileUtilMemoryDelegateTest, MoveFile) { @@ -426,7 +440,8 @@ TEST_F(ObfuscatedFileUtilMemoryDelegateTest, MoveFile) { ASSERT_EQ(base::File::FILE_OK, file_util()->CopyOrMoveFile( - from_file, to_file, FileSystemOperation::OPTION_NONE, move)); + from_file, to_file, FileSystemOperation::CopyOrMoveOptionSet(), + move)); EXPECT_FALSE(FileExists(from_file)); EXPECT_TRUE(FileExists(to_file)); @@ -442,9 +457,10 @@ TEST_F(ObfuscatedFileUtilMemoryDelegateTest, MoveFile) { file_util()->CreateDirectory(dir, false, false)); ASSERT_TRUE(file_util()->DirectoryExists(dir)); base::FilePath to_dir_file = dir.AppendASCII("file"); - ASSERT_EQ(base::File::FILE_OK, file_util()->CopyOrMoveFile( - from_file, to_dir_file, - FileSystemOperation::OPTION_NONE, move)); + ASSERT_EQ(base::File::FILE_OK, + file_util()->CopyOrMoveFile( + from_file, to_dir_file, + FileSystemOperation::CopyOrMoveOptionSet(), move)); EXPECT_FALSE(FileExists(from_file)); EXPECT_TRUE(FileExists(to_dir_file)); EXPECT_EQ(1020, GetSize(to_dir_file)); @@ -453,10 +469,10 @@ TEST_F(ObfuscatedFileUtilMemoryDelegateTest, MoveFile) { TEST_F(ObfuscatedFileUtilMemoryDelegateTest, MoveNonExistingFile) { const NativeFileUtil::CopyOrMoveMode move = NativeFileUtil::MOVE; - EXPECT_EQ( - base::File::FILE_ERROR_NOT_FOUND, - file_util()->CopyOrMoveFile(Path("nonexists"), Path("file"), - FileSystemOperation::OPTION_NONE, move)); + EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, + file_util()->CopyOrMoveFile( + Path("nonexists"), Path("file"), + FileSystemOperation::CopyOrMoveOptionSet(), move)); } TEST_F(ObfuscatedFileUtilMemoryDelegateTest, MoveDirectoryOverDirectory) { @@ -471,7 +487,7 @@ TEST_F(ObfuscatedFileUtilMemoryDelegateTest, MoveDirectoryOverDirectory) { file_util()->CreateDirectory(dir2, false, false)); base::File::Error result = file_util()->CopyOrMoveFile( - dir, dir2, FileSystemOperation::OPTION_NONE, move); + dir, dir2, FileSystemOperation::CopyOrMoveOptionSet(), move); #if defined(OS_WIN) EXPECT_EQ(base::File::FILE_ERROR_NOT_A_FILE, result); #else @@ -491,9 +507,10 @@ TEST_F(ObfuscatedFileUtilMemoryDelegateTest, MoveFileOverDirectory) { ASSERT_EQ(base::File::FILE_OK, file_util()->CreateDirectory(dir, false, false)); - EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, - file_util()->CopyOrMoveFile( - from_file, dir, FileSystemOperation::OPTION_NONE, move)); + EXPECT_EQ( + base::File::FILE_ERROR_INVALID_OPERATION, + file_util()->CopyOrMoveFile( + from_file, dir, FileSystemOperation::CopyOrMoveOptionSet(), move)); } TEST_F(ObfuscatedFileUtilMemoryDelegateTest, MoveFileToNonExistingDirectory) { @@ -505,10 +522,10 @@ TEST_F(ObfuscatedFileUtilMemoryDelegateTest, MoveFileToNonExistingDirectory) { ASSERT_EQ(base::File::FILE_OK, file_util()->EnsureFileExists(from_file, &created)); - EXPECT_EQ( - base::File::FILE_ERROR_NOT_FOUND, - file_util()->CopyOrMoveFile(from_file, Path("nodir").AppendASCII("file"), - FileSystemOperation::OPTION_NONE, move)); + EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, + file_util()->CopyOrMoveFile( + from_file, Path("nodir").AppendASCII("file"), + FileSystemOperation::CopyOrMoveOptionSet(), move)); } TEST_F(ObfuscatedFileUtilMemoryDelegateTest, MoveFileAsChildOfOtherFile) { @@ -523,10 +540,10 @@ TEST_F(ObfuscatedFileUtilMemoryDelegateTest, MoveFileAsChildOfOtherFile) { ASSERT_EQ(base::File::FILE_OK, file_util()->EnsureFileExists(to_file, &created)); - EXPECT_EQ( - base::File::FILE_ERROR_NOT_FOUND, - file_util()->CopyOrMoveFile(from_file, to_file.AppendASCII("file"), - FileSystemOperation::OPTION_NONE, move)); + EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, + file_util()->CopyOrMoveFile( + from_file, to_file.AppendASCII("file"), + FileSystemOperation::CopyOrMoveOptionSet(), move)); } TEST_F(ObfuscatedFileUtilMemoryDelegateTest, MoveFile_Directory) { @@ -549,9 +566,10 @@ TEST_F(ObfuscatedFileUtilMemoryDelegateTest, MoveFile_Directory) { EXPECT_TRUE(FileExists(from_file)); EXPECT_EQ(1020, GetSize(from_file)); - ASSERT_EQ(base::File::FILE_OK, file_util()->CopyOrMoveFile( - from_directory, to_directory, - FileSystemOperation::OPTION_NONE, move)); + ASSERT_EQ(base::File::FILE_OK, + file_util()->CopyOrMoveFile( + from_directory, to_directory, + FileSystemOperation::CopyOrMoveOptionSet(), move)); EXPECT_FALSE(file_util()->DirectoryExists(from_directory)); EXPECT_FALSE(FileExists(from_file)); @@ -582,9 +600,10 @@ TEST_F(ObfuscatedFileUtilMemoryDelegateTest, MoveFile_OverwriteEmptyDirectory) { EXPECT_TRUE(FileExists(from_file)); EXPECT_EQ(1020, GetSize(from_file)); - ASSERT_EQ(base::File::FILE_OK, file_util()->CopyOrMoveFile( - from_directory, to_directory, - FileSystemOperation::OPTION_NONE, move)); + ASSERT_EQ(base::File::FILE_OK, + file_util()->CopyOrMoveFile( + from_directory, to_directory, + FileSystemOperation::CopyOrMoveOptionSet(), move)); EXPECT_FALSE(file_util()->DirectoryExists(from_directory)); EXPECT_FALSE(FileExists(from_file)); @@ -613,7 +632,8 @@ TEST_F(ObfuscatedFileUtilMemoryDelegateTest, PreserveLastModified_NoSync) { ASSERT_EQ(base::File::FILE_OK, file_util()->CopyOrMoveFile( from_file, to_file, - FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED, nosync)); + CopyOrMoveOptionSet(CopyOrMoveOption::kPreserveLastModified), + nosync)); ASSERT_TRUE(FileExists(to_file)); base::File::Info file_info2; @@ -638,10 +658,11 @@ TEST_F(ObfuscatedFileUtilMemoryDelegateTest, PreserveLastModified_Sync) { ASSERT_EQ(base::File::FILE_OK, file_util()->GetFileInfo(from_file, &file_info1)); - ASSERT_EQ(base::File::FILE_OK, - file_util()->CopyOrMoveFile( - from_file, to_file, - FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED, sync)); + ASSERT_EQ( + base::File::FILE_OK, + file_util()->CopyOrMoveFile( + from_file, to_file, + CopyOrMoveOptionSet(CopyOrMoveOption::kPreserveLastModified), sync)); ASSERT_TRUE(FileExists(to_file)); base::File::Info file_info2; @@ -666,10 +687,11 @@ TEST_F(ObfuscatedFileUtilMemoryDelegateTest, PreserveLastModified_Move) { ASSERT_EQ(base::File::FILE_OK, file_util()->GetFileInfo(from_file, &file_info1)); - ASSERT_EQ(base::File::FILE_OK, - file_util()->CopyOrMoveFile( - from_file, to_file, - FileSystemOperation::OPTION_PRESERVE_LAST_MODIFIED, move)); + ASSERT_EQ( + base::File::FILE_OK, + file_util()->CopyOrMoveFile( + from_file, to_file, + CopyOrMoveOptionSet(CopyOrMoveOption::kPreserveLastModified), move)); ASSERT_TRUE(FileExists(to_file)); base::File::Info file_info2; diff --git a/chromium/storage/browser/file_system/obfuscated_file_util_unittest.cc b/chromium/storage/browser/file_system/obfuscated_file_util_unittest.cc index 0bedcb3baea..f8db2da7705 100644 --- a/chromium/storage/browser/file_system/obfuscated_file_util_unittest.cc +++ b/chromium/storage/browser/file_system/obfuscated_file_util_unittest.cc @@ -19,7 +19,7 @@ #include "base/files/file_path.h" #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" -#include "base/macros.h" +#include "base/memory/raw_ptr.h" #include "base/memory/scoped_refptr.h" #include "base/run_loop.h" #include "base/test/task_environment.h" @@ -463,9 +463,9 @@ class ObfuscatedFileUtilTest : public testing::Test, } std::unique_ptr<FileSystemOperationContext> context_; - SandboxFileSystemTestHelper* sandbox_file_system_; + raw_ptr<SandboxFileSystemTestHelper> sandbox_file_system_; int64_t expected_usage_; - ObfuscatedFileUtilTest* const test_; + const raw_ptr<ObfuscatedFileUtilTest> test_; }; std::unique_ptr<UsageVerifyHelper> AllowUsageIncrease( @@ -700,7 +700,8 @@ class ObfuscatedFileUtilTest : public testing::Test, context = NewContext(nullptr); EXPECT_EQ(base::File::FILE_OK, ofu()->CopyOrMoveFile(context.get(), src_file_url, dest_file_url, - FileSystemOperation::OPTION_NONE, copy)); + FileSystemOperation::CopyOrMoveOptionSet(), + copy)); if (copy) EXPECT_EQ(base::Time(), GetModifiedTime(src_dir_url)); else @@ -1305,14 +1306,14 @@ TEST_P(ObfuscatedFileUtilTest, TestCopyOrMoveFileNotFound) { bool is_copy_not_move = false; EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, ofu()->CopyOrMoveFile(context.get(), source_url, dest_url, - FileSystemOperation::OPTION_NONE, + FileSystemOperation::CopyOrMoveOptionSet(), is_copy_not_move)); EXPECT_TRUE(change_observer()->HasNoChange()); context = NewContext(nullptr); is_copy_not_move = true; EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, ofu()->CopyOrMoveFile(context.get(), source_url, dest_url, - FileSystemOperation::OPTION_NONE, + FileSystemOperation::CopyOrMoveOptionSet(), is_copy_not_move)); EXPECT_TRUE(change_observer()->HasNoChange()); source_url = CreateURLFromUTF8("dir/dir/file"); @@ -1327,14 +1328,14 @@ TEST_P(ObfuscatedFileUtilTest, TestCopyOrMoveFileNotFound) { is_copy_not_move = false; EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, ofu()->CopyOrMoveFile(context.get(), source_url, dest_url, - FileSystemOperation::OPTION_NONE, + FileSystemOperation::CopyOrMoveOptionSet(), is_copy_not_move)); EXPECT_TRUE(change_observer()->HasNoChange()); context = NewContext(nullptr); is_copy_not_move = true; EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, ofu()->CopyOrMoveFile(context.get(), source_url, dest_url, - FileSystemOperation::OPTION_NONE, + FileSystemOperation::CopyOrMoveOptionSet(), is_copy_not_move)); EXPECT_TRUE(change_observer()->HasNoChange()); } @@ -1394,7 +1395,7 @@ TEST_P(ObfuscatedFileUtilTest, TestCopyOrMoveFileSuccess) { context = NewContext(nullptr); EXPECT_EQ(base::File::FILE_OK, ofu()->CopyOrMoveFile(context.get(), source_url, dest_url, - FileSystemOperation::OPTION_NONE, + FileSystemOperation::CopyOrMoveOptionSet(), test_case.is_copy_not_move)); if (test_case.is_copy_not_move) { @@ -1439,20 +1440,23 @@ TEST_P(ObfuscatedFileUtilTest, TestCopyPathQuotas) { ObfuscatedFileUtil::ComputeFilePathCost(dest_url.path()) - 1); EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, ofu()->CopyOrMoveFile(context.get(), src_url, dest_url, - FileSystemOperation::OPTION_NONE, is_copy)); + FileSystemOperation::CopyOrMoveOptionSet(), + is_copy)); context = NewContext(nullptr); context->set_allowed_bytes_growth( ObfuscatedFileUtil::ComputeFilePathCost(dest_url.path())); EXPECT_EQ(base::File::FILE_OK, ofu()->CopyOrMoveFile(context.get(), src_url, dest_url, - FileSystemOperation::OPTION_NONE, is_copy)); + FileSystemOperation::CopyOrMoveOptionSet(), + is_copy)); // Copy, with overwrite. context = NewContext(nullptr); context->set_allowed_bytes_growth(0); EXPECT_EQ(base::File::FILE_OK, ofu()->CopyOrMoveFile(context.get(), src_url, dest_url, - FileSystemOperation::OPTION_NONE, is_copy)); + FileSystemOperation::CopyOrMoveOptionSet(), + is_copy)); } TEST_P(ObfuscatedFileUtilTest, TestMovePathQuotasWithRename) { @@ -1471,14 +1475,16 @@ TEST_P(ObfuscatedFileUtilTest, TestMovePathQuotasWithRename) { ObfuscatedFileUtil::ComputeFilePathCost(src_url.path()) - 1); EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, ofu()->CopyOrMoveFile(context.get(), src_url, dest_url, - FileSystemOperation::OPTION_NONE, is_copy)); + FileSystemOperation::CopyOrMoveOptionSet(), + is_copy)); context = NewContext(nullptr); context->set_allowed_bytes_growth( ObfuscatedFileUtil::ComputeFilePathCost(dest_url.path()) - ObfuscatedFileUtil::ComputeFilePathCost(src_url.path())); EXPECT_EQ(base::File::FILE_OK, ofu()->CopyOrMoveFile(context.get(), src_url, dest_url, - FileSystemOperation::OPTION_NONE, is_copy)); + FileSystemOperation::CopyOrMoveOptionSet(), + is_copy)); context = NewContext(nullptr); ASSERT_EQ(base::File::FILE_OK, @@ -1489,7 +1495,8 @@ TEST_P(ObfuscatedFileUtilTest, TestMovePathQuotasWithRename) { context->set_allowed_bytes_growth(0); EXPECT_EQ(base::File::FILE_OK, ofu()->CopyOrMoveFile(context.get(), src_url, dest_url, - FileSystemOperation::OPTION_NONE, is_copy)); + FileSystemOperation::CopyOrMoveOptionSet(), + is_copy)); } TEST_P(ObfuscatedFileUtilTest, TestMovePathQuotasWithoutRename) { @@ -1515,7 +1522,8 @@ TEST_P(ObfuscatedFileUtilTest, TestMovePathQuotasWithoutRename) { context->set_allowed_bytes_growth(allowed_bytes_growth); EXPECT_EQ(base::File::FILE_OK, ofu()->CopyOrMoveFile(context.get(), src_url, dest_url, - FileSystemOperation::OPTION_NONE, is_copy)); + FileSystemOperation::CopyOrMoveOptionSet(), + is_copy)); EXPECT_EQ(allowed_bytes_growth, context->allowed_bytes_growth()); // Move, no rename, with overwrite. @@ -1526,7 +1534,8 @@ TEST_P(ObfuscatedFileUtilTest, TestMovePathQuotasWithoutRename) { context->set_allowed_bytes_growth(allowed_bytes_growth); EXPECT_EQ(base::File::FILE_OK, ofu()->CopyOrMoveFile(context.get(), src_url, dest_url, - FileSystemOperation::OPTION_NONE, is_copy)); + FileSystemOperation::CopyOrMoveOptionSet(), + is_copy)); EXPECT_EQ(allowed_bytes_growth + ObfuscatedFileUtil::ComputeFilePathCost(src_url.path()), context->allowed_bytes_growth()); @@ -1753,10 +1762,10 @@ TEST_P(ObfuscatedFileUtilTest, TestInconsistency) { // Copy from sound `kPath1` to broken `kPath2`. context = NewContext(nullptr); - EXPECT_EQ( - base::File::FILE_OK, - ofu()->CopyOrMoveFile(context.get(), kPath1, kPath2, - FileSystemOperation::OPTION_NONE, true /* copy */)); + EXPECT_EQ(base::File::FILE_OK, + ofu()->CopyOrMoveFile(context.get(), kPath1, kPath2, + FileSystemOperation::CopyOrMoveOptionSet(), + true /* copy */)); ofu()->DestroyDirectoryDatabase(storage_key(), type_string()); context = NewContext(nullptr); @@ -2081,7 +2090,7 @@ TEST_P(ObfuscatedFileUtilTest, MAYBE_TestQuotaOnCopyFile) { base::File::FILE_OK, ofu()->CopyOrMoveFile( AllowUsageIncrease(PathCost(to_file1) + to_file1_size)->context(), - from_file, to_file1, FileSystemOperation::OPTION_NONE, + from_file, to_file1, FileSystemOperation::CopyOrMoveOptionSet(), true /* copy */)); ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); @@ -2089,7 +2098,7 @@ TEST_P(ObfuscatedFileUtilTest, MAYBE_TestQuotaOnCopyFile) { base::File::FILE_ERROR_NO_SPACE, ofu()->CopyOrMoveFile( DisallowUsageIncrease(PathCost(to_file2) + from_file_size)->context(), - from_file, to_file2, FileSystemOperation::OPTION_NONE, + from_file, to_file2, FileSystemOperation::CopyOrMoveOptionSet(), true /* copy */)); ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); @@ -2100,8 +2109,8 @@ TEST_P(ObfuscatedFileUtilTest, MAYBE_TestQuotaOnCopyFile) { ofu()->CopyOrMoveFile( AllowUsageIncrease(obstacle_file_size - old_obstacle_file_size) ->context(), - from_file, obstacle_file, FileSystemOperation::OPTION_NONE, - true /* copy */)); + from_file, obstacle_file, + FileSystemOperation::CopyOrMoveOptionSet(), true /* copy */)); ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); int64_t old_from_file_size = from_file_size; @@ -2125,7 +2134,7 @@ TEST_P(ObfuscatedFileUtilTest, MAYBE_TestQuotaOnCopyFile) { helper->context()->allowed_bytes_growth() - 1); ASSERT_EQ(base::File::FILE_OK, ofu()->CopyOrMoveFile(helper->context(), from_file, obstacle_file, - FileSystemOperation::OPTION_NONE, + FileSystemOperation::CopyOrMoveOptionSet(), true /* copy */)); ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); } @@ -2157,7 +2166,7 @@ TEST_P(ObfuscatedFileUtilTest, TestQuotaOnMoveFile) { ofu()->CopyOrMoveFile( AllowUsageIncrease(-PathCost(from_file) + PathCost(to_file)) ->context(), - from_file, to_file, FileSystemOperation::OPTION_NONE, + from_file, to_file, FileSystemOperation::CopyOrMoveOptionSet(), false /* move */)); ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); @@ -2198,7 +2207,7 @@ TEST_P(ObfuscatedFileUtilTest, TestQuotaOnMoveFile) { ofu()->CopyOrMoveFile( AllowUsageIncrease(-old_obstacle_file_size - PathCost(from_file)) ->context(), - from_file, obstacle_file, FileSystemOperation::OPTION_NONE, + from_file, obstacle_file, FileSystemOperation::CopyOrMoveOptionSet(), false /* move */)); ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); @@ -2225,7 +2234,7 @@ TEST_P(ObfuscatedFileUtilTest, TestQuotaOnMoveFile) { LimitedContext(-old_obstacle_file_size - PathCost(from_file) - 1); ASSERT_EQ(base::File::FILE_OK, ofu()->CopyOrMoveFile(context.get(), from_file, obstacle_file, - FileSystemOperation::OPTION_NONE, + FileSystemOperation::CopyOrMoveOptionSet(), false /* move */)); ASSERT_EQ(expected_total_file_size, ComputeTotalFileSize()); context.reset(); diff --git a/chromium/storage/browser/file_system/plugin_private_file_system_backend.cc b/chromium/storage/browser/file_system/plugin_private_file_system_backend.cc index 280ec770154..c42bd25902c 100644 --- a/chromium/storage/browser/file_system/plugin_private_file_system_backend.cc +++ b/chromium/storage/browser/file_system/plugin_private_file_system_backend.cc @@ -16,7 +16,7 @@ #include "base/files/file_path.h" #include "base/memory/scoped_refptr.h" #include "base/synchronization/lock.h" -#include "base/task_runner_util.h" +#include "base/task/task_runner_util.h" #include "base/threading/thread_task_runner_handle.h" #include "storage/browser/file_system/async_file_util_adapter.h" #include "storage/browser/file_system/file_system_context.h" @@ -114,7 +114,7 @@ PluginPrivateFileSystemBackend::PluginPrivateFileSystemBackend( std::make_unique<ObfuscatedFileUtil>( std::move(special_storage_policy), base_path_, env_override, base::BindRepeating(&FileSystemIDToPluginMap::GetPluginIDForURL, - base::Owned(plugin_map_)), + base::Owned(plugin_map_.get())), std::set<std::string>(), nullptr, file_system_options.is_incognito())); } diff --git a/chromium/storage/browser/file_system/plugin_private_file_system_backend.h b/chromium/storage/browser/file_system/plugin_private_file_system_backend.h index 5d02bc4b8f6..9174aa0c0cd 100644 --- a/chromium/storage/browser/file_system/plugin_private_file_system_backend.h +++ b/chromium/storage/browser/file_system/plugin_private_file_system_backend.h @@ -12,7 +12,7 @@ #include <vector> #include "base/component_export.h" -#include "base/macros.h" +#include "base/memory/raw_ptr.h" #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" #include "storage/browser/file_system/file_system_backend.h" @@ -43,6 +43,10 @@ class ObfuscatedFileUtilMemoryDelegate; class SpecialStoragePolicy; class WatcherManager; +// TODO(crbug.com/1231162): Remove this when removing the plugin private FS. +// Name of the root directory in the plugin private file system. +const char kPluginPrivateRootName[] = "pluginprivate"; + class COMPONENT_EXPORT(STORAGE_BROWSER) PluginPrivateFileSystemBackend : public FileSystemBackend, public FileSystemQuotaUtil { @@ -155,7 +159,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) PluginPrivateFileSystemBackend const FileSystemOptions file_system_options_; const base::FilePath base_path_; std::unique_ptr<AsyncFileUtil> file_util_; - FileSystemIDToPluginMap* plugin_map_; // Owned by file_util_. + raw_ptr<FileSystemIDToPluginMap> plugin_map_; // Owned by file_util_. base::WeakPtrFactory<PluginPrivateFileSystemBackend> weak_factory_{this}; }; diff --git a/chromium/storage/browser/file_system/quota/open_file_handle.h b/chromium/storage/browser/file_system/quota/open_file_handle.h index 7a3aa621829..8168025374a 100644 --- a/chromium/storage/browser/file_system/quota/open_file_handle.h +++ b/chromium/storage/browser/file_system/quota/open_file_handle.h @@ -8,7 +8,6 @@ #include <stdint.h> #include "base/component_export.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" diff --git a/chromium/storage/browser/file_system/quota/open_file_handle_context.h b/chromium/storage/browser/file_system/quota/open_file_handle_context.h index f63a10f4d6a..708bf4b94b3 100644 --- a/chromium/storage/browser/file_system/quota/open_file_handle_context.h +++ b/chromium/storage/browser/file_system/quota/open_file_handle_context.h @@ -8,7 +8,6 @@ #include <stdint.h> #include "base/files/file_path.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" #include "storage/common/file_system/file_system_types.h" @@ -27,6 +26,9 @@ class OpenFileHandleContext : public base::RefCounted<OpenFileHandleContext> { OpenFileHandleContext(const base::FilePath& platform_path, QuotaReservationBuffer* reservation_buffer); + OpenFileHandleContext(const OpenFileHandleContext&) = delete; + OpenFileHandleContext& operator=(const OpenFileHandleContext&) = delete; + // Updates the max written offset and returns the amount of growth. int64_t UpdateMaxWrittenOffset(int64_t offset); @@ -49,8 +51,6 @@ class OpenFileHandleContext : public base::RefCounted<OpenFileHandleContext> { scoped_refptr<QuotaReservationBuffer> reservation_buffer_; base::SequenceChecker sequence_checker_; - - DISALLOW_COPY_AND_ASSIGN(OpenFileHandleContext); }; } // namespace storage diff --git a/chromium/storage/browser/file_system/quota/quota_backend_impl.cc b/chromium/storage/browser/file_system/quota/quota_backend_impl.cc index a48eeb45947..6827bd07cb7 100644 --- a/chromium/storage/browser/file_system/quota/quota_backend_impl.cc +++ b/chromium/storage/browser/file_system/quota/quota_backend_impl.cc @@ -14,7 +14,7 @@ #include "base/callback.h" #include "base/check_op.h" #include "base/numerics/safe_conversions.h" -#include "base/sequenced_task_runner.h" +#include "base/task/sequenced_task_runner.h" #include "storage/browser/file_system/file_system_usage_cache.h" #include "storage/browser/file_system/file_system_util.h" #include "storage/browser/quota/quota_client_type.h" diff --git a/chromium/storage/browser/file_system/quota/quota_backend_impl.h b/chromium/storage/browser/file_system/quota/quota_backend_impl.h index c5a66224a5b..7b3415dd6d7 100644 --- a/chromium/storage/browser/file_system/quota/quota_backend_impl.h +++ b/chromium/storage/browser/file_system/quota/quota_backend_impl.h @@ -8,7 +8,7 @@ #include <stdint.h> #include "base/component_export.h" -#include "base/macros.h" +#include "base/memory/raw_ptr.h" #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" #include "storage/browser/file_system/quota/quota_reservation_manager.h" @@ -86,8 +86,8 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaBackendImpl const scoped_refptr<base::SequencedTaskRunner> file_task_runner_; // Owned by SandboxFileSystemBackendDelegate. - ObfuscatedFileUtil* const obfuscated_file_util_; - FileSystemUsageCache* const file_system_usage_cache_; + const raw_ptr<ObfuscatedFileUtil> obfuscated_file_util_; + const raw_ptr<FileSystemUsageCache> file_system_usage_cache_; const scoped_refptr<QuotaManagerProxy> quota_manager_proxy_; diff --git a/chromium/storage/browser/file_system/quota/quota_backend_impl_unittest.cc b/chromium/storage/browser/file_system/quota/quota_backend_impl_unittest.cc index cf8eddfd823..f03a7b5b5e8 100644 --- a/chromium/storage/browser/file_system/quota/quota_backend_impl_unittest.cc +++ b/chromium/storage/browser/file_system/quota/quota_backend_impl_unittest.cc @@ -13,10 +13,9 @@ #include "base/bind.h" #include "base/check.h" #include "base/files/scoped_temp_dir.h" -#include "base/macros.h" #include "base/memory/scoped_refptr.h" #include "base/run_loop.h" -#include "base/sequenced_task_runner.h" +#include "base/task/sequenced_task_runner.h" #include "base/test/task_environment.h" #include "base/threading/thread_task_runner_handle.h" #include "storage/browser/file_system/file_system_usage_cache.h" @@ -50,6 +49,9 @@ class MockQuotaManagerProxy : public QuotaManagerProxy { usage_(0), quota_(0) {} + MockQuotaManagerProxy(const MockQuotaManagerProxy&) = delete; + MockQuotaManagerProxy& operator=(const MockQuotaManagerProxy&) = delete; + // We don't mock them. void SetUsageCacheEnabled(QuotaClientType client_id, const blink::StorageKey& storage_key, @@ -93,8 +95,6 @@ class MockQuotaManagerProxy : public QuotaManagerProxy { int storage_modified_count_; int64_t usage_; int64_t quota_; - - DISALLOW_COPY_AND_ASSIGN(MockQuotaManagerProxy); }; } // namespace @@ -106,6 +106,9 @@ class QuotaBackendImplTest : public testing::Test, : file_system_usage_cache_(is_incognito()), quota_manager_proxy_(base::MakeRefCounted<MockQuotaManagerProxy>()) {} + QuotaBackendImplTest(const QuotaBackendImplTest&) = delete; + QuotaBackendImplTest& operator=(const QuotaBackendImplTest&) = delete; + void SetUp() override { ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); in_memory_env_ = leveldb_chrome::NewMemEnv("quota"); @@ -163,9 +166,6 @@ class QuotaBackendImplTest : public testing::Test, FileSystemUsageCache file_system_usage_cache_; scoped_refptr<MockQuotaManagerProxy> quota_manager_proxy_; std::unique_ptr<QuotaBackendImpl> backend_; - - private: - DISALLOW_COPY_AND_ASSIGN(QuotaBackendImplTest); }; INSTANTIATE_TEST_SUITE_P(All, QuotaBackendImplTest, testing::Bool()); diff --git a/chromium/storage/browser/file_system/quota/quota_reservation.h b/chromium/storage/browser/file_system/quota/quota_reservation.h index cee6d6d0490..38fd7e76eb1 100644 --- a/chromium/storage/browser/file_system/quota/quota_reservation.h +++ b/chromium/storage/browser/file_system/quota/quota_reservation.h @@ -12,7 +12,6 @@ #include "base/component_export.h" #include "base/files/file.h" #include "base/files/file_path.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" #include "storage/browser/file_system/quota/quota_reservation_manager.h" @@ -33,6 +32,9 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaReservation public: using StatusCallback = base::OnceCallback<void(base::File::Error error)>; + QuotaReservation(const QuotaReservation&) = delete; + QuotaReservation& operator=(const QuotaReservation&) = delete; + // Reclaims unused quota and reserves another |size| of quota. So that the // resulting new |remaining_quota_| will be same as |size| as far as available // space is enough. |remaining_quota_| may be less than |size| if there is @@ -92,8 +94,6 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaReservation base::SequenceChecker sequence_checker_; base::WeakPtrFactory<QuotaReservation> weak_ptr_factory_{this}; - - DISALLOW_COPY_AND_ASSIGN(QuotaReservation); }; } // namespace storage diff --git a/chromium/storage/browser/file_system/quota/quota_reservation_buffer.h b/chromium/storage/browser/file_system/quota/quota_reservation_buffer.h index ea3d6fbbe09..4b07269134c 100644 --- a/chromium/storage/browser/file_system/quota/quota_reservation_buffer.h +++ b/chromium/storage/browser/file_system/quota/quota_reservation_buffer.h @@ -12,7 +12,6 @@ #include "base/files/file.h" #include "base/files/file_path.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" #include "storage/common/file_system/file_system_types.h" @@ -39,6 +38,9 @@ class QuotaReservationBuffer : public base::RefCounted<QuotaReservationBuffer> { const url::Origin& origin, FileSystemType type); + QuotaReservationBuffer(const QuotaReservationBuffer&) = delete; + QuotaReservationBuffer& operator=(const QuotaReservationBuffer&) = delete; + scoped_refptr<QuotaReservation> CreateReservation(); std::unique_ptr<OpenFileHandle> GetOpenFileHandle( QuotaReservation* reservation, @@ -77,8 +79,6 @@ class QuotaReservationBuffer : public base::RefCounted<QuotaReservationBuffer> { int64_t reserved_quota_; base::SequenceChecker sequence_checker_; - - DISALLOW_COPY_AND_ASSIGN(QuotaReservationBuffer); }; } // namespace storage diff --git a/chromium/storage/browser/file_system/quota/quota_reservation_manager.h b/chromium/storage/browser/file_system/quota/quota_reservation_manager.h index 2c1463d85fb..c6d1240cf1f 100644 --- a/chromium/storage/browser/file_system/quota/quota_reservation_manager.h +++ b/chromium/storage/browser/file_system/quota/quota_reservation_manager.h @@ -14,7 +14,6 @@ #include "base/callback_forward.h" #include "base/component_export.h" #include "base/files/file.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" #include "storage/common/file_system/file_system_types.h" diff --git a/chromium/storage/browser/file_system/quota/quota_reservation_manager_unittest.cc b/chromium/storage/browser/file_system/quota/quota_reservation_manager_unittest.cc index 42b4605a69a..e40f5165aec 100644 --- a/chromium/storage/browser/file_system/quota/quota_reservation_manager_unittest.cc +++ b/chromium/storage/browser/file_system/quota/quota_reservation_manager_unittest.cc @@ -13,9 +13,8 @@ #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" #include "base/location.h" -#include "base/macros.h" #include "base/run_loop.h" -#include "base/single_thread_task_runner.h" +#include "base/task/single_thread_task_runner.h" #include "base/test/task_environment.h" #include "base/threading/thread_task_runner_handle.h" #include "storage/browser/file_system/quota/open_file_handle.h" diff --git a/chromium/storage/browser/file_system/recursive_operation_delegate.cc b/chromium/storage/browser/file_system/recursive_operation_delegate.cc index 33179820392..c2720657e1a 100644 --- a/chromium/storage/browser/file_system/recursive_operation_delegate.cc +++ b/chromium/storage/browser/file_system/recursive_operation_delegate.cc @@ -8,7 +8,7 @@ #include "base/bind.h" #include "base/containers/queue.h" -#include "base/single_thread_task_runner.h" +#include "base/task/single_thread_task_runner.h" #include "base/threading/thread_task_runner_handle.h" #include "storage/browser/file_system/file_system_context.h" #include "storage/browser/file_system/file_system_operation_runner.h" diff --git a/chromium/storage/browser/file_system/recursive_operation_delegate.h b/chromium/storage/browser/file_system/recursive_operation_delegate.h index bec65aacab3..371d073827b 100644 --- a/chromium/storage/browser/file_system/recursive_operation_delegate.h +++ b/chromium/storage/browser/file_system/recursive_operation_delegate.h @@ -9,7 +9,7 @@ #include "base/component_export.h" #include "base/containers/queue.h" #include "base/containers/stack.h" -#include "base/macros.h" +#include "base/memory/raw_ptr.h" #include "base/memory/weak_ptr.h" #include "storage/browser/file_system/file_system_operation.h" #include "storage/browser/file_system/file_system_url.h" @@ -145,7 +145,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) RecursiveOperationDelegate // Called when all recursive operation is done (or an error occurs). void Done(base::File::Error error); - FileSystemContext* file_system_context_; + raw_ptr<FileSystemContext> file_system_context_; StatusCallback callback_; base::stack<FileSystemURL> pending_directories_; base::stack<base::queue<FileSystemURL>> pending_directory_stack_; diff --git a/chromium/storage/browser/file_system/recursive_operation_delegate_unittest.cc b/chromium/storage/browser/file_system/recursive_operation_delegate_unittest.cc index 55f079e587d..5a9827959e8 100644 --- a/chromium/storage/browser/file_system/recursive_operation_delegate_unittest.cc +++ b/chromium/storage/browser/file_system/recursive_operation_delegate_unittest.cc @@ -13,10 +13,9 @@ #include "base/callback.h" #include "base/files/scoped_temp_dir.h" #include "base/location.h" -#include "base/macros.h" #include "base/memory/ptr_util.h" #include "base/run_loop.h" -#include "base/single_thread_task_runner.h" +#include "base/task/single_thread_task_runner.h" #include "base/test/task_environment.h" #include "base/threading/thread_task_runner_handle.h" #include "storage/browser/file_system/file_system_file_util.h" diff --git a/chromium/storage/browser/file_system/remove_operation_delegate.h b/chromium/storage/browser/file_system/remove_operation_delegate.h index f1a2bbfc037..ca47289cc0a 100644 --- a/chromium/storage/browser/file_system/remove_operation_delegate.h +++ b/chromium/storage/browser/file_system/remove_operation_delegate.h @@ -5,7 +5,6 @@ #ifndef STORAGE_BROWSER_FILE_SYSTEM_REMOVE_OPERATION_DELEGATE_H_ #define STORAGE_BROWSER_FILE_SYSTEM_REMOVE_OPERATION_DELEGATE_H_ -#include "base/macros.h" #include "storage/browser/file_system/recursive_operation_delegate.h" namespace storage { diff --git a/chromium/storage/browser/file_system/sandbox_directory_database.cc b/chromium/storage/browser/file_system/sandbox_directory_database.cc index 2539ab30527..e8eab17fd5e 100644 --- a/chromium/storage/browser/file_system/sandbox_directory_database.cc +++ b/chromium/storage/browser/file_system/sandbox_directory_database.cc @@ -17,7 +17,7 @@ #include "base/files/file_enumerator.h" #include "base/files/file_util.h" #include "base/location.h" -#include "base/macros.h" +#include "base/memory/raw_ptr.h" #include "base/metrics/histogram_macros.h" #include "base/pickle.h" #include "base/strings/string_number_conversions.h" @@ -158,8 +158,8 @@ class DatabaseCheckHelper { bool ScanDirectory(); bool ScanHierarchy(); - SandboxDirectoryDatabase* dir_db_; - leveldb::DB* db_; + raw_ptr<SandboxDirectoryDatabase> dir_db_; + raw_ptr<leveldb::DB> db_; base::FilePath path_; std::set<base::FilePath> files_in_db_; diff --git a/chromium/storage/browser/file_system/sandbox_directory_database.h b/chromium/storage/browser/file_system/sandbox_directory_database.h index 5a2d0bacfcc..48b2f86de48 100644 --- a/chromium/storage/browser/file_system/sandbox_directory_database.h +++ b/chromium/storage/browser/file_system/sandbox_directory_database.h @@ -14,7 +14,7 @@ #include "base/component_export.h" #include "base/files/file.h" #include "base/files/file_path.h" -#include "base/macros.h" +#include "base/memory/raw_ptr.h" #include "base/time/time.h" namespace base { @@ -126,7 +126,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) SandboxDirectoryDatabase { const leveldb::Status& status); const base::FilePath filesystem_data_directory_; - leveldb::Env* env_override_; + raw_ptr<leveldb::Env> env_override_; std::unique_ptr<leveldb::DB> db_; base::Time last_reported_time_; }; diff --git a/chromium/storage/browser/file_system/sandbox_directory_database_unittest.cc b/chromium/storage/browser/file_system/sandbox_directory_database_unittest.cc index e24f825f338..9c0c1dff8fe 100644 --- a/chromium/storage/browser/file_system/sandbox_directory_database_unittest.cc +++ b/chromium/storage/browser/file_system/sandbox_directory_database_unittest.cc @@ -14,7 +14,6 @@ #include "base/files/file.h" #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" -#include "base/macros.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_util.h" #include "storage/browser/test/sandbox_database_test_helper.h" @@ -40,6 +39,10 @@ class SandboxDirectoryDatabaseTest : public testing::Test { InitDatabase(); } + SandboxDirectoryDatabaseTest(const SandboxDirectoryDatabaseTest&) = delete; + SandboxDirectoryDatabaseTest& operator=(const SandboxDirectoryDatabaseTest&) = + delete; + SandboxDirectoryDatabase* db() { return db_.get(); } void InitDatabase() { @@ -136,9 +139,6 @@ class SandboxDirectoryDatabaseTest : public testing::Test { // Common temp base for nondestructive uses. base::ScopedTempDir base_; std::unique_ptr<SandboxDirectoryDatabase> db_; - - private: - DISALLOW_COPY_AND_ASSIGN(SandboxDirectoryDatabaseTest); }; TEST_F(SandboxDirectoryDatabaseTest, TestMissingFileGetInfo) { diff --git a/chromium/storage/browser/file_system/sandbox_file_stream_reader.cc b/chromium/storage/browser/file_system/sandbox_file_stream_reader.cc index 8c426a02055..cf8b331be8d 100644 --- a/chromium/storage/browser/file_system/sandbox_file_stream_reader.cc +++ b/chromium/storage/browser/file_system/sandbox_file_stream_reader.cc @@ -10,7 +10,7 @@ #include "base/memory/ptr_util.h" #include "base/memory/weak_ptr.h" -#include "base/single_thread_task_runner.h" +#include "base/task/single_thread_task_runner.h" #include "net/base/file_stream.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" diff --git a/chromium/storage/browser/file_system/sandbox_file_stream_reader.h b/chromium/storage/browser/file_system/sandbox_file_stream_reader.h index 7e9722b5bf0..5e815b1050f 100644 --- a/chromium/storage/browser/file_system/sandbox_file_stream_reader.h +++ b/chromium/storage/browser/file_system/sandbox_file_stream_reader.h @@ -12,7 +12,7 @@ #include "base/bind.h" #include "base/component_export.h" #include "base/files/file.h" -#include "base/macros.h" +#include "base/memory/raw_ptr.h" #include "base/memory/ref_counted.h" #include "base/time/time.h" #include "net/base/completion_once_callback.h" @@ -66,7 +66,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) SandboxFileStreamReader void OnRead(int rv); void OnGetLength(int64_t rv); - net::IOBuffer* read_buf_; + raw_ptr<net::IOBuffer> read_buf_; int read_buf_len_; net::CompletionOnceCallback read_callback_; net::Int64CompletionOnceCallback get_length_callback_; diff --git a/chromium/storage/browser/file_system/sandbox_file_stream_reader_unittest.cc b/chromium/storage/browser/file_system/sandbox_file_stream_reader_unittest.cc index ffc9dc6d58b..1aca0a236d1 100644 --- a/chromium/storage/browser/file_system/sandbox_file_stream_reader_unittest.cc +++ b/chromium/storage/browser/file_system/sandbox_file_stream_reader_unittest.cc @@ -13,7 +13,6 @@ #include "base/bind.h" #include "base/files/scoped_temp_dir.h" -#include "base/macros.h" #include "base/run_loop.h" #include "base/test/task_environment.h" #include "net/base/io_buffer.h" @@ -26,6 +25,8 @@ #include "storage/browser/file_system/file_system_file_util.h" #include "storage/browser/quota/quota_manager_proxy.h" #include "storage/browser/test/async_file_test_helper.h" +#include "storage/browser/test/mock_quota_manager_proxy.h" +#include "storage/browser/test/mock_special_storage_policy.h" #include "storage/browser/test/test_file_system_context.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/blink/public/common/storage_key/storage_key.h" @@ -45,8 +46,15 @@ class SandboxFileStreamReaderTest : public FileStreamReaderTest { void SetUp() override { ASSERT_TRUE(dir_.CreateUniqueTempDir()); + quota_manager_ = base::MakeRefCounted<storage::MockQuotaManager>( + /*is_incognito=*/false, dir_.GetPath(), + base::ThreadTaskRunnerHandle::Get(), + /*special_storage_policy=*/nullptr); + quota_manager_proxy_ = base::MakeRefCounted<storage::MockQuotaManagerProxy>( + quota_manager_.get(), base::ThreadTaskRunnerHandle::Get().get()); + file_system_context_ = CreateFileSystemContextForTesting( - /*quota_manager_proxy=*/nullptr, dir_.GetPath()); + quota_manager_proxy_.get(), dir_.GetPath()); file_system_context_->OpenFileSystem( blink::StorageKey::CreateFromStringForTesting(kURLOrigin), @@ -109,6 +117,8 @@ class SandboxFileStreamReaderTest : public FileStreamReaderTest { private: base::ScopedTempDir dir_; scoped_refptr<FileSystemContext> file_system_context_; + scoped_refptr<MockQuotaManager> quota_manager_; + scoped_refptr<MockQuotaManagerProxy> quota_manager_proxy_; }; INSTANTIATE_TYPED_TEST_SUITE_P(FileSystem, diff --git a/chromium/storage/browser/file_system/sandbox_file_stream_writer.cc b/chromium/storage/browser/file_system/sandbox_file_stream_writer.cc index 4e8fafcac34..e640397e0fa 100644 --- a/chromium/storage/browser/file_system/sandbox_file_stream_writer.cc +++ b/chromium/storage/browser/file_system/sandbox_file_stream_writer.cc @@ -12,7 +12,7 @@ #include "base/bind.h" #include "base/memory/weak_ptr.h" -#include "base/sequenced_task_runner.h" +#include "base/task/sequenced_task_runner.h" #include "base/threading/sequenced_task_runner_handle.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" @@ -179,8 +179,7 @@ void SandboxFileStreamWriter::DidCreateSnapshotFile( DCHECK(quota_manager_proxy); quota_manager_proxy->GetUsageAndQuota( - blink::StorageKey(url_.origin()), - FileSystemTypeToQuotaStorageType(url_.type()), + url_.storage_key(), FileSystemTypeToQuotaStorageType(url_.type()), base::SequencedTaskRunnerHandle::Get(), base::BindOnce(&SandboxFileStreamWriter::DidGetUsageAndQuota, weak_factory_.GetWeakPtr(), std::move(callback))); @@ -231,7 +230,7 @@ void SandboxFileStreamWriter::DidWrite(int write_response) { QuotaManagerProxy* quota_manager_proxy = file_system_context_->quota_manager_proxy(); if (quota_manager_proxy) { - quota_manager_proxy->NotifyWriteFailed(blink::StorageKey(url_.origin())); + quota_manager_proxy->NotifyWriteFailed(url_.storage_key()); } if (CancelIfRequested()) return; diff --git a/chromium/storage/browser/file_system/sandbox_file_stream_writer.h b/chromium/storage/browser/file_system/sandbox_file_stream_writer.h index 00a1c88b508..0d8a8cfccbb 100644 --- a/chromium/storage/browser/file_system/sandbox_file_stream_writer.h +++ b/chromium/storage/browser/file_system/sandbox_file_stream_writer.h @@ -12,7 +12,6 @@ #include "base/component_export.h" #include "base/files/file.h" #include "base/files/file_path.h" -#include "base/macros.h" #include "storage/browser/blob/shareable_file_reference.h" #include "storage/browser/file_system/file_stream_writer.h" #include "storage/browser/file_system/file_system_url.h" diff --git a/chromium/storage/browser/file_system/sandbox_file_stream_writer_unittest.cc b/chromium/storage/browser/file_system/sandbox_file_stream_writer_unittest.cc index f133512f99d..6e173b48c6b 100644 --- a/chromium/storage/browser/file_system/sandbox_file_stream_writer_unittest.cc +++ b/chromium/storage/browser/file_system/sandbox_file_stream_writer_unittest.cc @@ -16,6 +16,9 @@ #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" #include "base/time/time.h" +#include "components/services/storage/public/cpp/buckets/bucket_info.h" +#include "components/services/storage/public/cpp/buckets/constants.h" +#include "components/services/storage/public/cpp/quota_error_or.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" #include "storage/browser/file_system/file_stream_reader.h" @@ -26,6 +29,7 @@ #include "storage/browser/test/async_file_test_helper.h" #include "storage/browser/test/mock_quota_manager_proxy.h" #include "storage/browser/test/mock_special_storage_policy.h" +#include "storage/browser/test/quota_manager_proxy_sync.h" #include "storage/browser/test/test_file_system_context.h" #include "storage/common/file_system/file_system_types.h" #include "third_party/blink/public/common/storage_key/storage_key.h" @@ -177,6 +181,23 @@ class SandboxFileStreamWriterTest : public FileStreamWriterTest { SetQuota(info.usage + free_quota); } + void Test_Quota_DefaultBucketCreated() { + // Call method on context to ensure that OpenFileSystem task has completed. + EXPECT_TRUE(CreateFileWithContent("file_a", "foo")); + + QuotaManagerProxySync quota_manager_proxy_sync(quota_manager_proxy_.get()); + + // Check default bucket exist. + QuotaErrorOr<BucketInfo> result = quota_manager_proxy_sync.GetBucket( + blink::StorageKey::CreateFromStringForTesting(kURLOrigin), + kDefaultBucketName, blink::mojom::StorageType::kTemporary); + EXPECT_TRUE(result.ok()); + EXPECT_EQ(result->name, kDefaultBucketName); + EXPECT_EQ(result->storage_key, + blink::StorageKey::CreateFromStringForTesting(kURLOrigin)); + EXPECT_GT(result->id.value(), 0); + } + void Test_Quota_OK() { std::string name = "file_a"; EXPECT_TRUE(CreateFileWithContent(name, "foo")); @@ -285,6 +306,10 @@ class SandboxFileStreamWriterTest : public FileStreamWriterTest { } }; +TEST_F(SandboxFileStreamWriterTest, Test_Quota_DefaultBucketCreated) { + Test_Quota_DefaultBucketCreated(); +} + TEST_F(SandboxFileStreamWriterTest, Quota_OK) { Test_Quota_OK(); } @@ -335,6 +360,10 @@ class SandboxFileStreamWriterIncognitoTest bool is_incognito() override { return true; } }; +TEST_F(SandboxFileStreamWriterIncognitoTest, Test_Quota_DefaultBucketCreated) { + Test_Quota_DefaultBucketCreated(); +} + TEST_F(SandboxFileStreamWriterIncognitoTest, Quota_OK) { Test_Quota_OK(); } diff --git a/chromium/storage/browser/file_system/sandbox_file_system_backend.cc b/chromium/storage/browser/file_system/sandbox_file_system_backend.cc index 8b640d8b472..dba8a9fc1a3 100644 --- a/chromium/storage/browser/file_system/sandbox_file_system_backend.cc +++ b/chromium/storage/browser/file_system/sandbox_file_system_backend.cc @@ -13,7 +13,7 @@ #include "base/check.h" #include "base/files/file_util.h" #include "base/metrics/histogram.h" -#include "base/task_runner_util.h" +#include "base/task/task_runner_util.h" #include "storage/browser/file_system/async_file_util_adapter.h" #include "storage/browser/file_system/copy_or_move_file_validator.h" #include "storage/browser/file_system/file_stream_reader.h" diff --git a/chromium/storage/browser/file_system/sandbox_file_system_backend.h b/chromium/storage/browser/file_system/sandbox_file_system_backend.h index 9518e3eb81d..695a444d25f 100644 --- a/chromium/storage/browser/file_system/sandbox_file_system_backend.h +++ b/chromium/storage/browser/file_system/sandbox_file_system_backend.h @@ -13,7 +13,7 @@ #include "base/compiler_specific.h" #include "base/component_export.h" -#include "base/macros.h" +#include "base/memory/raw_ptr.h" #include "base/memory/ref_counted.h" #include "storage/browser/file_system/file_system_backend.h" #include "storage/browser/file_system/file_system_quota_util.h" @@ -78,7 +78,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) SandboxFileSystemBackend CreateStorageKeyEnumerator(); private: - SandboxFileSystemBackendDelegate* delegate_; // Not owned. + raw_ptr<SandboxFileSystemBackendDelegate> delegate_; // Not owned. }; } // namespace storage diff --git a/chromium/storage/browser/file_system/sandbox_file_system_backend_delegate.cc b/chromium/storage/browser/file_system/sandbox_file_system_backend_delegate.cc index cd90326262a..7c4a09757aa 100644 --- a/chromium/storage/browser/file_system/sandbox_file_system_backend_delegate.cc +++ b/chromium/storage/browser/file_system/sandbox_file_system_backend_delegate.cc @@ -15,9 +15,8 @@ #include "base/command_line.h" #include "base/containers/contains.h" #include "base/files/file_util.h" -#include "base/macros.h" #include "base/metrics/histogram_macros.h" -#include "base/task_runner_util.h" +#include "base/task/task_runner_util.h" #include "base/time/time.h" #include "storage/browser/file_system/async_file_util_adapter.h" #include "storage/browser/file_system/file_system_context.h" diff --git a/chromium/storage/browser/file_system/sandbox_file_system_backend_unittest.cc b/chromium/storage/browser/file_system/sandbox_file_system_backend_unittest.cc index 11ba94b9bf9..1367e29082a 100644 --- a/chromium/storage/browser/file_system/sandbox_file_system_backend_unittest.cc +++ b/chromium/storage/browser/file_system/sandbox_file_system_backend_unittest.cc @@ -14,7 +14,6 @@ #include "base/cxx17_backports.h" #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" -#include "base/macros.h" #include "base/run_loop.h" #include "base/test/scoped_feature_list.h" #include "base/test/task_environment.h" diff --git a/chromium/storage/browser/file_system/sandbox_origin_database.h b/chromium/storage/browser/file_system/sandbox_origin_database.h index 709ac336e46..177a1fa89e9 100644 --- a/chromium/storage/browser/file_system/sandbox_origin_database.h +++ b/chromium/storage/browser/file_system/sandbox_origin_database.h @@ -10,7 +10,7 @@ #include <vector> #include "base/component_export.h" -#include "base/macros.h" +#include "base/memory/raw_ptr.h" #include "base/time/time.h" #include "storage/browser/file_system/sandbox_origin_database_interface.h" @@ -75,7 +75,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) SandboxOriginDatabase bool GetLastPathNumber(int* number); base::FilePath file_system_directory_; - leveldb::Env* env_override_; + raw_ptr<leveldb::Env> env_override_; std::unique_ptr<leveldb::DB> db_; base::Time last_reported_time_; }; diff --git a/chromium/storage/browser/file_system/sandbox_origin_database_unittest.cc b/chromium/storage/browser/file_system/sandbox_origin_database_unittest.cc index 5b99ecd11eb..8f9c19880d4 100644 --- a/chromium/storage/browser/file_system/sandbox_origin_database_unittest.cc +++ b/chromium/storage/browser/file_system/sandbox_origin_database_unittest.cc @@ -16,7 +16,6 @@ #include "base/files/file_path.h" #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" -#include "base/macros.h" #include "storage/browser/file_system/sandbox_origin_database.h" #include "storage/browser/test/sandbox_database_test_helper.h" #include "storage/common/file_system/file_system_util.h" diff --git a/chromium/storage/browser/file_system/sandbox_quota_observer.cc b/chromium/storage/browser/file_system/sandbox_quota_observer.cc index f9a4a6c794e..d9855e49fd5 100644 --- a/chromium/storage/browser/file_system/sandbox_quota_observer.cc +++ b/chromium/storage/browser/file_system/sandbox_quota_observer.cc @@ -8,7 +8,7 @@ #include "base/bind.h" #include "base/memory/scoped_refptr.h" -#include "base/sequenced_task_runner.h" +#include "base/task/sequenced_task_runner.h" #include "storage/browser/file_system/file_system_usage_cache.h" #include "storage/browser/file_system/file_system_util.h" #include "storage/browser/file_system/sandbox_file_system_backend_delegate.h" @@ -44,7 +44,7 @@ void SandboxQuotaObserver::OnUpdate(const FileSystemURL& url, int64_t delta) { if (quota_manager_proxy_.get()) { quota_manager_proxy_->NotifyStorageModified( - QuotaClientType::kFileSystem, blink::StorageKey(url.origin()), + QuotaClientType::kFileSystem, url.storage_key(), FileSystemTypeToQuotaStorageType(url.type()), delta, base::Time::Now()); } @@ -81,8 +81,8 @@ void SandboxQuotaObserver::OnEndUpdate(const FileSystemURL& url) { void SandboxQuotaObserver::OnAccess(const FileSystemURL& url) { if (quota_manager_proxy_.get()) { quota_manager_proxy_->NotifyStorageAccessed( - blink::StorageKey(url.origin()), - FileSystemTypeToQuotaStorageType(url.type()), base::Time::Now()); + url.storage_key(), FileSystemTypeToQuotaStorageType(url.type()), + base::Time::Now()); } } diff --git a/chromium/storage/browser/file_system/sandbox_quota_observer.h b/chromium/storage/browser/file_system/sandbox_quota_observer.h index ed05a185962..59be57fbb44 100644 --- a/chromium/storage/browser/file_system/sandbox_quota_observer.h +++ b/chromium/storage/browser/file_system/sandbox_quota_observer.h @@ -11,7 +11,7 @@ #include "base/compiler_specific.h" #include "base/files/file_path.h" -#include "base/macros.h" +#include "base/memory/raw_ptr.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_refptr.h" #include "base/memory/weak_ptr.h" @@ -71,10 +71,10 @@ class SandboxQuotaObserver : public FileUpdateObserver, const scoped_refptr<base::SequencedTaskRunner> update_notify_runner_; // Not owned; sandbox_file_util_ should have identical lifetime with this. - ObfuscatedFileUtil* const sandbox_file_util_; + const raw_ptr<ObfuscatedFileUtil> sandbox_file_util_; // Not owned; file_system_usage_cache_ should have longer lifetime than this. - FileSystemUsageCache* const file_system_usage_cache_; + const raw_ptr<FileSystemUsageCache> file_system_usage_cache_; std::map<base::FilePath, int64_t> pending_update_notification_; base::OneShotTimer delayed_cache_update_helper_; diff --git a/chromium/storage/browser/file_system/task_runner_bound_observer_list.h b/chromium/storage/browser/file_system/task_runner_bound_observer_list.h index 52831803d04..6f960a09dad 100644 --- a/chromium/storage/browser/file_system/task_runner_bound_observer_list.h +++ b/chromium/storage/browser/file_system/task_runner_bound_observer_list.h @@ -11,7 +11,7 @@ #include "base/bind.h" #include "base/location.h" #include "base/memory/scoped_refptr.h" -#include "base/sequenced_task_runner.h" +#include "base/task/sequenced_task_runner.h" #include "base/threading/thread.h" namespace storage { diff --git a/chromium/storage/browser/file_system/transient_file_util.h b/chromium/storage/browser/file_system/transient_file_util.h index 64f6202928d..f99275bc64d 100644 --- a/chromium/storage/browser/file_system/transient_file_util.h +++ b/chromium/storage/browser/file_system/transient_file_util.h @@ -6,7 +6,6 @@ #define STORAGE_BROWSER_FILE_SYSTEM_TRANSIENT_FILE_UTIL_H_ #include "base/component_export.h" -#include "base/macros.h" #include "storage/browser/file_system/local_file_util.h" namespace storage { diff --git a/chromium/storage/browser/file_system/transient_file_util_unittest.cc b/chromium/storage/browser/file_system/transient_file_util_unittest.cc index a90a401e26f..a35166525f8 100644 --- a/chromium/storage/browser/file_system/transient_file_util_unittest.cc +++ b/chromium/storage/browser/file_system/transient_file_util_unittest.cc @@ -8,7 +8,6 @@ #include "base/files/file_path.h" #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" -#include "base/macros.h" #include "base/run_loop.h" #include "base/test/task_environment.h" #include "storage/browser/blob/scoped_file.h" diff --git a/chromium/storage/browser/quota/README.md b/chromium/storage/browser/quota/README.md index b1f532f9ec6..c94d182ac3c 100644 --- a/chromium/storage/browser/quota/README.md +++ b/chromium/storage/browser/quota/README.md @@ -30,7 +30,7 @@ outside of the quota system. ### PaddingKey Helpers for computing quota usage for opaque resources. Features that store -opaque resources (AppCache, Cache Storage) should use these helpers to avoid +opaque resources (e.g. Cache Storage) should use these helpers to avoid leaking cross-origin information via the quota usage they report. ### SpecialStoragePolicy diff --git a/chromium/storage/browser/quota/client_usage_tracker.h b/chromium/storage/browser/quota/client_usage_tracker.h index d8c79b7f549..e22336bb40d 100644 --- a/chromium/storage/browser/quota/client_usage_tracker.h +++ b/chromium/storage/browser/quota/client_usage_tracker.h @@ -14,6 +14,7 @@ #include <vector> #include "base/callback.h" +#include "base/memory/raw_ptr.h" #include "base/sequence_checker.h" #include "components/services/storage/public/mojom/quota_client.mojom.h" #include "storage/browser/quota/quota_callbacks.h" @@ -120,7 +121,7 @@ class ClientUsageTracker : public SpecialStoragePolicy::Observer { bool IsStorageUnlimited(const blink::StorageKey& storage_key) const; - mojom::QuotaClient* client_; + raw_ptr<mojom::QuotaClient> client_; const blink::mojom::StorageType type_; int64_t global_limited_usage_; diff --git a/chromium/storage/browser/quota/quota_callbacks.h b/chromium/storage/browser/quota/quota_callbacks.h index 36013d114c3..d64ab3dc188 100644 --- a/chromium/storage/browser/quota/quota_callbacks.h +++ b/chromium/storage/browser/quota/quota_callbacks.h @@ -15,7 +15,7 @@ #include "base/callback.h" #include "base/containers/contains.h" -#include "components/services/storage/public/cpp/buckets/bucket_info.h" +#include "components/services/storage/public/cpp/buckets/bucket_locator.h" #include "third_party/abseil-cpp/absl/types/optional.h" #include "third_party/blink/public/mojom/quota/quota_types.mojom-forward.h" @@ -43,13 +43,13 @@ using AvailableSpaceCallback = base::OnceCallback<void(blink::mojom::QuotaStatusCode, int64_t)>; using StatusCallback = base::OnceCallback<void(blink::mojom::QuotaStatusCode)>; using GetBucketsCallback = - base::OnceCallback<void(const std::set<BucketInfo>& buckets, + base::OnceCallback<void(const std::set<BucketLocator>& buckets, blink::mojom::StorageType type)>; using GetStorageKeysCallback = base::OnceCallback<void(const std::set<blink::StorageKey>& storage_keys)>; using GetUsageInfoCallback = base::OnceCallback<void(UsageInfoEntries)>; using GetBucketCallback = - base::OnceCallback<void(const absl::optional<BucketInfo>& bucket_info)>; + base::OnceCallback<void(const absl::optional<BucketLocator>& bucket_info)>; // Simple template wrapper for a callback queue. template <typename CallbackType, typename... Args> diff --git a/chromium/storage/browser/quota/quota_client_type.cc b/chromium/storage/browser/quota/quota_client_type.cc index f74f7236f29..cb737075211 100644 --- a/chromium/storage/browser/quota/quota_client_type.cc +++ b/chromium/storage/browser/quota/quota_client_type.cc @@ -12,7 +12,6 @@ const QuotaClientTypes& AllQuotaClientTypes() { static base::NoDestructor<QuotaClientTypes> all{{ QuotaClientType::kFileSystem, QuotaClientType::kDatabase, - QuotaClientType::kAppcache, QuotaClientType::kIndexedDatabase, QuotaClientType::kServiceWorkerCache, QuotaClientType::kServiceWorker, diff --git a/chromium/storage/browser/quota/quota_client_type.h b/chromium/storage/browser/quota/quota_client_type.h index c69f2b36df0..d90cf800803 100644 --- a/chromium/storage/browser/quota/quota_client_type.h +++ b/chromium/storage/browser/quota/quota_client_type.h @@ -21,8 +21,7 @@ enum class QuotaClientType { kServiceWorkerCache = 4, kServiceWorker = 5, kBackgroundFetch = 6, - kAppcache = 7, - kNativeIO = 8, + kNativeIO = 7, }; // Set of QuotaClientType values. diff --git a/chromium/storage/browser/quota/quota_database.cc b/chromium/storage/browser/quota/quota_database.cc index d1421d28dba..a995b943c57 100644 --- a/chromium/storage/browser/quota/quota_database.cc +++ b/chromium/storage/browser/quota/quota_database.cc @@ -129,13 +129,12 @@ QuotaDatabase::~QuotaDatabase() { } } -bool QuotaDatabase::GetHostQuota(const std::string& host, - StorageType type, - int64_t* quota) { +QuotaErrorOr<int64_t> QuotaDatabase::GetHostQuota(const std::string& host, + StorageType type) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - DCHECK(quota); - if (EnsureOpened(EnsureOpenedMode::kFailIfNotFound) != QuotaError::kNone) - return false; + QuotaError open_error = EnsureOpened(EnsureOpenedMode::kFailIfNotFound); + if (open_error != QuotaError::kNone) + return open_error; static constexpr char kSql[] = "SELECT quota FROM quota WHERE host = ? AND type = ?"; @@ -143,27 +142,36 @@ bool QuotaDatabase::GetHostQuota(const std::string& host, statement.BindString(0, host); statement.BindInt(1, static_cast<int>(type)); - if (!statement.Step()) - return false; - - *quota = statement.ColumnInt64(0); - return true; + if (!statement.Step()) { + return statement.Succeeded() ? QuotaError::kNotFound + : QuotaError::kDatabaseError; + } + return statement.ColumnInt64(0); } -bool QuotaDatabase::SetHostQuota(const std::string& host, - StorageType type, - int64_t quota) { +QuotaError QuotaDatabase::SetHostQuota(const std::string& host, + StorageType type, + int64_t quota) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_GE(quota, 0); - if (EnsureOpened(EnsureOpenedMode::kCreateIfNotFound) != QuotaError::kNone) - return false; + QuotaError open_error = EnsureOpened(EnsureOpenedMode::kCreateIfNotFound); + if (open_error != QuotaError::kNone) + return open_error; if (quota == 0) return DeleteHostQuota(host, type); - if (!InsertOrReplaceHostQuota(host, type, quota)) - return false; + + static constexpr char kSql[] = + "INSERT OR REPLACE INTO quota(quota, host, type) VALUES (?, ?, ?)"; + sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); + statement.BindInt64(0, quota); + statement.BindString(1, host); + statement.BindInt(2, static_cast<int>(type)); + if (!statement.Run()) + return QuotaError::kDatabaseError; + ScheduleCommit(); - return true; + return QuotaError::kNone; } QuotaErrorOr<BucketInfo> QuotaDatabase::GetOrCreateBucket( @@ -354,7 +362,7 @@ QuotaError QuotaDatabase::SetStorageKeyLastAccessTime( return QuotaError::kNone; } -QuotaError QuotaDatabase::SetBucketLastAccessTime(const BucketId bucket_id, +QuotaError QuotaDatabase::SetBucketLastAccessTime(BucketId bucket_id, base::Time last_accessed) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK(!bucket_id.is_null()); @@ -420,7 +428,7 @@ QuotaError QuotaDatabase::SetStorageKeyLastModifiedTime( return QuotaError::kNone; } -QuotaError QuotaDatabase::SetBucketLastModifiedTime(const BucketId bucket_id, +QuotaError QuotaDatabase::SetBucketLastModifiedTime(BucketId bucket_id, base::Time last_modified) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK(!bucket_id.is_null()); @@ -482,7 +490,7 @@ bool QuotaDatabase::RegisterInitialStorageKeyInfo( return true; } -bool QuotaDatabase::GetBucketInfo(const BucketId bucket_id, +bool QuotaDatabase::GetBucketInfo(BucketId bucket_id, QuotaDatabase::BucketTableEntry* entry) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK(!bucket_id.is_null()); @@ -519,11 +527,12 @@ bool QuotaDatabase::GetBucketInfo(const BucketId bucket_id, return true; } -bool QuotaDatabase::DeleteHostQuota( - const std::string& host, StorageType type) { +QuotaError QuotaDatabase::DeleteHostQuota(const std::string& host, + StorageType type) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - if (EnsureOpened(EnsureOpenedMode::kFailIfNotFound) != QuotaError::kNone) - return false; + QuotaError open_error = EnsureOpened(EnsureOpenedMode::kFailIfNotFound); + if (open_error != QuotaError::kNone) + return open_error; static constexpr char kSql[] = "DELETE FROM quota WHERE host = ? AND type = ?"; @@ -532,17 +541,18 @@ bool QuotaDatabase::DeleteHostQuota( statement.BindInt(1, static_cast<int>(type)); if (!statement.Run()) - return false; + return QuotaError::kDatabaseError; ScheduleCommit(); - return true; + return QuotaError::kNone; } -bool QuotaDatabase::DeleteStorageKeyInfo(const StorageKey& storage_key, - StorageType type) { +QuotaError QuotaDatabase::DeleteStorageKeyInfo(const StorageKey& storage_key, + StorageType type) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - if (EnsureOpened(EnsureOpenedMode::kFailIfNotFound) != QuotaError::kNone) - return false; + QuotaError open_error = EnsureOpened(EnsureOpenedMode::kFailIfNotFound); + if (open_error != QuotaError::kNone) + return open_error; static constexpr char kSql[] = "DELETE FROM buckets WHERE storage_key = ? AND type = ?"; @@ -551,30 +561,31 @@ bool QuotaDatabase::DeleteStorageKeyInfo(const StorageKey& storage_key, statement.BindInt(1, static_cast<int>(type)); if (!statement.Run()) - return false; + return QuotaError::kDatabaseError; ScheduleCommit(); - return true; + return QuotaError::kNone; } -bool QuotaDatabase::DeleteBucketInfo(const BucketId bucket_id) { +QuotaError QuotaDatabase::DeleteBucketInfo(BucketId bucket_id) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK(!bucket_id.is_null()); - if (EnsureOpened(EnsureOpenedMode::kFailIfNotFound) != QuotaError::kNone) - return false; + QuotaError open_error = EnsureOpened(EnsureOpenedMode::kFailIfNotFound); + if (open_error != QuotaError::kNone) + return open_error; static constexpr char kSql[] = "DELETE FROM buckets WHERE id = ?"; sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); statement.BindInt64(0, bucket_id.value()); if (!statement.Run()) - return false; + return QuotaError::kDatabaseError; ScheduleCommit(); - return true; + return QuotaError::kNone; } -QuotaErrorOr<BucketInfo> QuotaDatabase::GetLRUBucket( +QuotaErrorOr<BucketLocator> QuotaDatabase::GetLRUBucket( StorageType type, const std::set<BucketId>& bucket_exceptions, SpecialStoragePolicy* special_storage_policy) { @@ -585,8 +596,7 @@ QuotaErrorOr<BucketInfo> QuotaDatabase::GetLRUBucket( // clang-format off static constexpr char kSql[] = - "SELECT id, storage_key, name, expiration, quota " - "FROM buckets " + "SELECT id, storage_key, name FROM buckets " "WHERE type = ? " "ORDER BY last_accessed"; // clang-format on @@ -612,9 +622,8 @@ QuotaErrorOr<BucketInfo> QuotaDatabase::GetLRUBucket( special_storage_policy->IsStorageUnlimited(read_gurl))) { continue; } - return BucketInfo(read_bucket_id, std::move(read_storage_key).value(), type, - statement.ColumnString(2), statement.ColumnTime(3), - statement.ColumnInt(4)); + return BucketLocator(read_bucket_id, std::move(read_storage_key).value(), + type, statement.ColumnString(2) == kDefaultBucketName); } return QuotaError::kNotFound; } @@ -643,7 +652,7 @@ QuotaErrorOr<std::set<StorageKey>> QuotaDatabase::GetStorageKeysForType( return storage_keys; } -QuotaErrorOr<std::set<BucketInfo>> QuotaDatabase::GetBucketsModifiedBetween( +QuotaErrorOr<std::set<BucketLocator>> QuotaDatabase::GetBucketsModifiedBetween( StorageType type, base::Time begin, base::Time end) { @@ -656,7 +665,7 @@ QuotaErrorOr<std::set<BucketInfo>> QuotaDatabase::GetBucketsModifiedBetween( DCHECK(end != base::Time()); // clang-format off static constexpr char kSql[] = - "SELECT id, storage_key, name, expiration, quota FROM buckets " + "SELECT id, storage_key, name FROM buckets " "WHERE type = ? AND last_modified >= ? AND last_modified < ?"; // clang-format on @@ -665,15 +674,15 @@ QuotaErrorOr<std::set<BucketInfo>> QuotaDatabase::GetBucketsModifiedBetween( statement.BindTime(1, begin); statement.BindTime(2, end); - std::set<BucketInfo> buckets; + std::set<BucketLocator> buckets; while (statement.Step()) { absl::optional<StorageKey> read_storage_key = StorageKey::Deserialize(statement.ColumnString(1)); if (!read_storage_key.has_value()) continue; buckets.emplace(BucketId(statement.ColumnInt64(0)), - read_storage_key.value(), type, statement.ColumnString(2), - statement.ColumnTime(3), statement.ColumnInt(4)); + read_storage_key.value(), type, + statement.ColumnString(2) == kDefaultBucketName); } return buckets; } @@ -894,27 +903,11 @@ bool QuotaDatabase::ResetSchema() { return EnsureOpened(EnsureOpenedMode::kCreateIfNotFound) == QuotaError::kNone; } -bool QuotaDatabase::InsertOrReplaceHostQuota(const std::string& host, - StorageType type, - int64_t quota) { +QuotaError QuotaDatabase::DumpQuotaTable(const QuotaTableCallback& callback) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - DCHECK(db_.get()); - static constexpr char kSql[] = - // clang-format off - "INSERT OR REPLACE INTO quota(quota, host, type)" - "VALUES (?, ?, ?)"; - // clang-format on - sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); - statement.BindInt64(0, quota); - statement.BindString(1, host); - statement.BindInt(2, static_cast<int>(type)); - return statement.Run(); -} - -bool QuotaDatabase::DumpQuotaTable(const QuotaTableCallback& callback) { - DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - if (EnsureOpened(EnsureOpenedMode::kCreateIfNotFound) != QuotaError::kNone) - return false; + QuotaError open_error = EnsureOpened(EnsureOpenedMode::kCreateIfNotFound); + if (open_error != QuotaError::kNone) + return open_error; static constexpr char kSql[] = "SELECT * FROM quota"; sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); @@ -926,17 +919,16 @@ bool QuotaDatabase::DumpQuotaTable(const QuotaTableCallback& callback) { .quota = statement.ColumnInt64(2)}; if (!callback.Run(entry)) - return true; + return QuotaError::kNone; } - - return statement.Succeeded(); + return statement.Succeeded() ? QuotaError::kNone : QuotaError::kDatabaseError; } -bool QuotaDatabase::DumpBucketTable(const BucketTableCallback& callback) { +QuotaError QuotaDatabase::DumpBucketTable(const BucketTableCallback& callback) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - - if (EnsureOpened(EnsureOpenedMode::kCreateIfNotFound) != QuotaError::kNone) - return false; + QuotaError open_error = EnsureOpened(EnsureOpenedMode::kCreateIfNotFound); + if (open_error != QuotaError::kNone) + return open_error; static constexpr char kSql[] = // clang-format off @@ -958,17 +950,15 @@ bool QuotaDatabase::DumpBucketTable(const BucketTableCallback& callback) { StorageKey::Deserialize(statement.ColumnString(1)); if (!storage_key.has_value()) continue; - BucketTableEntry entry(std::move(bucket_id), std::move(storage_key).value(), static_cast<StorageType>(statement.ColumnInt(2)), statement.ColumnString(3), statement.ColumnInt(4), statement.ColumnTime(5), statement.ColumnTime(6)); if (!callback.Run(entry)) - return true; + return QuotaError::kNone; } - - return statement.Succeeded(); + return statement.Succeeded() ? QuotaError::kNone : QuotaError::kDatabaseError; } QuotaErrorOr<BucketInfo> QuotaDatabase::CreateBucketInternal( diff --git a/chromium/storage/browser/quota/quota_database.h b/chromium/storage/browser/quota/quota_database.h index 5864a9a3bf3..84b0f5f22be 100644 --- a/chromium/storage/browser/quota/quota_database.h +++ b/chromium/storage/browser/quota/quota_database.h @@ -16,7 +16,6 @@ #include "base/compiler_specific.h" #include "base/component_export.h" #include "base/files/file_path.h" -#include "base/macros.h" #include "base/sequence_checker.h" #include "base/time/time.h" #include "base/timer/timer.h" @@ -91,16 +90,17 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaDatabase { ~QuotaDatabase(); - // Returns whether the record could be found. - bool GetHostQuota(const std::string& host, - blink::mojom::StorageType type, - int64_t* quota); + // Returns quota if entry is found. Returns QuotaError::kNotFound no entry if + // found. + QuotaErrorOr<int64_t> GetHostQuota(const std::string& host, + blink::mojom::StorageType type); // Returns whether the operation succeeded. - bool SetHostQuota(const std::string& host, - blink::mojom::StorageType type, - int64_t quota); - bool DeleteHostQuota(const std::string& host, blink::mojom::StorageType type); + QuotaError SetHostQuota(const std::string& host, + blink::mojom::StorageType type, + int64_t quota); + QuotaError DeleteHostQuota(const std::string& host, + blink::mojom::StorageType type); // Gets the bucket with `bucket_name` for the `storage_key` for StorageType // kTemporary and returns the BucketInfo. If one doesn't exist, it creates @@ -182,16 +182,16 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaDatabase { bool GetBucketInfo(BucketId bucket_id, BucketTableEntry* entry); // Removes all buckets for `storage_key` with `type`. - bool DeleteStorageKeyInfo(const blink::StorageKey& storage_key, - blink::mojom::StorageType type); + QuotaError DeleteStorageKeyInfo(const blink::StorageKey& storage_key, + blink::mojom::StorageType type); // Deletes the specified bucket. - bool DeleteBucketInfo(BucketId bucket_id); + QuotaError DeleteBucketInfo(BucketId bucket_id); - // Returns the BucketInfo for the least recently used bucket. Will exclude + // Returns the BucketLocator for the least recently used bucket. Will exclude // buckets with ids in `bucket_exceptions` and origins that have the special // unlimited storage policy. Returns a QuotaError if the operation has failed. - QuotaErrorOr<BucketInfo> GetLRUBucket( + QuotaErrorOr<BucketLocator> GetLRUBucket( blink::mojom::StorageType type, const std::set<BucketId>& bucket_exceptions, SpecialStoragePolicy* special_storage_policy); @@ -202,7 +202,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaDatabase { // Returns a set of buckets that have been modified since the `begin` and // until the `end`. Returns a QuotaError if the operations has failed. - QuotaErrorOr<std::set<BucketInfo>> GetBucketsModifiedBetween( + QuotaErrorOr<std::set<BucketLocator>> GetBucketsModifiedBetween( blink::mojom::StorageType type, base::Time begin, base::Time end); @@ -263,17 +263,15 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaDatabase { bool EnsureDatabaseVersion(); bool ResetSchema(); bool UpgradeSchema(int current_version); - bool InsertOrReplaceHostQuota(const std::string& host, - blink::mojom::StorageType type, - int64_t quota); bool CreateSchema(); bool CreateTable(const TableSchema& table); bool CreateIndex(const IndexSchema& index); + // Dumps table entries for chrome://quota-internals page. // `callback` may return false to stop reading data. - bool DumpQuotaTable(const QuotaTableCallback& callback); - bool DumpBucketTable(const BucketTableCallback& callback); + QuotaError DumpQuotaTable(const QuotaTableCallback& callback); + QuotaError DumpBucketTable(const BucketTableCallback& callback); // Adds a new bucket entry in the buckets table. Will return a // QuotaError::kDatabaseError if the query fails. diff --git a/chromium/storage/browser/quota/quota_database_unittest.cc b/chromium/storage/browser/quota/quota_database_unittest.cc index 0a82637cb26..23c6820cae9 100644 --- a/chromium/storage/browser/quota/quota_database_unittest.cc +++ b/chromium/storage/browser/quota/quota_database_unittest.cc @@ -89,13 +89,14 @@ class QuotaDatabaseTest : public testing::TestWithParam<bool> { } }; - bool DumpQuotaTable(QuotaDatabase* quota_database, - const QuotaDatabase::QuotaTableCallback& callback) { + QuotaError DumpQuotaTable(QuotaDatabase* quota_database, + const QuotaDatabase::QuotaTableCallback& callback) { return quota_database->DumpQuotaTable(callback); } - bool DumpBucketTable(QuotaDatabase* quota_database, - const QuotaDatabase::BucketTableCallback& callback) { + QuotaError DumpBucketTable( + QuotaDatabase* quota_database, + const QuotaDatabase::BucketTableCallback& callback) { return quota_database->DumpBucketTable(callback); } @@ -184,30 +185,41 @@ TEST_P(QuotaDatabaseTest, HostQuota) { const int kQuota1 = 13579; const int kQuota2 = kQuota1 + 1024; - int64_t quota = -1; - EXPECT_FALSE(db.GetHostQuota(kHost, kTemp, "a)); - EXPECT_FALSE(db.GetHostQuota(kHost, kPerm, "a)); + QuotaErrorOr<int64_t> result = db.GetHostQuota(kHost, kTemp); + EXPECT_FALSE(result.ok()); + EXPECT_EQ(result.error(), QuotaError::kNotFound); + result = db.GetHostQuota(kHost, kPerm); + EXPECT_FALSE(result.ok()); + EXPECT_EQ(result.error(), QuotaError::kNotFound); // Insert quota for temporary. - EXPECT_TRUE(db.SetHostQuota(kHost, kTemp, kQuota1)); - EXPECT_TRUE(db.GetHostQuota(kHost, kTemp, "a)); - EXPECT_EQ(kQuota1, quota); + EXPECT_EQ(db.SetHostQuota(kHost, kTemp, kQuota1), QuotaError::kNone); + result = db.GetHostQuota(kHost, kTemp); + EXPECT_TRUE(result.ok()); + EXPECT_EQ(kQuota1, result.value()); // Update quota for temporary. - EXPECT_TRUE(db.SetHostQuota(kHost, kTemp, kQuota2)); - EXPECT_TRUE(db.GetHostQuota(kHost, kTemp, "a)); - EXPECT_EQ(kQuota2, quota); + EXPECT_EQ(db.SetHostQuota(kHost, kTemp, kQuota2), QuotaError::kNone); + result = db.GetHostQuota(kHost, kTemp); + EXPECT_TRUE(result.ok()); + EXPECT_EQ(kQuota2, result.value()); // Quota for persistent must not be updated. - EXPECT_FALSE(db.GetHostQuota(kHost, kPerm, "a)); + result = db.GetHostQuota(kHost, kPerm); + EXPECT_FALSE(result.ok()); + EXPECT_EQ(result.error(), QuotaError::kNotFound); // Delete temporary storage quota. - EXPECT_TRUE(db.DeleteHostQuota(kHost, kTemp)); - EXPECT_FALSE(db.GetHostQuota(kHost, kTemp, "a)); + EXPECT_EQ(db.DeleteHostQuota(kHost, kTemp), QuotaError::kNone); + result = db.GetHostQuota(kHost, kTemp); + EXPECT_FALSE(result.ok()); + EXPECT_EQ(result.error(), QuotaError::kNotFound); // Delete persistent quota by setting it to zero. - EXPECT_TRUE(db.SetHostQuota(kHost, kPerm, 0)); - EXPECT_FALSE(db.GetHostQuota(kHost, kPerm, "a)); + EXPECT_EQ(db.SetHostQuota(kHost, kPerm, 0), QuotaError::kNone); + result = db.GetHostQuota(kHost, kPerm); + EXPECT_FALSE(result.ok()); + EXPECT_EQ(result.error(), QuotaError::kNotFound); } TEST_P(QuotaDatabaseTest, GetOrCreateBucket) { @@ -503,7 +515,7 @@ TEST_P(QuotaDatabaseTest, BucketLastAccessTimeLRU) { EXPECT_TRUE(EnsureOpened(&db, EnsureOpenedMode::kCreateIfNotFound)); std::set<BucketId> bucket_exceptions; - QuotaErrorOr<BucketInfo> result = + QuotaErrorOr<BucketLocator> result = db.GetLRUBucket(kTemp, bucket_exceptions, nullptr); EXPECT_FALSE(result.ok()); EXPECT_EQ(result.error(), QuotaError::kNotFound); @@ -581,7 +593,7 @@ TEST_P(QuotaDatabaseTest, BucketLastAccessTimeLRU) { QuotaError::kNone); // Delete storage_key/type last access time information. - EXPECT_TRUE(db.DeleteBucketInfo(bucket3.bucket_id)); + EXPECT_EQ(db.DeleteBucketInfo(bucket3.bucket_id), QuotaError::kNone); // Querying again to see if the deletion has worked. bucket_exceptions.clear(); @@ -654,10 +666,10 @@ TEST_P(QuotaDatabaseTest, BucketLastModifiedBetween) { QuotaDatabase db(use_in_memory_db() ? base::FilePath() : DbPath()); EXPECT_TRUE(EnsureOpened(&db, EnsureOpenedMode::kCreateIfNotFound)); - QuotaErrorOr<std::set<BucketInfo>> result = + QuotaErrorOr<std::set<BucketLocator>> result = db.GetBucketsModifiedBetween(kTemp, base::Time(), base::Time::Max()); EXPECT_TRUE(result.ok()); - std::set<BucketInfo> buckets = result.value(); + std::set<BucketLocator> buckets = result.value(); EXPECT_TRUE(buckets.empty()); QuotaErrorOr<BucketInfo> result1 = db.CreateBucketForTesting( @@ -699,30 +711,30 @@ TEST_P(QuotaDatabaseTest, BucketLastModifiedBetween) { EXPECT_TRUE(result.ok()); buckets = result.value(); EXPECT_EQ(3U, buckets.size()); - EXPECT_EQ(1U, buckets.count(bucket1)); - EXPECT_EQ(1U, buckets.count(bucket2)); - EXPECT_EQ(1U, buckets.count(bucket3)); - EXPECT_EQ(0U, buckets.count(bucket4)); + EXPECT_TRUE(ContainsBucket(buckets, bucket1)); + EXPECT_TRUE(ContainsBucket(buckets, bucket2)); + EXPECT_TRUE(ContainsBucket(buckets, bucket3)); + EXPECT_FALSE(ContainsBucket(buckets, bucket4)); result = db.GetBucketsModifiedBetween(kTemp, base::Time::FromJavaTime(5), base::Time::Max()); EXPECT_TRUE(result.ok()); buckets = result.value(); EXPECT_EQ(2U, buckets.size()); - EXPECT_EQ(0U, buckets.count(bucket1)); - EXPECT_EQ(1U, buckets.count(bucket2)); - EXPECT_EQ(1U, buckets.count(bucket3)); - EXPECT_EQ(0U, buckets.count(bucket4)); + EXPECT_FALSE(ContainsBucket(buckets, bucket1)); + EXPECT_TRUE(ContainsBucket(buckets, bucket2)); + EXPECT_TRUE(ContainsBucket(buckets, bucket3)); + EXPECT_FALSE(ContainsBucket(buckets, bucket4)); result = db.GetBucketsModifiedBetween(kTemp, base::Time::FromJavaTime(15), base::Time::Max()); EXPECT_TRUE(result.ok()); buckets = result.value(); EXPECT_EQ(1U, buckets.size()); - EXPECT_EQ(0U, buckets.count(bucket1)); - EXPECT_EQ(0U, buckets.count(bucket2)); - EXPECT_EQ(1U, buckets.count(bucket3)); - EXPECT_EQ(0U, buckets.count(bucket4)); + EXPECT_FALSE(ContainsBucket(buckets, bucket1)); + EXPECT_FALSE(ContainsBucket(buckets, bucket2)); + EXPECT_TRUE(ContainsBucket(buckets, bucket3)); + EXPECT_FALSE(ContainsBucket(buckets, bucket4)); result = db.GetBucketsModifiedBetween(kTemp, base::Time::FromJavaTime(25), base::Time::Max()); @@ -735,30 +747,30 @@ TEST_P(QuotaDatabaseTest, BucketLastModifiedBetween) { EXPECT_TRUE(result.ok()); buckets = result.value(); EXPECT_EQ(1U, buckets.size()); - EXPECT_EQ(0U, buckets.count(bucket1)); - EXPECT_EQ(1U, buckets.count(bucket2)); - EXPECT_EQ(0U, buckets.count(bucket3)); - EXPECT_EQ(0U, buckets.count(bucket4)); + EXPECT_FALSE(ContainsBucket(buckets, bucket1)); + EXPECT_TRUE(ContainsBucket(buckets, bucket2)); + EXPECT_FALSE(ContainsBucket(buckets, bucket3)); + EXPECT_FALSE(ContainsBucket(buckets, bucket4)); result = db.GetBucketsModifiedBetween(kTemp, base::Time::FromJavaTime(0), base::Time::FromJavaTime(20)); EXPECT_TRUE(result.ok()); buckets = result.value(); EXPECT_EQ(2U, buckets.size()); - EXPECT_EQ(1U, buckets.count(bucket1)); - EXPECT_EQ(1U, buckets.count(bucket2)); - EXPECT_EQ(0U, buckets.count(bucket3)); - EXPECT_EQ(0U, buckets.count(bucket4)); + EXPECT_TRUE(ContainsBucket(buckets, bucket1)); + EXPECT_TRUE(ContainsBucket(buckets, bucket2)); + EXPECT_FALSE(ContainsBucket(buckets, bucket3)); + EXPECT_FALSE(ContainsBucket(buckets, bucket4)); result = db.GetBucketsModifiedBetween(kPerm, base::Time::FromJavaTime(0), base::Time::FromJavaTime(35)); EXPECT_TRUE(result.ok()); buckets = result.value(); EXPECT_EQ(1U, buckets.size()); - EXPECT_EQ(0U, buckets.count(bucket1)); - EXPECT_EQ(0U, buckets.count(bucket2)); - EXPECT_EQ(0U, buckets.count(bucket3)); - EXPECT_EQ(1U, buckets.count(bucket4)); + EXPECT_FALSE(ContainsBucket(buckets, bucket1)); + EXPECT_FALSE(ContainsBucket(buckets, bucket2)); + EXPECT_FALSE(ContainsBucket(buckets, bucket3)); + EXPECT_TRUE(ContainsBucket(buckets, bucket4)); } TEST_P(QuotaDatabaseTest, RegisterInitialStorageKeyInfo) { @@ -809,8 +821,10 @@ TEST_P(QuotaDatabaseTest, DumpQuotaTable) { using Verifier = EntryVerifier<QuotaTableEntry>; Verifier verifier(kTableEntries, std::end(kTableEntries)); - EXPECT_TRUE(DumpQuotaTable( - &db, base::BindRepeating(&Verifier::Run, base::Unretained(&verifier)))); + EXPECT_EQ( + DumpQuotaTable(&db, base::BindRepeating(&Verifier::Run, + base::Unretained(&verifier))), + QuotaError::kNone); EXPECT_TRUE(verifier.table.empty()); } @@ -832,8 +846,10 @@ TEST_P(QuotaDatabaseTest, DumpBucketTable) { using Verifier = EntryVerifier<Entry>; Verifier verifier(kTableEntries, std::end(kTableEntries)); - EXPECT_TRUE(DumpBucketTable( - &db, base::BindRepeating(&Verifier::Run, base::Unretained(&verifier)))); + EXPECT_EQ( + DumpBucketTable(&db, base::BindRepeating(&Verifier::Run, + base::Unretained(&verifier))), + QuotaError::kNone); EXPECT_TRUE(verifier.table.empty()); } diff --git a/chromium/storage/browser/quota/quota_device_info_helper.h b/chromium/storage/browser/quota/quota_device_info_helper.h index bedb8344133..2ce8b16f8ee 100644 --- a/chromium/storage/browser/quota/quota_device_info_helper.h +++ b/chromium/storage/browser/quota/quota_device_info_helper.h @@ -3,7 +3,6 @@ // found in the LICENSE file. #include "base/component_export.h" -#include "base/macros.h" #include "base/system/sys_info.h" #ifndef STORAGE_BROWSER_QUOTA_QUOTA_DEVICE_INFO_HELPER_H_ diff --git a/chromium/storage/browser/quota/quota_manager_impl.cc b/chromium/storage/browser/quota/quota_manager_impl.cc index 3cd39138b22..0ebb245ec41 100644 --- a/chromium/storage/browser/quota/quota_manager_impl.cc +++ b/chromium/storage/browser/quota/quota_manager_impl.cc @@ -19,20 +19,20 @@ #include "base/callback_helpers.h" #include "base/command_line.h" #include "base/files/file_util.h" -#include "base/macros.h" +#include "base/memory/raw_ptr.h" #include "base/memory/scoped_refptr.h" #include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_macros.h" #include "base/numerics/safe_conversions.h" #include "base/rand_util.h" #include "base/sequence_checker.h" -#include "base/sequenced_task_runner.h" -#include "base/single_thread_task_runner.h" #include "base/strings/string_number_conversions.h" #include "base/system/sys_info.h" #include "base/task/post_task.h" +#include "base/task/sequenced_task_runner.h" +#include "base/task/single_thread_task_runner.h" +#include "base/task/task_runner_util.h" #include "base/task/thread_pool.h" -#include "base/task_runner_util.h" #include "base/threading/thread_restrictions.h" #include "base/threading/thread_task_runner_handle.h" #include "base/time/time.h" @@ -151,7 +151,7 @@ QuotaErrorOr<std::set<BucketLocator>> GetBucketsForStorageKeyOnDBThread( return database->GetBucketsForStorageKey(storage_key, type); } -QuotaErrorOr<std::set<BucketInfo>> GetModifiedBetweenOnDBThread( +QuotaErrorOr<std::set<BucketLocator>> GetModifiedBetweenOnDBThread( StorageType type, base::Time begin, base::Time end, @@ -160,25 +160,21 @@ QuotaErrorOr<std::set<BucketInfo>> GetModifiedBetweenOnDBThread( return database->GetBucketsModifiedBetween(type, begin, end); } -bool GetPersistentHostQuotaOnDBThread(const std::string& host, - int64_t* quota, - QuotaDatabase* database) { +QuotaErrorOr<int64_t> GetPersistentHostQuotaOnDBThread( + const std::string& host, + QuotaDatabase* database) { DCHECK(database); - database->GetHostQuota(host, StorageType::kPersistent, quota); - return true; + return database->GetHostQuota(host, StorageType::kPersistent); } -bool SetPersistentHostQuotaOnDBThread(const std::string& host, - int64_t* new_quota, - QuotaDatabase* database) { +QuotaError SetPersistentHostQuotaOnDBThread(const std::string& host, + int64_t* new_quota, + QuotaDatabase* database) { DCHECK(database); - if (database->SetHostQuota(host, StorageType::kPersistent, *new_quota)) - return true; - *new_quota = 0; - return false; + return database->SetHostQuota(host, StorageType::kPersistent, *new_quota); } -QuotaErrorOr<BucketInfo> GetLRUBucketOnDBThread( +QuotaErrorOr<BucketLocator> GetLRUBucketOnDBThread( StorageType type, const std::set<BucketId>& bucket_exceptions, SpecialStoragePolicy* policy, @@ -187,16 +183,16 @@ QuotaErrorOr<BucketInfo> GetLRUBucketOnDBThread( return database->GetLRUBucket(type, bucket_exceptions, policy); } -bool DeleteStorageKeyInfoOnDBThread(const StorageKey& storage_key, - StorageType type, - QuotaDatabase* database) { +QuotaError DeleteStorageKeyInfoOnDBThread(const StorageKey& storage_key, + StorageType type, + QuotaDatabase* database) { DCHECK(database); return database->DeleteStorageKeyInfo(storage_key, type); } -bool DeleteBucketInfoOnDBThread(const BucketId bucket_id, - bool is_eviction, - QuotaDatabase* database) { +QuotaError DeleteBucketInfoOnDBThread(BucketId bucket_id, + bool is_eviction, + QuotaDatabase* database) { DCHECK(database); if (is_eviction) { @@ -229,42 +225,36 @@ bool BootstrapDatabaseOnDBThread(std::set<StorageKey> storage_keys, return false; } -bool UpdateAccessTimeOnDBThread(const StorageKey& storage_key, - StorageType type, - base::Time accessed_time, - QuotaDatabase* database) { - DCHECK(database); - QuotaError result = - database->SetStorageKeyLastAccessTime(storage_key, type, accessed_time); - return result != QuotaError::kDatabaseError; -} - -bool UpdateBucketAccessTimeOnDBThread(const BucketId bucket_id, +QuotaError UpdateAccessTimeOnDBThread(const StorageKey& storage_key, + StorageType type, base::Time accessed_time, QuotaDatabase* database) { DCHECK(database); - QuotaError result = - database->SetBucketLastAccessTime(bucket_id, accessed_time); - return result != QuotaError::kDatabaseError; + return database->SetStorageKeyLastAccessTime(storage_key, type, + accessed_time); } -bool UpdateModifiedTimeOnDBThread(const StorageKey& storage_key, - StorageType type, - base::Time modified_time, - QuotaDatabase* database) { +QuotaError UpdateBucketAccessTimeOnDBThread(BucketId bucket_id, + base::Time accessed_time, + QuotaDatabase* database) { DCHECK(database); - QuotaError result = - database->SetStorageKeyLastModifiedTime(storage_key, type, modified_time); - return result != QuotaError::kDatabaseError; + return database->SetBucketLastAccessTime(bucket_id, accessed_time); } -bool UpdateBucketModifiedTimeOnDBThread(const BucketId bucket_id, +QuotaError UpdateModifiedTimeOnDBThread(const StorageKey& storage_key, + StorageType type, base::Time modified_time, QuotaDatabase* database) { DCHECK(database); - QuotaError result = - database->SetBucketLastModifiedTime(bucket_id, modified_time); - return result != QuotaError::kDatabaseError; + return database->SetStorageKeyLastModifiedTime(storage_key, type, + modified_time); +} + +QuotaError UpdateBucketModifiedTimeOnDBThread(BucketId bucket_id, + base::Time modified_time, + QuotaDatabase* database) { + DCHECK(database); + return database->SetBucketLastModifiedTime(bucket_id, modified_time); } void DidGetUsageAndQuotaStripBreakdown( @@ -562,7 +552,7 @@ class QuotaManagerImpl::EvictionRoundInfoHelper { Completed(); } - QuotaManagerImpl* const manager_; + const raw_ptr<QuotaManagerImpl> manager_; EvictionRoundInfoCallback callback_; base::OnceClosure completion_closure_; QuotaSettings settings_; @@ -740,7 +730,7 @@ class QuotaManagerImpl::StorageKeyDataDeleter : public QuotaTask { class QuotaManagerImpl::BucketDataDeleter : public QuotaTask { public: BucketDataDeleter(QuotaManagerImpl* manager, - const BucketInfo& bucket, + const BucketLocator& bucket, QuotaClientTypes quota_client_types, bool is_eviction, StatusCallback callback) @@ -758,7 +748,7 @@ class QuotaManagerImpl::BucketDataDeleter : public QuotaTask { // they are not being tracked yet. // TODO(crbug.com/1199417): Update to call for all buckets once QuotaClient // is migrated to operate on buckets. - if (!bucket_.is_default()) { + if (!bucket_.is_default) { CallCompleted(); return; } @@ -772,7 +762,8 @@ class QuotaManagerImpl::BucketDataDeleter : public QuotaTask { static int tracing_id = 0; std::ostringstream bucket_params; bucket_params << "storage_key: " << bucket_.storage_key.Serialize() - << ", name: " << bucket_.name << ", id: " << bucket_.id; + << ", is_default: " << bucket_.is_default + << ", id: " << bucket_.id; TRACE_EVENT_NESTABLE_ASYNC_BEGIN2( "browsing_data", "QuotaManagerImpl::BucketDataDeleter", ++tracing_id, "client_type", client_type, "bucket", @@ -827,7 +818,7 @@ class QuotaManagerImpl::BucketDataDeleter : public QuotaTask { return static_cast<QuotaManagerImpl*>(observer()); } - const BucketInfo bucket_; + const BucketLocator bucket_; const QuotaClientTypes quota_client_types_; int error_count_ = 0; size_t remaining_clients_ = 0; @@ -999,7 +990,7 @@ class QuotaManagerImpl::StorageCleanupHelper : public QuotaTask { // modified. class QuotaManagerImpl::DumpQuotaTableHelper { public: - bool DumpQuotaTableOnDBThread(QuotaDatabase* database) { + QuotaError DumpQuotaTableOnDBThread(QuotaDatabase* database) { DCHECK(database); return database->DumpQuotaTable(base::BindRepeating( &DumpQuotaTableHelper::AppendEntry, base::Unretained(this))); @@ -1007,13 +998,13 @@ class QuotaManagerImpl::DumpQuotaTableHelper { void DidDumpQuotaTable(const base::WeakPtr<QuotaManagerImpl>& manager, DumpQuotaTableCallback callback, - bool success) { + QuotaError error) { if (!manager) { // The operation was aborted. std::move(callback).Run(QuotaTableEntries()); return; } - manager->DidDatabaseWork(success); + manager->DidDatabaseWork(error != QuotaError::kDatabaseError); std::move(callback).Run(entries_); } @@ -1035,7 +1026,7 @@ class QuotaManagerImpl::DumpQuotaTableHelper { // modified. class QuotaManagerImpl::DumpBucketTableHelper { public: - bool DumpBucketTableOnDBThread(QuotaDatabase* database) { + QuotaError DumpBucketTableOnDBThread(QuotaDatabase* database) { DCHECK(database); return database->DumpBucketTable(base::BindRepeating( &DumpBucketTableHelper::AppendEntry, base::Unretained(this))); @@ -1043,13 +1034,13 @@ class QuotaManagerImpl::DumpBucketTableHelper { void DidDumpBucketTable(const base::WeakPtr<QuotaManagerImpl>& manager, DumpBucketTableCallback callback, - bool success) { + QuotaError error) { if (!manager) { // The operation was aborted. std::move(callback).Run(BucketTableEntries()); return; } - manager->DidDatabaseWork(success); + manager->DidDatabaseWork(error != QuotaError::kDatabaseError); std::move(callback).Run(entries_); } @@ -1317,7 +1308,7 @@ void QuotaManagerImpl::SetUsageCacheEnabled(QuotaClientType client_id, GetUsageTracker(type)->SetUsageCacheEnabled(client_id, storage_key, enabled); } -void QuotaManagerImpl::DeleteBucketData(const BucketInfo& bucket, +void QuotaManagerImpl::DeleteBucketData(const BucketLocator& bucket, QuotaClientTypes quota_client_types, StatusCallback callback) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); @@ -1381,13 +1372,10 @@ void QuotaManagerImpl::GetPersistentHostQuota(const std::string& host, if (!persistent_host_quota_callbacks_.Add(host, std::move(callback))) return; - int64_t* quota_ptr = new int64_t(0); PostTaskAndReplyWithResultForDBThread( - FROM_HERE, - base::BindOnce(&GetPersistentHostQuotaOnDBThread, host, - base::Unretained(quota_ptr)), + base::BindOnce(&GetPersistentHostQuotaOnDBThread, host), base::BindOnce(&QuotaManagerImpl::DidGetPersistentHostQuota, - weak_factory_.GetWeakPtr(), host, base::Owned(quota_ptr))); + weak_factory_.GetWeakPtr(), host)); } void QuotaManagerImpl::SetPersistentHostQuota(const std::string& host, @@ -1419,7 +1407,6 @@ void QuotaManagerImpl::SetPersistentHostQuota(const std::string& host, int64_t* new_quota_ptr = new int64_t(new_quota); PostTaskAndReplyWithResultForDBThread( - FROM_HERE, base::BindOnce(&SetPersistentHostQuotaOnDBThread, host, base::Unretained(new_quota_ptr)), base::BindOnce(&QuotaManagerImpl::DidSetPersistentHostQuota, @@ -1641,14 +1628,13 @@ void QuotaManagerImpl::NotifyStorageAccessed(const StorageKey& storage_key, if (db_disabled_) return; PostTaskAndReplyWithResultForDBThread( - FROM_HERE, base::BindOnce(&UpdateAccessTimeOnDBThread, storage_key, type, access_time), - base::BindOnce(&QuotaManagerImpl::DidDatabaseWork, + base::BindOnce(&QuotaManagerImpl::OnComplete, weak_factory_.GetWeakPtr())); } -void QuotaManagerImpl::NotifyBucketAccessed(const BucketId bucket_id, +void QuotaManagerImpl::NotifyBucketAccessed(BucketId bucket_id, base::Time access_time) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); EnsureDatabaseOpened(); @@ -1661,9 +1647,8 @@ void QuotaManagerImpl::NotifyBucketAccessed(const BucketId bucket_id, if (db_disabled_) return; PostTaskAndReplyWithResultForDBThread( - FROM_HERE, base::BindOnce(&UpdateBucketAccessTimeOnDBThread, bucket_id, access_time), - base::BindOnce(&QuotaManagerImpl::DidDatabaseWork, + base::BindOnce(&QuotaManagerImpl::OnComplete, weak_factory_.GetWeakPtr())); } @@ -1685,15 +1670,14 @@ void QuotaManagerImpl::NotifyStorageModified(QuotaClientType client_id, return; PostTaskAndReplyWithResultForDBThread( - FROM_HERE, base::BindOnce(&UpdateModifiedTimeOnDBThread, storage_key, type, modification_time), - base::BindOnce(&QuotaManagerImpl::DidDatabaseWork, + base::BindOnce(&QuotaManagerImpl::OnComplete, weak_factory_.GetWeakPtr())); } void QuotaManagerImpl::NotifyBucketModified(QuotaClientType client_id, - const BucketId bucket_id, + BucketId bucket_id, int64_t delta, base::Time modification_time, base::OnceClosure callback) { @@ -1710,10 +1694,9 @@ void QuotaManagerImpl::NotifyBucketModified(QuotaClientType client_id, return; PostTaskAndReplyWithResultForDBThread( - FROM_HERE, base::BindOnce(&UpdateBucketModifiedTimeOnDBThread, bucket_id, modification_time), - base::BindOnce(&QuotaManagerImpl::DidDatabaseWork, + base::BindOnce(&QuotaManagerImpl::OnComplete, weak_factory_.GetWeakPtr())); } @@ -1721,7 +1704,6 @@ void QuotaManagerImpl::DumpQuotaTable(DumpQuotaTableCallback callback) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DumpQuotaTableHelper* helper = new DumpQuotaTableHelper; PostTaskAndReplyWithResultForDBThread( - FROM_HERE, base::BindOnce(&DumpQuotaTableHelper::DumpQuotaTableOnDBThread, base::Unretained(helper)), base::BindOnce(&DumpQuotaTableHelper::DidDumpQuotaTable, @@ -1733,7 +1715,6 @@ void QuotaManagerImpl::DumpBucketTable(DumpBucketTableCallback callback) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DumpBucketTableHelper* helper = new DumpBucketTableHelper; PostTaskAndReplyWithResultForDBThread( - FROM_HERE, base::BindOnce(&DumpBucketTableHelper::DumpBucketTableOnDBThread, base::Unretained(helper)), base::BindOnce(&DumpBucketTableHelper::DidDumpBucketTable, @@ -1760,9 +1741,8 @@ void QuotaManagerImpl::DeleteStorageKeyFromDatabase( return; PostTaskAndReplyWithResultForDBThread( - FROM_HERE, base::BindOnce(&DeleteStorageKeyInfoOnDBThread, storage_key, type), - base::BindOnce(&QuotaManagerImpl::DidDatabaseWork, + base::BindOnce(&QuotaManagerImpl::OnComplete, weak_factory_.GetWeakPtr())); } @@ -1774,9 +1754,8 @@ void QuotaManagerImpl::DeleteBucketFromDatabase(BucketId bucket_id, return; PostTaskAndReplyWithResultForDBThread( - FROM_HERE, base::BindOnce(&DeleteBucketInfoOnDBThread, bucket_id, is_eviction), - base::BindOnce(&QuotaManagerImpl::DidDatabaseWork, + base::BindOnce(&QuotaManagerImpl::OnComplete, weak_factory_.GetWeakPtr())); } @@ -1796,7 +1775,7 @@ void QuotaManagerImpl::DidBucketDataEvicted( } void QuotaManagerImpl::DeleteBucketDataInternal( - const BucketInfo& bucket, + const BucketLocator& bucket, QuotaClientTypes quota_client_types, bool is_eviction, StatusCallback callback) { @@ -2011,7 +1990,7 @@ std::set<BucketId> QuotaManagerImpl::GetEvictionBucketExceptions() { void QuotaManagerImpl::DidGetEvictionBucket( GetBucketCallback callback, - const absl::optional<BucketInfo>& bucket) { + const absl::optional<BucketLocator>& bucket) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); // Make sure the returned bucket has not been accessed since we posted the // eviction task. @@ -2020,7 +1999,7 @@ void QuotaManagerImpl::DidGetEvictionBucket( // TODO(crbug.com/1208141): Remove this evaluation for storage key once // QuotaClient is migrated to operate on buckets and NotifyStorageAccessed // no longer used. - if (bucket.has_value() && bucket->is_default() && + if (bucket.has_value() && bucket->is_default && base::Contains(access_notified_storage_keys_, bucket->storage_key)) { std::move(callback).Run(absl::nullopt); } else if (bucket.has_value() && @@ -2061,7 +2040,7 @@ void QuotaManagerImpl::GetEvictionBucket(StorageType type, GetLRUBucket(type, std::move(did_get_bucket_callback)); } -void QuotaManagerImpl::EvictBucketData(const BucketInfo& bucket, +void QuotaManagerImpl::EvictBucketData(const BucketLocator& bucket, StatusCallback callback) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK(io_thread_->BelongsToCurrentThread()); @@ -2116,28 +2095,36 @@ void QuotaManagerImpl::GetLRUBucket(StorageType type, } void QuotaManagerImpl::DidGetPersistentHostQuota(const std::string& host, - const int64_t* quota, - bool success) { + QuotaErrorOr<int64_t> result) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - DidDatabaseWork(success); + DidDatabaseWork(result.ok() || result.error() != QuotaError::kDatabaseError); + + if (!result.ok() && result.error() != QuotaError::kNotFound) { + persistent_host_quota_callbacks_.Run( + host, blink::mojom::QuotaStatusCode::kErrorInvalidAccess, /*quota=*/0); + return; + } persistent_host_quota_callbacks_.Run( host, blink::mojom::QuotaStatusCode::kOk, - std::min(*quota, kPerHostPersistentQuotaLimit)); + std::min(result.ok() ? result.value() : 0, kPerHostPersistentQuotaLimit)); } void QuotaManagerImpl::DidSetPersistentHostQuota(const std::string& host, QuotaCallback callback, const int64_t* new_quota, - bool success) { + QuotaError error) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - DidDatabaseWork(success); - std::move(callback).Run( - success ? blink::mojom::QuotaStatusCode::kOk - : blink::mojom::QuotaStatusCode::kErrorInvalidAccess, - *new_quota); + DidDatabaseWork(error != QuotaError::kDatabaseError); + + if (error == QuotaError::kNone) { + std::move(callback).Run(blink::mojom::QuotaStatusCode::kOk, *new_quota); + return; + } + std::move(callback).Run(blink::mojom::QuotaStatusCode::kErrorInvalidAccess, + /*new_quota=*/0); } -void QuotaManagerImpl::DidGetLRUBucket(QuotaErrorOr<BucketInfo> result) { +void QuotaManagerImpl::DidGetLRUBucket(QuotaErrorOr<BucketLocator> result) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DidDatabaseWork(result.ok() || result.error() != QuotaError::kDatabaseError); @@ -2239,6 +2226,11 @@ void QuotaManagerImpl::DidDatabaseWork(bool success) { db_disabled_ = !success; } +void QuotaManagerImpl::OnComplete(QuotaError result) { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + DidDatabaseWork(result != QuotaError::kDatabaseError); +} + void QuotaManagerImpl::DidGetBucket( base::OnceCallback<void(QuotaErrorOr<BucketInfo>)> callback, QuotaErrorOr<BucketInfo> result) { @@ -2261,7 +2253,9 @@ void QuotaManagerImpl::DidGetBucketForDeletion( return; } - DeleteBucketDataInternal(result.value(), AllQuotaClientTypes(), + BucketLocator bucket(result->id, result->storage_key, result->type, + result->name == kDefaultBucketName); + DeleteBucketDataInternal(bucket, AllQuotaClientTypes(), /*is_eviction=*/false, std::move(callback)); return; } @@ -2289,11 +2283,11 @@ void QuotaManagerImpl::DidGetBuckets( void QuotaManagerImpl::DidGetModifiedBetween( GetBucketsCallback callback, StorageType type, - QuotaErrorOr<std::set<BucketInfo>> result) { + QuotaErrorOr<std::set<BucketLocator>> result) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DidDatabaseWork(result.ok() || result.error() != QuotaError::kDatabaseError); if (!result.ok()) { - std::move(callback).Run(std::set<BucketInfo>(), type); + std::move(callback).Run(std::set<BucketLocator>(), type); return; } std::move(callback).Run(result.value(), type); @@ -2328,6 +2322,20 @@ void QuotaManagerImpl::PostTaskAndReplyWithResultForDBThread( std::move(reply)); } +void QuotaManagerImpl::PostTaskAndReplyWithResultForDBThread( + base::OnceCallback<QuotaError(QuotaDatabase*)> task, + base::OnceCallback<void(QuotaError)> reply, + const base::Location& from_here) { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + // Deleting manager will post another task to DB sequence to delete + // |database_|, therefore we can be sure that database_ is alive when this + // task runs. + base::PostTaskAndReplyWithResult( + db_runner_.get(), from_here, + base::BindOnce(std::move(task), base::Unretained(database_.get())), + std::move(reply)); +} + // static std::tuple<int64_t, int64_t> QuotaManagerImpl::CallGetVolumeInfo( GetVolumeInfoFn get_volume_info_fn, diff --git a/chromium/storage/browser/quota/quota_manager_impl.h b/chromium/storage/browser/quota/quota_manager_impl.h index eab17be27bc..8762f546418 100644 --- a/chromium/storage/browser/quota/quota_manager_impl.h +++ b/chromium/storage/browser/quota/quota_manager_impl.h @@ -18,9 +18,7 @@ #include "base/callback.h" #include "base/component_export.h" -#include "base/containers/contains.h" #include "base/files/file_path.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/ref_counted_delete_on_sequence.h" #include "base/memory/weak_ptr.h" @@ -85,7 +83,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaEvictionHandler { GetBucketCallback callback) = 0; // Called to evict a bucket. - virtual void EvictBucketData(const BucketInfo& bucket, + virtual void EvictBucketData(const BucketLocator& bucket, StatusCallback callback) = 0; protected: @@ -318,7 +316,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerImpl // the types of QuotaClients to delete from the storage key. // Pass in QuotaClientType::AllClients() to remove all clients from the // storage key, regardless of type. - virtual void DeleteBucketData(const BucketInfo& bucket, + virtual void DeleteBucketData(const BucketLocator& bucket, QuotaClientTypes quota_client_types, StatusCallback callback); void DeleteHostData(const std::string& host, @@ -331,9 +329,9 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerImpl // bucket. Used by the Storage Bucket API for bucket deletion. If no bucket is // found, it will return QuotaStatusCode::kOk since it has no bucket data to // delete. - void FindAndDeleteBucketData(const blink::StorageKey& storage_key, - const std::string& bucket_name, - StatusCallback callback); + virtual void FindAndDeleteBucketData(const blink::StorageKey& storage_key, + const std::string& bucket_name, + StatusCallback callback); // Instructs each QuotaClient to remove possible traces of deleted // data on the disk. @@ -468,7 +466,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerImpl struct EvictionContext { EvictionContext(); ~EvictionContext(); - BucketInfo evicted_bucket; + BucketLocator evicted_bucket; StatusCallback evict_bucket_data_callback; }; @@ -505,7 +503,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerImpl // Runs BucketDataDeleter which calls QuotaClients to clear data for the // bucket. Once the task is complete, calls the QuotaDatabase to delete the // bucket from the bucket table. - void DeleteBucketDataInternal(const BucketInfo& bucket, + void DeleteBucketDataInternal(const BucketLocator& bucket, QuotaClientTypes quota_client_types, bool is_eviction, StatusCallback callback); @@ -532,13 +530,13 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerImpl // consistent errors after multiple attempts. std::set<BucketId> GetEvictionBucketExceptions(); void DidGetEvictionBucket(GetBucketCallback callback, - const absl::optional<BucketInfo>& bucket); + const absl::optional<BucketLocator>& bucket); // QuotaEvictionHandler. void GetEvictionBucket(blink::mojom::StorageType type, int64_t global_quota, GetBucketCallback callback) override; - void EvictBucketData(const BucketInfo& bucket, + void EvictBucketData(const BucketLocator& bucket, StatusCallback callback) override; void GetEvictionRoundInfo(EvictionRoundInfoCallback callback) override; @@ -547,13 +545,12 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerImpl void GetLRUBucket(blink::mojom::StorageType type, GetBucketCallback callback); void DidGetPersistentHostQuota(const std::string& host, - const int64_t* quota, - bool success); + QuotaErrorOr<int64_t> result); void DidSetPersistentHostQuota(const std::string& host, QuotaCallback callback, const int64_t* new_quota, - bool success); - void DidGetLRUBucket(QuotaErrorOr<BucketInfo> result); + QuotaError error); + void DidGetLRUBucket(QuotaErrorOr<BucketLocator> result); void GetQuotaSettings(QuotaSettingsCallback callback); void DidGetSettings(absl::optional<QuotaSettings> settings); void GetStorageCapacity(StorageCapacityCallback callback); @@ -562,6 +559,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerImpl const std::tuple<int64_t, int64_t>& total_and_available); void DidDatabaseWork(bool success); + void OnComplete(QuotaError result); void DidGetBucket(base::OnceCallback<void(QuotaErrorOr<BucketInfo>)> callback, QuotaErrorOr<BucketInfo> result); @@ -574,7 +572,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerImpl QuotaErrorOr<std::set<BucketLocator>> result); void DidGetModifiedBetween(GetBucketsCallback callback, blink::mojom::StorageType type, - QuotaErrorOr<std::set<BucketInfo>> result); + QuotaErrorOr<std::set<BucketLocator>> result); void DeleteOnCorrectThread() const; @@ -608,6 +606,11 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerImpl base::OnceCallback<void(QuotaErrorOr<ValueType>)> reply, const base::Location& from_here = base::Location::Current()); + void PostTaskAndReplyWithResultForDBThread( + base::OnceCallback<QuotaError(QuotaDatabase*)> task, + base::OnceCallback<void(QuotaError)> reply, + const base::Location& from_here = base::Location::Current()); + static std::tuple<int64_t, int64_t> CallGetVolumeInfo( GetVolumeInfoFn get_volume_info_fn, const base::FilePath& path); diff --git a/chromium/storage/browser/quota/quota_manager_proxy.cc b/chromium/storage/browser/quota/quota_manager_proxy.cc index 5440c615199..196f97ca311 100644 --- a/chromium/storage/browser/quota/quota_manager_proxy.cc +++ b/chromium/storage/browser/quota/quota_manager_proxy.cc @@ -15,7 +15,7 @@ #include "base/location.h" #include "base/memory/scoped_refptr.h" #include "base/sequence_checker.h" -#include "base/sequenced_task_runner.h" +#include "base/task/sequenced_task_runner.h" #include "base/threading/thread_task_runner_handle.h" #include "base/time/time.h" #include "components/services/storage/public/mojom/quota_client.mojom.h" @@ -212,7 +212,7 @@ void QuotaManagerProxy::NotifyStorageAccessed(const StorageKey& storage_key, quota_manager_impl_->NotifyStorageAccessed(storage_key, type, access_time); } -void QuotaManagerProxy::NotifyBucketAccessed(const BucketId bucket_id, +void QuotaManagerProxy::NotifyBucketAccessed(BucketId bucket_id, base::Time access_time) { if (!quota_manager_impl_task_runner_->RunsTasksInCurrentSequence()) { quota_manager_impl_task_runner_->PostTask( @@ -267,7 +267,7 @@ void QuotaManagerProxy::NotifyStorageModified( void QuotaManagerProxy::NotifyBucketModified( QuotaClientType client_id, - const BucketId bucket_id, + BucketId bucket_id, int64_t delta, base::Time modification_time, scoped_refptr<base::SequencedTaskRunner> callback_task_runner, diff --git a/chromium/storage/browser/quota/quota_manager_proxy.h b/chromium/storage/browser/quota/quota_manager_proxy.h index 294406ac6be..a6f0648c1c7 100644 --- a/chromium/storage/browser/quota/quota_manager_proxy.h +++ b/chromium/storage/browser/quota/quota_manager_proxy.h @@ -12,9 +12,10 @@ #include "base/callback.h" #include "base/component_export.h" +#include "base/memory/raw_ptr.h" #include "base/memory/ref_counted.h" #include "base/sequence_checker.h" -#include "base/sequenced_task_runner_helpers.h" +#include "base/task/sequenced_task_runner_helpers.h" #include "base/thread_annotations.h" #include "base/time/time.h" #include "base/types/pass_key.h" @@ -215,7 +216,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerProxy // constructed. This is because the easiest way to ensure that // QuotaManagerImpl exposes its QuotaManagerProxy in a thread-safe manner // is to have the QuotaManagerImpl's QuotaManagerProxy reference be const. - QuotaManagerImpl* quota_manager_impl_ + raw_ptr<QuotaManagerImpl> quota_manager_impl_ GUARDED_BY_CONTEXT(quota_manager_impl_sequence_checker_); // TaskRunner that accesses QuotaManagerImpl's sequence. diff --git a/chromium/storage/browser/quota/quota_manager_unittest.cc b/chromium/storage/browser/quota/quota_manager_unittest.cc index 994b07ceed5..113ce82329e 100644 --- a/chromium/storage/browser/quota/quota_manager_unittest.cc +++ b/chromium/storage/browser/quota/quota_manager_unittest.cc @@ -15,11 +15,9 @@ #include "base/bind.h" #include "base/callback_forward.h" #include "base/callback_helpers.h" -#include "base/containers/contains.h" #include "base/containers/span.h" #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" -#include "base/macros.h" #include "base/memory/ptr_util.h" #include "base/memory/scoped_refptr.h" #include "base/memory/weak_ptr.h" @@ -113,6 +111,9 @@ class QuotaManagerImplTest : public testing::Test { public: QuotaManagerImplTest() : mock_time_counter_(0) {} + QuotaManagerImplTest(const QuotaManagerImplTest&) = delete; + QuotaManagerImplTest& operator=(const QuotaManagerImplTest&) = delete; + void SetUp() override { ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); mock_special_storage_policy_ = @@ -374,14 +375,14 @@ class QuotaManagerImplTest : public testing::Test { weak_factory_.GetWeakPtr())); } - void EvictBucketData(const BucketInfo& bucket) { + void EvictBucketData(const BucketLocator& bucket) { quota_status_ = QuotaStatusCode::kUnknown; quota_manager_impl_->EvictBucketData( bucket, base::BindOnce(&QuotaManagerImplTest::StatusCallback, weak_factory_.GetWeakPtr())); } - void DeleteBucketData(const BucketInfo& bucket, + void DeleteBucketData(const BucketLocator& bucket, QuotaClientTypes quota_client_types) { quota_status_ = QuotaStatusCode::kUnknown; quota_manager_impl_->DeleteBucketData( @@ -439,7 +440,7 @@ class QuotaManagerImplTest : public testing::Test { IncrementMockTime()); } - void NotifyBucketAccessed(const BucketId bucket_id) { + void NotifyBucketAccessed(BucketId bucket_id) { quota_manager_impl_->NotifyBucketAccessed(bucket_id, IncrementMockTime()); } @@ -582,14 +583,14 @@ class QuotaManagerImplTest : public testing::Test { usage_ = global_usage; } - void DidGetEvictionBucket(const absl::optional<BucketInfo>& bucket) { + void DidGetEvictionBucket(const absl::optional<BucketLocator>& bucket) { eviction_bucket_ = bucket; DCHECK(!bucket.has_value() || !bucket->storage_key.origin().GetURL().is_empty()); } void DidGetModifiedBuckets(base::OnceClosure quit_closure, - const std::set<BucketInfo>& buckets, + const std::set<BucketLocator>& buckets, StorageType type) { modified_buckets_ = buckets; modified_buckets_type_ = type; @@ -663,10 +664,10 @@ class QuotaManagerImplTest : public testing::Test { int64_t quota() const { return quota_; } int64_t total_space() const { return total_space_; } int64_t available_space() const { return available_space_; } - const absl::optional<BucketInfo>& eviction_bucket() const { + const absl::optional<BucketLocator>& eviction_bucket() const { return eviction_bucket_; } - const std::set<BucketInfo>& modified_buckets() const { + const std::set<BucketLocator>& modified_buckets() const { return modified_buckets_; } StorageType modified_buckets_type() const { return modified_buckets_type_; } @@ -701,8 +702,8 @@ class QuotaManagerImplTest : public testing::Test { int64_t quota_; int64_t total_space_; int64_t available_space_; - absl::optional<BucketInfo> eviction_bucket_; - std::set<BucketInfo> modified_buckets_; + absl::optional<BucketLocator> eviction_bucket_; + std::set<BucketLocator> modified_buckets_; StorageType modified_buckets_type_; QuotaTableEntries quota_entries_; BucketTableEntries bucket_entries_; @@ -714,8 +715,6 @@ class QuotaManagerImplTest : public testing::Test { int mock_time_counter_; base::WeakPtrFactory<QuotaManagerImplTest> weak_factory_{this}; - - DISALLOW_COPY_AND_ASSIGN(QuotaManagerImplTest); }; TEST_F(QuotaManagerImplTest, GetUsageInfo) { @@ -1802,7 +1801,7 @@ TEST_F(QuotaManagerImplTest, EvictBucketData) { GetBucket(ToStorageKey("http://foo.com/"), kDefaultBucketName, kTemp); ASSERT_TRUE(bucket_.ok()); - EvictBucketData(bucket_.value()); + EvictBucketData(bucket_->ToBucketLocator()); task_environment_.RunUntilIdle(); DumpBucketTable(); @@ -1844,7 +1843,7 @@ TEST_F(QuotaManagerImplTest, EvictNonDefaultBucketData) { ASSERT_TRUE(bucket_.ok()); BucketInfo created_bucket = bucket_.value(); - EvictBucketData(created_bucket); + EvictBucketData(created_bucket.ToBucketLocator()); task_environment_.RunUntilIdle(); EXPECT_EQ(QuotaStatusCode::kOk, status()); @@ -1868,7 +1867,7 @@ TEST_F(QuotaManagerImplTest, EvictNonDefaultBucketData) { ASSERT_TRUE(bucket_.ok()); BucketInfo default_bucket = bucket_.value(); - EvictBucketData(default_bucket); + EvictBucketData(default_bucket.ToBucketLocator()); task_environment_.RunUntilIdle(); EXPECT_EQ(QuotaStatusCode::kOk, status()); @@ -1897,7 +1896,7 @@ TEST_F(QuotaManagerImplTest, EvictBucketDataHistogram) { CreateBucketForTesting(kStorageKey, kDefaultBucketName, kTemp); ASSERT_TRUE(bucket_.ok()); - EvictBucketData(bucket_.value()); + EvictBucketData(bucket_->ToBucketLocator()); task_environment_.RunUntilIdle(); // Ensure use count and time since access are recorded. @@ -1917,7 +1916,7 @@ TEST_F(QuotaManagerImplTest, EvictBucketDataHistogram) { GetGlobalUsage(kTemp); - EvictBucketData(bucket_.value()); + EvictBucketData(bucket_->ToBucketLocator()); task_environment_.RunUntilIdle(); // The new use count should be logged. @@ -1962,7 +1961,7 @@ TEST_F(QuotaManagerImplTest, EvictBucketDataWithDeletionError) { for (int i = 0; i < QuotaManagerImpl::kThresholdOfErrorsToBeDenylisted + 1; ++i) { - EvictBucketData(bucket_.value()); + EvictBucketData(bucket_->ToBucketLocator()); task_environment_.RunUntilIdle(); EXPECT_EQ(QuotaStatusCode::kErrorInvalidModification, status()); } @@ -2245,7 +2244,7 @@ TEST_F(QuotaManagerImplTest, DeleteBucketNoClients) { kTemp); ASSERT_TRUE(bucket_.ok()); - DeleteBucketData(bucket_.value(), AllQuotaClientTypes()); + DeleteBucketData(bucket_->ToBucketLocator(), AllQuotaClientTypes()); task_environment_.RunUntilIdle(); EXPECT_EQ(QuotaStatusCode::kOk, status()); } @@ -2305,9 +2304,9 @@ TEST_F(QuotaManagerImplTest, DeleteBucketDataMultiple) { task_environment_.RunUntilIdle(); reset_status_callback_count(); - DeleteBucketData(foo_temp_bucket, AllQuotaClientTypes()); - DeleteBucketData(bar_temp_bucket, AllQuotaClientTypes()); - DeleteBucketData(foo_temp_bucket, AllQuotaClientTypes()); + DeleteBucketData(foo_temp_bucket.ToBucketLocator(), AllQuotaClientTypes()); + DeleteBucketData(bar_temp_bucket.ToBucketLocator(), AllQuotaClientTypes()); + DeleteBucketData(foo_temp_bucket.ToBucketLocator(), AllQuotaClientTypes()); task_environment_.RunUntilIdle(); EXPECT_EQ(3, status_callback_count()); @@ -2399,8 +2398,8 @@ TEST_F(QuotaManagerImplTest, DeleteBucketDataMultipleClientsDifferentTypes) { task_environment_.RunUntilIdle(); reset_status_callback_count(); - DeleteBucketData(foo_perm_bucket, AllQuotaClientTypes()); - DeleteBucketData(bar_perm_bucket, AllQuotaClientTypes()); + DeleteBucketData(foo_perm_bucket.ToBucketLocator(), AllQuotaClientTypes()); + DeleteBucketData(bar_perm_bucket.ToBucketLocator(), AllQuotaClientTypes()); task_environment_.RunUntilIdle(); EXPECT_EQ(2, status_callback_count()); @@ -2609,13 +2608,13 @@ TEST_F(QuotaManagerImplTest, GetLRUBucket) { GetEvictionBucket(kTemp); task_environment_.RunUntilIdle(); - EXPECT_EQ(bucket_a, eviction_bucket()); + EXPECT_EQ(bucket_a.ToBucketLocator(), eviction_bucket()); // Notify that the `bucket_a` is accessed. NotifyBucketAccessed(bucket_a.id); GetEvictionBucket(kTemp); task_environment_.RunUntilIdle(); - EXPECT_EQ(bucket_b, eviction_bucket()); + EXPECT_EQ(bucket_b.ToBucketLocator(), eviction_bucket()); // Notify that the `bucket_b` is accessed while GetEvictionBucket is running. GetEvictionBucket(kTemp); @@ -2638,7 +2637,6 @@ TEST_F(QuotaManagerImplTest, GetBucketsModifiedBetween) { blink::mojom::StorageType::kPersistent}); GetBucketsModifiedBetween(kTemp, base::Time(), base::Time::Max()); - task_environment_.RunUntilIdle(); EXPECT_TRUE(modified_buckets().empty()); EXPECT_EQ(modified_buckets_type(), kTemp); @@ -2652,35 +2650,31 @@ TEST_F(QuotaManagerImplTest, GetBucketsModifiedBetween) { base::Time time3 = client->IncrementMockTime(); GetBucketsModifiedBetween(kTemp, time1, base::Time::Max()); - task_environment_.RunUntilIdle(); EXPECT_EQ(modified_buckets_type(), kTemp); EXPECT_THAT(modified_buckets(), testing::UnorderedElementsAre( - testing::Field(&BucketInfo::storage_key, + testing::Field(&BucketLocator::storage_key, ToStorageKey("http://a.com")), - testing::Field(&BucketInfo::storage_key, + testing::Field(&BucketLocator::storage_key, ToStorageKey("http://a.com:1")), - testing::Field(&BucketInfo::storage_key, + testing::Field(&BucketLocator::storage_key, ToStorageKey("https://a.com")), - testing::Field(&BucketInfo::storage_key, + testing::Field(&BucketLocator::storage_key, ToStorageKey("http://c.com")))); GetBucketsModifiedBetween(kTemp, time2, base::Time::Max()); - task_environment_.RunUntilIdle(); EXPECT_EQ(2U, modified_buckets().size()); GetBucketsModifiedBetween(kTemp, time3, base::Time::Max()); - task_environment_.RunUntilIdle(); EXPECT_TRUE(modified_buckets().empty()); EXPECT_EQ(modified_buckets_type(), kTemp); client->ModifyStorageKeyAndNotify(ToStorageKey("http://a.com/"), kTemp, 10); GetBucketsModifiedBetween(kTemp, time3, base::Time::Max()); - task_environment_.RunUntilIdle(); EXPECT_THAT(modified_buckets(), testing::UnorderedElementsAre(testing::Field( - &BucketInfo::storage_key, ToStorageKey("http://a.com/")))); + &BucketLocator::storage_key, ToStorageKey("http://a.com/")))); EXPECT_EQ(modified_buckets_type(), kTemp); } @@ -2691,7 +2685,6 @@ TEST_F(QuotaManagerImplTest, GetBucketsModifiedBetweenWithDatabaseError) { disable_quota_database(true); GetBucketsModifiedBetween(kTemp, base::Time(), base::Time::Max()); - task_environment_.RunUntilIdle(); // Return empty set when error is encountered. EXPECT_TRUE(modified_buckets().empty()); @@ -2777,22 +2770,25 @@ TEST_F(QuotaManagerImplTest, DeleteSpecificClientTypeSingleBucket) { GetHostUsageWithBreakdown("foo.com", kTemp); const int64_t predelete_foo_tmp = usage(); - DeleteBucketData(foo_bucket, {QuotaClientType::kFileSystem}); + DeleteBucketData(foo_bucket.ToBucketLocator(), + {QuotaClientType::kFileSystem}); task_environment_.RunUntilIdle(); GetHostUsageWithBreakdown("foo.com", kTemp); EXPECT_EQ(predelete_foo_tmp - 1, usage()); - DeleteBucketData(foo_bucket, {QuotaClientType::kServiceWorkerCache}); + DeleteBucketData(foo_bucket.ToBucketLocator(), + {QuotaClientType::kServiceWorkerCache}); task_environment_.RunUntilIdle(); GetHostUsageWithBreakdown("foo.com", kTemp); EXPECT_EQ(predelete_foo_tmp - 2 - 1, usage()); - DeleteBucketData(foo_bucket, {QuotaClientType::kDatabase}); + DeleteBucketData(foo_bucket.ToBucketLocator(), {QuotaClientType::kDatabase}); task_environment_.RunUntilIdle(); GetHostUsageWithBreakdown("foo.com", kTemp); EXPECT_EQ(predelete_foo_tmp - 4 - 2 - 1, usage()); - DeleteBucketData(foo_bucket, {QuotaClientType::kIndexedDatabase}); + DeleteBucketData(foo_bucket.ToBucketLocator(), + {QuotaClientType::kIndexedDatabase}); task_environment_.RunUntilIdle(); GetHostUsageWithBreakdown("foo.com", kTemp); EXPECT_EQ(predelete_foo_tmp - 8 - 4 - 2 - 1, usage()); @@ -2874,14 +2870,15 @@ TEST_F(QuotaManagerImplTest, DeleteMultipleClientTypesSingleBucket) { GetHostUsageWithBreakdown("foo.com", kTemp); const int64_t predelete_foo_tmp = usage(); - DeleteBucketData(foo_bucket, + DeleteBucketData(foo_bucket.ToBucketLocator(), {QuotaClientType::kFileSystem, QuotaClientType::kDatabase}); task_environment_.RunUntilIdle(); GetHostUsageWithBreakdown("foo.com", kTemp); EXPECT_EQ(predelete_foo_tmp - 4 - 1, usage()); - DeleteBucketData(foo_bucket, {QuotaClientType::kServiceWorkerCache, - QuotaClientType::kIndexedDatabase}); + DeleteBucketData(foo_bucket.ToBucketLocator(), + {QuotaClientType::kServiceWorkerCache, + QuotaClientType::kIndexedDatabase}); task_environment_.RunUntilIdle(); GetHostUsageWithBreakdown("foo.com", kTemp); EXPECT_EQ(predelete_foo_tmp - 8 - 4 - 2 - 1, usage()); diff --git a/chromium/storage/browser/quota/quota_override_handle.h b/chromium/storage/browser/quota/quota_override_handle.h index 065e8acf574..28907d870e6 100644 --- a/chromium/storage/browser/quota/quota_override_handle.h +++ b/chromium/storage/browser/quota/quota_override_handle.h @@ -9,7 +9,7 @@ #include "base/memory/scoped_refptr.h" #include "base/memory/weak_ptr.h" #include "base/sequence_checker.h" -#include "base/sequenced_task_runner.h" +#include "base/task/sequenced_task_runner.h" #include "base/thread_annotations.h" #include "third_party/blink/public/common/storage_key/storage_key.h" diff --git a/chromium/storage/browser/quota/quota_task.cc b/chromium/storage/browser/quota/quota_task.cc index 24674ca68e6..acbe14a848f 100644 --- a/chromium/storage/browser/quota/quota_task.cc +++ b/chromium/storage/browser/quota/quota_task.cc @@ -10,7 +10,7 @@ #include "base/bind.h" #include "base/containers/contains.h" #include "base/location.h" -#include "base/single_thread_task_runner.h" +#include "base/task/single_thread_task_runner.h" #include "base/threading/thread_task_runner_handle.h" using base::TaskRunner; diff --git a/chromium/storage/browser/quota/quota_task.h b/chromium/storage/browser/quota/quota_task.h index 49fe6cb75ed..86224e94bab 100644 --- a/chromium/storage/browser/quota/quota_task.h +++ b/chromium/storage/browser/quota/quota_task.h @@ -9,8 +9,9 @@ #include "base/compiler_specific.h" #include "base/component_export.h" +#include "base/memory/raw_ptr.h" #include "base/memory/ref_counted.h" -#include "base/sequenced_task_runner_helpers.h" +#include "base/task/sequenced_task_runner_helpers.h" namespace base { class SingleThreadTaskRunner; @@ -61,7 +62,7 @@ class QuotaTask { void Abort(); - QuotaTaskObserver* observer_; + raw_ptr<QuotaTaskObserver> observer_; const scoped_refptr<base::SingleThreadTaskRunner> original_task_runner_; bool delete_scheduled_; }; diff --git a/chromium/storage/browser/quota/quota_temporary_storage_evictor.cc b/chromium/storage/browser/quota/quota_temporary_storage_evictor.cc index d6e4b90f10a..38faa8a0da4 100644 --- a/chromium/storage/browser/quota/quota_temporary_storage_evictor.cc +++ b/chromium/storage/browser/quota/quota_temporary_storage_evictor.cc @@ -216,7 +216,7 @@ void QuotaTemporaryStorageEvictor::OnGotEvictionRoundInfo( } void QuotaTemporaryStorageEvictor::OnGotEvictionBucket( - const absl::optional<BucketInfo>& bucket) { + const absl::optional<BucketLocator>& bucket) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); if (!bucket.has_value()) { diff --git a/chromium/storage/browser/quota/quota_temporary_storage_evictor.h b/chromium/storage/browser/quota/quota_temporary_storage_evictor.h index fb536df79e3..b130c16a1cb 100644 --- a/chromium/storage/browser/quota/quota_temporary_storage_evictor.h +++ b/chromium/storage/browser/quota/quota_temporary_storage_evictor.h @@ -12,11 +12,11 @@ #include <string> #include "base/component_export.h" -#include "base/macros.h" +#include "base/memory/raw_ptr.h" #include "base/memory/weak_ptr.h" #include "base/sequence_checker.h" #include "base/timer/timer.h" -#include "components/services/storage/public/cpp/buckets/bucket_info.h" +#include "components/services/storage/public/cpp/buckets/bucket_locator.h" #include "third_party/abseil-cpp/absl/types/optional.h" #include "third_party/blink/public/mojom/quota/quota_types.mojom.h" @@ -79,14 +79,14 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaTemporaryStorageEvictor { int64_t total_space, int64_t current_usage, bool current_usage_is_complete); - void OnGotEvictionBucket(const absl::optional<BucketInfo>& bucket); + void OnGotEvictionBucket(const absl::optional<BucketLocator>& bucket); void OnEvictionComplete(blink::mojom::QuotaStatusCode status); void OnEvictionRoundStarted(); void OnEvictionRoundFinished(); // Not owned; quota_eviction_handler owns us. - QuotaEvictionHandler* quota_eviction_handler_; + raw_ptr<QuotaEvictionHandler> quota_eviction_handler_; Statistics statistics_; Statistics previous_statistics_; diff --git a/chromium/storage/browser/quota/quota_temporary_storage_evictor_unittest.cc b/chromium/storage/browser/quota/quota_temporary_storage_evictor_unittest.cc index 89ffbc6d1c7..ab8e9fc940f 100644 --- a/chromium/storage/browser/quota/quota_temporary_storage_evictor_unittest.cc +++ b/chromium/storage/browser/quota/quota_temporary_storage_evictor_unittest.cc @@ -12,12 +12,11 @@ #include "base/bind.h" #include "base/callback.h" #include "base/containers/contains.h" -#include "base/macros.h" #include "base/memory/weak_ptr.h" #include "base/run_loop.h" #include "base/test/task_environment.h" #include "components/services/storage/public/cpp/buckets/bucket_id.h" -#include "components/services/storage/public/cpp/buckets/bucket_info.h" +#include "components/services/storage/public/cpp/buckets/bucket_locator.h" #include "storage/browser/quota/quota_manager_impl.h" #include "storage/browser/quota/quota_temporary_storage_evictor.h" #include "testing/gtest/include/gtest/gtest.h" @@ -37,7 +36,7 @@ class MockQuotaEvictionHandler : public QuotaEvictionHandler { error_on_evict_buckets_data_(false), error_on_get_usage_and_quota_(false) {} - void EvictBucketData(const BucketInfo& bucket, + void EvictBucketData(const BucketLocator& bucket, StatusCallback callback) override { if (error_on_evict_buckets_data_) { std::move(callback).Run( @@ -103,7 +102,7 @@ class MockQuotaEvictionHandler : public QuotaEvictionHandler { // Simulates an access to `bucket`. It reorders the internal LRU list. // It internally uses AddBucket(). - void AccessBucket(const BucketInfo& bucket) { + void AccessBucket(const BucketLocator& bucket) { const auto& it = buckets_.find(bucket.id); EXPECT_TRUE(buckets_.end() != it); AddBucket(bucket, it->second); @@ -112,14 +111,14 @@ class MockQuotaEvictionHandler : public QuotaEvictionHandler { // Simulates adding or overwriting the `bucket` to the internal bucket set // with the `usage`. It also adds or moves the `bucket` to the // end of the LRU list. - void AddBucket(const BucketInfo& bucket, int64_t usage) { + void AddBucket(const BucketLocator& bucket, int64_t usage) { EnsureBucketRemoved(bucket); bucket_order_.push_back(bucket); buckets_[bucket.id] = usage; } private: - int64_t EnsureBucketRemoved(const BucketInfo& bucket) { + int64_t EnsureBucketRemoved(const BucketLocator& bucket) { int64_t bucket_usage; if (!base::Contains(buckets_, bucket.id)) return -1; @@ -133,7 +132,7 @@ class MockQuotaEvictionHandler : public QuotaEvictionHandler { QuotaSettings settings_; int64_t available_space_; - std::list<BucketInfo> bucket_order_; + std::list<BucketLocator> bucket_order_; std::map<BucketId, int64_t> buckets_; bool error_on_evict_buckets_data_; bool error_on_get_usage_and_quota_; @@ -148,6 +147,11 @@ class QuotaTemporaryStorageEvictorTest : public testing::Test { QuotaTemporaryStorageEvictorTest() : num_get_usage_and_quota_for_eviction_(0) {} + QuotaTemporaryStorageEvictorTest(const QuotaTemporaryStorageEvictorTest&) = + delete; + QuotaTemporaryStorageEvictorTest& operator=( + const QuotaTemporaryStorageEvictorTest&) = delete; + void SetUp() override { quota_eviction_handler_ = std::make_unique<MockQuotaEvictionHandler>(this); @@ -163,8 +167,9 @@ class QuotaTemporaryStorageEvictorTest : public testing::Test { } void TaskForRepeatedEvictionTest( - const std::pair<absl::optional<BucketInfo>, int64_t>& bucket_to_be_added, - const absl::optional<BucketInfo> bucket_to_be_accessed, + const std::pair<absl::optional<BucketLocator>, int64_t>& + bucket_to_be_added, + const absl::optional<BucketLocator> bucket_to_be_accessed, int expected_usage_after_first, int expected_usage_after_second) { EXPECT_GE(4, num_get_usage_and_quota_for_eviction_); @@ -187,11 +192,10 @@ class QuotaTemporaryStorageEvictorTest : public testing::Test { ++num_get_usage_and_quota_for_eviction_; } - BucketInfo CreateBucket(const std::string& url, const std::string& name) { - return BucketInfo(bucket_id_generator_.GenerateNextId(), - blink::StorageKey::CreateFromStringForTesting(url), - blink::mojom::StorageType::kTemporary, name, - /*expiration=*/base::Time::Max(), /*quota=*/0); + BucketLocator CreateBucket(const std::string& url, bool is_default) { + return BucketLocator(bucket_id_generator_.GenerateNextId(), + blink::StorageKey::CreateFromStringForTesting(url), + blink::mojom::StorageType::kTemporary, is_default); } protected: @@ -222,16 +226,15 @@ class QuotaTemporaryStorageEvictorTest : public testing::Test { std::unique_ptr<QuotaTemporaryStorageEvictor> temporary_storage_evictor_; int num_get_usage_and_quota_for_eviction_; base::WeakPtrFactory<QuotaTemporaryStorageEvictorTest> weak_factory_{this}; - DISALLOW_COPY_AND_ASSIGN(QuotaTemporaryStorageEvictorTest); }; TEST_F(QuotaTemporaryStorageEvictorTest, SimpleEvictionTest) { - quota_eviction_handler()->AddBucket(CreateBucket("http://www.z.com", "test"), - 3000); - quota_eviction_handler()->AddBucket(CreateBucket("http://www.y.com", "test"), - 200); - quota_eviction_handler()->AddBucket(CreateBucket("http://www.x.com", "test"), - 500); + quota_eviction_handler()->AddBucket( + CreateBucket("http://www.z.com", /*is_default=*/false), 3000); + quota_eviction_handler()->AddBucket( + CreateBucket("http://www.y.com", /*is_default=*/false), 200); + quota_eviction_handler()->AddBucket( + CreateBucket("http://www.x.com", /*is_default=*/false), 500); quota_eviction_handler()->SetPoolSize(4000); quota_eviction_handler()->set_available_space(1000000000); EXPECT_EQ(3000 + 200 + 500, quota_eviction_handler()->GetUsage()); @@ -248,13 +251,13 @@ TEST_F(QuotaTemporaryStorageEvictorTest, SimpleEvictionTest) { TEST_F(QuotaTemporaryStorageEvictorTest, MultipleEvictionTest) { quota_eviction_handler()->AddBucket( - CreateBucket("http://www.z.com", kDefaultBucketName), 20); + CreateBucket("http://www.z.com", /*is_default=*/true), 20); quota_eviction_handler()->AddBucket( - CreateBucket("http://www.y.com", kDefaultBucketName), 2900); + CreateBucket("http://www.y.com", /*is_default=*/true), 2900); quota_eviction_handler()->AddBucket( - CreateBucket("http://www.x.com", kDefaultBucketName), 450); + CreateBucket("http://www.x.com", /*is_default=*/true), 450); quota_eviction_handler()->AddBucket( - CreateBucket("http://www.w.com", kDefaultBucketName), 400); + CreateBucket("http://www.w.com", /*is_default=*/true), 400); quota_eviction_handler()->SetPoolSize(4000); quota_eviction_handler()->set_available_space(1000000000); EXPECT_EQ(20 + 2900 + 450 + 400, quota_eviction_handler()->GetUsage()); @@ -277,21 +280,22 @@ TEST_F(QuotaTemporaryStorageEvictorTest, RepeatedEvictionTest) { const int64_t initial_total_size = a_size + b_size + c_size + d_size; const int64_t e_size = 275; - quota_eviction_handler()->AddBucket(CreateBucket("http://www.d.com", "test"), - d_size); - quota_eviction_handler()->AddBucket(CreateBucket("http://www.c.com", "test"), - c_size); - quota_eviction_handler()->AddBucket(CreateBucket("http://www.b.com", "test"), - b_size); - quota_eviction_handler()->AddBucket(CreateBucket("http://www.a.com", "test"), - a_size); + quota_eviction_handler()->AddBucket( + CreateBucket("http://www.d.com", /*is_default=*/false), d_size); + quota_eviction_handler()->AddBucket( + CreateBucket("http://www.c.com", /*is_default=*/false), c_size); + quota_eviction_handler()->AddBucket( + CreateBucket("http://www.b.com", /*is_default=*/false), b_size); + quota_eviction_handler()->AddBucket( + CreateBucket("http://www.a.com", /*is_default=*/false), a_size); quota_eviction_handler()->SetPoolSize(1000); quota_eviction_handler()->set_available_space(1000000000); quota_eviction_handler()->set_task_for_get_usage_and_quota( base::BindRepeating( &QuotaTemporaryStorageEvictorTest::TaskForRepeatedEvictionTest, weak_factory_.GetWeakPtr(), - std::make_pair(CreateBucket("http://www.e.com", "test"), e_size), + std::make_pair(CreateBucket("http://www.e.com", /*is_default=*/false), + e_size), absl::nullopt, initial_total_size - d_size, initial_total_size - d_size + e_size - c_size)); EXPECT_EQ(initial_total_size, quota_eviction_handler()->GetUsage()); @@ -315,13 +319,13 @@ TEST_F(QuotaTemporaryStorageEvictorTest, RepeatedEvictionSkippedTest) { const int64_t initial_total_size = a_size + b_size + c_size + d_size; quota_eviction_handler()->AddBucket( - CreateBucket("http://www.d.com", kDefaultBucketName), d_size); + CreateBucket("http://www.d.com", /*is_default=*/true), d_size); quota_eviction_handler()->AddBucket( - CreateBucket("http://www.c.com", kDefaultBucketName), c_size); + CreateBucket("http://www.c.com", /*is_default=*/true), c_size); quota_eviction_handler()->AddBucket( - CreateBucket("http://www.b.com", kDefaultBucketName), b_size); + CreateBucket("http://www.b.com", /*is_default=*/true), b_size); quota_eviction_handler()->AddBucket( - CreateBucket("http://www.a.com", kDefaultBucketName), a_size); + CreateBucket("http://www.a.com", /*is_default=*/true), a_size); quota_eviction_handler()->SetPoolSize(1000); quota_eviction_handler()->set_available_space(1000000000); quota_eviction_handler()->set_task_for_get_usage_and_quota( @@ -351,11 +355,16 @@ TEST_F(QuotaTemporaryStorageEvictorTest, RepeatedEvictionWithAccessBucketTest) { const int64_t initial_total_size = a_size + b_size + c_size + d_size; const int64_t e_size = 275; - BucketInfo a_bucket = CreateBucket("http://www.a.com", kDefaultBucketName); - BucketInfo b_bucket = CreateBucket("http://www.b.com", kDefaultBucketName); - BucketInfo c_bucket = CreateBucket("http://www.c.com", kDefaultBucketName); - BucketInfo d_bucket = CreateBucket("http://www.d.com", kDefaultBucketName); - BucketInfo e_bucket = CreateBucket("http://www.e.com", kDefaultBucketName); + BucketLocator a_bucket = + CreateBucket("http://www.a.com", /*is_default=*/true); + BucketLocator b_bucket = + CreateBucket("http://www.b.com", /*is_default=*/true); + BucketLocator c_bucket = + CreateBucket("http://www.c.com", /*is_default=*/true); + BucketLocator d_bucket = + CreateBucket("http://www.d.com", /*is_default=*/true); + BucketLocator e_bucket = + CreateBucket("http://www.e.com", /*is_default=*/true); quota_eviction_handler()->AddBucket(d_bucket, d_size); quota_eviction_handler()->AddBucket(c_bucket, c_size); @@ -386,9 +395,9 @@ TEST_F(QuotaTemporaryStorageEvictorTest, DiskSpaceNonEvictionTest) { // If we're using so little that evicting all of it wouldn't // do enough to alleviate a diskspace shortage, we don't evict. quota_eviction_handler()->AddBucket( - CreateBucket("http://www.z.com", kDefaultBucketName), 10); + CreateBucket("http://www.z.com", /*is_default=*/true), 10); quota_eviction_handler()->AddBucket( - CreateBucket("http://www.x.com", kDefaultBucketName), 20); + CreateBucket("http://www.x.com", /*is_default=*/true), 20); quota_eviction_handler()->SetPoolSize(10000); quota_eviction_handler()->set_available_space( quota_eviction_handler()->settings().should_remain_available - 350); @@ -406,13 +415,13 @@ TEST_F(QuotaTemporaryStorageEvictorTest, DiskSpaceNonEvictionTest) { TEST_F(QuotaTemporaryStorageEvictorTest, DiskSpaceEvictionTest) { quota_eviction_handler()->AddBucket( - CreateBucket("http://www.z.com", kDefaultBucketName), 294); + CreateBucket("http://www.z.com", /*is_default=*/true), 294); quota_eviction_handler()->AddBucket( - CreateBucket("http://www.y.com", kDefaultBucketName), 120); + CreateBucket("http://www.y.com", /*is_default=*/true), 120); quota_eviction_handler()->AddBucket( - CreateBucket("http://www.x.com", kDefaultBucketName), 150); + CreateBucket("http://www.x.com", /*is_default=*/true), 150); quota_eviction_handler()->AddBucket( - CreateBucket("http://www.w.com", kDefaultBucketName), 300); + CreateBucket("http://www.w.com", /*is_default=*/true), 300); quota_eviction_handler()->SetPoolSize(10000); quota_eviction_handler()->set_available_space( quota_eviction_handler()->settings().should_remain_available - 350); diff --git a/chromium/storage/browser/quota/usage_tracker.cc b/chromium/storage/browser/quota/usage_tracker.cc index 8d702005fd3..87624191bd2 100644 --- a/chromium/storage/browser/quota/usage_tracker.cc +++ b/chromium/storage/browser/quota/usage_tracker.cc @@ -224,9 +224,6 @@ void UsageTracker::AccumulateClientHostUsage(base::OnceClosure callback, case QuotaClientType::kDatabase: info->usage_breakdown->webSql += usage; break; - case QuotaClientType::kAppcache: - info->usage_breakdown->appcache += usage; - break; case QuotaClientType::kIndexedDatabase: info->usage_breakdown->indexedDatabase += usage; break; diff --git a/chromium/storage/browser/quota/usage_tracker_unittest.cc b/chromium/storage/browser/quota/usage_tracker_unittest.cc index b71773be0e8..28e09638fe2 100644 --- a/chromium/storage/browser/quota/usage_tracker_unittest.cc +++ b/chromium/storage/browser/quota/usage_tracker_unittest.cc @@ -9,10 +9,9 @@ #include "base/bind.h" #include "base/location.h" -#include "base/macros.h" #include "base/memory/scoped_refptr.h" #include "base/run_loop.h" -#include "base/single_thread_task_runner.h" +#include "base/task/single_thread_task_runner.h" #include "base/test/task_environment.h" #include "base/threading/thread_task_runner_handle.h" #include "components/services/storage/public/mojom/quota_client.mojom.h" @@ -45,6 +44,10 @@ class UsageTrackerTestQuotaClient : public mojom::QuotaClient { public: UsageTrackerTestQuotaClient() = default; + UsageTrackerTestQuotaClient(const UsageTrackerTestQuotaClient&) = delete; + UsageTrackerTestQuotaClient& operator=(const UsageTrackerTestQuotaClient&) = + delete; + void GetStorageKeyUsage(const StorageKey& storage_key, StorageType type, GetStorageKeyUsageCallback callback) override { @@ -110,8 +113,6 @@ class UsageTrackerTestQuotaClient : public mojom::QuotaClient { private: std::map<StorageKey, int64_t> storage_key_usage_map_; - - DISALLOW_COPY_AND_ASSIGN(UsageTrackerTestQuotaClient); }; } // namespace diff --git a/chromium/storage/common/database/database_identifier.cc b/chromium/storage/common/database/database_identifier.cc index 29f58e75c8c..9e369f69521 100644 --- a/chromium/storage/common/database/database_identifier.cc +++ b/chromium/storage/common/database/database_identifier.cc @@ -7,7 +7,6 @@ #include <stddef.h> #include "base/cxx17_backports.h" -#include "base/macros.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_util.h" #include "url/url_canon.h" diff --git a/chromium/storage/common/database/database_identifier_unittest.cc b/chromium/storage/common/database/database_identifier_unittest.cc index e85cbc9e07e..01597087c04 100644 --- a/chromium/storage/common/database/database_identifier_unittest.cc +++ b/chromium/storage/common/database/database_identifier_unittest.cc @@ -7,7 +7,6 @@ #include <stddef.h> #include "base/cxx17_backports.h" -#include "base/macros.h" #include "testing/gtest/include/gtest/gtest.h" #include "url/gurl.h" #include "url/origin.h" @@ -291,8 +290,8 @@ static void TestValidOriginIdentifier(bool expected_result, } TEST(DatabaseIdentifierTest, OriginIdentifiers) { - const GURL kFileOriginURL(GURL("file:///").GetOrigin()); - const GURL kHttpOriginURL(GURL("http://bar/").GetOrigin()); + const GURL kFileOriginURL(GURL("file:///").DeprecatedGetOriginAsURL()); + const GURL kHttpOriginURL(GURL("http://bar/").DeprecatedGetOriginAsURL()); const url::Origin kFileOrigin = url::Origin::Create(kFileOriginURL); const url::Origin kHttpOrigin = url::Origin::Create(kHttpOriginURL); diff --git a/chromium/storage/common/file_system/file_system_util.cc b/chromium/storage/common/file_system/file_system_util.cc index e9402ff65aa..34aa58cfd30 100644 --- a/chromium/storage/common/file_system/file_system_util.cc +++ b/chromium/storage/common/file_system/file_system_util.cc @@ -9,8 +9,6 @@ #include <algorithm> #include "base/check.h" -#include "base/containers/contains.h" -#include "base/macros.h" #include "base/notreached.h" #include "base/strings/string_util.h" #include "base/strings/sys_string_conversions.h" @@ -189,7 +187,7 @@ bool ParseFileSystemSchemeURL(const GURL& url, return false; if (origin_url) - *origin_url = url.GetOrigin(); + *origin_url = url.DeprecatedGetOriginAsURL(); if (type) *type = file_system_type; if (virtual_path) diff --git a/chromium/storage/common/file_system/file_system_util_unittest.cc b/chromium/storage/common/file_system/file_system_util_unittest.cc index e146f09600f..67dba4267a6 100644 --- a/chromium/storage/common/file_system/file_system_util_unittest.cc +++ b/chromium/storage/common/file_system/file_system_util_unittest.cc @@ -7,7 +7,6 @@ #include <stddef.h> #include "base/files/file_path.h" -#include "base/macros.h" #include "testing/gtest/include/gtest/gtest.h" #include "url/gurl.h" |