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> |
(...skipping 2015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2026 } | 2026 } |
2027 | 2027 |
2028 std::unique_ptr<storage::QuotaEvictionPolicy> | 2028 std::unique_ptr<storage::QuotaEvictionPolicy> |
2029 ChromeContentBrowserClient::GetTemporaryStorageEvictionPolicy( | 2029 ChromeContentBrowserClient::GetTemporaryStorageEvictionPolicy( |
2030 content::BrowserContext* context) { | 2030 content::BrowserContext* context) { |
2031 return SiteEngagementEvictionPolicy::IsEnabled() | 2031 return SiteEngagementEvictionPolicy::IsEnabled() |
2032 ? base::WrapUnique(new SiteEngagementEvictionPolicy(context)) | 2032 ? base::WrapUnique(new SiteEngagementEvictionPolicy(context)) |
2033 : nullptr; | 2033 : nullptr; |
2034 } | 2034 } |
2035 | 2035 |
2036 namespace { | |
2037 #define UMA_HISTOGRAM_MBYTES(name, sample) \ | |
2038 UMA_HISTOGRAM_CUSTOM_COUNTS( \ | |
2039 (name), static_cast<int>((sample) / kMBytes), \ | |
2040 1, 10 * 1024 * 1024 /* 10TB */, 100) | |
2041 | |
2042 storage::TemporaryStorageConfiguration CalculateTemporaryStorageConfig( | |
2043 const base::FilePath& profile_path, bool is_incognito) { | |
2044 const int64_t kMBytes = 1024 * 1024; | |
2045 | |
2046 if (is_incognito) { | |
2047 // TODO(michaeln): Base the poolsize on SysInfo::AmountOfPhysicalMemory(). | |
2048 storage::TemporaryStorageConfiguration config; | |
2049 config.pool_size = 300 * kMBytes; | |
2050 config.must_remain_available = 0; | |
2051 config.per_host_portion = 3; | |
2052 config.refresh_interval = base::TimeDelta::Max(); | |
2053 return config; | |
2054 } | |
2055 | |
2056 // The fraction of the device's storage the browser is willing to | |
2057 // use for temporary storage, this is applied after adjusting the | |
2058 // total to take os_accomodation into account. | |
2059 const double kTemporaryPoolSizeRatio = 1.0 / 3.0; // 33% | |
2060 | |
2061 // Determines the portion of the temp pool that can be | |
2062 // utilized by a single host (ie. 5 for 20%). | |
2063 const int kPerHostTemporaryPortion = 5; | |
2064 | |
2065 // os_accomodation is an estimate of how much storage is needed for | |
2066 // the os and essential application code outside of the browser. | |
2067 #if defined(OS_ANDROID) | |
2068 uint64_t os_accomodation = 1000 * kMBytes; | |
2069 #elif defined(OS_CHROMEOS) | |
2070 uint64_t os_accomodation = 1000 * kMBytes; | |
2071 #elif defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) | |
2072 uint64_t os_accomodation = 10000 * kMBytes; | |
2073 #else | |
2074 #error "Port: Need to define os_accomodation for unknown os." | |
2075 #endif | |
2076 | |
2077 int64_t pool_size = 0; | |
2078 uint64_t available, total; | |
2079 if (storage::QuotaManager::GetVolumeInfo(profile_path, &available, &total)) { | |
2080 // If our hardcoded os_accomodation is too large for the volume size, define | |
2081 // the value as a large fraction of the total volume size instead. | |
2082 os_accomodation = std::min(os_accomodation, | |
2083 static_cast<uint64_t>(total * 0.8)); | |
2084 | |
2085 int64_t adjusted_total = total - os_accomodation; | |
2086 pool_size = static_cast<int64_t>(adjusted_total * kTemporaryPoolSizeRatio); | |
2087 UMA_HISTOGRAM_MBYTES("Quota.GlobalTemporaryPoolSize", pool_size); | |
2088 } | |
2089 | |
2090 storage::TemporaryStorageConfiguration config; | |
2091 config.pool_size = pool_size; | |
2092 config.must_remain_available = pool_size / kPerHostTemporaryPortion; | |
2093 config.per_host_portion = kPerHostTemporaryPortion; | |
2094 config.refresh_interval = base::TimeDelta::FromSeconds(60); | |
2095 return config; | |
2096 } | |
2097 | |
2098 void GetTemporaryStorageConfiguration( | |
2099 const base::FilePath& profile_path, bool is_incognito, | |
2100 storage::TemporaryStorageConfigurationCallback callback) { | |
kinuko
2016/07/27 14:23:25
nit: const ref
| |
2101 content::BrowserThread::PostTaskAndReplyWithResult( | |
kinuko
2016/07/27 14:23:25
Why this one needs to be called from the UI thread
| |
2102 content::BrowserThread::FILE, | |
2103 FROM_HERE, | |
2104 base::Bind(&CalculateTemporaryStorageConfig, profile_path, is_incognito), | |
2105 callback); | |
2106 } | |
2107 } // namespace | |
2108 | |
2109 storage::GetTemporaryStorageConfigurationFunc | |
2110 ChromeContentBrowserClient::GetTemporaryStorageConfigurationFunction( | |
2111 content::BrowserContext* context) { | |
2112 return base::Bind(&GetTemporaryStorageConfiguration); | |
2113 } | |
2114 | |
2036 void ChromeContentBrowserClient::AllowCertificateError( | 2115 void ChromeContentBrowserClient::AllowCertificateError( |
2037 content::WebContents* web_contents, | 2116 content::WebContents* web_contents, |
2038 int cert_error, | 2117 int cert_error, |
2039 const net::SSLInfo& ssl_info, | 2118 const net::SSLInfo& ssl_info, |
2040 const GURL& request_url, | 2119 const GURL& request_url, |
2041 ResourceType resource_type, | 2120 ResourceType resource_type, |
2042 bool overridable, | 2121 bool overridable, |
2043 bool strict_enforcement, | 2122 bool strict_enforcement, |
2044 bool expired_previous_decision, | 2123 bool expired_previous_decision, |
2045 const base::Callback<void(bool)>& callback, | 2124 const base::Callback<void(bool)>& callback, |
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3053 if (channel <= kMaxDisableEncryptionChannel) { | 3132 if (channel <= kMaxDisableEncryptionChannel) { |
3054 static const char* const kWebRtcDevSwitchNames[] = { | 3133 static const char* const kWebRtcDevSwitchNames[] = { |
3055 switches::kDisableWebRtcEncryption, | 3134 switches::kDisableWebRtcEncryption, |
3056 }; | 3135 }; |
3057 to_command_line->CopySwitchesFrom(from_command_line, | 3136 to_command_line->CopySwitchesFrom(from_command_line, |
3058 kWebRtcDevSwitchNames, | 3137 kWebRtcDevSwitchNames, |
3059 arraysize(kWebRtcDevSwitchNames)); | 3138 arraysize(kWebRtcDevSwitchNames)); |
3060 } | 3139 } |
3061 } | 3140 } |
3062 #endif // defined(ENABLE_WEBRTC) | 3141 #endif // defined(ENABLE_WEBRTC) |
OLD | NEW |