Commit d9e64e11 authored by Lexi Stavrakos's avatar Lexi Stavrakos Committed by Commit Bot

Quota: Implement DetermineStoragePressure().

This function will allow QuotaManager to identify the state of
storage pressure when given information about disk capacity and usage.
QuotaManager will ultimately use this signal to dispatch a storage pressure event to script.

This change also moves the kStoragePressureEvent flag from content_features to quota_features so that it can be accessed from quota code, and content can never be included in storage.
This flag will remain accessible from content.

Design Doc: https://docs.google.com/document/d/1-ZzFe7ITnzW-G7uymhv_obPwfQjJwzA6wh10tfl5tCw/edit

Bug: 1088004
Change-Id: I84387f0599dde3404ffbae9014bf389bd0039ba0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2252032
Commit-Queue: Lexi Stavrakos <astavrakos@google.com>
Reviewed-by: default avatarJarryd Goodman <jarrydg@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarDarwin Huang <huangdarwin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790575}
parent d983c6ef
......@@ -164,6 +164,7 @@
#include "services/media_session/public/cpp/features.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/cpp/network_switches.h"
#include "storage/browser/quota/quota_features.h"
#include "third_party/blink/public/common/experiments/memory_ablation_experiment.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/forcedark/forcedark_switches.h"
......@@ -3995,7 +3996,7 @@ const FeatureEntry kFeatureEntries[] = {
{"enable-storage-pressure-event",
flag_descriptions::kStoragePressureEventName,
flag_descriptions::kStoragePressureEventDescription, kOsAll,
FEATURE_VALUE_TYPE(features::kStoragePressureEvent)},
FEATURE_VALUE_TYPE(storage::features::kStoragePressureEvent)},
{"enable-storage-pressure-ui", flag_descriptions::kStoragePressureUIName,
flag_descriptions::kStoragePressureUIDescription, kOsAll,
......
......@@ -624,10 +624,6 @@ const base::Feature kSiteIsolationEnforcementForFileSystemApi{
const base::Feature kSpareRendererForSitePerProcess{
"SpareRendererForSitePerProcess", base::FEATURE_ENABLED_BY_DEFAULT};
// Enables Storage Pressure Event.
const base::Feature kStoragePressureEvent{"StoragePressureEvent",
base::FEATURE_DISABLED_BY_DEFAULT};
// Enables Storage Pressure notifications and settings pages.
const base::Feature kStoragePressureUI {
"StoragePressureUI",
......
......@@ -136,7 +136,6 @@ CONTENT_EXPORT extern const base::Feature
kSiteIsolationEnforcementForFileSystemApi;
CONTENT_EXPORT extern const base::Feature kSmsReceiver;
CONTENT_EXPORT extern const base::Feature kSpareRendererForSitePerProcess;
CONTENT_EXPORT extern const base::Feature kStoragePressureEvent;
CONTENT_EXPORT extern const base::Feature kStoragePressureUI;
CONTENT_EXPORT extern const base::Feature kStorageServiceOutOfProcess;
CONTENT_EXPORT extern const base::Feature kStorageServiceSandbox;
......
......@@ -37,5 +37,9 @@ constexpr base::FeatureParam<double> kIncognitoQuotaRatioLowerBound{
constexpr base::FeatureParam<double> kIncognitoQuotaRatioUpperBound{
&kIncognitoDynamicQuota, "IncognitoQuotaRatioUpperBound", 0.2};
// Enables Storage Pressure Event.
const base::Feature kStoragePressureEvent{"StoragePressureEvent",
base::FEATURE_DISABLED_BY_DEFAULT};
} // namespace features
} // namespace storage
......@@ -26,6 +26,9 @@ 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
} // namespace storage
......
......@@ -17,11 +17,11 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/files/file_util.h"
#include "base/macros.h"
#include "base/metrics/histogram_macros.h"
#include "base/numerics/safe_conversions.h"
#include "base/rand_util.h"
#include "base/sequence_checker.h"
#include "base/sequenced_task_runner.h"
#include "base/single_thread_task_runner.h"
......@@ -60,6 +60,12 @@ constexpr double kStoragePressureThresholdRatio = 2;
constexpr base::TimeDelta kStoragePressureCheckDiskStatsInterval =
base::TimeDelta::FromMinutes(5);
// Modifies a given value by a uniformly random amount from
// -percent to +percent.
int64_t RandomizeByPercent(int64_t value, int percent) {
double random_percent = (base::RandDouble() - 0.5) * percent * 2;
return value * (1 + (random_percent / 100.0));
}
} // namespace
// Heuristics: assuming average cloud server allows a few Gigs storage
......@@ -185,10 +191,12 @@ void DidGetUsageAndQuotaStripBreakdown(
} // namespace
constexpr int64_t QuotaManager::kGBytes;
constexpr int64_t QuotaManager::kNoLimit;
constexpr int64_t QuotaManager::kPerHostPersistentQuotaLimit;
constexpr int QuotaManager::kEvictionIntervalInMilliSeconds;
constexpr int QuotaManager::kThresholdOfErrorsToBeDenylisted;
constexpr int QuotaManager::kThresholdRandomizationPercent;
constexpr char QuotaManager::kDatabaseName[];
constexpr char QuotaManager::kDaysBetweenRepeatedOriginEvictionsHistogram[];
constexpr char QuotaManager::kEvictedOriginAccessedCountHistogram[];
......@@ -1485,6 +1493,25 @@ void QuotaManager::SimulateStoragePressure(const url::Origin origin) {
storage_pressure_callback_.Run(origin);
}
void QuotaManager::DetermineStoragePressure(int64_t free_space,
int64_t total_space) {
if (!base::FeatureList::IsEnabled(features::kStoragePressureEvent)) {
return;
}
int64_t threshold_bytes =
RandomizeByPercent(kGBytes, kThresholdRandomizationPercent);
int64_t threshold = RandomizeByPercent(
static_cast<int64_t>(total_space *
(kThresholdRandomizationPercent / 100.0)),
kThresholdRandomizationPercent);
threshold = std::min(threshold_bytes, threshold);
if (free_space < threshold) {
// TODO(https://crbug.com/1096549): Implement StoragePressureEvent
// dispatching.
}
}
void QuotaManager::SetStoragePressureCallback(
base::RepeatingCallback<void(url::Origin)> storage_pressure_callback) {
storage_pressure_callback_ = storage_pressure_callback;
......
......@@ -121,6 +121,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManager
int64_t quota,
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;
static constexpr int kMinutesInMilliSeconds = 60 * 1000;
......@@ -260,6 +261,7 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManager
static constexpr int kEvictionIntervalInMilliSeconds =
30 * kMinutesInMilliSeconds;
static constexpr int kThresholdOfErrorsToBeDenylisted = 3;
static constexpr int kThresholdRandomizationPercent = 5;
static constexpr char kDatabaseName[] = "QuotaManager";
static constexpr char kDaysBetweenRepeatedOriginEvictionsHistogram[] =
......@@ -433,6 +435,14 @@ class COMPONENT_EXPORT(STORAGE_BROWSER) QuotaManager
// callback.
void SimulateStoragePressure(const url::Origin origin);
// Evaluates disk statistics to identify storage pressure
// (low disk space availability) and starts the storage
// pressure event dispatch if appropriate.
// TODO(crbug.com/1088004): Implement UsageAndQuotaInfoGatherer::Completed()
// to use DetermineStoragePressure().
// TODO(crbug.com/1102433): Define and explain StoragePressure in the README.
void DetermineStoragePressure(int64_t free_space, int64_t total_space);
void PostTaskAndReplyWithResultForDBThread(
const base::Location& from_here,
base::OnceCallback<bool(QuotaDatabase*)> task,
......
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