OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef STORAGE_BROWSER_QUOTA_QUOTA_SETTINGS_H_ |
| 6 #define STORAGE_BROWSER_QUOTA_QUOTA_SETTINGS_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "base/files/file_path.h" |
| 12 #include "base/optional.h" |
| 13 #include "base/time/time.h" |
| 14 #include "storage/browser/storage_browser_export.h" |
| 15 |
| 16 namespace storage { |
| 17 |
| 18 // Settings the storage lib embedder must provide to the QuotaManager. |
| 19 struct QuotaSettings { |
| 20 QuotaSettings() = default; |
| 21 QuotaSettings(int64_t pool_size, |
| 22 int64_t per_host_quota, |
| 23 int64_t must_remain_available) |
| 24 : pool_size(pool_size), |
| 25 per_host_quota(per_host_quota), |
| 26 must_remain_available(must_remain_available) {} |
| 27 |
| 28 // The target size in bytes of the shared pool of disk space the quota |
| 29 // system allows for use by websites using HTML5 storage apis, for |
| 30 // example an embedder may use 50% of the total volume size. |
| 31 int64_t pool_size = 0; |
| 32 |
| 33 // The amount in bytes of the pool an individual site may consume. The |
| 34 // value must be less than or equal to the pool_size. |
| 35 int64_t per_host_quota = 0; |
| 36 |
| 37 // The amount of space that must remain available on the storage |
| 38 // volume. As the volume approaches this limit, the quota system gets |
| 39 // more aggressive about evicting data and disallowing new data. |
| 40 int64_t must_remain_available = 0; |
| 41 |
| 42 // The quota system querries the embedder for the QuataSettings, |
| 43 // but will rate limit the frequency of the querries to no more than once |
| 44 // per refresh interval. |
| 45 base::TimeDelta refresh_interval = base::TimeDelta::Max(); |
| 46 }; |
| 47 |
| 48 // Function type used to return the settings in response to a |
| 49 // GetQuotaSettingsFunc invocation. If the embedder cannot |
| 50 // produce a settings values, base::nullopt can be returned. |
| 51 using OptionalQuotaSettingsCallback = |
| 52 base::Callback<void(base::Optional<QuotaSettings>)>; |
| 53 |
| 54 // Function type used to query the embedder about the quota manager settings. |
| 55 // This function is invoked on the UI thread. |
| 56 using GetQuotaSettingsFunc = |
| 57 base::Callback<void(const OptionalQuotaSettingsCallback& callback)>; |
| 58 |
| 59 // Returns settings based on the size of the volume containing the storage |
| 60 // partition and a guestimate of the size required for the OS. The refresh |
| 61 // interval is 60 seconds to accomodate changes to the size of the volume. |
| 62 // Except, in the case of incognito, the poolize and quota values are based |
| 63 // on the amount of physical memory and the rerfresh interval is max'd out. |
| 64 STORAGE_EXPORT |
| 65 base::Optional<storage::QuotaSettings> CalculateNominalDynamicSettings( |
| 66 const base::FilePath& partition_path, |
| 67 bool is_incognito); |
| 68 |
| 69 // Returns settings with a poolsize of zero and no per host quota. |
| 70 inline QuotaSettings GetNoQuotaSettings() { |
| 71 return QuotaSettings(); |
| 72 } |
| 73 |
| 74 // Returns settings that provide given |per_host_quota| and a total poolsize of |
| 75 // five times that. |
| 76 inline QuotaSettings GetHardCodedSettings(int64_t per_host_quota) { |
| 77 return QuotaSettings(per_host_quota * 5, per_host_quota, per_host_quota); |
| 78 } |
| 79 |
| 80 } // namespace storage |
| 81 |
| 82 #endif // STORAGE_BROWSER_QUOTA_QUOTA_MANAGER_H_ |
OLD | NEW |