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

Unified Diff: chrome/browser/chrome_content_browser_client.cc

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: address review comments Created 4 years, 5 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: 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..48497f9cd0829d0c5a7846825e3d14e77b1459bd 100644
--- a/chrome/browser/chrome_content_browser_client.cc
+++ b/chrome/browser/chrome_content_browser_client.cc
@@ -24,6 +24,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"
@@ -2033,6 +2034,82 @@ 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& partition_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_quota = config.pool_size / 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)
+ int64_t os_accomodation = 1000 * kMBytes;
+#elif defined(OS_CHROMEOS)
+ int64_t os_accomodation = 1000 * kMBytes;
+#elif defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX)
+ int64_t os_accomodation = 10000 * kMBytes;
+#else
+#error "Port: Need to define os_accomodation for unknown os."
+#endif
+
+ int64_t pool_size = 0;
+ int64_t total = base::SysInfo::AmountOfTotalDiskSpace(partition_path);
+ if (total != -1) {
+ // 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<int64_t>(total * 0.8));
+
+ int64_t adjusted_total = total - os_accomodation;
+ pool_size = 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_quota = pool_size / kPerHostTemporaryPortion;;
+ config.refresh_interval = base::TimeDelta::FromSeconds(60);
+ return config;
+}
+
+} // namespace
+
+void ChromeContentBrowserClient::GetTemporaryStorageConfiguration(
+ content::BrowserContext* context,
+ const base::FilePath& partition_path, bool is_incognito,
+ const storage::TemporaryStorageConfigurationCallback& callback) {
+ content::BrowserThread::PostTaskAndReplyWithResult(
+ content::BrowserThread::FILE,
+ FROM_HERE,
+ base::Bind(&CalculateTemporaryStorageConfig,
+ partition_path, is_incognito),
+ callback);
+}
+
void ChromeContentBrowserClient::AllowCertificateError(
content::WebContents* web_contents,
int cert_error,

Powered by Google App Engine
This is Rietveld 408576698