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

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: rebase Created 4 years, 2 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/json/json_reader.h" 17 #include "base/json/json_reader.h"
18 #include "base/lazy_instance.h" 18 #include "base/lazy_instance.h"
19 #include "base/macros.h" 19 #include "base/macros.h"
20 #include "base/memory/ptr_util.h" 20 #include "base/memory/ptr_util.h"
21 #include "base/metrics/histogram_macros.h" 21 #include "base/metrics/histogram_macros.h"
22 #include "base/path_service.h" 22 #include "base/path_service.h"
23 #include "base/strings/string_number_conversions.h" 23 #include "base/strings/string_number_conversions.h"
24 #include "base/strings/string_split.h" 24 #include "base/strings/string_split.h"
25 #include "base/strings/string_util.h" 25 #include "base/strings/string_util.h"
26 #include "base/strings/stringprintf.h" 26 #include "base/strings/stringprintf.h"
27 #include "base/strings/utf_string_conversions.h" 27 #include "base/strings/utf_string_conversions.h"
28 #include "base/sys_info.h"
28 #include "base/threading/sequenced_worker_pool.h" 29 #include "base/threading/sequenced_worker_pool.h"
29 #include "base/threading/thread_task_runner_handle.h" 30 #include "base/threading/thread_task_runner_handle.h"
30 #include "build/build_config.h" 31 #include "build/build_config.h"
31 #include "chrome/browser/after_startup_task_utils.h" 32 #include "chrome/browser/after_startup_task_utils.h"
32 #include "chrome/browser/apps/app_url_redirector.h" 33 #include "chrome/browser/apps/app_url_redirector.h"
33 #include "chrome/browser/browser_about_handler.h" 34 #include "chrome/browser/browser_about_handler.h"
34 #include "chrome/browser/browser_process.h" 35 #include "chrome/browser/browser_process.h"
35 #include "chrome/browser/browser_shutdown.h" 36 #include "chrome/browser/browser_shutdown.h"
36 #include "chrome/browser/browsing_data/browsing_data_helper.h" 37 #include "chrome/browser/browsing_data/browsing_data_helper.h"
37 #include "chrome/browser/browsing_data/browsing_data_remover.h" 38 #include "chrome/browser/browsing_data/browsing_data_remover.h"
(...skipping 2071 matching lines...) Expand 10 before | Expand all | Expand 10 after
2109 } 2110 }
2110 2111
2111 std::unique_ptr<storage::QuotaEvictionPolicy> 2112 std::unique_ptr<storage::QuotaEvictionPolicy>
2112 ChromeContentBrowserClient::GetTemporaryStorageEvictionPolicy( 2113 ChromeContentBrowserClient::GetTemporaryStorageEvictionPolicy(
2113 content::BrowserContext* context) { 2114 content::BrowserContext* context) {
2114 return SiteEngagementEvictionPolicy::IsEnabled() 2115 return SiteEngagementEvictionPolicy::IsEnabled()
2115 ? base::MakeUnique<SiteEngagementEvictionPolicy>(context) 2116 ? base::MakeUnique<SiteEngagementEvictionPolicy>(context)
2116 : nullptr; 2117 : nullptr;
2117 } 2118 }
2118 2119
2120 namespace {
2121 #define UMA_HISTOGRAM_MBYTES(name, sample) \
cmumford 2016/10/25 20:30:54 Do you want the do/while(0) style for multi-line m
michaeln 2016/10/26 21:47:53 i don't think so, there are multiple lines, but th
2122 UMA_HISTOGRAM_CUSTOM_COUNTS( \
2123 (name), static_cast<int>((sample) / kMBytes), \
2124 1, 10 * 1024 * 1024 /* 10TB */, 100)
2125
2126 storage::TemporaryStorageConfiguration CalculateTemporaryStorageConfig(
2127 const base::FilePath& partition_path, bool is_incognito) {
2128 const int64_t kMBytes = 1024 * 1024;
2129
2130 if (is_incognito) {
2131 // TODO(michaeln): Base the poolsize on SysInfo::AmountOfPhysicalMemory().
cmumford 2016/10/25 20:30:54 This seems like something we should do in this fir
michaeln 2016/10/26 21:47:53 agreed, but not done yet
2132 storage::TemporaryStorageConfiguration config;
2133 config.pool_size = 300 * kMBytes;
2134 config.must_remain_available = 0;
cmumford 2016/10/25 20:30:54 Why not leave default values alone?
michaeln 2016/10/26 21:47:53 Done.
2135 config.per_host_quota = config.pool_size / 3;
2136 config.refresh_interval = base::TimeDelta::Max();
2137 return config;
2138 }
2139
2140 // The fraction of the device's storage the browser is willing to
2141 // use for temporary storage, this is applied after adjusting the
2142 // total to take os_accomodation into account.
2143 const double kTemporaryPoolSizeRatio = 1.0 / 3.0; // 33%
2144
2145 // The fraction of the device's storage the browser attempts to
2146 // keep free.
2147 const double kMustRemainAvailableRatio = 0.1;
2148
2149 // Determines the portion of the temp pool that can be
2150 // utilized by a single host (ie. 5 for 20%).
2151 const int kPerHostTemporaryPortion = 5;
2152
2153 // os_accomodation is an estimate of how much storage is needed for
2154 // the os and essential application code outside of the browser.
2155 const int64_t kDefaultOSAccomodation =
2156 #if defined(OS_ANDROID)
2157 1000 * kMBytes;
2158 #elif defined(OS_CHROMEOS)
cmumford 2016/10/25 20:30:54 Do you think we should have a different value for
michaeln 2016/10/26 21:47:53 i think chromecast uses a different ContentBrowser
2159 1000 * kMBytes;
2160 #elif defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX)
2161 10000 * kMBytes;
2162 #else
2163 #error "Port: Need to define os_accomodation for unknown os."
2164 #endif
2165
2166 storage::TemporaryStorageConfiguration config;
2167
2168 int64_t total = base::SysInfo::AmountOfTotalDiskSpace(partition_path);
2169 if (total == -1) {
2170 LOG(ERROR) << "Failed to get the amount of total disk space.";
2171 config.refresh_interval = base::TimeDelta::FromSeconds(60);
2172 return config;
2173 }
2174
2175 // If our hardcoded os accomodation is too large for the volume size, define
2176 // the value as a large fraction of the total volume size instead.
2177 int64_t os_accomodation = std::min(kDefaultOSAccomodation,
2178 static_cast<int64_t>(total * 0.8));
2179
2180 int64_t adjusted_total = total - os_accomodation;
2181 int64_t pool_size = adjusted_total * kTemporaryPoolSizeRatio;
2182 UMA_HISTOGRAM_MBYTES("Quota.GlobalTemporaryPoolSize", pool_size);
2183
2184 config.pool_size = pool_size;
2185 config.must_remain_available = total * kMustRemainAvailableRatio;
2186 config.per_host_quota = pool_size / kPerHostTemporaryPortion;;
cmumford 2016/10/25 20:30:54 double ;;
michaeln 2016/10/26 21:47:53 Done.
2187 config.refresh_interval = base::TimeDelta::FromSeconds(60);
2188 return config;
2189 }
2190
2191 } // namespace
2192
2193 void ChromeContentBrowserClient::GetTemporaryStorageConfiguration(
2194 content::BrowserContext* context,
2195 const base::FilePath& partition_path, bool is_incognito,
2196 const storage::TemporaryStorageConfigurationCallback& callback) {
2197 content::BrowserThread::PostTaskAndReplyWithResult(
2198 content::BrowserThread::FILE,
2199 FROM_HERE,
2200 base::Bind(&CalculateTemporaryStorageConfig,
2201 partition_path, is_incognito),
2202 callback);
2203 }
2204
2119 void ChromeContentBrowserClient::AllowCertificateError( 2205 void ChromeContentBrowserClient::AllowCertificateError(
2120 content::WebContents* web_contents, 2206 content::WebContents* web_contents,
2121 int cert_error, 2207 int cert_error,
2122 const net::SSLInfo& ssl_info, 2208 const net::SSLInfo& ssl_info,
2123 const GURL& request_url, 2209 const GURL& request_url,
2124 ResourceType resource_type, 2210 ResourceType resource_type,
2125 bool overridable, 2211 bool overridable,
2126 bool strict_enforcement, 2212 bool strict_enforcement,
2127 bool expired_previous_decision, 2213 bool expired_previous_decision,
2128 const base::Callback<void(content::CertificateRequestResultType)>& 2214 const base::Callback<void(content::CertificateRequestResultType)>&
(...skipping 1120 matching lines...) Expand 10 before | Expand all | Expand 10 after
3249 kWebRtcDevSwitchNames, 3335 kWebRtcDevSwitchNames,
3250 arraysize(kWebRtcDevSwitchNames)); 3336 arraysize(kWebRtcDevSwitchNames));
3251 } 3337 }
3252 } 3338 }
3253 #endif // defined(ENABLE_WEBRTC) 3339 #endif // defined(ENABLE_WEBRTC)
3254 3340
3255 std::unique_ptr<content::MemoryCoordinatorDelegate> 3341 std::unique_ptr<content::MemoryCoordinatorDelegate>
3256 ChromeContentBrowserClient::GetMemoryCoordinatorDelegate() { 3342 ChromeContentBrowserClient::GetMemoryCoordinatorDelegate() {
3257 return memory::ChromeMemoryCoordinatorDelegate::Create(); 3343 return memory::ChromeMemoryCoordinatorDelegate::Create();
3258 } 3344 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698