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

Side by Side 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, 4 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chrome_content_browser_client.h" 5 #include "chrome/browser/chrome_content_browser_client.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/base_switches.h" 12 #include "base/base_switches.h"
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/bind_helpers.h" 14 #include "base/bind_helpers.h"
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/files/scoped_file.h" 16 #include "base/files/scoped_file.h"
17 #include "base/lazy_instance.h" 17 #include "base/lazy_instance.h"
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/memory/ptr_util.h" 19 #include "base/memory/ptr_util.h"
20 #include "base/metrics/histogram_macros.h" 20 #include "base/metrics/histogram_macros.h"
21 #include "base/path_service.h" 21 #include "base/path_service.h"
22 #include "base/strings/string_number_conversions.h" 22 #include "base/strings/string_number_conversions.h"
23 #include "base/strings/string_split.h" 23 #include "base/strings/string_split.h"
24 #include "base/strings/string_util.h" 24 #include "base/strings/string_util.h"
25 #include "base/strings/stringprintf.h" 25 #include "base/strings/stringprintf.h"
26 #include "base/strings/utf_string_conversions.h" 26 #include "base/strings/utf_string_conversions.h"
27 #include "base/sys_info.h"
27 #include "base/threading/sequenced_worker_pool.h" 28 #include "base/threading/sequenced_worker_pool.h"
28 #include "base/threading/thread_task_runner_handle.h" 29 #include "base/threading/thread_task_runner_handle.h"
29 #include "build/build_config.h" 30 #include "build/build_config.h"
30 #include "chrome/browser/after_startup_task_utils.h" 31 #include "chrome/browser/after_startup_task_utils.h"
31 #include "chrome/browser/apps/app_url_redirector.h" 32 #include "chrome/browser/apps/app_url_redirector.h"
32 #include "chrome/browser/browser_about_handler.h" 33 #include "chrome/browser/browser_about_handler.h"
33 #include "chrome/browser/browser_process.h" 34 #include "chrome/browser/browser_process.h"
34 #include "chrome/browser/browser_shutdown.h" 35 #include "chrome/browser/browser_shutdown.h"
35 #include "chrome/browser/browsing_data/browsing_data_helper.h" 36 #include "chrome/browser/browsing_data/browsing_data_helper.h"
36 #include "chrome/browser/browsing_data/browsing_data_remover.h" 37 #include "chrome/browser/browsing_data/browsing_data_remover.h"
(...skipping 1989 matching lines...) Expand 10 before | Expand all | Expand 10 after
2026 } 2027 }
2027 2028
2028 std::unique_ptr<storage::QuotaEvictionPolicy> 2029 std::unique_ptr<storage::QuotaEvictionPolicy>
2029 ChromeContentBrowserClient::GetTemporaryStorageEvictionPolicy( 2030 ChromeContentBrowserClient::GetTemporaryStorageEvictionPolicy(
2030 content::BrowserContext* context) { 2031 content::BrowserContext* context) {
2031 return SiteEngagementEvictionPolicy::IsEnabled() 2032 return SiteEngagementEvictionPolicy::IsEnabled()
2032 ? base::WrapUnique(new SiteEngagementEvictionPolicy(context)) 2033 ? base::WrapUnique(new SiteEngagementEvictionPolicy(context))
2033 : nullptr; 2034 : nullptr;
2034 } 2035 }
2035 2036
2037 namespace {
2038 #define UMA_HISTOGRAM_MBYTES(name, sample) \
2039 UMA_HISTOGRAM_CUSTOM_COUNTS( \
2040 (name), static_cast<int>((sample) / kMBytes), \
2041 1, 10 * 1024 * 1024 /* 10TB */, 100)
2042
2043 storage::TemporaryStorageConfiguration CalculateTemporaryStorageConfig(
2044 const base::FilePath& partition_path, bool is_incognito) {
2045 const int64_t kMBytes = 1024 * 1024;
2046
2047 if (is_incognito) {
2048 // TODO(michaeln): Base the poolsize on SysInfo::AmountOfPhysicalMemory().
2049 storage::TemporaryStorageConfiguration config;
2050 config.pool_size = 300 * kMBytes;
2051 config.must_remain_available = 0;
2052 config.per_host_quota = config.pool_size / 3;
2053 config.refresh_interval = base::TimeDelta::Max();
2054 return config;
2055 }
2056
2057 // The fraction of the device's storage the browser is willing to
2058 // use for temporary storage, this is applied after adjusting the
2059 // total to take os_accomodation into account.
2060 const double kTemporaryPoolSizeRatio = 1.0 / 3.0; // 33%
2061
2062 // Determines the portion of the temp pool that can be
2063 // utilized by a single host (ie. 5 for 20%).
2064 const int kPerHostTemporaryPortion = 5;
2065
2066 // os_accomodation is an estimate of how much storage is needed for
2067 // the os and essential application code outside of the browser.
2068 #if defined(OS_ANDROID)
2069 int64_t os_accomodation = 1000 * kMBytes;
2070 #elif defined(OS_CHROMEOS)
2071 int64_t os_accomodation = 1000 * kMBytes;
2072 #elif defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX)
2073 int64_t os_accomodation = 10000 * kMBytes;
2074 #else
2075 #error "Port: Need to define os_accomodation for unknown os."
2076 #endif
2077
2078 int64_t pool_size = 0;
2079 int64_t total = base::SysInfo::AmountOfTotalDiskSpace(partition_path);
2080 if (total != -1) {
2081 // If our hardcoded os_accomodation is too large for the volume size, define
2082 // the value as a large fraction of the total volume size instead.
2083 os_accomodation = std::min(os_accomodation,
2084 static_cast<int64_t>(total * 0.8));
2085
2086 int64_t adjusted_total = total - os_accomodation;
2087 pool_size = adjusted_total * kTemporaryPoolSizeRatio;
2088 UMA_HISTOGRAM_MBYTES("Quota.GlobalTemporaryPoolSize", pool_size);
2089 }
2090
2091 storage::TemporaryStorageConfiguration config;
2092 config.pool_size = pool_size;
2093 config.must_remain_available = pool_size / kPerHostTemporaryPortion;
2094 config.per_host_quota = pool_size / kPerHostTemporaryPortion;;
2095 config.refresh_interval = base::TimeDelta::FromSeconds(60);
2096 return config;
2097 }
2098
2099 } // namespace
2100
2101 void ChromeContentBrowserClient::GetTemporaryStorageConfiguration(
2102 content::BrowserContext* context,
2103 const base::FilePath& partition_path, bool is_incognito,
2104 const storage::TemporaryStorageConfigurationCallback& callback) {
2105 content::BrowserThread::PostTaskAndReplyWithResult(
2106 content::BrowserThread::FILE,
2107 FROM_HERE,
2108 base::Bind(&CalculateTemporaryStorageConfig,
2109 partition_path, is_incognito),
2110 callback);
2111 }
2112
2036 void ChromeContentBrowserClient::AllowCertificateError( 2113 void ChromeContentBrowserClient::AllowCertificateError(
2037 content::WebContents* web_contents, 2114 content::WebContents* web_contents,
2038 int cert_error, 2115 int cert_error,
2039 const net::SSLInfo& ssl_info, 2116 const net::SSLInfo& ssl_info,
2040 const GURL& request_url, 2117 const GURL& request_url,
2041 ResourceType resource_type, 2118 ResourceType resource_type,
2042 bool overridable, 2119 bool overridable,
2043 bool strict_enforcement, 2120 bool strict_enforcement,
2044 bool expired_previous_decision, 2121 bool expired_previous_decision,
2045 const base::Callback<void(bool)>& callback, 2122 const base::Callback<void(bool)>& callback,
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after
3053 if (channel <= kMaxDisableEncryptionChannel) { 3130 if (channel <= kMaxDisableEncryptionChannel) {
3054 static const char* const kWebRtcDevSwitchNames[] = { 3131 static const char* const kWebRtcDevSwitchNames[] = {
3055 switches::kDisableWebRtcEncryption, 3132 switches::kDisableWebRtcEncryption,
3056 }; 3133 };
3057 to_command_line->CopySwitchesFrom(from_command_line, 3134 to_command_line->CopySwitchesFrom(from_command_line,
3058 kWebRtcDevSwitchNames, 3135 kWebRtcDevSwitchNames,
3059 arraysize(kWebRtcDevSwitchNames)); 3136 arraysize(kWebRtcDevSwitchNames));
3060 } 3137 }
3061 } 3138 }
3062 #endif // defined(ENABLE_WEBRTC) 3139 #endif // defined(ENABLE_WEBRTC)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698