Chromium Code Reviews| Index: storage/browser/quota/quota_settings.cc |
| diff --git a/storage/browser/quota/quota_settings.cc b/storage/browser/quota/quota_settings.cc |
| index 97daf843933b9d6bb861b010738b96352669b26d..e76e885a7004d28fc5fff754f6d10d5539c41e89 100644 |
| --- a/storage/browser/quota/quota_settings.cc |
| +++ b/storage/browser/quota/quota_settings.cc |
| @@ -7,6 +7,7 @@ |
| #include <algorithm> |
| #include "base/metrics/histogram_macros.h" |
| +#include "base/rand_util.h" |
| #include "base/sys_info.h" |
| #define UMA_HISTOGRAM_MBYTES(name, sample) \ |
| @@ -15,16 +16,35 @@ |
| namespace storage { |
| +namespace { |
| + |
| +// Skews |value| by +/- |percent|. |
| +int64_t RandomizeByPercent(int64_t value, int percent) { |
| + double random_percent = (base::RandDouble() - 0.5) * percent; |
|
jsbell
2017/04/07 23:48:58
Since this is *half* of the percentage, maybe * 2
michaeln
2017/04/11 01:06:07
Done, but it's an additional multiply :)
|
| + return value + (value * (random_percent / 50.0)); |
| +} |
| + |
| +} // anon namespace |
|
jsbell
2017/04/07 23:48:58
nit: don't abbreviate anonymous (looks like you di
michaeln
2017/04/11 01:06:07
Done.
|
| + |
| base::Optional<storage::QuotaSettings> CalculateNominalDynamicSettings( |
| const base::FilePath& partition_path, |
| bool is_incognito) { |
| const int64_t kMBytes = 1024 * 1024; |
| + const int kRandomizedPercentage = 10; |
| if (is_incognito) { |
| + // The incognito pool size is a fraction of the amount of system memory, |
| + // and the amount is capped to a hard limit. |
| + const double kIncognitoPoolSizeRatio = 0.1; // 10% |
| + const int64_t kMaxIncognitoPoolSize = 300 * kMBytes; |
| + |
| storage::QuotaSettings settings; |
| - settings.pool_size = |
| - std::min(300 * kMBytes, base::SysInfo::AmountOfPhysicalMemory() / 10); |
| + settings.pool_size = std::min( |
| + RandomizeByPercent(kMaxIncognitoPoolSize, kRandomizedPercentage), |
| + static_cast<int64_t>(base::SysInfo::AmountOfPhysicalMemory() * |
| + kIncognitoPoolSizeRatio)); |
| settings.per_host_quota = settings.pool_size / 3; |
| + settings.session_only_per_host_quota = settings.per_host_quota; |
| settings.refresh_interval = base::TimeDelta::Max(); |
| return settings; |
| } |
| @@ -46,6 +66,11 @@ base::Optional<storage::QuotaSettings> CalculateNominalDynamicSettings( |
| // utilized by a single host (ie. 5 for 20%). |
| const int kPerHostTemporaryPortion = 5; |
| + // SessionOnly (or ephemeral) origins are allotted a fraction of what |
| + // normal origins are provided, and the amount is capped to a hard limit. |
| + const double kSessionOnlyHostQuotaRatio = 0.1; // 10% |
| + const int64_t kMaxSessionOnlyHostQuota = 300 * kMBytes; |
| + |
| // os_accomodation is an estimate of how much storage is needed for |
| // the os and essential application code outside of the browser. |
| const int64_t kDefaultOSAccomodation = |
| @@ -81,6 +106,10 @@ base::Optional<storage::QuotaSettings> CalculateNominalDynamicSettings( |
| settings.should_remain_available = total * kShouldRemainAvailableRatio; |
| settings.must_remain_available = total * kMustRemainAvailableRatio; |
| settings.per_host_quota = pool_size / kPerHostTemporaryPortion; |
| + settings.session_only_per_host_quota = std::min( |
| + RandomizeByPercent(kMaxSessionOnlyHostQuota, kRandomizedPercentage), |
| + static_cast<int64_t>(settings.per_host_quota * |
| + kSessionOnlyHostQuotaRatio)); |
| settings.refresh_interval = base::TimeDelta::FromSeconds(60); |
| return settings; |
| } |