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

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, 1 month 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 2065 matching lines...) Expand 10 before | Expand all | Expand 10 after
2103 } 2104 }
2104 2105
2105 std::unique_ptr<storage::QuotaEvictionPolicy> 2106 std::unique_ptr<storage::QuotaEvictionPolicy>
2106 ChromeContentBrowserClient::GetTemporaryStorageEvictionPolicy( 2107 ChromeContentBrowserClient::GetTemporaryStorageEvictionPolicy(
2107 content::BrowserContext* context) { 2108 content::BrowserContext* context) {
2108 return SiteEngagementEvictionPolicy::IsEnabled() 2109 return SiteEngagementEvictionPolicy::IsEnabled()
2109 ? base::MakeUnique<SiteEngagementEvictionPolicy>(context) 2110 ? base::MakeUnique<SiteEngagementEvictionPolicy>(context)
2110 : nullptr; 2111 : nullptr;
2111 } 2112 }
2112 2113
2114 namespace {
2115 #define UMA_HISTOGRAM_MBYTES(name, sample) \
2116 UMA_HISTOGRAM_CUSTOM_COUNTS((name), static_cast<int>((sample) / kMBytes), 1, \
2117 10 * 1024 * 1024 /* 10TB */, 100)
2118
2119 base::Optional<storage::QuotaSettings> CalculateQuotaSettings(
2120 const base::FilePath& partition_path,
2121 bool is_incognito) {
2122 const int64_t kMBytes = 1024 * 1024;
2123
2124 if (is_incognito) {
2125 storage::QuotaSettings settings;
2126 settings.pool_size =
2127 std::min(300 * kMBytes, base::SysInfo::AmountOfPhysicalMemory() / 10);
2128 settings.per_host_quota = settings.pool_size / 3;
2129 settings.refresh_interval = base::TimeDelta::Max();
2130 return settings;
2131 }
2132
2133 // The fraction of the device's storage the browser is willing to
2134 // use for temporary storage, this is applied after adjusting the
2135 // total to take os_accomodation into account.
2136 const double kTemporaryPoolSizeRatio = 1.0 / 3.0; // 33%
2137
2138 // The fraction of the device's storage the browser attempts to
2139 // keep free.
2140 const double kMustRemainAvailableRatio = 0.1;
2141
2142 // Determines the portion of the temp pool that can be
2143 // utilized by a single host (ie. 5 for 20%).
2144 const int kPerHostTemporaryPortion = 5;
2145
2146 // os_accomodation is an estimate of how much storage is needed for
2147 // the os and essential application code outside of the browser.
2148 const int64_t kDefaultOSAccomodation =
2149 #if defined(OS_ANDROID)
2150 1000 * kMBytes;
2151 #elif defined(OS_CHROMEOS)
2152 1000 * kMBytes;
2153 #elif defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX)
2154 10000 * kMBytes;
2155 #else
2156 #error "Port: Need to define an OS accomodation value for unknown OS."
2157 #endif
2158
2159 storage::QuotaSettings settings;
2160
2161 int64_t total = base::SysInfo::AmountOfTotalDiskSpace(partition_path);
2162 if (total == -1) {
2163 LOG(ERROR) << "Unable to compute QuotaSettings.";
2164 return base::nullopt;
2165 }
2166
2167 // If our hardcoded OS accomodation is too large for the volume size, define
2168 // the value as a fraction of the total volume size instead.
2169 int64_t os_accomodation =
2170 std::min(kDefaultOSAccomodation, static_cast<int64_t>(total * 0.8));
2171 UMA_HISTOGRAM_MBYTES("Quota.OSAccomodationDelta",
2172 kDefaultOSAccomodation - os_accomodation);
2173
2174 int64_t adjusted_total = total - os_accomodation;
2175 int64_t pool_size = adjusted_total * kTemporaryPoolSizeRatio;
2176
2177 settings.pool_size = pool_size;
2178 settings.must_remain_available = total * kMustRemainAvailableRatio;
2179 settings.per_host_quota = pool_size / kPerHostTemporaryPortion;
2180 settings.refresh_interval = base::TimeDelta::FromSeconds(60);
2181 return settings;
2182 }
2183
2184 } // namespace
2185
2186 void ChromeContentBrowserClient::GetQuotaSettings(
2187 content::BrowserContext* context,
2188 const base::FilePath& partition_path,
2189 bool is_incognito,
2190 const storage::OptionalQuotaSettingsCallback& callback) {
2191 content::BrowserThread::PostTaskAndReplyWithResult(
2192 content::BrowserThread::FILE, FROM_HERE,
2193 base::Bind(&CalculateQuotaSettings, partition_path, is_incognito),
2194 callback);
2195 }
2196
2113 void ChromeContentBrowserClient::AllowCertificateError( 2197 void ChromeContentBrowserClient::AllowCertificateError(
2114 content::WebContents* web_contents, 2198 content::WebContents* web_contents,
2115 int cert_error, 2199 int cert_error,
2116 const net::SSLInfo& ssl_info, 2200 const net::SSLInfo& ssl_info,
2117 const GURL& request_url, 2201 const GURL& request_url,
2118 ResourceType resource_type, 2202 ResourceType resource_type,
2119 bool overridable, 2203 bool overridable,
2120 bool strict_enforcement, 2204 bool strict_enforcement,
2121 bool expired_previous_decision, 2205 bool expired_previous_decision,
2122 const base::Callback<void(content::CertificateRequestResultType)>& 2206 const base::Callback<void(content::CertificateRequestResultType)>&
(...skipping 1103 matching lines...) Expand 10 before | Expand all | Expand 10 after
3226 kWebRtcDevSwitchNames, 3310 kWebRtcDevSwitchNames,
3227 arraysize(kWebRtcDevSwitchNames)); 3311 arraysize(kWebRtcDevSwitchNames));
3228 } 3312 }
3229 } 3313 }
3230 #endif // defined(ENABLE_WEBRTC) 3314 #endif // defined(ENABLE_WEBRTC)
3231 3315
3232 std::unique_ptr<content::MemoryCoordinatorDelegate> 3316 std::unique_ptr<content::MemoryCoordinatorDelegate>
3233 ChromeContentBrowserClient::GetMemoryCoordinatorDelegate() { 3317 ChromeContentBrowserClient::GetMemoryCoordinatorDelegate() {
3234 return memory::ChromeMemoryCoordinatorDelegate::Create(); 3318 return memory::ChromeMemoryCoordinatorDelegate::Create();
3235 } 3319 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698