summaryrefslogtreecommitdiff
path: root/chromium/storage
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2021-03-12 09:13:00 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2021-03-16 09:58:26 +0000
commit03561cae90f1d99b5c54b1ef3be69f10e882b25e (patch)
treecc5f0958e823c044e7ae51cc0117fe51432abe5e /chromium/storage
parentfa98118a45f7e169f8846086dc2c22c49a8ba310 (diff)
downloadqtwebengine-chromium-03561cae90f1d99b5c54b1ef3be69f10e882b25e.tar.gz
BASELINE: Update Chromium to 88.0.4324.208
Change-Id: I3ae87d23e4eff4b4a469685658740a213600c667 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/storage')
-rw-r--r--chromium/storage/DIR_METADATA12
-rw-r--r--chromium/storage/OWNERS3
-rw-r--r--chromium/storage/browser/BUILD.gn8
-rw-r--r--chromium/storage/browser/blob/DIR_METADATA12
-rw-r--r--chromium/storage/browser/blob/OWNERS3
-rw-r--r--chromium/storage/browser/blob/blob_builder_from_stream_unittest.cc4
-rw-r--r--chromium/storage/browser/blob/blob_memory_controller.cc7
-rw-r--r--chromium/storage/browser/blob/blob_memory_controller_unittest.cc2
-rw-r--r--chromium/storage/browser/blob/blob_reader.cc4
-rw-r--r--chromium/storage/browser/blob/blob_reader_unittest.cc4
-rw-r--r--chromium/storage/browser/blob/blob_registry_impl_unittest.cc4
-rw-r--r--chromium/storage/browser/blob/blob_storage_context_mojo_unittest.cc2
-rw-r--r--chromium/storage/browser/blob/blob_transport_strategy_unittest.cc2
-rw-r--r--chromium/storage/browser/blob/blob_url_store_impl_unittest.cc4
-rw-r--r--chromium/storage/browser/database/DIR_METADATA12
-rw-r--r--chromium/storage/browser/database/OWNERS3
-rw-r--r--chromium/storage/browser/database/database_quota_client.cc1
-rw-r--r--chromium/storage/browser/database/database_quota_client_unittest.cc108
-rw-r--r--chromium/storage/browser/database/database_tracker_unittest.cc2
-rw-r--r--chromium/storage/browser/file_system/DIR_METADATA12
-rw-r--r--chromium/storage/browser/file_system/OWNERS3
-rw-r--r--chromium/storage/browser/file_system/copy_or_move_operation_delegate_unittest.cc8
-rw-r--r--chromium/storage/browser/file_system/external_mount_points.cc7
-rw-r--r--chromium/storage/browser/file_system/external_mount_points.h2
-rw-r--r--chromium/storage/browser/file_system/file_stream_reader_test.h2
-rw-r--r--chromium/storage/browser/file_system/file_stream_writer_test.cc11
-rw-r--r--chromium/storage/browser/file_system/file_stream_writer_test.h237
-rw-r--r--chromium/storage/browser/file_system/file_system_context_unittest.cc3
-rw-r--r--chromium/storage/browser/file_system/file_system_operation_impl_unittest.cc11
-rw-r--r--chromium/storage/browser/file_system/file_writer_delegate_unittest.cc2
-rw-r--r--chromium/storage/browser/file_system/filesystem_proxy_file_stream_reader_unittest.cc2
-rw-r--r--chromium/storage/browser/file_system/isolated_context.cc4
-rw-r--r--chromium/storage/browser/file_system/isolated_context.h2
-rw-r--r--chromium/storage/browser/file_system/local_file_stream_reader_unittest.cc2
-rw-r--r--chromium/storage/browser/file_system/local_file_stream_writer_unittest.cc165
-rw-r--r--chromium/storage/browser/file_system/memory_file_stream_reader_unittest.cc2
-rw-r--r--chromium/storage/browser/file_system/memory_file_stream_writer_unittest.cc179
-rw-r--r--chromium/storage/browser/file_system/mount_points.h8
-rw-r--r--chromium/storage/browser/file_system/native_file_util.cc3
-rw-r--r--chromium/storage/browser/file_system/quota/quota_reservation_manager_unittest.cc2
-rw-r--r--chromium/storage/browser/file_system/sandbox_file_stream_writer.cc18
-rw-r--r--chromium/storage/browser/file_system/sandbox_file_stream_writer.h2
-rw-r--r--chromium/storage/browser/file_system/sandbox_file_stream_writer_unittest.cc134
-rw-r--r--chromium/storage/browser/file_system/sandbox_file_system_backend_delegate.cc2
-rw-r--r--chromium/storage/browser/quota/DIR_METADATA12
-rw-r--r--chromium/storage/browser/quota/OWNERS3
-rw-r--r--chromium/storage/browser/quota/client_usage_tracker.cc1
-rw-r--r--chromium/storage/browser/quota/quota_features.cc13
-rw-r--r--chromium/storage/browser/quota/quota_features.h5
-rw-r--r--chromium/storage/browser/quota/quota_manager.cc126
-rw-r--r--chromium/storage/browser/quota/quota_manager.h48
-rw-r--r--chromium/storage/browser/quota/quota_manager_proxy.cc38
-rw-r--r--chromium/storage/browser/quota/quota_manager_proxy.h13
-rw-r--r--chromium/storage/browser/quota/quota_manager_unittest.cc99
-rw-r--r--chromium/storage/browser/quota/quota_override_handle.cc57
-rw-r--r--chromium/storage/browser/quota/quota_override_handle.h51
-rw-r--r--chromium/storage/browser/quota/quota_settings.cc33
-rw-r--r--chromium/storage/browser/quota/quota_settings.h5
-rw-r--r--chromium/storage/browser/quota/quota_settings_unittest.cc114
-rw-r--r--chromium/storage/browser/quota/usage_tracker_unittest.cc3
-rw-r--r--chromium/storage/common/database/DIR_METADATA12
-rw-r--r--chromium/storage/common/database/OWNERS2
-rw-r--r--chromium/storage/common/file_system/DIR_METADATA12
-rw-r--r--chromium/storage/common/file_system/OWNERS3
64 files changed, 1107 insertions, 563 deletions
diff --git a/chromium/storage/DIR_METADATA b/chromium/storage/DIR_METADATA
new file mode 100644
index 00000000000..f9e9509fabc
--- /dev/null
+++ b/chromium/storage/DIR_METADATA
@@ -0,0 +1,12 @@
+# Metadata information for this directory.
+#
+# For more information on DIR_METADATA files, see:
+# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/README.md
+#
+# For the schema of this file, see Metadata message:
+# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/proto/dir_metadata.proto
+
+monorail {
+ component: "Blink>Storage"
+}
+team_email: "storage-dev@chromium.org" \ No newline at end of file
diff --git a/chromium/storage/OWNERS b/chromium/storage/OWNERS
index 499dd913f4d..919ed9bbf50 100644
--- a/chromium/storage/OWNERS
+++ b/chromium/storage/OWNERS
@@ -3,6 +3,3 @@ jsbell@chromium.org
pwnall@chromium.org
mek@chromium.org
kinuko@chromium.org
-
-# TEAM: storage-dev@chromium.org
-# COMPONENT: Blink>Storage
diff --git a/chromium/storage/browser/BUILD.gn b/chromium/storage/browser/BUILD.gn
index 3ac459e3459..92d357a9636 100644
--- a/chromium/storage/browser/BUILD.gn
+++ b/chromium/storage/browser/BUILD.gn
@@ -199,6 +199,8 @@ component("browser") {
"quota/quota_manager.h",
"quota/quota_manager_proxy.cc",
"quota/quota_manager_proxy.h",
+ "quota/quota_override_handle.cc",
+ "quota/quota_override_handle.h",
"quota/quota_settings.cc",
"quota/quota_settings.h",
"quota/quota_task.cc",
@@ -226,6 +228,7 @@ component("browser") {
"//base",
"//base:i18n",
"//base/third_party/dynamic_annotations",
+ "//build:chromeos_buildflags",
"//components/services/storage/public/cpp/filesystem",
"//mojo/public/cpp/bindings",
"//net",
@@ -282,6 +285,8 @@ source_set("unittests") {
"file_system/file_stream_reader_test.h",
"file_system/file_stream_test_utils.cc",
"file_system/file_stream_test_utils.h",
+ "file_system/file_stream_writer_test.cc",
+ "file_system/file_stream_writer_test.h",
"file_system/file_system_context_unittest.cc",
"file_system/file_system_file_stream_reader_unittest.cc",
"file_system/file_system_operation_impl_unittest.cc",
@@ -305,6 +310,7 @@ source_set("unittests") {
"file_system/quota/quota_reservation_manager_unittest.cc",
"file_system/recursive_operation_delegate_unittest.cc",
"file_system/sandbox_directory_database_unittest.cc",
+ "file_system/sandbox_file_stream_writer_unittest.cc",
"file_system/sandbox_file_system_backend_delegate_unittest.cc",
"file_system/sandbox_file_system_backend_unittest.cc",
"file_system/sandbox_isolated_origin_database_unittest.cc",
@@ -323,6 +329,7 @@ source_set("unittests") {
":browser",
":test_support",
"//base/test:test_support",
+ "//build:chromeos_buildflags",
"//components/services/filesystem/public/mojom",
"//components/services/storage/public/cpp/filesystem",
"//mojo/public/cpp/system",
@@ -385,6 +392,7 @@ static_library("test_support") {
deps = [
":browser",
"//base/test:test_support",
+ "//build:chromeos_buildflags",
"//components/services/storage/public/mojom",
"//net:test_support",
"//services/network:network_service",
diff --git a/chromium/storage/browser/blob/DIR_METADATA b/chromium/storage/browser/blob/DIR_METADATA
new file mode 100644
index 00000000000..433b3a9e88c
--- /dev/null
+++ b/chromium/storage/browser/blob/DIR_METADATA
@@ -0,0 +1,12 @@
+# Metadata information for this directory.
+#
+# For more information on DIR_METADATA files, see:
+# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/README.md
+#
+# For the schema of this file, see Metadata message:
+# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/proto/dir_metadata.proto
+
+monorail {
+ component: "Blink>Storage>FileAPI"
+}
+team_email: "storage-dev@chromium.org" \ No newline at end of file
diff --git a/chromium/storage/browser/blob/OWNERS b/chromium/storage/browser/blob/OWNERS
index 3568456627a..85cf2580291 100644
--- a/chromium/storage/browser/blob/OWNERS
+++ b/chromium/storage/browser/blob/OWNERS
@@ -1,6 +1,3 @@
dmurph@chromium.org
mek@chromium.org
jianli@chromium.org
-
-# TEAM: storage-dev@chromium.org
-# COMPONENT: Blink>Storage>FileAPI
diff --git a/chromium/storage/browser/blob/blob_builder_from_stream_unittest.cc b/chromium/storage/browser/blob/blob_builder_from_stream_unittest.cc
index 3c27c863187..89df0f70f96 100644
--- a/chromium/storage/browser/blob/blob_builder_from_stream_unittest.cc
+++ b/chromium/storage/browser/blob/blob_builder_from_stream_unittest.cc
@@ -7,7 +7,7 @@
#include <algorithm>
#include "base/bind.h"
-#include "base/bind_helpers.h"
+#include "base/callback_helpers.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/rand_util.h"
@@ -15,7 +15,7 @@
#include "base/task/post_task.h"
#include "base/task/thread_pool.h"
#include "base/task/thread_pool/thread_pool_instance.h"
-#include "base/test/bind_test_util.h"
+#include "base/test/bind.h"
#include "base/test/task_environment.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
diff --git a/chromium/storage/browser/blob/blob_memory_controller.cc b/chromium/storage/browser/blob/blob_memory_controller.cc
index 6c23efafc0c..1c8cbfe80ae 100644
--- a/chromium/storage/browser/blob/blob_memory_controller.cc
+++ b/chromium/storage/browser/blob/blob_memory_controller.cc
@@ -9,7 +9,6 @@
#include <numeric>
#include "base/bind.h"
-#include "base/bind_helpers.h"
#include "base/callback.h"
#include "base/callback_helpers.h"
#include "base/command_line.h"
@@ -32,6 +31,7 @@
#include "base/threading/scoped_blocking_call.h"
#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
+#include "build/chromeos_buildflags.h"
#include "storage/browser/blob/blob_data_builder.h"
#include "storage/browser/blob/blob_data_item.h"
#include "storage/browser/blob/shareable_blob_data_item.h"
@@ -94,7 +94,8 @@ BlobStorageLimits CalculateBlobStorageLimitsImpl(
// Don't do specialty configuration for error size (-1).
if (memory_size > 0) {
-#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) && defined(ARCH_CPU_64_BITS)
+#if !BUILDFLAG(IS_CHROMEOS_ASH) && !defined(OS_ANDROID) && \
+ defined(ARCH_CPU_64_BITS)
constexpr size_t kTwoGigabytes = 2ull * 1024 * 1024 * 1024;
limits.max_blob_in_memory_space = kTwoGigabytes;
#elif defined(OS_ANDROID)
@@ -111,7 +112,7 @@ BlobStorageLimits CalculateBlobStorageLimitsImpl(
// Don't do specialty configuration for error size (-1). Allow no disk.
if (disk_size >= 0) {
-#if defined(OS_CHROMEOS)
+#if BUILDFLAG(IS_CHROMEOS_ASH)
limits.desired_max_disk_space = static_cast<uint64_t>(disk_size / 2ll);
#elif defined(OS_ANDROID)
limits.desired_max_disk_space = static_cast<uint64_t>(3ll * disk_size / 50);
diff --git a/chromium/storage/browser/blob/blob_memory_controller_unittest.cc b/chromium/storage/browser/blob/blob_memory_controller_unittest.cc
index 89b811e7740..320d505e7cb 100644
--- a/chromium/storage/browser/blob/blob_memory_controller_unittest.cc
+++ b/chromium/storage/browser/blob/blob_memory_controller_unittest.cc
@@ -5,7 +5,7 @@
#include "storage/browser/blob/blob_memory_controller.h"
#include "base/bind.h"
-#include "base/bind_helpers.h"
+#include "base/callback_helpers.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/run_loop.h"
diff --git a/chromium/storage/browser/blob/blob_reader.cc b/chromium/storage/browser/blob/blob_reader.cc
index 40e5c49b919..9be28796b69 100644
--- a/chromium/storage/browser/blob/blob_reader.cc
+++ b/chromium/storage/browser/blob/blob_reader.cc
@@ -338,6 +338,10 @@ BlobReader::Status BlobReader::CalculateSizeImpl(
DCHECK(!total_size_calculated_);
DCHECK(size_callback_.is_null());
+ if (!blob_data_) {
+ return ReportError(net::ERR_UNEXPECTED);
+ }
+
net_error_ = net::OK;
total_size_ = 0;
const auto& items = blob_data_->items();
diff --git a/chromium/storage/browser/blob/blob_reader_unittest.cc b/chromium/storage/browser/blob/blob_reader_unittest.cc
index bdba18feb7e..1d56b6c7ac9 100644
--- a/chromium/storage/browser/blob/blob_reader_unittest.cc
+++ b/chromium/storage/browser/blob/blob_reader_unittest.cc
@@ -13,8 +13,8 @@
#include <vector>
#include "base/bind.h"
-#include "base/bind_helpers.h"
#include "base/callback.h"
+#include "base/callback_helpers.h"
#include "base/files/file_path.h"
#include "base/location.h"
#include "base/macros.h"
@@ -22,7 +22,7 @@
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/task_runner.h"
-#include "base/test/bind_test_util.h"
+#include "base/test/bind.h"
#include "base/test/task_environment.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
diff --git a/chromium/storage/browser/blob/blob_registry_impl_unittest.cc b/chromium/storage/browser/blob/blob_registry_impl_unittest.cc
index 8f076e17c24..69039f08d5a 100644
--- a/chromium/storage/browser/blob/blob_registry_impl_unittest.cc
+++ b/chromium/storage/browser/blob/blob_registry_impl_unittest.cc
@@ -11,14 +11,14 @@
#include <vector>
#include "base/bind.h"
-#include "base/bind_helpers.h"
+#include "base/callback_helpers.h"
#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/thread_pool.h"
-#include "base/test/bind_test_util.h"
+#include "base/test/bind.h"
#include "base/test/task_environment.h"
#include "base/threading/thread_restrictions.h"
#include "mojo/public/cpp/bindings/associated_receiver.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 9a6d716e1e4..ea95526e8bd 100644
--- a/chromium/storage/browser/blob/blob_storage_context_mojo_unittest.cc
+++ b/chromium/storage/browser/blob/blob_storage_context_mojo_unittest.cc
@@ -14,7 +14,7 @@
#include "base/task/post_task.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
-#include "base/test/bind_test_util.h"
+#include "base/test/bind.h"
#include "base/test/task_environment.h"
#include "base/test/test_simple_task_runner.h"
#include "base/threading/thread_restrictions.h"
diff --git a/chromium/storage/browser/blob/blob_transport_strategy_unittest.cc b/chromium/storage/browser/blob/blob_transport_strategy_unittest.cc
index b092056823f..409042178da 100644
--- a/chromium/storage/browser/blob/blob_transport_strategy_unittest.cc
+++ b/chromium/storage/browser/blob/blob_transport_strategy_unittest.cc
@@ -11,7 +11,7 @@
#include <vector>
#include "base/bind.h"
-#include "base/bind_helpers.h"
+#include "base/callback_helpers.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/rand_util.h"
diff --git a/chromium/storage/browser/blob/blob_url_store_impl_unittest.cc b/chromium/storage/browser/blob/blob_url_store_impl_unittest.cc
index 13de8d09ca4..69428d0adeb 100644
--- a/chromium/storage/browser/blob/blob_url_store_impl_unittest.cc
+++ b/chromium/storage/browser/blob/blob_url_store_impl_unittest.cc
@@ -5,8 +5,8 @@
#include "storage/browser/blob/blob_url_store_impl.h"
#include "base/bind.h"
-#include "base/bind_helpers.h"
-#include "base/test/bind_test_util.h"
+#include "base/callback_helpers.h"
+#include "base/test/bind.h"
#include "base/test/task_environment.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "mojo/public/cpp/system/functions.h"
diff --git a/chromium/storage/browser/database/DIR_METADATA b/chromium/storage/browser/database/DIR_METADATA
new file mode 100644
index 00000000000..f337a384213
--- /dev/null
+++ b/chromium/storage/browser/database/DIR_METADATA
@@ -0,0 +1,12 @@
+# Metadata information for this directory.
+#
+# For more information on DIR_METADATA files, see:
+# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/README.md
+#
+# For the schema of this file, see Metadata message:
+# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/proto/dir_metadata.proto
+
+monorail {
+ component: "Blink>Storage>WebSQL"
+}
+team_email: "storage-dev@chromium.org" \ No newline at end of file
diff --git a/chromium/storage/browser/database/OWNERS b/chromium/storage/browser/database/OWNERS
index 07618c5c7d3..5b2fdf3f2f4 100644
--- a/chromium/storage/browser/database/OWNERS
+++ b/chromium/storage/browser/database/OWNERS
@@ -1,4 +1 @@
pwnall@chromium.org
-
-# TEAM: storage-dev@chromium.org
-# COMPONENT: Blink>Storage>WebSQL
diff --git a/chromium/storage/browser/database/database_quota_client.cc b/chromium/storage/browser/database/database_quota_client.cc
index e2a6374fbf8..7f0c4424153 100644
--- a/chromium/storage/browser/database/database_quota_client.cc
+++ b/chromium/storage/browser/database/database_quota_client.cc
@@ -11,7 +11,6 @@
#include <vector>
#include "base/bind.h"
-#include "base/bind_helpers.h"
#include "base/callback_helpers.h"
#include "base/location.h"
#include "base/task_runner_util.h"
diff --git a/chromium/storage/browser/database/database_quota_client_unittest.cc b/chromium/storage/browser/database/database_quota_client_unittest.cc
index 46479548476..2b3c50443f6 100644
--- a/chromium/storage/browser/database/database_quota_client_unittest.cc
+++ b/chromium/storage/browser/database/database_quota_client_unittest.cc
@@ -13,10 +13,11 @@
#include "base/callback_helpers.h"
#include "base/files/file_path.h"
#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/test/bind_test_util.h"
+#include "base/test/bind.h"
#include "base/test/task_environment.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "net/base/completion_once_callback.h"
@@ -24,6 +25,7 @@
#include "storage/browser/database/database_quota_client.h"
#include "storage/browser/database/database_tracker.h"
#include "storage/browser/database/database_util.h"
+#include "storage/browser/quota/quota_client.h"
#include "storage/common/database/database_identifier.h"
#include "testing/gmock/include/gmock/gmock-matchers.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -42,10 +44,7 @@ static const blink::mojom::StorageType kTemp =
class MockDatabaseTracker : public DatabaseTracker {
public:
MockDatabaseTracker()
- : DatabaseTracker(base::FilePath(), false, nullptr, nullptr),
- delete_called_count_(0),
- async_delete_(false) {
- }
+ : DatabaseTracker(base::FilePath(), false, nullptr, nullptr) {}
bool GetOriginInfo(const std::string& origin_identifier,
OriginInfo* info) override {
@@ -114,8 +113,8 @@ class MockDatabaseTracker : public DatabaseTracker {
}
};
- int delete_called_count_;
- bool async_delete_;
+ int delete_called_count_ = 0;
+ bool async_delete_ = false;
std::map<url::Origin, MockOriginInfo> mock_origin_infos_;
};
@@ -130,62 +129,62 @@ class DatabaseQuotaClientTest : public testing::Test {
: kOriginA(url::Origin::Create(GURL("http://host"))),
kOriginB(url::Origin::Create(GURL("http://host:8000"))),
kOriginOther(url::Origin::Create(GURL("http://other"))),
- mock_tracker_(new MockDatabaseTracker) {}
+ mock_tracker_(base::MakeRefCounted<MockDatabaseTracker>()) {}
- static int64_t GetOriginUsage(scoped_refptr<QuotaClient> client,
+ static int64_t GetOriginUsage(QuotaClient& client,
const url::Origin& origin,
blink::mojom::StorageType type) {
int result = -1;
base::RunLoop loop;
- client->GetOriginUsage(origin, type,
- base::BindLambdaForTesting([&](int64_t usage) {
- result = usage;
- loop.Quit();
- }));
+ client.GetOriginUsage(origin, type,
+ base::BindLambdaForTesting([&](int64_t usage) {
+ result = usage;
+ loop.Quit();
+ }));
loop.Run();
EXPECT_GT(result, -1);
return result;
}
static std::vector<url::Origin> GetOriginsForType(
- scoped_refptr<QuotaClient> client,
+ QuotaClient& client,
blink::mojom::StorageType type) {
std::vector<url::Origin> result;
base::RunLoop loop;
- client->GetOriginsForType(type,
- base::BindLambdaForTesting(
- [&](const std::vector<url::Origin>& origins) {
- result = origins;
- loop.Quit();
- }));
+ client.GetOriginsForType(type,
+ base::BindLambdaForTesting(
+ [&](const std::vector<url::Origin>& origins) {
+ result = origins;
+ loop.Quit();
+ }));
loop.Run();
return result;
}
static std::vector<url::Origin> GetOriginsForHost(
- scoped_refptr<QuotaClient> client,
+ QuotaClient& client,
blink::mojom::StorageType type,
const std::string& host) {
std::vector<url::Origin> result;
base::RunLoop loop;
- client->GetOriginsForHost(type, host,
- base::BindLambdaForTesting(
- [&](const std::vector<url::Origin>& origins) {
- result = origins;
- loop.Quit();
- }));
+ client.GetOriginsForHost(type, host,
+ base::BindLambdaForTesting(
+ [&](const std::vector<url::Origin>& origins) {
+ result = origins;
+ loop.Quit();
+ }));
loop.Run();
return result;
}
static blink::mojom::QuotaStatusCode DeleteOriginData(
- scoped_refptr<QuotaClient> client,
+ QuotaClient& client,
blink::mojom::StorageType type,
const url::Origin& origin) {
blink::mojom::QuotaStatusCode result =
blink::mojom::QuotaStatusCode::kUnknown;
base::RunLoop loop;
- client->DeleteOriginData(
+ client.DeleteOriginData(
origin, type,
base::BindLambdaForTesting([&](blink::mojom::QuotaStatusCode code) {
result = code;
@@ -195,72 +194,69 @@ class DatabaseQuotaClientTest : public testing::Test {
return result;
}
- MockDatabaseTracker* mock_tracker() { return mock_tracker_.get(); }
-
- private:
base::test::TaskEnvironment task_environment_;
scoped_refptr<MockDatabaseTracker> mock_tracker_;
base::WeakPtrFactory<DatabaseQuotaClientTest> weak_factory_{this};
};
TEST_F(DatabaseQuotaClientTest, GetOriginUsage) {
- auto client = base::MakeRefCounted<DatabaseQuotaClient>(mock_tracker());
+ auto client = base::MakeRefCounted<DatabaseQuotaClient>(mock_tracker_);
- EXPECT_EQ(0, GetOriginUsage(client, kOriginA, kTemp));
+ EXPECT_EQ(0, GetOriginUsage(*client, kOriginA, kTemp));
- mock_tracker()->AddMockDatabase(kOriginA, "fooDB", 1000);
- EXPECT_EQ(1000, GetOriginUsage(client, kOriginA, kTemp));
+ mock_tracker_->AddMockDatabase(kOriginA, "fooDB", 1000);
+ EXPECT_EQ(1000, GetOriginUsage(*client, kOriginA, kTemp));
- EXPECT_EQ(0, GetOriginUsage(client, kOriginB, kTemp));
+ EXPECT_EQ(0, GetOriginUsage(*client, kOriginB, kTemp));
}
TEST_F(DatabaseQuotaClientTest, GetOriginsForHost) {
- auto client = base::MakeRefCounted<DatabaseQuotaClient>(mock_tracker());
+ auto client = base::MakeRefCounted<DatabaseQuotaClient>(mock_tracker_);
EXPECT_EQ(kOriginA.host(), kOriginB.host());
EXPECT_NE(kOriginA.host(), kOriginOther.host());
std::vector<url::Origin> origins =
- GetOriginsForHost(client, kTemp, kOriginA.host());
+ GetOriginsForHost(*client, kTemp, kOriginA.host());
EXPECT_TRUE(origins.empty());
- mock_tracker()->AddMockDatabase(kOriginA, "fooDB", 1000);
- origins = GetOriginsForHost(client, kTemp, kOriginA.host());
+ mock_tracker_->AddMockDatabase(kOriginA, "fooDB", 1000);
+ origins = GetOriginsForHost(*client, kTemp, kOriginA.host());
EXPECT_EQ(origins.size(), 1ul);
EXPECT_THAT(origins, testing::Contains(kOriginA));
- mock_tracker()->AddMockDatabase(kOriginB, "barDB", 1000);
- origins = GetOriginsForHost(client, kTemp, kOriginA.host());
+ mock_tracker_->AddMockDatabase(kOriginB, "barDB", 1000);
+ origins = GetOriginsForHost(*client, kTemp, kOriginA.host());
EXPECT_EQ(origins.size(), 2ul);
EXPECT_THAT(origins, testing::Contains(kOriginA));
EXPECT_THAT(origins, testing::Contains(kOriginB));
- EXPECT_TRUE(GetOriginsForHost(client, kTemp, kOriginOther.host()).empty());
+ EXPECT_TRUE(GetOriginsForHost(*client, kTemp, kOriginOther.host()).empty());
}
TEST_F(DatabaseQuotaClientTest, GetOriginsForType) {
- auto client = base::MakeRefCounted<DatabaseQuotaClient>(mock_tracker());
+ auto client = base::MakeRefCounted<DatabaseQuotaClient>(mock_tracker_);
- EXPECT_TRUE(GetOriginsForType(client, kTemp).empty());
+ EXPECT_TRUE(GetOriginsForType(*client, kTemp).empty());
- mock_tracker()->AddMockDatabase(kOriginA, "fooDB", 1000);
- std::vector<url::Origin> origins = GetOriginsForType(client, kTemp);
+ mock_tracker_->AddMockDatabase(kOriginA, "fooDB", 1000);
+ std::vector<url::Origin> origins = GetOriginsForType(*client, kTemp);
EXPECT_EQ(origins.size(), 1ul);
EXPECT_THAT(origins, testing::Contains(kOriginA));
}
TEST_F(DatabaseQuotaClientTest, DeleteOriginData) {
- auto client = base::MakeRefCounted<DatabaseQuotaClient>(mock_tracker());
+ auto client = base::MakeRefCounted<DatabaseQuotaClient>(mock_tracker_);
- mock_tracker()->set_async_delete(false);
+ mock_tracker_->set_async_delete(false);
EXPECT_EQ(blink::mojom::QuotaStatusCode::kOk,
- DeleteOriginData(client, kTemp, kOriginA));
- EXPECT_EQ(1, mock_tracker()->delete_called_count());
+ DeleteOriginData(*client, kTemp, kOriginA));
+ EXPECT_EQ(1, mock_tracker_->delete_called_count());
- mock_tracker()->set_async_delete(true);
+ mock_tracker_->set_async_delete(true);
EXPECT_EQ(blink::mojom::QuotaStatusCode::kOk,
- DeleteOriginData(client, kTemp, kOriginA));
- EXPECT_EQ(2, mock_tracker()->delete_called_count());
+ DeleteOriginData(*client, kTemp, kOriginA));
+ EXPECT_EQ(2, mock_tracker_->delete_called_count());
}
} // namespace storage
diff --git a/chromium/storage/browser/database/database_tracker_unittest.cc b/chromium/storage/browser/database/database_tracker_unittest.cc
index 4a4edf9174b..04c31e2b0d1 100644
--- a/chromium/storage/browser/database/database_tracker_unittest.cc
+++ b/chromium/storage/browser/database/database_tracker_unittest.cc
@@ -15,7 +15,7 @@
#include "base/memory/ptr_util.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
-#include "base/test/bind_test_util.h"
+#include "base/test/bind.h"
#include "base/test/task_environment.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "base/time/time.h"
diff --git a/chromium/storage/browser/file_system/DIR_METADATA b/chromium/storage/browser/file_system/DIR_METADATA
new file mode 100644
index 00000000000..e704db93ca3
--- /dev/null
+++ b/chromium/storage/browser/file_system/DIR_METADATA
@@ -0,0 +1,12 @@
+# Metadata information for this directory.
+#
+# For more information on DIR_METADATA files, see:
+# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/README.md
+#
+# For the schema of this file, see Metadata message:
+# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/proto/dir_metadata.proto
+
+monorail {
+ component: "Blink>Storage>FileSystem"
+}
+team_email: "storage-dev@chromium.org" \ No newline at end of file
diff --git a/chromium/storage/browser/file_system/OWNERS b/chromium/storage/browser/file_system/OWNERS
index 95336597f2f..3fbd89ad98c 100644
--- a/chromium/storage/browser/file_system/OWNERS
+++ b/chromium/storage/browser/file_system/OWNERS
@@ -1,5 +1,2 @@
mek@chromium.org
nhiroki@chromium.org
-
-# TEAM: storage-dev@chromium.org
-# COMPONENT: Blink>Storage>FileSystem
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 c965b63762b..7d8aa80bc98 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
@@ -11,7 +11,7 @@
#include <vector>
#include "base/bind.h"
-#include "base/bind_helpers.h"
+#include "base/callback_helpers.h"
#include "base/containers/queue.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
@@ -305,15 +305,15 @@ class CopyOrMoveOperationTestHelper {
FileSystemURL dir = directories.front();
directories.pop();
ASSERT_EQ(base::File::FILE_OK, ReadDirectory(dir, &entries));
- for (size_t i = 0; i < entries.size(); ++i) {
+ for (const filesystem::mojom::DirectoryEntry& entry : entries) {
FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL(
dir.origin(), dir.mount_type(),
- dir.virtual_path().Append(entries[i].name));
+ dir.virtual_path().Append(entry.name));
base::FilePath relative;
root.virtual_path().AppendRelativePath(url.virtual_path(), &relative);
relative = relative.NormalizePathSeparators();
ASSERT_TRUE(base::Contains(test_case_map, relative));
- if (entries[i].type == filesystem::mojom::FsFileType::DIRECTORY) {
+ if (entry.type == filesystem::mojom::FsFileType::DIRECTORY) {
EXPECT_TRUE(test_case_map[relative]->is_directory);
directories.push(url);
} else {
diff --git a/chromium/storage/browser/file_system/external_mount_points.cc b/chromium/storage/browser/file_system/external_mount_points.cc
index 22ed0f7769b..0c2e804bcce 100644
--- a/chromium/storage/browser/file_system/external_mount_points.cc
+++ b/chromium/storage/browser/file_system/external_mount_points.cc
@@ -10,6 +10,7 @@
#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"
namespace storage {
@@ -195,8 +196,8 @@ FileSystemURL ExternalMountPoints::CrackURL(const GURL& url) const {
FileSystemURL ExternalMountPoints::CreateCrackedFileSystemURL(
const url::Origin& origin,
FileSystemType type,
- const base::FilePath& path) const {
- return CrackFileSystemURL(FileSystemURL(origin, type, path));
+ const base::FilePath& virtual_path) const {
+ return CrackFileSystemURL(FileSystemURL(origin, type, virtual_path));
}
void ExternalMountPoints::AddMountPointInfosTo(
@@ -264,7 +265,7 @@ FileSystemURL ExternalMountPoints::CrackFileSystemURL(
base::FilePath virtual_path = url.path();
if (url.type() == kFileSystemTypeNativeForPlatformApp) {
-#if defined(OS_CHROMEOS)
+#if BUILDFLAG(IS_CHROMEOS_ASH)
// On Chrome OS, find a mount point and virtual path for the external fs.
if (!GetVirtualPath(url.path(), &virtual_path))
return FileSystemURL();
diff --git a/chromium/storage/browser/file_system/external_mount_points.h b/chromium/storage/browser/file_system/external_mount_points.h
index 6df0f41f8cf..381592d95bf 100644
--- a/chromium/storage/browser/file_system/external_mount_points.h
+++ b/chromium/storage/browser/file_system/external_mount_points.h
@@ -82,7 +82,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) ExternalMountPoints
FileSystemURL CreateCrackedFileSystemURL(
const url::Origin& origin,
FileSystemType type,
- const base::FilePath& path) const override;
+ const base::FilePath& virtual_path) const override;
// Returns a list of registered MountPointInfos (of <mount_name, path>).
void AddMountPointInfosTo(std::vector<MountPointInfo>* mount_points) const;
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 f82e7cb00dd..a0c77e5ec82 100644
--- a/chromium/storage/browser/file_system/file_stream_reader_test.h
+++ b/chromium/storage/browser/file_system/file_stream_reader_test.h
@@ -5,7 +5,7 @@
#ifndef STORAGE_BROWSER_FILE_SYSTEM_FILE_STREAM_READER_TEST_H_
#define STORAGE_BROWSER_FILE_SYSTEM_FILE_STREAM_READER_TEST_H_
-#include "base/bind_helpers.h"
+#include "base/callback_helpers.h"
#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "base/single_thread_task_runner.h"
diff --git a/chromium/storage/browser/file_system/file_stream_writer_test.cc b/chromium/storage/browser/file_system/file_stream_writer_test.cc
new file mode 100644
index 00000000000..62f15b89f0b
--- /dev/null
+++ b/chromium/storage/browser/file_system/file_stream_writer_test.cc
@@ -0,0 +1,11 @@
+// Copyright 2020 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_stream_writer_test.h"
+
+namespace storage {
+
+const base::StringPiece FileStreamWriterTest::kTestFileName;
+
+} // namespace storage \ No newline at end of file
diff --git a/chromium/storage/browser/file_system/file_stream_writer_test.h b/chromium/storage/browser/file_system/file_stream_writer_test.h
new file mode 100644
index 00000000000..e8cf2d74dc5
--- /dev/null
+++ b/chromium/storage/browser/file_system/file_stream_writer_test.h
@@ -0,0 +1,237 @@
+// Copyright 2020 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_STREAM_WRITER_TEST_H_
+#define STORAGE_BROWSER_FILE_SYSTEM_FILE_STREAM_WRITER_TEST_H_
+
+#include <cstdio>
+#include "base/callback_helpers.h"
+#include "base/files/file_path.h"
+#include "base/files/file_util.h"
+#include "base/files/scoped_temp_dir.h"
+#include "base/single_thread_task_runner.h"
+#include "base/test/task_environment.h"
+#include "base/threading/thread.h"
+#include "net/base/io_buffer.h"
+#include "net/base/net_errors.h"
+#include "net/base/test_completion_callback.h"
+#include "storage/browser/file_system/file_stream_test_utils.h"
+#include "storage/browser/file_system/file_stream_writer.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace storage {
+
+// An interface for derived FileStreamWriter to implement. This allows multiple
+// FileStreamWriter implementations can share the same test framework. Tests
+// should implement CreateFileWithContent, CreateWriter, FilePathExists, and
+// GetFileContent to manipulate files for their particular implementation.
+class FileStreamWriterTest : public testing::Test {
+ public:
+ static constexpr base::StringPiece kTestFileName = "file_a";
+
+ virtual bool CreateFileWithContent(const std::string& name,
+ const std::string& data) = 0;
+ virtual std::unique_ptr<FileStreamWriter> CreateWriter(
+ const std::string& name,
+ int64_t offset) = 0;
+ virtual bool FilePathExists(const std::string& name) = 0;
+ virtual std::string GetFileContent(const std::string& name) = 0;
+
+ static void NeverCalled(int unused) { ADD_FAILURE(); }
+
+ private:
+ base::test::SingleThreadTaskEnvironment task_environment_{
+ base::test::SingleThreadTaskEnvironment::MainThreadType::IO};
+};
+
+template <class SubClass>
+class FileStreamWriterTypedTest : public SubClass {
+ public:
+ void SetUp() override { SubClass::SetUp(); }
+};
+
+TYPED_TEST_SUITE_P(FileStreamWriterTypedTest);
+
+TYPED_TEST_P(FileStreamWriterTypedTest, Write) {
+ EXPECT_TRUE(
+ this->CreateFileWithContent(std::string(this->kTestFileName), "foobar"));
+
+ std::unique_ptr<FileStreamWriter> writer(
+ this->CreateWriter(std::string(this->kTestFileName), 0));
+ EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "foo"));
+ EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "bar"));
+
+ EXPECT_TRUE(this->FilePathExists(std::string(this->kTestFileName)));
+ EXPECT_EQ("foobar", this->GetFileContent(std::string(this->kTestFileName)));
+}
+
+TYPED_TEST_P(FileStreamWriterTypedTest, WriteMiddle) {
+ EXPECT_TRUE(
+ this->CreateFileWithContent(std::string(this->kTestFileName), "foobar"));
+
+ std::unique_ptr<FileStreamWriter> writer(
+ this->CreateWriter(std::string(this->kTestFileName), 2));
+ EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "xxx"));
+
+ EXPECT_TRUE(this->FilePathExists(std::string(this->kTestFileName)));
+ EXPECT_EQ("foxxxr", this->GetFileContent(std::string(this->kTestFileName)));
+}
+
+TYPED_TEST_P(FileStreamWriterTypedTest, WriteNearEnd) {
+ EXPECT_TRUE(
+ this->CreateFileWithContent(std::string(this->kTestFileName), "foobar"));
+
+ std::unique_ptr<FileStreamWriter> writer(
+ this->CreateWriter(std::string(this->kTestFileName), 5));
+ EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "xxx"));
+
+ EXPECT_TRUE(this->FilePathExists(std::string(this->kTestFileName)));
+ EXPECT_EQ("foobaxxx", this->GetFileContent(std::string(this->kTestFileName)));
+}
+
+TYPED_TEST_P(FileStreamWriterTypedTest, WriteEnd) {
+ EXPECT_TRUE(
+ this->CreateFileWithContent(std::string(this->kTestFileName), "foobar"));
+
+ std::unique_ptr<FileStreamWriter> writer(
+ this->CreateWriter(std::string(this->kTestFileName), 6));
+ EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "xxx"));
+
+ EXPECT_TRUE(this->FilePathExists(std::string(this->kTestFileName)));
+ EXPECT_EQ("foobarxxx",
+ this->GetFileContent(std::string(this->kTestFileName)));
+}
+
+TYPED_TEST_P(FileStreamWriterTypedTest, WriteAfterEnd) {
+ EXPECT_TRUE(
+ this->CreateFileWithContent(std::string(this->kTestFileName), "foobar"));
+
+ std::unique_ptr<FileStreamWriter> writer(
+ this->CreateWriter(std::string(this->kTestFileName), 7));
+ EXPECT_EQ(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE,
+ WriteStringToWriter(writer.get(), "xxx"));
+
+ EXPECT_TRUE(this->FilePathExists(std::string(this->kTestFileName)));
+ EXPECT_EQ("foobar", this->GetFileContent(std::string(this->kTestFileName)));
+}
+
+TYPED_TEST_P(FileStreamWriterTypedTest, WriteFailForNonexistingFile) {
+ ASSERT_FALSE(this->FilePathExists(std::string(this->kTestFileName)));
+
+ std::unique_ptr<FileStreamWriter> writer(
+ this->CreateWriter(std::string(this->kTestFileName), 0));
+ EXPECT_EQ(net::ERR_FILE_NOT_FOUND, WriteStringToWriter(writer.get(), "foo"));
+
+ EXPECT_FALSE(this->FilePathExists(std::string(this->kTestFileName)));
+}
+
+TYPED_TEST_P(FileStreamWriterTypedTest, CancelBeforeOperation) {
+ std::unique_ptr<FileStreamWriter> writer(
+ this->CreateWriter(std::string(this->kTestFileName), 0));
+ // Cancel immediately fails when there's no in-flight operation.
+ EXPECT_EQ(net::ERR_UNEXPECTED, writer->Cancel(base::DoNothing()));
+}
+
+TYPED_TEST_P(FileStreamWriterTypedTest, CancelAfterFinishedOperation) {
+ EXPECT_TRUE(
+ this->CreateFileWithContent(std::string(this->kTestFileName), "foobar"));
+ std::unique_ptr<FileStreamWriter> writer(
+ this->CreateWriter(std::string(this->kTestFileName), 0));
+ EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "foo"));
+
+ // Cancel immediately fails when there's no in-flight operation.
+ EXPECT_EQ(net::ERR_UNEXPECTED, writer->Cancel(base::DoNothing()));
+
+ // Write operation is already completed.
+ EXPECT_TRUE(this->FilePathExists(std::string(this->kTestFileName)));
+ EXPECT_EQ("foobar", this->GetFileContent(std::string(this->kTestFileName)));
+}
+
+TYPED_TEST_P(FileStreamWriterTypedTest, CancelWrite) {
+ EXPECT_TRUE(
+ this->CreateFileWithContent(std::string(this->kTestFileName), "foobar"));
+ std::unique_ptr<FileStreamWriter> writer(
+ this->CreateWriter(std::string(this->kTestFileName), 0));
+
+ scoped_refptr<net::StringIOBuffer> buffer(
+ base::MakeRefCounted<net::StringIOBuffer>("xxx"));
+ int result =
+ writer->Write(buffer.get(), buffer->size(),
+ base::BindOnce(&FileStreamWriterTest::NeverCalled));
+ ASSERT_EQ(net::ERR_IO_PENDING, result);
+
+ net::TestCompletionCallback callback;
+ writer->Cancel(callback.callback());
+ int cancel_result = writer->Cancel(callback.callback());
+ EXPECT_EQ(net::OK, callback.GetResult(cancel_result));
+}
+
+TYPED_TEST_P(FileStreamWriterTypedTest, CancelFlush) {
+ EXPECT_TRUE(
+ this->CreateFileWithContent(std::string(this->kTestFileName), ""));
+ std::unique_ptr<FileStreamWriter> writer(
+ this->CreateWriter(std::string(this->kTestFileName), 0));
+
+ EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "foo"));
+
+ int cancel_expectation = net::OK;
+ int result = writer->Flush(base::DoNothing());
+ // Flush can run synchronously or asynchronously.
+ if (result == net::OK) {
+ // Cancel() should error if called when there is no in-flight operation.
+ cancel_expectation = net::ERR_UNEXPECTED;
+ } else {
+ EXPECT_EQ(net::ERR_IO_PENDING, result);
+ }
+ net::TestCompletionCallback callback;
+ int cancel_result = writer->Cancel(callback.callback());
+ EXPECT_EQ(cancel_expectation, callback.GetResult(cancel_result));
+
+ EXPECT_EQ("foo", this->GetFileContent(std::string(this->kTestFileName)));
+}
+
+TYPED_TEST_P(FileStreamWriterTypedTest, FlushBeforeWriting) {
+ EXPECT_TRUE(
+ this->CreateFileWithContent(std::string(this->kTestFileName), ""));
+ std::unique_ptr<FileStreamWriter> writer(
+ this->CreateWriter(std::string(this->kTestFileName), 0));
+
+ EXPECT_EQ(net::OK, writer->Flush(base::DoNothing()));
+ EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "foo"));
+ EXPECT_EQ("foo", this->GetFileContent(std::string(this->kTestFileName)));
+}
+
+TYPED_TEST_P(FileStreamWriterTypedTest, FlushAfterWriting) {
+ EXPECT_TRUE(
+ this->CreateFileWithContent(std::string(this->kTestFileName), ""));
+ std::unique_ptr<FileStreamWriter> writer(
+ this->CreateWriter(std::string(this->kTestFileName), 0));
+
+ EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "foo"));
+
+ net::TestCompletionCallback callback;
+ int result =
+ writer->Flush(base::OnceCallback<void(int)>(callback.callback()));
+ ASSERT_EQ(net::OK, callback.GetResult(result));
+
+ EXPECT_EQ("foo", this->GetFileContent(std::string(this->kTestFileName)));
+}
+
+REGISTER_TYPED_TEST_SUITE_P(FileStreamWriterTypedTest,
+ Write,
+ WriteMiddle,
+ WriteNearEnd,
+ WriteEnd,
+ WriteAfterEnd,
+ WriteFailForNonexistingFile,
+ CancelBeforeOperation,
+ CancelAfterFinishedOperation,
+ CancelWrite,
+ CancelFlush,
+ FlushBeforeWriting,
+ FlushAfterWriting);
+
+} // namespace storage
+
+#endif // STORAGE_BROWSER_FILE_SYSTEM_FILE_STREAM_WRITER_TEST_H_ \ No newline at end of file
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 76c142737f5..2cc657c177f 100644
--- a/chromium/storage/browser/file_system/file_system_context_unittest.cc
+++ b/chromium/storage/browser/file_system/file_system_context_unittest.cc
@@ -13,6 +13,7 @@
#include "base/test/task_environment.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
+#include "build/chromeos_buildflags.h"
#include "storage/browser/file_system/external_mount_points.h"
#include "storage/browser/file_system/file_system_backend.h"
#include "storage/browser/file_system/isolated_context.h"
@@ -96,7 +97,7 @@ class FileSystemContextTest : public testing::Test {
// It is not valid to pass nullptr ExternalMountPoints to FileSystemContext on
// ChromeOS.
-#if !defined(OS_CHROMEOS)
+#if !BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(FileSystemContextTest, NullExternalMountPoints) {
scoped_refptr<FileSystemContext> file_system_context(
CreateFileSystemContextForTest(nullptr));
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 0751995c806..d1eb56cdc3c 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
@@ -979,11 +979,12 @@ TEST_F(FileSystemOperationImplTest, TestReadDirSuccess) {
EXPECT_EQ(base::File::FILE_OK, ReadDirectory(parent_dir));
EXPECT_EQ(2u, entries().size());
- for (size_t i = 0; i < entries().size(); ++i) {
- if (entries()[i].type == filesystem::mojom::FsFileType::DIRECTORY)
- EXPECT_EQ(FILE_PATH_LITERAL("child_dir"), entries()[i].name.value());
- else
- EXPECT_EQ(FILE_PATH_LITERAL("child_file"), entries()[i].name.value());
+ for (const filesystem::mojom::DirectoryEntry& entry : entries()) {
+ if (entry.type == filesystem::mojom::FsFileType::DIRECTORY) {
+ EXPECT_EQ(FILE_PATH_LITERAL("child_dir"), entry.name.value());
+ } else {
+ EXPECT_EQ(FILE_PATH_LITERAL("child_file"), entry.name.value());
+ }
}
EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count());
EXPECT_TRUE(change_observer()->HasNoChange());
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 91b854b869e..645791fb470 100644
--- a/chromium/storage/browser/file_system/file_writer_delegate_unittest.cc
+++ b/chromium/storage/browser/file_system/file_writer_delegate_unittest.cc
@@ -9,7 +9,7 @@
#include <vector>
#include "base/bind.h"
-#include "base/bind_helpers.h"
+#include "base/callback_helpers.h"
#include "base/files/scoped_temp_dir.h"
#include "base/location.h"
#include "base/macros.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 0cfd7801075..1019e272a9a 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
@@ -11,7 +11,7 @@
#include <string>
#include "base/bind.h"
-#include "base/bind_helpers.h"
+#include "base/callback_helpers.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
diff --git a/chromium/storage/browser/file_system/isolated_context.cc b/chromium/storage/browser/file_system/isolated_context.cc
index b24d7f20d13..6bf7acbe685 100644
--- a/chromium/storage/browser/file_system/isolated_context.cc
+++ b/chromium/storage/browser/file_system/isolated_context.cc
@@ -398,8 +398,8 @@ FileSystemURL IsolatedContext::CrackURL(const GURL& url) const {
FileSystemURL IsolatedContext::CreateCrackedFileSystemURL(
const url::Origin& origin,
FileSystemType type,
- const base::FilePath& path) const {
- return CrackFileSystemURL(FileSystemURL(origin, type, path));
+ const base::FilePath& virtual_path) const {
+ return CrackFileSystemURL(FileSystemURL(origin, type, virtual_path));
}
void IsolatedContext::RevokeFileSystemByPath(const base::FilePath& path_in) {
diff --git a/chromium/storage/browser/file_system/isolated_context.h b/chromium/storage/browser/file_system/isolated_context.h
index 1eaa9fbb6f5..c70f51d37f8 100644
--- a/chromium/storage/browser/file_system/isolated_context.h
+++ b/chromium/storage/browser/file_system/isolated_context.h
@@ -177,7 +177,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) IsolatedContext : public MountPoints {
FileSystemURL CreateCrackedFileSystemURL(
const url::Origin& origin,
FileSystemType type,
- const base::FilePath& path) const override;
+ const base::FilePath& virtual_path) const override;
// Returns the virtual root path that looks like /<filesystem_id>.
base::FilePath CreateVirtualRootPath(const std::string& filesystem_id) const;
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 d1f6bf8fe82..d5f477f68cc 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
@@ -11,7 +11,7 @@
#include <string>
#include "base/bind.h"
-#include "base/bind_helpers.h"
+#include "base/callback_helpers.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
diff --git a/chromium/storage/browser/file_system/local_file_stream_writer_unittest.cc b/chromium/storage/browser/file_system/local_file_stream_writer_unittest.cc
index 704fe4f1d37..1648557d2e8 100644
--- a/chromium/storage/browser/file_system/local_file_stream_writer_unittest.cc
+++ b/chromium/storage/browser/file_system/local_file_stream_writer_unittest.cc
@@ -10,33 +10,26 @@
#include <string>
#include "base/bind.h"
-#include "base/callback.h"
+#include "base/callback_helpers.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
+#include "base/memory/ptr_util.h"
#include "base/run_loop.h"
-#include "base/single_thread_task_runner.h"
-#include "base/test/task_environment.h"
-#include "base/threading/thread.h"
#include "net/base/io_buffer.h"
+#include "net/base/net_errors.h"
#include "net/base/test_completion_callback.h"
#include "storage/browser/file_system/file_stream_test_utils.h"
-#include "testing/gtest/include/gtest/gtest.h"
+#include "storage/browser/file_system/file_stream_writer_test.h"
namespace storage {
-namespace {
-void NeverCalled(int unused) {
- ADD_FAILURE();
-}
-} // namespace
-
-class LocalFileStreamWriterTest : public testing::Test {
+class LocalFileStreamWriterTest : public FileStreamWriterTest {
public:
LocalFileStreamWriterTest() : file_thread_("TestFileThread") {}
void SetUp() override {
ASSERT_TRUE(file_thread_.Start());
- ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ ASSERT_TRUE(file_system_directory_.CreateUniqueTempDir());
}
void TearDown() override {
@@ -44,143 +37,47 @@ class LocalFileStreamWriterTest : public testing::Test {
base::RunLoop().RunUntilIdle();
file_thread_.Stop();
base::RunLoop().RunUntilIdle();
+ ASSERT_TRUE(file_system_directory_.Delete());
}
- protected:
base::FilePath Path(const std::string& name) {
- return temp_dir_.GetPath().AppendASCII(name);
+ return file_system_directory_.GetPath().AppendASCII(name);
}
- std::string GetFileContent(const base::FilePath& path) {
- std::string content;
- base::ReadFileToString(path, &content);
- return content;
+ protected:
+ bool CreateFileWithContent(const std::string& name,
+ const std::string& data) override {
+ return base::WriteFile(Path(name), data);
}
- base::FilePath CreateFileWithContent(const std::string& name,
- const std::string& data) {
- base::FilePath path = Path(name);
- base::WriteFile(path, data);
- return path;
+ std::unique_ptr<FileStreamWriter> CreateWriter(const std::string& name,
+ int64_t offset) override {
+ return base::WrapUnique(
+ new LocalFileStreamWriter(file_task_runner(), Path(name), offset,
+ FileStreamWriter::OPEN_EXISTING_FILE));
}
- base::SingleThreadTaskRunner* file_task_runner() const {
- return file_thread_.task_runner().get();
+ bool FilePathExists(const std::string& name) override {
+ return base::PathExists(Path(name));
}
- LocalFileStreamWriter* CreateWriter(const base::FilePath& path,
- int64_t offset) {
- return new LocalFileStreamWriter(file_task_runner(), path, offset,
- FileStreamWriter::OPEN_EXISTING_FILE);
+ std::string GetFileContent(const std::string& name) override {
+ std::string content;
+ base::ReadFileToString(Path(name), &content);
+ return content;
+ }
+
+ base::SingleThreadTaskRunner* file_task_runner() const {
+ return file_thread_.task_runner().get();
}
private:
- base::test::SingleThreadTaskEnvironment task_environment_{
- base::test::SingleThreadTaskEnvironment::MainThreadType::IO};
+ base::ScopedTempDir file_system_directory_;
base::Thread file_thread_;
- base::ScopedTempDir temp_dir_;
};
-TEST_F(LocalFileStreamWriterTest, Write) {
- base::FilePath path = CreateFileWithContent("file_a", std::string());
- std::unique_ptr<LocalFileStreamWriter> writer(CreateWriter(path, 0));
- EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "foo"));
- EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "bar"));
- writer.reset();
- base::RunLoop().RunUntilIdle();
- EXPECT_TRUE(base::PathExists(path));
- EXPECT_EQ("foobar", GetFileContent(path));
-}
-
-TEST_F(LocalFileStreamWriterTest, WriteMiddle) {
- base::FilePath path = CreateFileWithContent("file_a", "foobar");
- std::unique_ptr<LocalFileStreamWriter> writer(CreateWriter(path, 2));
- EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "xxx"));
- writer.reset();
- base::RunLoop().RunUntilIdle();
- EXPECT_TRUE(base::PathExists(path));
- EXPECT_EQ("foxxxr", GetFileContent(path));
-}
-
-TEST_F(LocalFileStreamWriterTest, WriteNearEnd) {
- base::FilePath path = CreateFileWithContent("file_a", "foobar");
- std::unique_ptr<LocalFileStreamWriter> writer(CreateWriter(path, 5));
- EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "xxx"));
- writer.reset();
- base::RunLoop().RunUntilIdle();
- EXPECT_TRUE(base::PathExists(path));
- EXPECT_EQ("foobaxxx", GetFileContent(path));
-}
-
-TEST_F(LocalFileStreamWriterTest, WriteEnd) {
- base::FilePath path = CreateFileWithContent("file_a", "foobar");
- std::unique_ptr<LocalFileStreamWriter> writer(CreateWriter(path, 6));
- EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "xxx"));
- writer.reset();
- base::RunLoop().RunUntilIdle();
- EXPECT_TRUE(base::PathExists(path));
- EXPECT_EQ("foobarxxx", GetFileContent(path));
-}
-
-TEST_F(LocalFileStreamWriterTest, WriteAfterEnd) {
- base::FilePath path = CreateFileWithContent("file_a", "foobar");
- std::unique_ptr<LocalFileStreamWriter> writer(CreateWriter(path, 7));
- EXPECT_EQ(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE,
- WriteStringToWriter(writer.get(), "xxx"));
- writer.reset();
- base::RunLoop().RunUntilIdle();
- EXPECT_TRUE(base::PathExists(path));
- EXPECT_EQ("foobar", GetFileContent(path));
-}
-
-TEST_F(LocalFileStreamWriterTest, WriteFailForNonexistingFile) {
- base::FilePath path = Path("file_a");
- ASSERT_FALSE(base::PathExists(path));
- std::unique_ptr<LocalFileStreamWriter> writer(CreateWriter(path, 0));
- EXPECT_EQ(net::ERR_FILE_NOT_FOUND, WriteStringToWriter(writer.get(), "foo"));
- writer.reset();
- base::RunLoop().RunUntilIdle();
- EXPECT_FALSE(base::PathExists(path));
-}
-
-TEST_F(LocalFileStreamWriterTest, CancelBeforeOperation) {
- base::FilePath path = Path("file_a");
- std::unique_ptr<LocalFileStreamWriter> writer(CreateWriter(path, 0));
- // Cancel immediately fails when there's no in-flight operation.
- int cancel_result = writer->Cancel(base::BindOnce(&NeverCalled));
- EXPECT_EQ(net::ERR_UNEXPECTED, cancel_result);
-}
-
-TEST_F(LocalFileStreamWriterTest, CancelAfterFinishedOperation) {
- base::FilePath path = CreateFileWithContent("file_a", std::string());
- std::unique_ptr<LocalFileStreamWriter> writer(CreateWriter(path, 0));
- EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "foo"));
-
- // Cancel immediately fails when there's no in-flight operation.
- int cancel_result = writer->Cancel(base::BindOnce(&NeverCalled));
- EXPECT_EQ(net::ERR_UNEXPECTED, cancel_result);
-
- writer.reset();
- base::RunLoop().RunUntilIdle();
- // Write operation is already completed.
- EXPECT_TRUE(base::PathExists(path));
- EXPECT_EQ("foo", GetFileContent(path));
-}
-
-TEST_F(LocalFileStreamWriterTest, CancelWrite) {
- base::FilePath path = CreateFileWithContent("file_a", "foobar");
- std::unique_ptr<LocalFileStreamWriter> writer(CreateWriter(path, 0));
-
- scoped_refptr<net::StringIOBuffer> buffer(
- base::MakeRefCounted<net::StringIOBuffer>("xxx"));
- int result =
- writer->Write(buffer.get(), buffer->size(), base::BindOnce(&NeverCalled));
- ASSERT_EQ(net::ERR_IO_PENDING, result);
-
- net::TestCompletionCallback callback;
- writer->Cancel(callback.callback());
- int cancel_result = callback.WaitForResult();
- EXPECT_EQ(net::OK, cancel_result);
-}
+INSTANTIATE_TYPED_TEST_SUITE_P(Local,
+ FileStreamWriterTypedTest,
+ LocalFileStreamWriterTest);
} // namespace storage
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 685f49c22ef..ebc2dec4cc6 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
@@ -11,7 +11,7 @@
#include <string>
#include <utility>
-#include "base/bind_helpers.h"
+#include "base/callback_helpers.h"
#include "base/containers/span.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
diff --git a/chromium/storage/browser/file_system/memory_file_stream_writer_unittest.cc b/chromium/storage/browser/file_system/memory_file_stream_writer_unittest.cc
index f15892c57e0..550b9d3d4ac 100644
--- a/chromium/storage/browser/file_system/memory_file_stream_writer_unittest.cc
+++ b/chromium/storage/browser/file_system/memory_file_stream_writer_unittest.cc
@@ -10,29 +10,21 @@
#include <string>
#include "base/bind.h"
-#include "base/bind_helpers.h"
+#include "base/callback_helpers.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
-#include "base/test/task_environment.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
-#include "net/base/test_completion_callback.h"
#include "storage/browser/file_system/file_stream_test_utils.h"
#include "storage/browser/file_system/file_stream_writer.h"
+#include "storage/browser/file_system/file_stream_writer_test.h"
#include "storage/browser/file_system/obfuscated_file_util_memory_delegate.h"
-#include "testing/gtest/include/gtest/gtest.h"
namespace storage {
-namespace {
-void NeverCalled(int unused) {
- ADD_FAILURE();
-}
-} // namespace
-
-class MemoryFileStreamWriterTest : public testing::Test {
+class MemoryFileStreamWriterTest : public FileStreamWriterTest {
public:
- MemoryFileStreamWriterTest() {}
+ MemoryFileStreamWriterTest() = default;
void SetUp() override {
ASSERT_TRUE(file_system_directory_.CreateUniqueTempDir());
@@ -48,12 +40,30 @@ class MemoryFileStreamWriterTest : public testing::Test {
ObfuscatedFileUtilMemoryDelegate* file_util() { return file_util_.get(); }
- protected:
base::FilePath Path(const std::string& name) {
return file_system_directory_.GetPath().AppendASCII(name);
}
- std::string GetFileContent(const base::FilePath& path) {
+ protected:
+ bool CreateFileWithContent(const std::string& name,
+ const std::string& data) override {
+ return file_util()->CreateFileForTesting(Path(name), data) ==
+ base::File::FILE_OK;
+ }
+
+ std::unique_ptr<FileStreamWriter> CreateWriter(const std::string& name,
+ int64_t offset) override {
+ return FileStreamWriter::CreateForMemoryFile(
+ base::ThreadTaskRunnerHandle::Get(), file_util_->GetWeakPtr(),
+ Path(name), offset);
+ }
+
+ bool FilePathExists(const std::string& name) override {
+ return file_util()->PathExists(Path(name));
+ }
+
+ std::string GetFileContent(const std::string& name) override {
+ base::FilePath path = Path(name);
base::File::Info info;
EXPECT_EQ(base::File::FILE_OK, file_util()->GetFileInfo(path, &info));
@@ -65,148 +75,13 @@ class MemoryFileStreamWriterTest : public testing::Test {
return std::string(content->data(), info.size);
}
- std::unique_ptr<FileStreamWriter> CreateWriter(const base::FilePath& path,
- int64_t offset) {
- return FileStreamWriter::CreateForMemoryFile(
- base::ThreadTaskRunnerHandle::Get(), file_util_->GetWeakPtr(), path,
- offset);
- }
-
private:
- base::test::TaskEnvironment task_environment_;
base::ScopedTempDir file_system_directory_;
std::unique_ptr<ObfuscatedFileUtilMemoryDelegate> file_util_;
};
-TEST_F(MemoryFileStreamWriterTest, Write) {
- base::FilePath path = Path("file_a");
- bool created;
- EXPECT_EQ(base::File::FILE_OK, file_util()->EnsureFileExists(path, &created));
-
- std::unique_ptr<FileStreamWriter> writer(CreateWriter(path, 0));
- EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "foo"));
- EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "bar"));
- EXPECT_TRUE(file_util()->PathExists(path));
- EXPECT_EQ("foobar", GetFileContent(path));
-}
-
-TEST_F(MemoryFileStreamWriterTest, WriteMiddle) {
- base::FilePath path = Path("file_a");
- EXPECT_EQ(base::File::FILE_OK,
- file_util()->CreateFileForTesting(path, std::string("foobar")));
-
- std::unique_ptr<FileStreamWriter> writer(CreateWriter(path, 2));
- EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "xxx"));
- EXPECT_TRUE(file_util()->PathExists(path));
- EXPECT_EQ("foxxxr", GetFileContent(path));
-}
-
-TEST_F(MemoryFileStreamWriterTest, WriteNearEnd) {
- base::FilePath path = Path("file_a");
- EXPECT_EQ(base::File::FILE_OK,
- file_util()->CreateFileForTesting(path, std::string("foobar")));
-
- std::unique_ptr<FileStreamWriter> writer(CreateWriter(path, 5));
- EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "xxx"));
- EXPECT_TRUE(file_util()->PathExists(path));
- EXPECT_EQ("foobaxxx", GetFileContent(path));
-}
-
-TEST_F(MemoryFileStreamWriterTest, WriteEnd) {
- base::FilePath path = Path("file_a");
- EXPECT_EQ(base::File::FILE_OK,
- file_util()->CreateFileForTesting(path, std::string("foobar")));
-
- std::unique_ptr<FileStreamWriter> writer(CreateWriter(path, 6));
- EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "xxx"));
- EXPECT_TRUE(file_util()->PathExists(path));
- EXPECT_EQ("foobarxxx", GetFileContent(path));
-}
-
-TEST_F(MemoryFileStreamWriterTest, WriteAfterEnd) {
- base::FilePath path = Path("file_a");
- EXPECT_EQ(base::File::FILE_OK,
- file_util()->CreateFileForTesting(path, std::string("foobar")));
-
- std::unique_ptr<FileStreamWriter> writer(CreateWriter(path, 7));
- EXPECT_EQ(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE,
- WriteStringToWriter(writer.get(), "xxx"));
- EXPECT_TRUE(file_util()->PathExists(path));
- EXPECT_EQ("foobar", GetFileContent(path));
-}
-
-TEST_F(MemoryFileStreamWriterTest, WriteFailForNonexistingFile) {
- base::FilePath path = Path("file_a");
- ASSERT_FALSE(file_util()->PathExists(path));
- std::unique_ptr<FileStreamWriter> writer(CreateWriter(path, 0));
- EXPECT_EQ(net::ERR_FILE_NOT_FOUND, WriteStringToWriter(writer.get(), "foo"));
- EXPECT_FALSE(file_util()->PathExists(path));
-}
-
-TEST_F(MemoryFileStreamWriterTest, CancelBeforeOperation) {
- base::FilePath path = Path("file_a");
- std::unique_ptr<FileStreamWriter> writer(CreateWriter(path, 0));
- // Cancel immediately fails when there's no in-flight operation.
- EXPECT_EQ(net::ERR_UNEXPECTED, writer->Cancel(base::DoNothing()));
-}
-
-TEST_F(MemoryFileStreamWriterTest, CancelAfterFinishedOperation) {
- base::FilePath path = Path("file_a");
- bool created;
- EXPECT_EQ(base::File::FILE_OK, file_util()->EnsureFileExists(path, &created));
-
- std::unique_ptr<FileStreamWriter> writer(CreateWriter(path, 0));
- EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "foo"));
-
- // Cancel immediately fails when there's no in-flight operation.
- EXPECT_EQ(net::ERR_UNEXPECTED, writer->Cancel(base::DoNothing()));
-
- // Write operation is already completed.
- EXPECT_TRUE(file_util()->PathExists(path));
- EXPECT_EQ("foo", GetFileContent(path));
-}
-
-TEST_F(MemoryFileStreamWriterTest, CancelWrite) {
- base::FilePath path = Path("file_a");
- bool created;
- EXPECT_EQ(base::File::FILE_OK, file_util()->EnsureFileExists(path, &created));
-
- std::unique_ptr<FileStreamWriter> writer(CreateWriter(path, 0));
-
- scoped_refptr<net::StringIOBuffer> buffer(
- base::MakeRefCounted<net::StringIOBuffer>("xxx"));
- int result =
- writer->Write(buffer.get(), buffer->size(), base::BindOnce(&NeverCalled));
- ASSERT_EQ(net::ERR_IO_PENDING, result);
-
- net::TestCompletionCallback callback;
- writer->Cancel(callback.callback());
- int cancel_result = callback.WaitForResult();
- EXPECT_EQ(net::OK, cancel_result);
-}
-
-TEST_F(MemoryFileStreamWriterTest, FlushBeforeWriting) {
- base::FilePath path = Path("file_a");
- bool created;
- EXPECT_EQ(base::File::FILE_OK, file_util()->EnsureFileExists(path, &created));
-
- std::unique_ptr<FileStreamWriter> writer(CreateWriter(path, 0));
-
- EXPECT_EQ(net::OK, writer->Flush(base::DoNothing()));
- EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "foo"));
- EXPECT_EQ("foo", GetFileContent(path));
-}
-
-TEST_F(MemoryFileStreamWriterTest, FlushAfterWriting) {
- base::FilePath path = Path("file_a");
- bool created;
- EXPECT_EQ(base::File::FILE_OK, file_util()->EnsureFileExists(path, &created));
-
- std::unique_ptr<FileStreamWriter> writer(CreateWriter(path, 0));
-
- EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "foo"));
- EXPECT_EQ(net::OK, writer->Flush(base::DoNothing()));
- EXPECT_EQ("foo", GetFileContent(path));
-}
+INSTANTIATE_TYPED_TEST_SUITE_P(Memory,
+ FileStreamWriterTypedTest,
+ MemoryFileStreamWriterTest);
} // namespace storage
diff --git a/chromium/storage/browser/file_system/mount_points.h b/chromium/storage/browser/file_system/mount_points.h
index 4fb761f3480..c803364cc7c 100644
--- a/chromium/storage/browser/file_system/mount_points.h
+++ b/chromium/storage/browser/file_system/mount_points.h
@@ -59,14 +59,14 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) MountPoints {
// from |url|.
virtual FileSystemURL CrackURL(const GURL& url) const = 0;
- // Creates a FileSystemURL with the given origin, type and path and tries to
- // crack it as a part of one of the registered mount points.
- // If the the URL is not valid or does not belong to any of the mount points
+ // Creates a FileSystemURL with the given origin, type and virtual path and
+ // tries to crack it as a part of one of the registered mount points. If the
+ // the URL is not valid or does not belong to any of the mount points
// registered in this context, returns empty, invalid FileSystemURL.
virtual FileSystemURL CreateCrackedFileSystemURL(
const url::Origin& origin,
FileSystemType type,
- const base::FilePath& path) const = 0;
+ const base::FilePath& virtual_path) const = 0;
// Returns the mount point root path registered for a given |mount_name|.
// Returns false if the given |mount_name| is not valid.
diff --git a/chromium/storage/browser/file_system/native_file_util.cc b/chromium/storage/browser/file_system/native_file_util.cc
index 2e53b92bcc8..42b1496c162 100644
--- a/chromium/storage/browser/file_system/native_file_util.cc
+++ b/chromium/storage/browser/file_system/native_file_util.cc
@@ -11,6 +11,7 @@
#include "base/files/file_enumerator.h"
#include "base/files/file_util.h"
#include "build/build_config.h"
+#include "build/chromeos_buildflags.h"
#include "storage/browser/file_system/file_system_operation_context.h"
#include "storage/browser/file_system/file_system_url.h"
#include "storage/common/file_system/file_system_mount_option.h"
@@ -24,7 +25,7 @@ namespace {
//
// TODO(benchan): Find a better place outside webkit to host this function.
bool SetPlatformSpecificDirectoryPermissions(const base::FilePath& dir_path) {
-#if defined(OS_CHROMEOS)
+#if BUILDFLAG(IS_CHROMEOS_ASH)
// System daemons on Chrome OS may run as a user different than the Chrome
// process but need to access files under the directories created here.
// Because of that, grant the execute permission on the created directory
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 8e7f8fc4ec3..3e5f74dc6ba 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
@@ -8,7 +8,7 @@
#include <utility>
#include "base/bind.h"
-#include "base/bind_helpers.h"
+#include "base/callback_helpers.h"
#include "base/files/file.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
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 3f29d3c707e..2a09c4cf6ec 100644
--- a/chromium/storage/browser/file_system/sandbox_file_stream_writer.cc
+++ b/chromium/storage/browser/file_system/sandbox_file_stream_writer.cc
@@ -266,7 +266,23 @@ int SandboxFileStreamWriter::Flush(net::CompletionOnceCallback callback) {
if (!file_writer_)
return net::OK;
- return file_writer_->Flush(std::move(callback));
+ has_pending_operation_ = true;
+ int result = file_writer_->Flush(
+ base::BindOnce(&SandboxFileStreamWriter::DidFlush,
+ weak_factory_.GetWeakPtr(), std::move(callback)));
+ if (result != net::ERR_IO_PENDING)
+ has_pending_operation_ = false;
+ return result;
+}
+
+void SandboxFileStreamWriter::DidFlush(net::CompletionOnceCallback callback,
+ int result) {
+ DCHECK(has_pending_operation_);
+
+ if (CancelIfRequested())
+ return;
+ has_pending_operation_ = false;
+ std::move(callback).Run(result);
}
} // namespace storage
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 df3609502c6..3fc751e101e 100644
--- a/chromium/storage/browser/file_system/sandbox_file_stream_writer.h
+++ b/chromium/storage/browser/file_system/sandbox_file_stream_writer.h
@@ -64,6 +64,8 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) SandboxFileStreamWriter
void DidWrite(int write_response);
+ void DidFlush(net::CompletionOnceCallback callback, int result);
+
// Stops the in-flight operation, calls |cancel_callback_| and returns true
// if there's a pending cancel request.
bool CancelIfRequested();
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
new file mode 100644
index 00000000000..f88ef6970f7
--- /dev/null
+++ b/chromium/storage/browser/file_system/sandbox_file_stream_writer_unittest.cc
@@ -0,0 +1,134 @@
+// Copyright 2020 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/sandbox_file_stream_writer.h"
+#include "storage/browser/file_system/file_stream_writer_test.h"
+
+#include <stdint.h>
+
+#include <memory>
+#include <string>
+
+#include "base/bind.h"
+#include "base/callback_helpers.h"
+#include "base/files/file_util.h"
+#include "base/files/scoped_temp_dir.h"
+#include "base/time/time.h"
+#include "net/base/io_buffer.h"
+#include "net/base/net_errors.h"
+#include "storage/browser/file_system/file_stream_reader.h"
+#include "storage/browser/file_system/file_stream_test_utils.h"
+#include "storage/browser/file_system/file_stream_writer.h"
+#include "storage/browser/file_system/file_system_context.h"
+#include "storage/browser/test/async_file_test_helper.h"
+#include "storage/browser/test/test_file_system_context.h"
+#include "storage/common/file_system/file_system_types.h"
+
+namespace storage {
+
+namespace {
+const char kURLOrigin[] = "http://remote/";
+} // namespace
+
+class SandboxFileStreamWriterTest : public FileStreamWriterTest {
+ public:
+ SandboxFileStreamWriterTest() = default;
+
+ void SetUp() override {
+ ASSERT_TRUE(dir_.CreateUniqueTempDir());
+
+ file_system_context_ = CreateFileSystemContext(dir_);
+
+ file_system_context_->OpenFileSystem(
+ url::Origin::Create(GURL(kURLOrigin)), kFileSystemTypeTemporary,
+ OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT,
+ base::BindOnce([](const GURL& root_url, const std::string& name,
+ base::File::Error result) {
+ ASSERT_EQ(base::File::FILE_OK, result);
+ }));
+ base::RunLoop().RunUntilIdle();
+ }
+
+ void TearDown() override { base::RunLoop().RunUntilIdle(); }
+
+ protected:
+ base::ScopedTempDir dir_;
+ scoped_refptr<FileSystemContext> file_system_context_;
+
+ virtual FileSystemContext* CreateFileSystemContext(
+ const base::ScopedTempDir& dir) {
+ return CreateFileSystemContextForTesting(nullptr, dir.GetPath());
+ }
+
+ FileSystemURL GetFileSystemURL(const std::string& file_name) {
+ return file_system_context_->CreateCrackedFileSystemURL(
+ url::Origin::Create(GURL(kURLOrigin)), kFileSystemTypeTemporary,
+ base::FilePath().AppendASCII(file_name));
+ }
+
+ bool CreateFileWithContent(const std::string& name,
+ const std::string& data) override {
+ return AsyncFileTestHelper::CreateFileWithData(
+ file_system_context_.get(), GetFileSystemURL(name), data.data(),
+ data.size()) == base::File::FILE_OK;
+ }
+
+ std::unique_ptr<FileStreamWriter> CreateWriter(const std::string& name,
+ int64_t offset) override {
+ auto writer = std::make_unique<SandboxFileStreamWriter>(
+ file_system_context_.get(), GetFileSystemURL(name), offset,
+ *file_system_context_->GetUpdateObservers(kFileSystemTypeTemporary));
+ return writer;
+ }
+
+ bool FilePathExists(const std::string& name) override {
+ return AsyncFileTestHelper::FileExists(file_system_context_.get(),
+ GetFileSystemURL(name),
+ AsyncFileTestHelper::kDontCheckSize);
+ }
+
+ std::string GetFileContent(const std::string& name) override {
+ base::File::Info info;
+ const FileSystemURL url = GetFileSystemURL(name);
+
+ EXPECT_EQ(base::File::FILE_OK, AsyncFileTestHelper::GetMetadata(
+ file_system_context_.get(), url, &info));
+
+ std::unique_ptr<FileStreamReader> reader(
+ file_system_context_.get()->CreateFileStreamReader(url, 0, info.size,
+ base::Time()));
+
+ int result = 0;
+ std::string content;
+ ReadFromReader(reader.get(), &content, info.size, &result);
+ EXPECT_EQ(net::OK, result);
+ EXPECT_EQ(info.size, long(content.length()));
+
+ return content;
+ }
+};
+
+INSTANTIATE_TYPED_TEST_SUITE_P(Sandbox,
+ FileStreamWriterTypedTest,
+ SandboxFileStreamWriterTest);
+
+class SandboxFileStreamWriterIncognitoTest
+ : public SandboxFileStreamWriterTest {
+ public:
+ SandboxFileStreamWriterIncognitoTest() = default;
+
+ protected:
+ FileSystemContext* CreateFileSystemContext(
+ const base::ScopedTempDir& dir) override {
+ return CreateIncognitoFileSystemContextForTesting(
+ base::ThreadTaskRunnerHandle::Get(),
+ base::ThreadTaskRunnerHandle::Get(), nullptr, dir.GetPath());
+ }
+};
+
+INSTANTIATE_TYPED_TEST_SUITE_P(SandboxIncognito,
+ FileStreamWriterTypedTest,
+ SandboxFileStreamWriterIncognitoTest);
+
+} // namespace storage \ No newline at end of file
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 97831c3a7e9..17a9a301c67 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
@@ -11,7 +11,7 @@
#include <vector>
#include "base/bind.h"
-#include "base/bind_helpers.h"
+#include "base/callback_helpers.h"
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/macros.h"
diff --git a/chromium/storage/browser/quota/DIR_METADATA b/chromium/storage/browser/quota/DIR_METADATA
new file mode 100644
index 00000000000..c03de17c44a
--- /dev/null
+++ b/chromium/storage/browser/quota/DIR_METADATA
@@ -0,0 +1,12 @@
+# Metadata information for this directory.
+#
+# For more information on DIR_METADATA files, see:
+# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/README.md
+#
+# For the schema of this file, see Metadata message:
+# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/proto/dir_metadata.proto
+
+monorail {
+ component: "Blink>Storage>Quota"
+}
+team_email: "storage-dev@chromium.org" \ No newline at end of file
diff --git a/chromium/storage/browser/quota/OWNERS b/chromium/storage/browser/quota/OWNERS
index 148302e8cb4..5d7b9c5d488 100644
--- a/chromium/storage/browser/quota/OWNERS
+++ b/chromium/storage/browser/quota/OWNERS
@@ -6,6 +6,3 @@ jsbell@chromium.org
kinuko@chromium.org
nhiroki@chromium.org
pwnall@chromium.org
-
-# TEAM: storage-dev@chromium.org
-# COMPONENT: Blink>Storage>Quota
diff --git a/chromium/storage/browser/quota/client_usage_tracker.cc b/chromium/storage/browser/quota/client_usage_tracker.cc
index 139104c8e78..f06c6a342ba 100644
--- a/chromium/storage/browser/quota/client_usage_tracker.cc
+++ b/chromium/storage/browser/quota/client_usage_tracker.cc
@@ -7,7 +7,6 @@
#include <stdint.h>
#include "base/bind.h"
-#include "base/bind_helpers.h"
#include "base/callback_helpers.h"
#include "base/metrics/histogram_macros.h"
#include "base/stl_util.h"
diff --git a/chromium/storage/browser/quota/quota_features.cc b/chromium/storage/browser/quota/quota_features.cc
index 5fe119cfd43..b638a01437b 100644
--- a/chromium/storage/browser/quota/quota_features.cc
+++ b/chromium/storage/browser/quota/quota_features.cc
@@ -8,19 +8,6 @@ namespace storage {
namespace features {
-// IncognitoDynamicQuota enables dynamic assignment of quota to incognito mode
-// based on the physical memory size and removes the fixed upper cap for it.
-const base::Feature kIncognitoDynamicQuota{"IncognitoDynamicQuota",
- base::FEATURE_ENABLED_BY_DEFAULT};
-
-// Dynamic quota for incognito mode would be set by a random fraction of
-// physical memory, between |IncognitoQuotaRatioLowerBound| and
-// |IncognitoQuotaRatioUpperBound|.
-constexpr base::FeatureParam<double> kIncognitoQuotaRatioLowerBound{
- &kIncognitoDynamicQuota, "IncognitoQuotaRatioLowerBound", 0.15};
-constexpr base::FeatureParam<double> kIncognitoQuotaRatioUpperBound{
- &kIncognitoDynamicQuota, "IncognitoQuotaRatioUpperBound", 0.2};
-
// Enables Storage Pressure Event.
const base::Feature kStoragePressureEvent{"StoragePressureEvent",
base::FEATURE_DISABLED_BY_DEFAULT};
diff --git a/chromium/storage/browser/quota/quota_features.h b/chromium/storage/browser/quota/quota_features.h
index 6364087068d..2203dd63248 100644
--- a/chromium/storage/browser/quota/quota_features.h
+++ b/chromium/storage/browser/quota/quota_features.h
@@ -14,11 +14,6 @@ namespace storage {
namespace features {
COMPONENT_EXPORT(STORAGE_BROWSER)
-extern const base::Feature kIncognitoDynamicQuota;
-extern const base::FeatureParam<double> kIncognitoQuotaRatioLowerBound;
-extern const base::FeatureParam<double> kIncognitoQuotaRatioUpperBound;
-
-COMPONENT_EXPORT(STORAGE_BROWSER)
extern const base::Feature kStoragePressureEvent;
} // namespace features
diff --git a/chromium/storage/browser/quota/quota_manager.cc b/chromium/storage/browser/quota/quota_manager.cc
index 8bb8ee893da..4b1d43e3ff6 100644
--- a/chromium/storage/browser/quota/quota_manager.cc
+++ b/chromium/storage/browser/quota/quota_manager.cc
@@ -15,7 +15,7 @@
#include "base/barrier_closure.h"
#include "base/bind.h"
-#include "base/bind_helpers.h"
+#include "base/callback_helpers.h"
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/macros.h"
@@ -39,6 +39,7 @@
#include "storage/browser/quota/quota_features.h"
#include "storage/browser/quota/quota_macros.h"
#include "storage/browser/quota/quota_manager_proxy.h"
+#include "storage/browser/quota/quota_override_handle.h"
#include "storage/browser/quota/quota_temporary_storage_evictor.h"
#include "storage/browser/quota/usage_tracker.h"
#include "third_party/blink/public/mojom/quota/quota_types.mojom-shared.h"
@@ -189,6 +190,16 @@ void DidGetUsageAndQuotaStripBreakdown(
std::move(callback).Run(status, usage, quota);
}
+void DidGetUsageAndQuotaStripOverride(
+ QuotaManager::UsageAndQuotaWithBreakdownCallback callback,
+ blink::mojom::QuotaStatusCode status,
+ int64_t usage,
+ int64_t quota,
+ bool is_override_enabled,
+ blink::mojom::UsageBreakdownPtr usage_breakdown) {
+ std::move(callback).Run(status, usage, quota, std::move(usage_breakdown));
+}
+
} // namespace
constexpr int64_t QuotaManager::kGBytes;
@@ -202,6 +213,9 @@ constexpr char QuotaManager::kDaysBetweenRepeatedOriginEvictionsHistogram[];
constexpr char QuotaManager::kEvictedOriginAccessedCountHistogram[];
constexpr char QuotaManager::kEvictedOriginDaysSinceAccessHistogram[];
+QuotaManager::QuotaOverride::QuotaOverride() = default;
+QuotaManager::QuotaOverride::~QuotaOverride() = default;
+
class QuotaManager::UsageAndQuotaInfoGatherer : public QuotaTask {
public:
UsageAndQuotaInfoGatherer(QuotaManager* manager,
@@ -210,14 +224,17 @@ class QuotaManager::UsageAndQuotaInfoGatherer : public QuotaTask {
bool is_unlimited,
bool is_session_only,
bool is_incognito,
- UsageAndQuotaWithBreakdownCallback callback)
+ base::Optional<int64_t> quota_override_size,
+ UsageAndQuotaForDevtoolsCallback callback)
: QuotaTask(manager),
origin_(origin),
callback_(std::move(callback)),
type_(type),
is_unlimited_(is_unlimited),
is_session_only_(is_session_only),
- is_incognito_(is_incognito) {}
+ is_incognito_(is_incognito),
+ is_override_enabled_(quota_override_size.has_value()),
+ quota_override_size_(quota_override_size) {}
protected:
void Run() override {
@@ -262,11 +279,11 @@ class QuotaManager::UsageAndQuotaInfoGatherer : public QuotaTask {
void Aborted() override {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
weak_factory_.InvalidateWeakPtrs();
- std::move(callback_).Run(
- blink::mojom::QuotaStatusCode::kErrorAbort, /*status*/
- 0, /*usage*/
- 0, /*quota*/
- nullptr); /*usage_breakdown*/
+ std::move(callback_).Run(blink::mojom::QuotaStatusCode::kErrorAbort,
+ /*usage=*/0,
+ /*quota=*/0,
+ /*is_override_enabled=*/false,
+ /*usage_breakdown=*/nullptr);
DeleteSoon();
}
@@ -274,7 +291,9 @@ class QuotaManager::UsageAndQuotaInfoGatherer : public QuotaTask {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
weak_factory_.InvalidateWeakPtrs();
- int64_t host_quota = desired_host_quota_;
+ int64_t host_quota = quota_override_size_.has_value()
+ ? quota_override_size_.value()
+ : desired_host_quota_;
int64_t temp_pool_free_space =
std::max(static_cast<int64_t>(0),
available_space_ - settings_.must_remain_available);
@@ -287,7 +306,8 @@ class QuotaManager::UsageAndQuotaInfoGatherer : public QuotaTask {
}
std::move(callback_).Run(blink::mojom::QuotaStatusCode::kOk, host_usage_,
- host_quota, std::move(host_usage_breakdown_));
+ host_quota, is_override_enabled_,
+ std::move(host_usage_breakdown_));
if (type_ == StorageType::kTemporary && !is_incognito_ &&
!is_unlimited_) {
UMA_HISTOGRAM_MBYTES("Quota.QuotaForOrigin", host_quota);
@@ -349,7 +369,7 @@ class QuotaManager::UsageAndQuotaInfoGatherer : public QuotaTask {
void OnBarrierComplete() { CallCompleted(); }
const url::Origin origin_;
- QuotaManager::UsageAndQuotaWithBreakdownCallback callback_;
+ QuotaManager::UsageAndQuotaForDevtoolsCallback callback_;
const StorageType type_;
const bool is_unlimited_;
const bool is_session_only_;
@@ -358,6 +378,8 @@ class QuotaManager::UsageAndQuotaInfoGatherer : public QuotaTask {
int64_t total_space_ = 0;
int64_t desired_host_quota_ = 0;
int64_t host_usage_ = 0;
+ const bool is_override_enabled_;
+ base::Optional<int64_t> quota_override_size_;
blink::mojom::UsageBreakdownPtr host_usage_breakdown_;
QuotaSettings settings_;
SEQUENCE_CHECKER(sequence_checker_);
@@ -937,13 +959,23 @@ void QuotaManager::GetUsageAndQuotaWithBreakdown(
StorageType type,
UsageAndQuotaWithBreakdownCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
+ GetUsageAndQuotaForDevtools(
+ origin, type,
+ base::BindOnce(&DidGetUsageAndQuotaStripOverride, std::move(callback)));
+}
+
+void QuotaManager::GetUsageAndQuotaForDevtools(
+ const url::Origin& origin,
+ StorageType type,
+ UsageAndQuotaForDevtoolsCallback callback) {
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!IsSupportedType(type) ||
(is_incognito_ && !IsSupportedIncognitoType(type))) {
- std::move(callback).Run(
- blink::mojom::QuotaStatusCode::kErrorNotSupported, /*status*/
- 0, /*usage*/
- 0, /*quota*/
- nullptr); /*usage_breakdown*/
+ std::move(callback).Run(blink::mojom::QuotaStatusCode::kErrorNotSupported,
+ /*usage=*/0,
+ /*quota=*/0,
+ /*is_override_enabled=*/false,
+ /*usage_breakdown=*/nullptr);
return;
}
LazyInitialize();
@@ -951,9 +983,12 @@ void QuotaManager::GetUsageAndQuotaWithBreakdown(
bool is_session_only =
type == StorageType::kTemporary && special_storage_policy_ &&
special_storage_policy_->IsStorageSessionOnly(origin.GetURL());
+
+ base::Optional<int64_t> quota_override = GetQuotaOverrideForOrigin(origin);
+
UsageAndQuotaInfoGatherer* helper = new UsageAndQuotaInfoGatherer(
this, origin, type, IsStorageUnlimited(origin, type), is_session_only,
- is_incognito_, std::move(callback));
+ is_incognito_, quota_override, std::move(callback));
helper->Start();
}
@@ -981,10 +1016,15 @@ void QuotaManager::GetUsageAndQuota(const url::Origin& origin,
bool is_session_only =
type == StorageType::kTemporary && special_storage_policy_ &&
special_storage_policy_->IsStorageSessionOnly(origin.GetURL());
+
+ base::Optional<int64_t> quota_override = GetQuotaOverrideForOrigin(origin);
+
UsageAndQuotaInfoGatherer* helper = new UsageAndQuotaInfoGatherer(
this, origin, type, IsStorageUnlimited(origin, type), is_session_only,
- is_incognito_,
- base::BindOnce(&DidGetUsageAndQuotaStripBreakdown, std::move(callback)));
+ is_incognito_, quota_override,
+ base::BindOnce(&DidGetUsageAndQuotaStripOverride,
+ base::BindOnce(&DidGetUsageAndQuotaStripBreakdown,
+ std::move(callback))));
helper->Start();
}
@@ -1525,6 +1565,54 @@ void QuotaManager::SetStoragePressureCallback(
}
}
+int QuotaManager::GetOverrideHandleId() {
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
+ return ++next_override_handle_id_;
+}
+
+void QuotaManager::OverrideQuotaForOrigin(int handle_id,
+ const url::Origin& origin,
+ base::Optional<int64_t> quota_size) {
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
+ if (quota_size.has_value()) {
+ DCHECK_GE(next_override_handle_id_, handle_id);
+ // Bracket notation is safe here because we want to construct a new
+ // QuotaOverride in the case that one does not exist for origin.
+ devtools_overrides_[origin].active_override_session_ids.insert(handle_id);
+ devtools_overrides_[origin].quota_size = quota_size.value();
+ } else {
+ devtools_overrides_.erase(origin);
+ }
+}
+
+void QuotaManager::WithdrawOverridesForHandle(int handle_id) {
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
+ std::vector<url::Origin> origins_to_clear;
+ for (auto& devtools_override : devtools_overrides_) {
+ auto& quota_override = devtools_override.second;
+ auto& origin = devtools_override.first;
+
+ quota_override.active_override_session_ids.erase(handle_id);
+
+ if (!quota_override.active_override_session_ids.size()) {
+ origins_to_clear.push_back(origin);
+ }
+ }
+
+ for (auto& origin : origins_to_clear) {
+ devtools_overrides_.erase(origin);
+ }
+}
+
+base::Optional<int64_t> QuotaManager::GetQuotaOverrideForOrigin(
+ const url::Origin& origin) {
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
+ if (!base::Contains(devtools_overrides_, origin)) {
+ return base::nullopt;
+ }
+ return devtools_overrides_[origin].quota_size;
+}
+
void QuotaManager::ReportHistogram() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!is_incognito_);
diff --git a/chromium/storage/browser/quota/quota_manager.h b/chromium/storage/browser/quota/quota_manager.h
index 2748c4f7724..75b74e97f7a 100644
--- a/chromium/storage/browser/quota/quota_manager.h
+++ b/chromium/storage/browser/quota/quota_manager.h
@@ -37,6 +37,7 @@
#include "storage/browser/quota/special_storage_policy.h"
#include "third_party/blink/public/mojom/quota/quota_types.mojom-forward.h"
#include "third_party/blink/public/mojom/quota/quota_types.mojom-shared.h"
+#include "url/origin.h"
namespace base {
class SequencedTaskRunner;
@@ -51,6 +52,7 @@ class QuotaInternalsProxy;
namespace storage {
class QuotaManagerProxy;
+class QuotaOverrideHandle;
class QuotaTemporaryStorageEvictor;
class UsageTracker;
@@ -121,6 +123,13 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManager
int64_t quota,
blink::mojom::UsageBreakdownPtr usage_breakdown)>;
+ using UsageAndQuotaForDevtoolsCallback =
+ base::OnceCallback<void(blink::mojom::QuotaStatusCode,
+ int64_t usage,
+ int64_t quota,
+ bool is_override_enabled,
+ blink::mojom::UsageBreakdownPtr usage_breakdown)>;
+
static constexpr int64_t kGBytes = 1024 * 1024 * 1024;
static constexpr int64_t kNoLimit = INT64_MAX;
static constexpr int64_t kMBytes = 1024 * 1024;
@@ -141,18 +150,25 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManager
// Called by clients or webapps. Returns usage per host.
void GetUsageInfo(GetUsageInfoCallback callback);
- // Called by Web Apps.
+ // Called by Web Apps (deprecated quota API).
// This method is declared as virtual to allow test code to override it.
virtual void GetUsageAndQuotaForWebApps(const url::Origin& origin,
blink::mojom::StorageType type,
UsageAndQuotaCallback callback);
- // Called by DevTools.
+
+ // Called by Web Apps (navigator.storage.estimate())
// This method is declared as virtual to allow test code to override it.
virtual void GetUsageAndQuotaWithBreakdown(
const url::Origin& origin,
blink::mojom::StorageType type,
UsageAndQuotaWithBreakdownCallback callback);
+ // Called by DevTools.
+ virtual void GetUsageAndQuotaForDevtools(
+ const url::Origin& origin,
+ blink::mojom::StorageType type,
+ UsageAndQuotaForDevtoolsCallback callback);
+
// Called by storage backends.
//
// For UnlimitedStorage origins, this version skips usage and quota handling
@@ -253,6 +269,16 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManager
void SetStoragePressureCallback(
base::RepeatingCallback<void(url::Origin)> storage_pressure_callback);
+ // DevTools Quota Override methods:
+ int GetOverrideHandleId();
+ void OverrideQuotaForOrigin(int handle_id,
+ const url::Origin& origin,
+ base::Optional<int64_t> quota_size);
+ // Called when a DevTools client releases all overrides, however, overrides
+ // will not be disabled for any origins for which there are other DevTools
+ // clients/QuotaOverrideHandle with an active override.
+ void WithdrawOverridesForHandle(int handle_id);
+
// Cap size for per-host persistent quota determined by the histogram.
// This is a bit lax value because the histogram says nothing about per-host
// persistent storage usage and we determined by global persistent storage
@@ -302,6 +328,19 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManager
class DumpOriginInfoTableHelper;
class StorageCleanupHelper;
+ struct QuotaOverride {
+ QuotaOverride();
+ ~QuotaOverride();
+
+ QuotaOverride(const QuotaOverride& quota_override) = delete;
+ QuotaOverride& operator=(const QuotaOverride&) = delete;
+
+ int64_t quota_size;
+
+ // Keeps track of the DevTools clients that have an active override.
+ std::set<int> active_override_session_ids;
+ };
+
using QuotaTableEntry = QuotaDatabase::QuotaTableEntry;
using OriginInfoTableEntry = QuotaDatabase::OriginInfoTableEntry;
using QuotaTableEntries = std::vector<QuotaTableEntry>;
@@ -444,6 +483,8 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManager
// TODO(crbug.com/1102433): Define and explain StoragePressure in the README.
void DetermineStoragePressure(int64_t free_space, int64_t total_space);
+ base::Optional<int64_t> GetQuotaOverrideForOrigin(const url::Origin&);
+
void PostTaskAndReplyWithResultForDBThread(
const base::Location& from_here,
base::OnceCallback<bool(QuotaDatabase*)> task,
@@ -482,6 +523,9 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManager
GetOriginCallback lru_origin_callback_;
std::set<url::Origin> access_notified_origins_;
+ std::map<url::Origin, QuotaOverride> devtools_overrides_;
+ int next_override_handle_id_ = 0;
+
// Owns the QuotaClient instances registered via RegisterClient().
//
// Iterating over this list is almost always incorrect. Most algorithms should
diff --git a/chromium/storage/browser/quota/quota_manager_proxy.cc b/chromium/storage/browser/quota/quota_manager_proxy.cc
index f331f574255..df7ec05bc43 100644
--- a/chromium/storage/browser/quota/quota_manager_proxy.cc
+++ b/chromium/storage/browser/quota/quota_manager_proxy.cc
@@ -8,12 +8,15 @@
#include <utility>
#include "base/bind.h"
-#include "base/bind_helpers.h"
+#include "base/callback_helpers.h"
#include "base/sequenced_task_runner.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/string_number_conversions.h"
+#include "base/task/post_task.h"
#include "base/task_runner_util.h"
+#include "base/threading/thread_task_runner_handle.h"
#include "storage/browser/quota/quota_client_type.h"
+#include "storage/browser/quota/quota_manager.h"
#include "third_party/blink/public/mojom/quota/quota_types.mojom.h"
namespace storage {
@@ -157,6 +160,30 @@ void QuotaManagerProxy::GetUsageAndQuota(
std::move(callback)));
}
+std::unique_ptr<QuotaOverrideHandle>
+QuotaManagerProxy::GetQuotaOverrideHandle() {
+ return std::make_unique<QuotaOverrideHandle>(this);
+}
+
+void QuotaManagerProxy::OverrideQuotaForOrigin(
+ int handle_id,
+ url::Origin origin,
+ base::Optional<int64_t> quota_size,
+ base::OnceClosure callback) {
+ io_thread_->PostTaskAndReply(
+ FROM_HERE,
+ base::BindOnce(&QuotaManager::OverrideQuotaForOrigin,
+ base::RetainedRef(manager_), handle_id, origin,
+ quota_size),
+ std::move(callback));
+}
+
+void QuotaManagerProxy::WithdrawOverridesForHandle(int handle_id) {
+ io_thread_->PostTask(FROM_HERE,
+ base::BindOnce(&QuotaManager::WithdrawOverridesForHandle,
+ base::RetainedRef(manager_), handle_id));
+}
+
QuotaManager* QuotaManagerProxy::quota_manager() const {
DCHECK(!io_thread_.get() || io_thread_->BelongsToCurrentThread());
return manager_;
@@ -169,4 +196,13 @@ QuotaManagerProxy::QuotaManagerProxy(
QuotaManagerProxy::~QuotaManagerProxy() = default;
+void QuotaManagerProxy::GetOverrideHandleId(
+ base::OnceCallback<void(int)> callback) {
+ io_thread_->PostTaskAndReplyWithResult(
+ FROM_HERE,
+ base::BindOnce(&QuotaManager::GetOverrideHandleId,
+ base::RetainedRef(manager_)),
+ std::move(callback));
+}
+
} // namespace storage
diff --git a/chromium/storage/browser/quota/quota_manager_proxy.h b/chromium/storage/browser/quota/quota_manager_proxy.h
index 235ee5a784c..4655f7da5cb 100644
--- a/chromium/storage/browser/quota/quota_manager_proxy.h
+++ b/chromium/storage/browser/quota/quota_manager_proxy.h
@@ -22,6 +22,7 @@
#include "storage/browser/quota/quota_client_type.h"
#include "storage/browser/quota/quota_database.h"
#include "storage/browser/quota/quota_manager.h"
+#include "storage/browser/quota/quota_override_handle.h"
#include "storage/browser/quota/quota_task.h"
#include "storage/browser/quota/special_storage_policy.h"
#include "third_party/blink/public/mojom/quota/quota_types.mojom.h"
@@ -63,6 +64,17 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerProxy
blink::mojom::StorageType type,
UsageAndQuotaCallback callback);
+ // DevTools Quota Override methods:
+ std::unique_ptr<QuotaOverrideHandle> GetQuotaOverrideHandle();
+ // Called by QuotaOverrideHandle upon construction to asynchronously
+ // fetch an id.
+ void GetOverrideHandleId(base::OnceCallback<void(int)>);
+ void OverrideQuotaForOrigin(int handle_id,
+ url::Origin origin,
+ base::Optional<int64_t> quota_size,
+ base::OnceClosure callback);
+ void WithdrawOverridesForHandle(int handle_id);
+
// This method may only be called on the IO thread.
// It may return nullptr if the manager has already been deleted.
QuotaManager* quota_manager() const;
@@ -75,6 +87,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManagerProxy
scoped_refptr<base::SingleThreadTaskRunner> io_thread);
virtual ~QuotaManagerProxy();
+ private:
QuotaManager* manager_; // only accessed on the io thread
scoped_refptr<base::SingleThreadTaskRunner> io_thread_;
diff --git a/chromium/storage/browser/quota/quota_manager_unittest.cc b/chromium/storage/browser/quota/quota_manager_unittest.cc
index 9837c45e989..434521fcd47 100644
--- a/chromium/storage/browser/quota/quota_manager_unittest.cc
+++ b/chromium/storage/browser/quota/quota_manager_unittest.cc
@@ -23,6 +23,7 @@
#include "base/run_loop.h"
#include "base/stl_util.h"
#include "base/system/sys_info.h"
+#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
@@ -448,6 +449,10 @@ class QuotaManagerTest : public testing::Test {
return mock_special_storage_policy_.get();
}
+ std::unique_ptr<QuotaOverrideHandle> GetQuotaOverrideHandle() {
+ return quota_manager_->proxy()->GetQuotaOverrideHandle();
+ }
+
QuotaStatusCode status() const { return quota_status_; }
const UsageInfoEntries& usage_info() const { return usage_info_; }
int64_t usage() const { return usage_; }
@@ -2699,4 +2704,98 @@ TEST_F(QuotaManagerTest, MaybeRunStoragePressureCallback) {
EXPECT_TRUE(callback_ran);
}
+TEST_F(QuotaManagerTest, OverrideQuotaForOrigin) {
+ url::Origin origin = ToOrigin("https://foo.com");
+ std::unique_ptr<QuotaOverrideHandle> handle = GetQuotaOverrideHandle();
+
+ base::RunLoop run_loop;
+ handle->OverrideQuotaForOrigin(
+ origin, 5000, base::BindLambdaForTesting([&]() { run_loop.Quit(); }));
+ run_loop.Run();
+
+ GetUsageAndQuotaForWebApps(origin, kTemp);
+ task_environment_.RunUntilIdle();
+ EXPECT_EQ(QuotaStatusCode::kOk, status());
+ EXPECT_EQ(0, usage());
+ EXPECT_EQ(5000, quota());
+}
+
+TEST_F(QuotaManagerTest, OverrideQuotaForOrigin_Disable) {
+ url::Origin origin = ToOrigin("https://foo.com");
+ std::unique_ptr<QuotaOverrideHandle> handle1 = GetQuotaOverrideHandle();
+ std::unique_ptr<QuotaOverrideHandle> handle2 = GetQuotaOverrideHandle();
+
+ base::RunLoop run_loop1;
+ handle1->OverrideQuotaForOrigin(
+ origin, 5000, base::BindLambdaForTesting([&]() { run_loop1.Quit(); }));
+ run_loop1.Run();
+
+ GetUsageAndQuotaForWebApps(origin, kTemp);
+ task_environment_.RunUntilIdle();
+ EXPECT_EQ(QuotaStatusCode::kOk, status());
+ EXPECT_EQ(5000, quota());
+
+ base::RunLoop run_loop2;
+ handle2->OverrideQuotaForOrigin(
+ origin, 9000, base::BindLambdaForTesting([&]() { run_loop2.Quit(); }));
+ run_loop2.Run();
+
+ GetUsageAndQuotaForWebApps(origin, kTemp);
+ task_environment_.RunUntilIdle();
+ EXPECT_EQ(QuotaStatusCode::kOk, status());
+ EXPECT_EQ(9000, quota());
+
+ base::RunLoop run_loop3;
+ handle2->OverrideQuotaForOrigin(
+ origin, base::nullopt,
+ base::BindLambdaForTesting([&]() { run_loop3.Quit(); }));
+ run_loop3.Run();
+
+ GetUsageAndQuotaForWebApps(origin, kTemp);
+ task_environment_.RunUntilIdle();
+ EXPECT_EQ(QuotaStatusCode::kOk, status());
+ EXPECT_EQ(kDefaultPerHostQuota, quota());
+}
+
+TEST_F(QuotaManagerTest, WithdrawQuotaOverride) {
+ url::Origin origin = ToOrigin("https://foo.com");
+ std::unique_ptr<QuotaOverrideHandle> handle1 = GetQuotaOverrideHandle();
+ std::unique_ptr<QuotaOverrideHandle> handle2 = GetQuotaOverrideHandle();
+
+ base::RunLoop run_loop1;
+ handle1->OverrideQuotaForOrigin(
+ origin, 5000, base::BindLambdaForTesting([&]() { run_loop1.Quit(); }));
+ run_loop1.Run();
+
+ GetUsageAndQuotaForWebApps(origin, kTemp);
+ task_environment_.RunUntilIdle();
+ EXPECT_EQ(QuotaStatusCode::kOk, status());
+ EXPECT_EQ(5000, quota());
+
+ base::RunLoop run_loop2;
+ handle1->OverrideQuotaForOrigin(
+ origin, 8000, base::BindLambdaForTesting([&]() { run_loop2.Quit(); }));
+ run_loop2.Run();
+
+ GetUsageAndQuotaForWebApps(origin, kTemp);
+ task_environment_.RunUntilIdle();
+ EXPECT_EQ(QuotaStatusCode::kOk, status());
+ EXPECT_EQ(8000, quota());
+
+ // Quota should remain overridden if only one of the two handles withdraws
+ // it's overrides
+ handle2.reset();
+ GetUsageAndQuotaForWebApps(origin, kTemp);
+ task_environment_.RunUntilIdle();
+ EXPECT_EQ(QuotaStatusCode::kOk, status());
+ EXPECT_EQ(8000, quota());
+
+ handle1.reset();
+ task_environment_.RunUntilIdle();
+ GetUsageAndQuotaForWebApps(origin, kTemp);
+ task_environment_.RunUntilIdle();
+ EXPECT_EQ(QuotaStatusCode::kOk, status());
+ EXPECT_EQ(kDefaultPerHostQuota, quota());
+}
+
} // namespace storage
diff --git a/chromium/storage/browser/quota/quota_override_handle.cc b/chromium/storage/browser/quota/quota_override_handle.cc
new file mode 100644
index 00000000000..5c9ab714678
--- /dev/null
+++ b/chromium/storage/browser/quota/quota_override_handle.cc
@@ -0,0 +1,57 @@
+// Copyright 2020 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/quota/quota_override_handle.h"
+
+#include "base/memory/scoped_refptr.h"
+#include "base/sequence_checker.h"
+#include "storage/browser/quota/quota_manager_proxy.h"
+
+namespace storage {
+
+QuotaOverrideHandle::QuotaOverrideHandle(
+ scoped_refptr<QuotaManagerProxy> quota_manager)
+ : quota_manager_(quota_manager) {
+ quota_manager_->GetOverrideHandleId(
+ base::BindOnce(&QuotaOverrideHandle::DidGetOverrideHandleId,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
+QuotaOverrideHandle::~QuotaOverrideHandle() {
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
+ if (id_.has_value()) {
+ quota_manager_->WithdrawOverridesForHandle(id_.value());
+ }
+}
+
+void QuotaOverrideHandle::OverrideQuotaForOrigin(
+ url::Origin origin,
+ base::Optional<int64_t> quota_size,
+ base::OnceClosure callback) {
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
+ if (!id_.has_value()) {
+ // base::Unretained is safe here because this class owns the callback queue
+ // and the callbacks within, so it's guaranteed to be alive when the
+ // callback is dispatched.
+ override_callback_queue_.push_back(base::BindOnce(
+ &QuotaOverrideHandle::OverrideQuotaForOrigin, base::Unretained(this),
+ origin, quota_size, std::move(callback)));
+ return;
+ }
+ quota_manager_->OverrideQuotaForOrigin(id_.value(), origin, quota_size,
+ std::move(callback));
+}
+
+void QuotaOverrideHandle::DidGetOverrideHandleId(int id) {
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
+ DCHECK(!id_.has_value());
+ id_ = base::make_optional(id);
+
+ for (auto& callback : override_callback_queue_) {
+ std::move(callback).Run();
+ }
+ override_callback_queue_.clear();
+}
+
+} // namespace storage
diff --git a/chromium/storage/browser/quota/quota_override_handle.h b/chromium/storage/browser/quota/quota_override_handle.h
new file mode 100644
index 00000000000..e7b6ec918f2
--- /dev/null
+++ b/chromium/storage/browser/quota/quota_override_handle.h
@@ -0,0 +1,51 @@
+// Copyright 2020 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_QUOTA_QUOTA_OVERRIDE_HANDLE_H_
+#define STORAGE_BROWSER_QUOTA_QUOTA_OVERRIDE_HANDLE_H_
+
+#include "base/callback_forward.h"
+#include "base/memory/scoped_refptr.h"
+#include "base/memory/weak_ptr.h"
+#include "base/sequence_checker.h"
+#include "base/sequenced_task_runner.h"
+#include "url/origin.h"
+
+namespace storage {
+
+class QuotaManagerProxy;
+
+// Used by DevTools clients and exposes the API to override and/or
+// manage an active override for storage quota on a per-origin basis.
+// QuotaOverrideHandle instances are owned by StorageHandler (DevTools client),
+// and each DevTools session will have at most 1 instance.
+// This class is not thread-safe. An instance must always be used from the same
+// sequence. However, this sequence can be different from the one that
+// QuotaManager lives on.
+class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaOverrideHandle {
+ public:
+ explicit QuotaOverrideHandle(scoped_refptr<QuotaManagerProxy> quota_manager);
+ ~QuotaOverrideHandle();
+ QuotaOverrideHandle(const QuotaOverrideHandle&) = delete;
+
+ void OverrideQuotaForOrigin(url::Origin origin,
+ base::Optional<int64_t> quota_size,
+ base::OnceClosure callback);
+
+ private:
+ void GetUniqueId();
+ void DidGetUniqueId();
+ void DidGetOverrideHandleId(int id);
+
+ base::Optional<int> id_;
+ std::vector<base::OnceClosure> override_callback_queue_;
+ scoped_refptr<QuotaManagerProxy> quota_manager_;
+
+ SEQUENCE_CHECKER(sequence_checker_);
+ base::WeakPtrFactory<QuotaOverrideHandle> weak_ptr_factory_{this};
+};
+
+} // namespace storage
+
+#endif // STORAGE_BROWSER_QUOTA_QUOTA_OVERRIDE_HANDLE_
diff --git a/chromium/storage/browser/quota/quota_settings.cc b/chromium/storage/browser/quota/quota_settings.cc
index 27c280b3638..4b8ac29b314 100644
--- a/chromium/storage/browser/quota/quota_settings.cc
+++ b/chromium/storage/browser/quota/quota_settings.cc
@@ -28,6 +28,8 @@ const int64_t kMBytes = 1024 * 1024;
const int kRandomizedPercentage = 10;
const double kDefaultPerHostRatio = 0.75;
const double kDefaultPoolSizeRatio = 0.8;
+const double kIncognitoQuotaRatioLowerBound = 0.15;
+const double kIncognitoQuotaRatioUpperBound = 0.2;
// Skews |value| by +/- |percent|.
int64_t RandomizeByPercent(int64_t value, int percent) {
@@ -37,25 +39,15 @@ int64_t RandomizeByPercent(int64_t value, int percent) {
QuotaSettings CalculateIncognitoDynamicSettings(
int64_t physical_memory_amount) {
- // The incognito pool size is a fraction of the amount of system memory,
- // and the amount is capped to a hard limit.
- double incognito_pool_size_ratio = 0.1; // 10%
- int64_t max_incognito_pool_size = 300 * kMBytes;
- if (base::FeatureList::IsEnabled(features::kIncognitoDynamicQuota)) {
- const double lower_bound = features::kIncognitoQuotaRatioLowerBound.Get();
- const double upper_bound = features::kIncognitoQuotaRatioUpperBound.Get();
- incognito_pool_size_ratio =
- lower_bound + (base::RandDouble() * (upper_bound - lower_bound));
- max_incognito_pool_size = std::numeric_limits<int64_t>::max();
- } else {
- max_incognito_pool_size =
- RandomizeByPercent(max_incognito_pool_size, kRandomizedPercentage);
- }
+ // The incognito pool size is a fraction of the amount of system memory.
+ double incognito_pool_size_ratio =
+ kIncognitoQuotaRatioLowerBound +
+ (base::RandDouble() *
+ (kIncognitoQuotaRatioUpperBound - kIncognitoQuotaRatioLowerBound));
QuotaSettings settings;
- settings.pool_size = std::min(
- max_incognito_pool_size,
- static_cast<int64_t>(physical_memory_amount * incognito_pool_size_ratio));
+ settings.pool_size =
+ static_cast<int64_t>(physical_memory_amount * incognito_pool_size_ratio);
settings.per_host_quota = settings.pool_size / 3;
settings.session_only_per_host_quota = settings.per_host_quota;
settings.refresh_interval = base::TimeDelta::Max();
@@ -163,4 +155,11 @@ QuotaDeviceInfoHelper* GetDefaultDeviceInfoHelper() {
return singleton.get();
}
+double GetIncognitoQuotaRatioLowerBound_ForTesting() {
+ return kIncognitoQuotaRatioLowerBound;
+}
+double GetIncognitoQuotaRatioUpperBound_ForTesting() {
+ return kIncognitoQuotaRatioUpperBound;
+}
+
} // namespace storage
diff --git a/chromium/storage/browser/quota/quota_settings.h b/chromium/storage/browser/quota/quota_settings.h
index c01ce6dcf82..971adebed31 100644
--- a/chromium/storage/browser/quota/quota_settings.h
+++ b/chromium/storage/browser/quota/quota_settings.h
@@ -96,6 +96,11 @@ inline QuotaSettings GetHardCodedSettings(int64_t per_host_quota) {
per_host_quota, per_host_quota);
}
+COMPONENT_EXPORT(STORAGE_BROWSER)
+double GetIncognitoQuotaRatioLowerBound_ForTesting();
+COMPONENT_EXPORT(STORAGE_BROWSER)
+double GetIncognitoQuotaRatioUpperBound_ForTesting();
+
// Returns object that can fetch actual total disk space; instance lives
// as long as the process is a live.
COMPONENT_EXPORT(STORAGE_BROWSER)
diff --git a/chromium/storage/browser/quota/quota_settings_unittest.cc b/chromium/storage/browser/quota/quota_settings_unittest.cc
index 25ae21522c9..2654212f214 100644
--- a/chromium/storage/browser/quota/quota_settings_unittest.cc
+++ b/chromium/storage/browser/quota/quota_settings_unittest.cc
@@ -8,7 +8,7 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/files/scoped_temp_dir.h"
-#include "base/test/bind_test_util.h"
+#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "storage/browser/quota/quota_device_info_helper.h"
@@ -20,16 +20,8 @@ using ::testing::_;
namespace {
-constexpr int64_t kMBytes = 1024 * 1024;
-
-// 10% is the non-experimental incognito pool size ratio
-// as defined in storage/browser/quota/quota_settings.cc line 37.
-constexpr double kIncognitoPoolSizeRatio = 0.1;
-
-// 300 MB + 10% is the max incognito pool size as set in
-// storage/browser/quota/quota_settings.cc line 48.
-constexpr int64_t kMaxIncognitoPoolSize =
- (300 + 300 * kIncognitoPoolSizeRatio) * kMBytes;
+constexpr int64_t kLowPhysicalMemory = 1024 * 1024;
+constexpr int64_t kHighPhysicalMemory = 65536 * kLowPhysicalMemory;
} // namespace
@@ -71,40 +63,18 @@ class QuotaSettingsIncognitoTest : public QuotaSettingsTest {
.Times(expected_calls);
}
- void EnableFeature() {
- scoped_feature_list_.Reset();
- scoped_feature_list_.InitAndEnableFeatureWithParameters(
- features::kIncognitoDynamicQuota,
- {{"IncognitoQuotaRatioLowerBound", ratio_lower_bound_},
- {"IncognitoQuotaRatioUpperBound", ratio_upper_bound_}});
- }
-
- void DisableFeature() {
- scoped_feature_list_.Reset();
- scoped_feature_list_.InitAndDisableFeature(
- features::kIncognitoDynamicQuota);
- }
-
- void GetAndTestExperimentalSettings(const int64_t physical_memory_amount) {
- bool callback_executed = false;
- GetNominalDynamicSettings(
- profile_path(), true, device_info_helper(),
- base::BindLambdaForTesting([&](base::Optional<QuotaSettings> settings) {
- callback_executed = true;
- EXPECT_LE(physical_memory_amount * 0.2, settings->pool_size);
- EXPECT_GE(physical_memory_amount * 0.3, settings->pool_size);
- }));
- task_environment_.RunUntilIdle();
- EXPECT_TRUE(callback_executed);
- }
-
- void GetAndTestDefaultSettings() {
+ void GetAndTestSettings(const int64_t physical_memory_amount) {
bool callback_executed = false;
GetNominalDynamicSettings(
profile_path(), true, device_info_helper(),
base::BindLambdaForTesting([&](base::Optional<QuotaSettings> settings) {
callback_executed = true;
- EXPECT_GE(kMaxIncognitoPoolSize, settings->pool_size);
+ EXPECT_LE(physical_memory_amount *
+ GetIncognitoQuotaRatioLowerBound_ForTesting(),
+ settings->pool_size);
+ EXPECT_GE(physical_memory_amount *
+ GetIncognitoQuotaRatioUpperBound_ForTesting(),
+ settings->pool_size);
}));
task_environment_.RunUntilIdle();
EXPECT_TRUE(callback_executed);
@@ -116,8 +86,6 @@ class QuotaSettingsIncognitoTest : public QuotaSettingsTest {
private:
MockQuotaDeviceInfoHelper device_info_helper_;
- std::string ratio_lower_bound_ = "0.2";
- std::string ratio_upper_bound_ = "0.3";
};
TEST_F(QuotaSettingsTest, Default) {
@@ -140,64 +108,18 @@ TEST_F(QuotaSettingsTest, Default) {
EXPECT_TRUE(callback_executed);
}
-TEST_F(QuotaSettingsTest, IncognitoQuotaCapped) {
- MockQuotaDeviceInfoHelper device_info_helper;
- EXPECT_CALL(device_info_helper, AmountOfPhysicalMemory()).Times(1);
- ON_CALL(device_info_helper, AmountOfPhysicalMemory())
- .WillByDefault(::testing::Return(kMaxIncognitoPoolSize));
-
- scoped_feature_list_.InitAndDisableFeature(features::kIncognitoDynamicQuota);
- bool callback_executed = false;
- GetNominalDynamicSettings(
- profile_path(), true, &device_info_helper,
- base::BindLambdaForTesting([&](base::Optional<QuotaSettings> settings) {
- callback_executed = true;
- EXPECT_GE(kMaxIncognitoPoolSize, settings->pool_size);
- }));
- task_environment_.RunUntilIdle();
- EXPECT_TRUE(callback_executed);
-}
-
-TEST_F(QuotaSettingsIncognitoTest, IncognitoDynamicQuota_BelowStaticLimit) {
- const int expected_device_info_calls = 2;
- const int64_t physical_memory_amount = 1000 * kMBytes;
- static_assert(
- physical_memory_amount * kIncognitoPoolSizeRatio < kMaxIncognitoPoolSize,
- "10% of physical_memory_amount should be less than "
- "kMaxIncognitoPoolSize");
-
- SetUpDeviceInfoHelper(expected_device_info_calls, physical_memory_amount);
- EnableFeature();
- GetAndTestExperimentalSettings(physical_memory_amount);
- DisableFeature();
- GetAndTestDefaultSettings();
-}
+TEST_F(QuotaSettingsIncognitoTest, IncognitoDynamicQuota_LowPhysicalMemory) {
+ const int expected_device_info_calls = 1;
-TEST_F(QuotaSettingsIncognitoTest, IncognitoDynamicQuota_AtStaticLimit) {
- const int expected_device_info_calls = 2;
- const int64_t physical_memory_amount = 3300 * kMBytes;
- static_assert(physical_memory_amount * 0.1 == kMaxIncognitoPoolSize,
- "10% of physical_memory_amount should be equal to "
- "kMaxIncognitoPoolSize");
-
- SetUpDeviceInfoHelper(expected_device_info_calls, physical_memory_amount);
- EnableFeature();
- GetAndTestExperimentalSettings(physical_memory_amount);
- DisableFeature();
- GetAndTestDefaultSettings();
+ SetUpDeviceInfoHelper(expected_device_info_calls, kLowPhysicalMemory);
+ GetAndTestSettings(kLowPhysicalMemory);
}
-TEST_F(QuotaSettingsIncognitoTest, IncognitoDynamicQuota_AboveStaticLimit) {
+TEST_F(QuotaSettingsIncognitoTest, IncognitoDynamicQuota_HighPhysicalMemory) {
const int expected_device_info_calls = 1;
- const int64_t physical_memory_amount = 10000 * kMBytes;
- static_assert(
- physical_memory_amount * kIncognitoPoolSizeRatio > kMaxIncognitoPoolSize,
- "10% of physical_memory_amount should "
- "be greater than kMaxIncognitoPoolSize");
-
- SetUpDeviceInfoHelper(expected_device_info_calls, physical_memory_amount);
- EnableFeature();
- GetAndTestExperimentalSettings(physical_memory_amount);
+
+ SetUpDeviceInfoHelper(expected_device_info_calls, kHighPhysicalMemory);
+ GetAndTestSettings(kHighPhysicalMemory);
}
} // namespace storage
diff --git a/chromium/storage/browser/quota/usage_tracker_unittest.cc b/chromium/storage/browser/quota/usage_tracker_unittest.cc
index df85bd1a87c..c3016b801d0 100644
--- a/chromium/storage/browser/quota/usage_tracker_unittest.cc
+++ b/chromium/storage/browser/quota/usage_tracker_unittest.cc
@@ -10,6 +10,7 @@
#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/test/task_environment.h"
@@ -117,7 +118,7 @@ class UsageTrackerTestQuotaClient : public QuotaClient {
class UsageTrackerTest : public testing::Test {
public:
UsageTrackerTest()
- : storage_policy_(new MockSpecialStoragePolicy()),
+ : storage_policy_(base::MakeRefCounted<MockSpecialStoragePolicy>()),
quota_client_(base::MakeRefCounted<UsageTrackerTestQuotaClient>()),
usage_tracker_(GetQuotaClientMap(),
StorageType::kTemporary,
diff --git a/chromium/storage/common/database/DIR_METADATA b/chromium/storage/common/database/DIR_METADATA
new file mode 100644
index 00000000000..f337a384213
--- /dev/null
+++ b/chromium/storage/common/database/DIR_METADATA
@@ -0,0 +1,12 @@
+# Metadata information for this directory.
+#
+# For more information on DIR_METADATA files, see:
+# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/README.md
+#
+# For the schema of this file, see Metadata message:
+# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/proto/dir_metadata.proto
+
+monorail {
+ component: "Blink>Storage>WebSQL"
+}
+team_email: "storage-dev@chromium.org" \ No newline at end of file
diff --git a/chromium/storage/common/database/OWNERS b/chromium/storage/common/database/OWNERS
index 50969733054..e69de29bb2d 100644
--- a/chromium/storage/common/database/OWNERS
+++ b/chromium/storage/common/database/OWNERS
@@ -1,2 +0,0 @@
-# TEAM: storage-dev@chromium.org
-# COMPONENT: Blink>Storage>WebSQL
diff --git a/chromium/storage/common/file_system/DIR_METADATA b/chromium/storage/common/file_system/DIR_METADATA
new file mode 100644
index 00000000000..e704db93ca3
--- /dev/null
+++ b/chromium/storage/common/file_system/DIR_METADATA
@@ -0,0 +1,12 @@
+# Metadata information for this directory.
+#
+# For more information on DIR_METADATA files, see:
+# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/README.md
+#
+# For the schema of this file, see Metadata message:
+# https://source.chromium.org/chromium/infra/infra/+/master:go/src/infra/tools/dirmd/proto/dir_metadata.proto
+
+monorail {
+ component: "Blink>Storage>FileSystem"
+}
+team_email: "storage-dev@chromium.org" \ No newline at end of file
diff --git a/chromium/storage/common/file_system/OWNERS b/chromium/storage/common/file_system/OWNERS
index ea2b5772218..d872f10c932 100644
--- a/chromium/storage/common/file_system/OWNERS
+++ b/chromium/storage/common/file_system/OWNERS
@@ -3,6 +3,3 @@ nhiroki@chromium.org
per-file *_type_converter*.*=set noparent
per-file *_type_converter*.*=file://ipc/SECURITY_OWNERS
-
-# TEAM: storage-dev@chromium.org
-# COMPONENT: Blink>Storage>FileSystem