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 e1358873a5259d609c310974225a6475060e0ad0..093b8196fc25dc504163be63e7495bebda7b01bf 100644 |
| --- a/chrome/browser/chrome_content_browser_client.cc |
| +++ b/chrome/browser/chrome_content_browser_client.cc |
| @@ -2033,6 +2033,85 @@ 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) |
| + |
| +storage::TemporaryStorageConfiguration CalculateTemporaryStorageConfig( |
| + const base::FilePath& profile_path, bool is_incognito) { |
| + const int64_t kMBytes = 1024 * 1024; |
| + |
| + if (is_incognito) { |
| + // TODO(michaeln): Base the poolsize on SysInfo::AmountOfPhysicalMemory(). |
| + storage::TemporaryStorageConfiguration config; |
| + config.pool_size = 300 * kMBytes; |
| + config.must_remain_available = 0; |
| + config.per_host_portion = 3; |
| + config.refresh_interval = base::TimeDelta::Max(); |
| + return config; |
| + } |
| + |
| + // 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% |
| + |
| + // 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. |
| +#if defined(OS_ANDROID) |
| + uint64_t os_accomodation = 1000 * kMBytes; |
| +#elif defined(OS_CHROMEOS) |
| + uint64_t os_accomodation = 1000 * kMBytes; |
| +#elif defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) |
| + uint64_t os_accomodation = 10000 * kMBytes; |
| +#else |
| +#error "Port: Need to define os_accomodation for unknown os." |
| +#endif |
| + |
| + int64_t pool_size = 0; |
| + uint64_t available, total; |
| + if (storage::QuotaManager::GetVolumeInfo(profile_path, &available, &total)) { |
| + // If our hardcoded os_accomodation is too large for the volume size, define |
| + // the value as a large fraction of the total volume size instead. |
| + os_accomodation = std::min(os_accomodation, |
| + static_cast<uint64_t>(total * 0.8)); |
| + |
| + int64_t adjusted_total = total - os_accomodation; |
| + pool_size = static_cast<int64_t>(adjusted_total * kTemporaryPoolSizeRatio); |
| + UMA_HISTOGRAM_MBYTES("Quota.GlobalTemporaryPoolSize", pool_size); |
| + } |
| + |
| + storage::TemporaryStorageConfiguration config; |
| + config.pool_size = pool_size; |
| + config.must_remain_available = pool_size / kPerHostTemporaryPortion; |
| + config.per_host_portion = kPerHostTemporaryPortion; |
| + config.refresh_interval = base::TimeDelta::FromSeconds(60); |
| + return config; |
| +} |
| + |
| +void GetTemporaryStorageConfiguration( |
| + const base::FilePath& profile_path, bool is_incognito, |
| + storage::TemporaryStorageConfigurationCallback callback) { |
|
kinuko
2016/07/27 14:23:25
nit: const ref
|
| + content::BrowserThread::PostTaskAndReplyWithResult( |
|
kinuko
2016/07/27 14:23:25
Why this one needs to be called from the UI thread
|
| + content::BrowserThread::FILE, |
| + FROM_HERE, |
| + base::Bind(&CalculateTemporaryStorageConfig, profile_path, is_incognito), |
| + callback); |
| +} |
| +} // namespace |
| + |
| +storage::GetTemporaryStorageConfigurationFunc |
| +ChromeContentBrowserClient::GetTemporaryStorageConfigurationFunction( |
| + content::BrowserContext* context) { |
| + return base::Bind(&GetTemporaryStorageConfiguration); |
| +} |
| + |
| void ChromeContentBrowserClient::AllowCertificateError( |
| content::WebContents* web_contents, |
| int cert_error, |