Commit 57c1df38 authored by Jarryd's avatar Jarryd Committed by Commit Bot

Quota: Update the quota returned to origins with unlimitedStorage.

For origins with unlimitedStorage permission, the Quota system will now return
available disk space + usage by origin as the quota for that origin.

Change-Id: Ic49b0488c35c0396fbfc1754da2fba063f38452e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1736002
Commit-Queue: Jarryd Goodman <jarrydg@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#684168}
parent 2dd7ac85
......@@ -271,20 +271,23 @@ class QuotaManager::UsageAndQuotaInfoGatherer : public QuotaTask {
weak_factory_.InvalidateWeakPtrs();
int64_t host_quota = desired_host_quota_;
if (!base::FeatureList::IsEnabled(features::kStaticHostQuota)) {
// Constrain the desired |host_quota| to something that fits.
// If available space is too low, cap usage at current levels.
// If it's close to being too low, cap growth to avoid it getting too low.
int64_t temp_pool_free_space =
std::max(static_cast<int64_t>(0),
available_space_ - settings_.must_remain_available);
host_quota = std::min(host_quota, temp_pool_free_space + host_usage_);
int64_t temp_pool_free_space =
std::max(static_cast<int64_t>(0),
available_space_ - settings_.must_remain_available);
// Constrain the desired |host_quota| to something that fits.
if (host_quota > temp_pool_free_space) {
if (is_unlimited_) {
host_quota = available_space_ + host_usage_;
} else if (!base::FeatureList::IsEnabled(features::kStaticHostQuota)) {
host_quota = temp_pool_free_space + host_usage_;
}
}
std::move(callback_).Run(blink::mojom::QuotaStatusCode::kOk, host_usage_,
host_quota, std::move(host_usage_breakdown_));
if (type_ == StorageType::kTemporary && !is_incognito_ && !is_unlimited_) {
if (type_ == StorageType::kTemporary && !is_incognito_ &&
!is_unlimited_) {
UMA_HISTOGRAM_MBYTES("Quota.QuotaForOrigin", host_quota);
UMA_HISTOGRAM_MBYTES("Quota.UsageByOrigin", host_usage_);
if (host_quota > 0) {
......
......@@ -694,6 +694,7 @@ TEST_F(QuotaManagerTest, GetUsage_MultipleClients) {
{ "http://unlimited/", kTemp, 512 },
};
mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/"));
GetStorageCapacity();
RegisterClient(
CreateClient(kData1, base::size(kData1), QuotaClient::kFileSystem));
RegisterClient(
......@@ -719,13 +720,13 @@ TEST_F(QuotaManagerTest, GetUsage_MultipleClients) {
scoped_task_environment_.RunUntilIdle();
EXPECT_EQ(QuotaStatusCode::kOk, status());
EXPECT_EQ(512, usage());
EXPECT_EQ(kAvailableSpaceForApp + usage(), quota());
EXPECT_EQ(available_space() + usage(), quota());
GetUsageAndQuotaForWebApps(ToOrigin("http://unlimited/"), kPerm);
scoped_task_environment_.RunUntilIdle();
EXPECT_EQ(QuotaStatusCode::kOk, status());
EXPECT_EQ(8, usage());
EXPECT_EQ(kAvailableSpaceForApp + usage(), quota());
EXPECT_EQ(available_space() + usage(), quota());
GetGlobalUsage(kTemp);
scoped_task_environment_.RunUntilIdle();
......@@ -1041,6 +1042,7 @@ TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Unlimited) {
{ "http://unlimited/", kTemp, 4000 },
};
mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/"));
GetStorageCapacity();
MockStorageClient* client =
CreateClient(kData, base::size(kData), QuotaClient::kFileSystem);
RegisterClient(client);
......@@ -1048,7 +1050,6 @@ TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Unlimited) {
// Test when not overbugdet.
const int kPerHostQuotaFor1000 = 200;
SetQuotaSettings(1000, kPerHostQuotaFor1000, kMustRemainAvailableForSystem);
GetGlobalUsage(kTemp);
scoped_task_environment_.RunUntilIdle();
EXPECT_EQ(10 + 50 + 4000, usage());
......@@ -1070,7 +1071,7 @@ TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Unlimited) {
scoped_task_environment_.RunUntilIdle();
EXPECT_EQ(QuotaStatusCode::kOk, status());
EXPECT_EQ(4000, usage());
EXPECT_EQ(kAvailableSpaceForApp + usage(), quota());
EXPECT_EQ(available_space() + usage(), quota());
GetUsageAndQuotaForStorageClient(ToOrigin("http://unlimited/"), kTemp);
scoped_task_environment_.RunUntilIdle();
......@@ -1098,7 +1099,7 @@ TEST_F(QuotaManagerTest, GetTemporaryUsageAndQuota_Unlimited) {
scoped_task_environment_.RunUntilIdle();
EXPECT_EQ(QuotaStatusCode::kOk, status());
EXPECT_EQ(4000, usage());
EXPECT_EQ(kAvailableSpaceForApp + usage(), quota());
EXPECT_EQ(available_space() + usage(), quota());
GetUsageAndQuotaForStorageClient(ToOrigin("http://unlimited/"), kTemp);
scoped_task_environment_.RunUntilIdle();
......@@ -1190,6 +1191,7 @@ TEST_F(QuotaManagerTest, GetAndSetPerststentHostQuota) {
}
TEST_F(QuotaManagerTest, GetAndSetPersistentUsageAndQuota) {
GetStorageCapacity();
RegisterClient(CreateClient(nullptr, 0, QuotaClient::kFileSystem));
GetUsageAndQuotaForWebApps(ToOrigin("http://foo.com/"), kPerm);
......@@ -1209,7 +1211,7 @@ TEST_F(QuotaManagerTest, GetAndSetPersistentUsageAndQuota) {
mock_special_storage_policy()->AddUnlimited(GURL("http://unlimited/"));
GetUsageAndQuotaForWebApps(ToOrigin("http://unlimited/"), kPerm);
scoped_task_environment_.RunUntilIdle();
EXPECT_EQ(kAvailableSpaceForApp, quota());
EXPECT_EQ(available_space() + usage(), quota());
// GetUsageAndQuotaForStorageClient should just return 0 usage and
// kNoLimit quota.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment