Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(722)

Unified Diff: storage/browser/quota/quota_settings.cc

Issue 2777183010: [Quota] Lower quota for ephemeral mode (ie. session only) (Closed)
Patch Set: comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « storage/browser/quota/quota_settings.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..d428822d61c370d75650c1165fa15482cc2f7345 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 * 2;
+ return value + (value * (random_percent / 100.0));
+}
+
+} // anonymous namespace
+
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;
}
« no previous file with comments | « storage/browser/quota/quota_settings.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698