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 2021 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2059 } | 2060 } |
| 2060 | 2061 |
| 2061 std::unique_ptr<storage::QuotaEvictionPolicy> | 2062 std::unique_ptr<storage::QuotaEvictionPolicy> |
| 2062 ChromeContentBrowserClient::GetTemporaryStorageEvictionPolicy( | 2063 ChromeContentBrowserClient::GetTemporaryStorageEvictionPolicy( |
| 2063 content::BrowserContext* context) { | 2064 content::BrowserContext* context) { |
| 2064 return SiteEngagementEvictionPolicy::IsEnabled() | 2065 return SiteEngagementEvictionPolicy::IsEnabled() |
| 2065 ? base::MakeUnique<SiteEngagementEvictionPolicy>(context) | 2066 ? base::MakeUnique<SiteEngagementEvictionPolicy>(context) |
| 2066 : nullptr; | 2067 : nullptr; |
| 2067 } | 2068 } |
| 2068 | 2069 |
| 2070 namespace { | |
| 2071 #define UMA_HISTOGRAM_MBYTES(name, sample) \ | |
| 2072 UMA_HISTOGRAM_CUSTOM_COUNTS( \ | |
| 2073 (name), static_cast<int>((sample) / kMBytes), \ | |
| 2074 1, 10 * 1024 * 1024 /* 10TB */, 100) | |
| 2075 | |
| 2076 storage::TemporaryStorageConfiguration CalculateTemporaryStorageConfig( | |
| 2077 const base::FilePath& partition_path, bool is_incognito) { | |
| 2078 const int64_t kMBytes = 1024 * 1024; | |
| 2079 | |
| 2080 if (is_incognito) { | |
| 2081 // TODO(michaeln): Base the poolsize on SysInfo::AmountOfPhysicalMemory(). | |
| 2082 storage::TemporaryStorageConfiguration config; | |
| 2083 config.pool_size = 300 * kMBytes; | |
| 2084 config.must_remain_available = 0; | |
| 2085 config.per_host_quota = config.pool_size / 3; | |
| 2086 config.refresh_interval = base::TimeDelta::Max(); | |
| 2087 return config; | |
| 2088 } | |
| 2089 | |
| 2090 // The fraction of the device's storage the browser is willing to | |
| 2091 // use for temporary storage, this is applied after adjusting the | |
| 2092 // total to take os_accomodation into account. | |
| 2093 const double kTemporaryPoolSizeRatio = 1.0 / 3.0; // 33% | |
| 2094 | |
| 2095 // The fraction of the device's storage the browser attempts to | |
| 2096 // keep free. | |
| 2097 const double kMustRemainAvailableRatio = 0.1; | |
| 2098 | |
| 2099 // Determines the portion of the temp pool that can be | |
| 2100 // utilized by a single host (ie. 5 for 20%). | |
| 2101 const int kPerHostTemporaryPortion = 5; | |
| 2102 | |
| 2103 // os_accomodation is an estimate of how much storage is needed for | |
| 2104 // the os and essential application code outside of the browser. | |
|
jsbell
2016/10/17 23:56:54
Nit: capitalize OS in comments/strings (here and b
michaeln
2016/10/26 21:47:53
Done.
| |
| 2105 const int64_t kDefaultOSAccomodation = | |
| 2106 #if defined(OS_ANDROID) | |
| 2107 1000 * kMBytes; | |
| 2108 #elif defined(OS_CHROMEOS) | |
| 2109 1000 * kMBytes; | |
| 2110 #elif defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) | |
| 2111 10000 * kMBytes; | |
| 2112 #else | |
| 2113 #error "Port: Need to define os_accomodation for unknown os." | |
| 2114 #endif | |
| 2115 | |
| 2116 storage::TemporaryStorageConfiguration config; | |
| 2117 | |
| 2118 int64_t total = base::SysInfo::AmountOfTotalDiskSpace(partition_path); | |
| 2119 if (total == -1) { | |
| 2120 LOG(ERROR) << "Failed to get the amount of total disk space."; | |
| 2121 config.refresh_interval = base::TimeDelta::FromSeconds(60); | |
| 2122 return config; | |
| 2123 } | |
| 2124 | |
| 2125 // If our hardcoded os accomodation is too large for the volume size, define | |
| 2126 // the value as a large fraction of the total volume size instead. | |
| 2127 int64_t os_accomodation = std::min(kDefaultOSAccomodation, | |
|
jsbell
2016/10/17 23:56:54
TODO: UMA histogram for kDefaultOSAccomodation / (
michaeln
2016/10/26 21:47:53
Done.
| |
| 2128 static_cast<int64_t>(total * 0.8)); | |
| 2129 | |
| 2130 int64_t adjusted_total = total - os_accomodation; | |
| 2131 int64_t pool_size = adjusted_total * kTemporaryPoolSizeRatio; | |
| 2132 UMA_HISTOGRAM_MBYTES("Quota.GlobalTemporaryPoolSize", pool_size); | |
|
jsbell
2016/10/17 23:56:53
This was UMA stat was previously recorded from Quo
michaeln
2016/10/26 21:47:53
Done - now gathering this stat in quota_manager.cc
| |
| 2133 | |
| 2134 config.pool_size = pool_size; | |
| 2135 config.must_remain_available = total * kMustRemainAvailableRatio; | |
| 2136 config.per_host_quota = pool_size / kPerHostTemporaryPortion;; | |
| 2137 config.refresh_interval = base::TimeDelta::FromSeconds(60); | |
| 2138 return config; | |
| 2139 } | |
| 2140 | |
| 2141 } // namespace | |
| 2142 | |
| 2143 void ChromeContentBrowserClient::GetTemporaryStorageConfiguration( | |
| 2144 content::BrowserContext* context, | |
| 2145 const base::FilePath& partition_path, bool is_incognito, | |
| 2146 const storage::TemporaryStorageConfigurationCallback& callback) { | |
| 2147 content::BrowserThread::PostTaskAndReplyWithResult( | |
| 2148 content::BrowserThread::FILE, | |
| 2149 FROM_HERE, | |
| 2150 base::Bind(&CalculateTemporaryStorageConfig, | |
| 2151 partition_path, is_incognito), | |
| 2152 callback); | |
| 2153 } | |
| 2154 | |
| 2069 void ChromeContentBrowserClient::AllowCertificateError( | 2155 void ChromeContentBrowserClient::AllowCertificateError( |
| 2070 content::WebContents* web_contents, | 2156 content::WebContents* web_contents, |
| 2071 int cert_error, | 2157 int cert_error, |
| 2072 const net::SSLInfo& ssl_info, | 2158 const net::SSLInfo& ssl_info, |
| 2073 const GURL& request_url, | 2159 const GURL& request_url, |
| 2074 ResourceType resource_type, | 2160 ResourceType resource_type, |
| 2075 bool overridable, | 2161 bool overridable, |
| 2076 bool strict_enforcement, | 2162 bool strict_enforcement, |
| 2077 bool expired_previous_decision, | 2163 bool expired_previous_decision, |
| 2078 const base::Callback<void(content::CertificateRequestResultType)>& | 2164 const base::Callback<void(content::CertificateRequestResultType)>& |
| (...skipping 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3223 if (channel <= kMaxDisableEncryptionChannel) { | 3309 if (channel <= kMaxDisableEncryptionChannel) { |
| 3224 static const char* const kWebRtcDevSwitchNames[] = { | 3310 static const char* const kWebRtcDevSwitchNames[] = { |
| 3225 switches::kDisableWebRtcEncryption, | 3311 switches::kDisableWebRtcEncryption, |
| 3226 }; | 3312 }; |
| 3227 to_command_line->CopySwitchesFrom(from_command_line, | 3313 to_command_line->CopySwitchesFrom(from_command_line, |
| 3228 kWebRtcDevSwitchNames, | 3314 kWebRtcDevSwitchNames, |
| 3229 arraysize(kWebRtcDevSwitchNames)); | 3315 arraysize(kWebRtcDevSwitchNames)); |
| 3230 } | 3316 } |
| 3231 } | 3317 } |
| 3232 #endif // defined(ENABLE_WEBRTC) | 3318 #endif // defined(ENABLE_WEBRTC) |
| OLD | NEW |