Chromium Code Reviews| Index: chrome/browser/chrome_content_browser_client.cc |
| diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc |
| index 29b4b647c2ca7301936cae35eb0e65833f6d9fe6..1291240556bd99806934d1756b797caeeebd255a 100644 |
| --- a/chrome/browser/chrome_content_browser_client.cc |
| +++ b/chrome/browser/chrome_content_browser_client.cc |
| @@ -25,6 +25,7 @@ |
| #include "base/strings/string_util.h" |
| #include "base/strings/stringprintf.h" |
| #include "base/strings/utf_string_conversions.h" |
| +#include "base/sys_info.h" |
| #include "base/threading/sequenced_worker_pool.h" |
| #include "base/threading/thread_task_runner_handle.h" |
| #include "build/build_config.h" |
| @@ -2118,6 +2119,89 @@ ChromeContentBrowserClient::GetTemporaryStorageEvictionPolicy( |
| : nullptr; |
| } |
| +namespace { |
| +#define UMA_HISTOGRAM_MBYTES(name, sample) \ |
| + UMA_HISTOGRAM_CUSTOM_COUNTS((name), static_cast<int>((sample) / kMBytes), 1, \ |
| + 10 * 1024 * 1024 /* 10TB */, 100) |
|
kinuko
2016/11/10 17:49:22
nit: if the only usage of this macros is for OSAcc
|
| + |
| +base::Optional<storage::QuotaSettings> CalculateQuotaSettings( |
|
kinuko
2016/11/10 17:49:22
Is this same as storage::CalculateNominalDynamicSe
michaeln
2016/11/11 02:31:53
it is the same, i'll call the storage lib function
|
| + const base::FilePath& partition_path, |
| + bool is_incognito) { |
| + const int64_t kMBytes = 1024 * 1024; |
| + |
| + if (is_incognito) { |
| + storage::QuotaSettings settings; |
| + settings.pool_size = |
| + std::min(300 * kMBytes, base::SysInfo::AmountOfPhysicalMemory() / 10); |
| + settings.per_host_quota = settings.pool_size / 3; |
| + settings.refresh_interval = base::TimeDelta::Max(); |
| + return settings; |
| + } |
| + |
| + // The fraction of the device's storage the browser is willing to |
| + // use for temporary storage, this is applied after adjusting the |
| + // total to take os_accomodation into account. |
| + const double kTemporaryPoolSizeRatio = 1.0 / 3.0; // 33% |
| + |
| + // The fraction of the device's storage the browser attempts to |
| + // keep free. |
| + const double kMustRemainAvailableRatio = 0.1; |
| + |
| + // Determines the portion of the temp pool that can be |
| + // utilized by a single host (ie. 5 for 20%). |
| + const int kPerHostTemporaryPortion = 5; |
| + |
| + // 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 = |
| +#if defined(OS_ANDROID) |
| + 1000 * kMBytes; |
| +#elif defined(OS_CHROMEOS) |
| + 1000 * kMBytes; |
| +#elif defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) |
| + 10000 * kMBytes; |
| +#else |
| +#error "Port: Need to define an OS accomodation value for unknown OS." |
| +#endif |
| + |
| + storage::QuotaSettings settings; |
| + |
| + int64_t total = base::SysInfo::AmountOfTotalDiskSpace(partition_path); |
| + if (total == -1) { |
| + LOG(ERROR) << "Unable to compute QuotaSettings."; |
| + return base::nullopt; |
| + } |
| + |
| + // If our hardcoded OS accomodation is too large for the volume size, define |
| + // the value as a fraction of the total volume size instead. |
| + int64_t os_accomodation = |
| + std::min(kDefaultOSAccomodation, static_cast<int64_t>(total * 0.8)); |
| + UMA_HISTOGRAM_MBYTES("Quota.OSAccomodationDelta", |
| + kDefaultOSAccomodation - os_accomodation); |
| + |
| + int64_t adjusted_total = total - os_accomodation; |
| + int64_t pool_size = adjusted_total * kTemporaryPoolSizeRatio; |
| + |
| + settings.pool_size = pool_size; |
| + settings.must_remain_available = total * kMustRemainAvailableRatio; |
| + settings.per_host_quota = pool_size / kPerHostTemporaryPortion; |
| + settings.refresh_interval = base::TimeDelta::FromSeconds(60); |
|
kinuko
2016/11/10 17:49:22
nit: define some constant for this too?
|
| + return settings; |
| +} |
| + |
| +} // namespace |
| + |
| +void ChromeContentBrowserClient::GetQuotaSettings( |
| + content::BrowserContext* context, |
| + const base::FilePath& partition_path, |
| + bool is_incognito, |
| + const storage::OptionalQuotaSettingsCallback& callback) { |
| + content::BrowserThread::PostTaskAndReplyWithResult( |
| + content::BrowserThread::FILE, FROM_HERE, |
| + base::Bind(&CalculateQuotaSettings, partition_path, is_incognito), |
| + callback); |
| +} |
| + |
| void ChromeContentBrowserClient::AllowCertificateError( |
| content::WebContents* web_contents, |
| int cert_error, |