Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 2073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2111 } | 2112 } |
| 2112 | 2113 |
| 2113 std::unique_ptr<storage::QuotaEvictionPolicy> | 2114 std::unique_ptr<storage::QuotaEvictionPolicy> |
| 2114 ChromeContentBrowserClient::GetTemporaryStorageEvictionPolicy( | 2115 ChromeContentBrowserClient::GetTemporaryStorageEvictionPolicy( |
| 2115 content::BrowserContext* context) { | 2116 content::BrowserContext* context) { |
| 2116 return SiteEngagementEvictionPolicy::IsEnabled() | 2117 return SiteEngagementEvictionPolicy::IsEnabled() |
| 2117 ? base::MakeUnique<SiteEngagementEvictionPolicy>(context) | 2118 ? base::MakeUnique<SiteEngagementEvictionPolicy>(context) |
| 2118 : nullptr; | 2119 : nullptr; |
| 2119 } | 2120 } |
| 2120 | 2121 |
| 2122 namespace { | |
| 2123 #define UMA_HISTOGRAM_MBYTES(name, sample) \ | |
| 2124 UMA_HISTOGRAM_CUSTOM_COUNTS((name), static_cast<int>((sample) / kMBytes), 1, \ | |
| 2125 10 * 1024 * 1024 /* 10TB */, 100) | |
|
kinuko
2016/11/10 17:49:22
nit: if the only usage of this macros is for OSAcc
| |
| 2126 | |
| 2127 base::Optional<storage::QuotaSettings> CalculateQuotaSettings( | |
|
kinuko
2016/11/10 17:49:22
Is this same as storage::CalculateNominalDynamicSe
michaeln
2016/11/11 02:31:53
it is the same, i'll call the storage lib function
| |
| 2128 const base::FilePath& partition_path, | |
| 2129 bool is_incognito) { | |
| 2130 const int64_t kMBytes = 1024 * 1024; | |
| 2131 | |
| 2132 if (is_incognito) { | |
| 2133 storage::QuotaSettings settings; | |
| 2134 settings.pool_size = | |
| 2135 std::min(300 * kMBytes, base::SysInfo::AmountOfPhysicalMemory() / 10); | |
| 2136 settings.per_host_quota = settings.pool_size / 3; | |
| 2137 settings.refresh_interval = base::TimeDelta::Max(); | |
| 2138 return settings; | |
| 2139 } | |
| 2140 | |
| 2141 // The fraction of the device's storage the browser is willing to | |
| 2142 // use for temporary storage, this is applied after adjusting the | |
| 2143 // total to take os_accomodation into account. | |
| 2144 const double kTemporaryPoolSizeRatio = 1.0 / 3.0; // 33% | |
| 2145 | |
| 2146 // The fraction of the device's storage the browser attempts to | |
| 2147 // keep free. | |
| 2148 const double kMustRemainAvailableRatio = 0.1; | |
| 2149 | |
| 2150 // Determines the portion of the temp pool that can be | |
| 2151 // utilized by a single host (ie. 5 for 20%). | |
| 2152 const int kPerHostTemporaryPortion = 5; | |
| 2153 | |
| 2154 // os_accomodation is an estimate of how much storage is needed for | |
| 2155 // the os and essential application code outside of the browser. | |
| 2156 const int64_t kDefaultOSAccomodation = | |
| 2157 #if defined(OS_ANDROID) | |
| 2158 1000 * kMBytes; | |
| 2159 #elif defined(OS_CHROMEOS) | |
| 2160 1000 * kMBytes; | |
| 2161 #elif defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) | |
| 2162 10000 * kMBytes; | |
| 2163 #else | |
| 2164 #error "Port: Need to define an OS accomodation value for unknown OS." | |
| 2165 #endif | |
| 2166 | |
| 2167 storage::QuotaSettings settings; | |
| 2168 | |
| 2169 int64_t total = base::SysInfo::AmountOfTotalDiskSpace(partition_path); | |
| 2170 if (total == -1) { | |
| 2171 LOG(ERROR) << "Unable to compute QuotaSettings."; | |
| 2172 return base::nullopt; | |
| 2173 } | |
| 2174 | |
| 2175 // If our hardcoded OS accomodation is too large for the volume size, define | |
| 2176 // the value as a fraction of the total volume size instead. | |
| 2177 int64_t os_accomodation = | |
| 2178 std::min(kDefaultOSAccomodation, static_cast<int64_t>(total * 0.8)); | |
| 2179 UMA_HISTOGRAM_MBYTES("Quota.OSAccomodationDelta", | |
| 2180 kDefaultOSAccomodation - os_accomodation); | |
| 2181 | |
| 2182 int64_t adjusted_total = total - os_accomodation; | |
| 2183 int64_t pool_size = adjusted_total * kTemporaryPoolSizeRatio; | |
| 2184 | |
| 2185 settings.pool_size = pool_size; | |
| 2186 settings.must_remain_available = total * kMustRemainAvailableRatio; | |
| 2187 settings.per_host_quota = pool_size / kPerHostTemporaryPortion; | |
| 2188 settings.refresh_interval = base::TimeDelta::FromSeconds(60); | |
|
kinuko
2016/11/10 17:49:22
nit: define some constant for this too?
| |
| 2189 return settings; | |
| 2190 } | |
| 2191 | |
| 2192 } // namespace | |
| 2193 | |
| 2194 void ChromeContentBrowserClient::GetQuotaSettings( | |
| 2195 content::BrowserContext* context, | |
| 2196 const base::FilePath& partition_path, | |
| 2197 bool is_incognito, | |
| 2198 const storage::OptionalQuotaSettingsCallback& callback) { | |
| 2199 content::BrowserThread::PostTaskAndReplyWithResult( | |
| 2200 content::BrowserThread::FILE, FROM_HERE, | |
| 2201 base::Bind(&CalculateQuotaSettings, partition_path, is_incognito), | |
| 2202 callback); | |
| 2203 } | |
| 2204 | |
| 2121 void ChromeContentBrowserClient::AllowCertificateError( | 2205 void ChromeContentBrowserClient::AllowCertificateError( |
| 2122 content::WebContents* web_contents, | 2206 content::WebContents* web_contents, |
| 2123 int cert_error, | 2207 int cert_error, |
| 2124 const net::SSLInfo& ssl_info, | 2208 const net::SSLInfo& ssl_info, |
| 2125 const GURL& request_url, | 2209 const GURL& request_url, |
| 2126 ResourceType resource_type, | 2210 ResourceType resource_type, |
| 2127 bool overridable, | 2211 bool overridable, |
| 2128 bool strict_enforcement, | 2212 bool strict_enforcement, |
| 2129 bool expired_previous_decision, | 2213 bool expired_previous_decision, |
| 2130 const base::Callback<void(content::CertificateRequestResultType)>& | 2214 const base::Callback<void(content::CertificateRequestResultType)>& |
| (...skipping 1103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3234 kWebRtcDevSwitchNames, | 3318 kWebRtcDevSwitchNames, |
| 3235 arraysize(kWebRtcDevSwitchNames)); | 3319 arraysize(kWebRtcDevSwitchNames)); |
| 3236 } | 3320 } |
| 3237 } | 3321 } |
| 3238 #endif // defined(ENABLE_WEBRTC) | 3322 #endif // defined(ENABLE_WEBRTC) |
| 3239 | 3323 |
| 3240 std::unique_ptr<content::MemoryCoordinatorDelegate> | 3324 std::unique_ptr<content::MemoryCoordinatorDelegate> |
| 3241 ChromeContentBrowserClient::GetMemoryCoordinatorDelegate() { | 3325 ChromeContentBrowserClient::GetMemoryCoordinatorDelegate() { |
| 3242 return memory::ChromeMemoryCoordinatorDelegate::Create(); | 3326 return memory::ChromeMemoryCoordinatorDelegate::Create(); |
| 3243 } | 3327 } |
| OLD | NEW |