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

Unified Diff: storage/browser/quota/quota_manager.h

Issue 1782053004: Change how the quota system computes the total poolsize for temporary storage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: big delta Created 4 years, 2 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
Index: storage/browser/quota/quota_manager.h
diff --git a/storage/browser/quota/quota_manager.h b/storage/browser/quota/quota_manager.h
index a1ef11d2a55fbdeb64aa37463f469d6fa92ef775..ecf8a2666e0755827fee4ab3ba5b9174bda7c46a 100644
--- a/storage/browser/quota/quota_manager.h
+++ b/storage/browser/quota/quota_manager.h
@@ -60,19 +60,43 @@ class UsageTracker;
struct QuotaManagerDeleter;
-struct STORAGE_EXPORT UsageAndQuota {
- int64_t usage;
- int64_t global_limited_usage;
- int64_t quota;
- int64_t available_disk_space;
-
- UsageAndQuota();
- UsageAndQuota(int64_t usage,
- int64_t global_limited_usage,
- int64_t quota,
- int64_t available_disk_space);
+// todo: new file temporary_storage_configuration.h
+// Configuration parameters the storage lib embedder must provide
+// to the QuotaManager.
+struct TemporaryStorageConfiguration {
+ TemporaryStorageConfiguration() = default;
+
+ // The target size in bytes of the shared pool of disk space the quota
+ // system allows for use by by websites using HTML5 storage apis, for
+ // example an embedder may use 50% of the total volume size.
+ int64_t pool_size = 0;
+
+ // The amount in bytes of the pool an individual site may consume. The
+ // value must be less than or equal to the pool_size.
+ int64_t per_host_quota = 0;
+
+ // The amount of space that must remain available on the storage
+ // volume. As the volume approaches this limit, the quota system gets
+ // more aggressive about evicting data and disallowing new data.
+ int64_t must_remain_available = 0;
+
+ // The quota system querries the embedder for the TemporaryPoolConfiguration,
+ // but will rate limit the frequency of the querries to no more than once
+ // per refresh interval.
+ base::TimeDelta refresh_interval = base::TimeDelta::Max();
};
+// Function type used to return the temp storage config in response to a
+// GetTemporaryStorageConfigurationFunc invocation.
+using TemporaryStorageConfigurationCallback =
+ base::Callback<void(const TemporaryStorageConfiguration&)>;
+
+// Function type used to query the embedder about the temporary pool
+// configuration. This function is invoked on the UI thread.
+using GetTemporaryStorageConfigurationFunc = base::Callback<
+ void(const base::FilePath& partition_path, bool is_incognito,
+ const TemporaryStorageConfigurationCallback& callback)>;
+
// TODO(calamity): Use this in the temporary storage eviction path.
// An interface for deciding which origin's storage should be evicted when the
// quota is exceeded.
@@ -93,11 +117,16 @@ class STORAGE_EXPORT QuotaEvictionPolicy {
// An interface called by QuotaTemporaryStorageEvictor.
class STORAGE_EXPORT QuotaEvictionHandler {
public:
- using EvictOriginDataCallback = StatusCallback;
- using UsageAndQuotaCallback = base::Callback<
- void(QuotaStatusCode status, const UsageAndQuota& usage_and_quota)>;
- using VolumeInfoCallback = base::Callback<
- void(bool success, uint64_t available_space, uint64_t total_space)>;
+ using EvictionRoundInfoCallback = base::Callback<
+ void(QuotaStatusCode status, const TemporaryStorageConfiguration& config,
+ int64_t available_space, int64_t total_space,
+ int64_t global_usage, bool global_usage_is_complete)>;
+
+ // Called at the beginning of an eviction round to gather the info about
+ // the current configuration and usage.
+ virtual void GetEvictionRoundInfo(
+ const EvictionRoundInfoCallback& callback) = 0;
+
// Returns next origin to evict. It might return an empty GURL when there are
// no evictable origins.
@@ -106,14 +135,11 @@ class STORAGE_EXPORT QuotaEvictionHandler {
int64_t global_quota,
const GetOriginCallback& callback) = 0;
+ // Called to evict an origin.
virtual void EvictOriginData(
const GURL& origin,
StorageType type,
- const EvictOriginDataCallback& callback) = 0;
-
- virtual void AsyncGetVolumeInfo(const VolumeInfoCallback& callback) = 0;
- virtual void GetUsageAndQuotaForEviction(
- const UsageAndQuotaCallback& callback) = 0;
+ const StatusCallback& callback) = 0;
protected:
virtual ~QuotaEvictionHandler() {}
@@ -137,9 +163,8 @@ class STORAGE_EXPORT QuotaManager
public:
typedef base::Callback<void(QuotaStatusCode,
int64_t /* usage */,
- int64_t /* quota */)> GetUsageAndQuotaCallback;
+ int64_t /* quota */)> UsageAndQuotaCallback;
- static const int64_t kIncognitoDefaultQuotaLimit;
static const int64_t kNoLimit;
QuotaManager(
@@ -147,7 +172,14 @@ class STORAGE_EXPORT QuotaManager
const base::FilePath& profile_path,
const scoped_refptr<base::SingleThreadTaskRunner>& io_thread,
const scoped_refptr<base::SequencedTaskRunner>& db_thread,
- const scoped_refptr<SpecialStoragePolicy>& special_storage_policy);
+ const scoped_refptr<SpecialStoragePolicy>& special_storage_policy,
+ const GetTemporaryStorageConfigurationFunc& get_config_function);
+
+ const TemporaryStorageConfiguration& storage_config() const {
+ return storage_config_;
+ }
+ void SetTemporaryStorageConfiguration(
+ const TemporaryStorageConfiguration& storage_config);
// Returns a proxy object that can be used on any thread.
QuotaManagerProxy* proxy() { return proxy_.get(); }
@@ -160,7 +192,7 @@ class STORAGE_EXPORT QuotaManager
virtual void GetUsageAndQuotaForWebApps(
const GURL& origin,
StorageType type,
- const GetUsageAndQuotaCallback& callback);
+ const UsageAndQuotaCallback& callback);
// Called by StorageClients.
// This method is declared as virtual to allow test code to override it.
@@ -171,7 +203,7 @@ class STORAGE_EXPORT QuotaManager
virtual void GetUsageAndQuota(
const GURL& origin,
StorageType type,
- const GetUsageAndQuotaCallback& callback);
+ const UsageAndQuotaCallback& callback);
// Called by clients via proxy.
// Client storage should call this method when storage is accessed.
@@ -223,13 +255,6 @@ class STORAGE_EXPORT QuotaManager
const StatusCallback& callback);
// Called by UI and internal modules.
- void GetAvailableSpace(const AvailableSpaceCallback& callback);
- void GetTemporaryGlobalQuota(const QuotaCallback& callback);
-
- // Ok to call with NULL callback.
- void SetTemporaryGlobalOverrideQuota(int64_t new_quota,
- const QuotaCallback& callback);
-
void GetPersistentHostQuota(const std::string& host,
const QuotaCallback& callback);
void SetPersistentHostQuota(const std::string& host,
@@ -249,6 +274,7 @@ class STORAGE_EXPORT QuotaManager
bool IsStorageUnlimited(const GURL& origin, StorageType type) const;
bool CanQueryDiskSize(const GURL& origin) const {
+ // TODO: not currently used?
return special_storage_policy_.get() &&
special_storage_policy_->CanQueryDiskSize(origin);
}
@@ -266,26 +292,17 @@ class STORAGE_EXPORT QuotaManager
void RemoveStorageObserverForFilter(StorageObserver* observer,
const StorageObserver::Filter& filter);
- // Determines the portion of the temp pool that can be
- // utilized by a single host (ie. 5 for 20%).
- static const int kPerHostTemporaryPortion;
-
static const int64_t kPerHostPersistentQuotaLimit;
-
static const char kDatabaseName[];
-
static const int kThresholdOfErrorsToBeBlacklisted;
-
static const int kEvictionIntervalInMilliSeconds;
-
static const char kTimeBetweenRepeatedOriginEvictionsHistogram[];
static const char kEvictedOriginAccessedCountHistogram[];
static const char kEvictedOriginTimeSinceAccessHistogram[];
- // These are kept non-const so that test code can change the value.
+ // Kept non-const so that test code can change the value.
// TODO(kinuko): Make this a real const value and add a proper way to set
// the quota for syncable storage. (http://crbug.com/155488)
- static int64_t kMinimumPreserveForSystem;
static int64_t kSyncableStorageDefaultHostQuota;
protected:
@@ -304,11 +321,11 @@ class STORAGE_EXPORT QuotaManager
friend struct QuotaManagerDeleter;
friend class ::SiteEngagementEvictionPolicyWithQuotaManagerTest;
+ class EvictionRoundInfoHelper;
+ class UsageAndQuotaHelper;
class GetUsageInfoTask;
-
class OriginDataDeleter;
class HostDataDeleter;
-
class GetModifiedSinceHelper;
class DumpQuotaTableHelper;
class DumpOriginInfoTableHelper;
@@ -320,8 +337,8 @@ class STORAGE_EXPORT QuotaManager
// Function pointer type used to store the function which returns
// information about the volume containing the given FilePath.
- using GetVolumeInfoFn = bool(*)(const base::FilePath&,
- uint64_t* available, uint64_t* total);
+ // The value returned is std::pair<total_space, available_space>.
+ using GetVolumeInfoFn = std::pair<int64_t,int64_t>(*)(const base::FilePath&);
typedef base::Callback<void(const QuotaTableEntries&)>
DumpQuotaTableCallback;
@@ -329,23 +346,25 @@ class STORAGE_EXPORT QuotaManager
DumpOriginInfoTableCallback;
typedef CallbackQueue<base::Closure> ClosureQueue;
- typedef CallbackQueue<AvailableSpaceCallback, QuotaStatusCode, int64_t>
- AvailableSpaceCallbackQueue;
typedef CallbackQueueMap<QuotaCallback, std::string, QuotaStatusCode, int64_t>
HostQuotaCallbackMap;
+ using TemporaryConfigCallbackQueue =
+ CallbackQueue<TemporaryStorageConfigurationCallback,
+ const TemporaryStorageConfiguration&>;
+
+ // The values returned total_space, available_space.
+ using StorageCapacityCallback = base::Callback<void(int64_t, int64_t)>;
+ using StorageCapacityCallbackQueue =
+ CallbackQueue<StorageCapacityCallback, int64_t, int64_t>;
struct EvictionContext {
EvictionContext();
- virtual ~EvictionContext();
+ ~EvictionContext();
GURL evicted_origin;
StorageType evicted_type;
-
- EvictOriginDataCallback evict_origin_data_callback;
+ StatusCallback evict_origin_data_callback;
};
- typedef QuotaEvictionHandler::UsageAndQuotaCallback
- UsageAndQuotaDispatcherCallback;
-
// This initialization method is lazily called on the IO thread
// when the first quota manager API is called.
// Initialize must be called after all quota clients are added to the
@@ -412,20 +431,13 @@ class STORAGE_EXPORT QuotaManager
const GetOriginCallback& callback) override;
void EvictOriginData(const GURL& origin,
StorageType type,
- const EvictOriginDataCallback& callback) override;
- void GetUsageAndQuotaForEviction(
- const UsageAndQuotaCallback& callback) override;
- void AsyncGetVolumeInfo(const VolumeInfoCallback& callback) override;
+ const StatusCallback& callback) override;
+ void GetEvictionRoundInfo(
+ const EvictionRoundInfoCallback& callback) override;
- void DidGetVolumeInfo(
- const VolumeInfoCallback& callback,
- uint64_t* available_space, uint64_t* total_space, bool success);
void GetLRUOrigin(StorageType type, const GetOriginCallback& callback);
- void DidSetTemporaryGlobalOverrideQuota(const QuotaCallback& callback,
- const int64_t* new_quota,
- bool success);
void DidGetPersistentHostQuota(const std::string& host,
const int64_t* quota,
bool success);
@@ -433,16 +445,20 @@ class STORAGE_EXPORT QuotaManager
const QuotaCallback& callback,
const int64_t* new_quota,
bool success);
- void DidInitialize(int64_t* temporary_quota_override,
- int64_t* desired_available_space,
- bool success);
void DidGetLRUOrigin(const GURL* origin,
bool success);
- void DidGetInitialTemporaryGlobalQuota(base::TimeTicks start_ticks,
- QuotaStatusCode status,
- int64_t quota_unused);
void DidInitializeTemporaryOriginsInfo(bool success);
- void DidGetAvailableSpace(int64_t space);
+ void GetTemporaryStorageConfig(
+ const TemporaryStorageConfigurationCallback& callback);
+ void DidGetTemporaryStorageConfig(
+ const TemporaryStorageConfiguration& storage_config);
+ void GetDeviceStorageCapacity(
+ const StorageCapacityCallback& callback);
+ void ContinueIncognitoGetStorageCapacity(
+ const TemporaryStorageConfiguration& config);
+ void DidGetDeviceStorageCapacity(
+ const std::pair<int64_t, int64_t>& total_and_available);
+
void DidDatabaseWork(bool success);
void DeleteOnCorrectThread() const;
@@ -452,12 +468,10 @@ class STORAGE_EXPORT QuotaManager
const base::Callback<bool(QuotaDatabase*)>& task,
const base::Callback<void(bool)>& reply);
- static int64_t CallGetAmountOfFreeDiskSpace(
- GetVolumeInfoFn get_vol_info_fn,
- const base::FilePath& profile_path);
- static bool GetVolumeInfo(const base::FilePath& path,
- uint64_t* available_space,
- uint64_t* total_size);
+ static std::pair<int64_t, int64_t> CallGetVolumeInfo(
+ GetVolumeInfoFn get_volume_info_fn,
+ const base::FilePath& path);
+ static std::pair<int64_t,int64_t> GetVolumeInfo(const base::FilePath& path);
const bool is_incognito_;
const base::FilePath profile_path_;
@@ -469,6 +483,13 @@ class STORAGE_EXPORT QuotaManager
scoped_refptr<base::SequencedTaskRunner> db_thread_;
mutable std::unique_ptr<QuotaDatabase> database_;
+ GetTemporaryStorageConfigurationFunc get_config_function_;
+ scoped_refptr<base::TaskRunner> get_config_task_runner_;
+ TemporaryStorageConfiguration storage_config_;
+ base::TimeTicks storage_config_timestamp_;
+ TemporaryConfigCallbackQueue storage_config_callbacks_;
+ StorageCapacityCallbackQueue storage_capacity_callbacks_;
+
GetOriginCallback lru_origin_callback_;
std::set<GURL> access_notified_origins_;
@@ -485,14 +506,8 @@ class STORAGE_EXPORT QuotaManager
std::unique_ptr<QuotaEvictionPolicy> temporary_storage_eviction_policy_;
bool is_getting_eviction_origin_;
- ClosureQueue db_initialization_callbacks_;
- AvailableSpaceCallbackQueue available_space_callbacks_;
HostQuotaCallbackMap persistent_host_quota_callbacks_;
- bool temporary_quota_initialized_;
- int64_t temporary_quota_override_;
- int64_t desired_available_space_;
-
// Map from origin to count.
std::map<GURL, int> origins_in_use_;
// Map from origin to error count.

Powered by Google App Engine
This is Rietveld 408576698