| 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/net/chrome_network_delegate.h" | 5 #include "chrome/browser/net/chrome_network_delegate.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "chrome/browser/net/safe_search_util.h" | 27 #include "chrome/browser/net/safe_search_util.h" |
| 28 #include "chrome/browser/performance_monitor/performance_monitor.h" | 28 #include "chrome/browser/performance_monitor/performance_monitor.h" |
| 29 #include "chrome/browser/prerender/prerender_tracker.h" | 29 #include "chrome/browser/prerender/prerender_tracker.h" |
| 30 #include "chrome/browser/profiles/profile_manager.h" | 30 #include "chrome/browser/profiles/profile_manager.h" |
| 31 #include "chrome/browser/task_manager/task_manager.h" | 31 #include "chrome/browser/task_manager/task_manager.h" |
| 32 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
| 33 #include "components/data_reduction_proxy/browser/data_reduction_proxy_auth_requ
est_handler.h" | 33 #include "components/data_reduction_proxy/browser/data_reduction_proxy_auth_requ
est_handler.h" |
| 34 #include "components/data_reduction_proxy/browser/data_reduction_proxy_metrics.h
" | 34 #include "components/data_reduction_proxy/browser/data_reduction_proxy_metrics.h
" |
| 35 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" | 35 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" |
| 36 #include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol.
h" | 36 #include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol.
h" |
| 37 #include "components/data_reduction_proxy/browser/data_reduction_proxy_statistic
s_prefs.h" |
| 37 #include "components/data_reduction_proxy/browser/data_reduction_proxy_usage_sta
ts.h" | 38 #include "components/data_reduction_proxy/browser/data_reduction_proxy_usage_sta
ts.h" |
| 38 #include "components/domain_reliability/monitor.h" | 39 #include "components/domain_reliability/monitor.h" |
| 39 #include "content/public/browser/browser_thread.h" | 40 #include "content/public/browser/browser_thread.h" |
| 40 #include "content/public/browser/render_frame_host.h" | 41 #include "content/public/browser/render_frame_host.h" |
| 41 #include "content/public/browser/render_view_host.h" | 42 #include "content/public/browser/render_view_host.h" |
| 42 #include "content/public/browser/resource_request_info.h" | 43 #include "content/public/browser/resource_request_info.h" |
| 43 #include "net/base/host_port_pair.h" | 44 #include "net/base/host_port_pair.h" |
| 44 #include "net/base/net_errors.h" | 45 #include "net/base/net_errors.h" |
| 45 #include "net/base/net_log.h" | 46 #include "net/base/net_log.h" |
| 46 #include "net/cookies/canonical_cookie.h" | 47 #include "net/cookies/canonical_cookie.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 int rv) { | 110 int rv) { |
| 110 if (rv == net::OK && new_url->is_empty()) | 111 if (rv == net::OK && new_url->is_empty()) |
| 111 safe_search_util::ForceGoogleSafeSearch(request, new_url); | 112 safe_search_util::ForceGoogleSafeSearch(request, new_url); |
| 112 callback.Run(rv); | 113 callback.Run(rv); |
| 113 } | 114 } |
| 114 | 115 |
| 115 void UpdateContentLengthPrefs( | 116 void UpdateContentLengthPrefs( |
| 116 int received_content_length, | 117 int received_content_length, |
| 117 int original_content_length, | 118 int original_content_length, |
| 118 data_reduction_proxy::DataReductionProxyRequestType request_type, | 119 data_reduction_proxy::DataReductionProxyRequestType request_type, |
| 119 Profile* profile) { | 120 Profile* profile, |
| 121 data_reduction_proxy::DataReductionProxyStatisticsPrefs* statistics_prefs) { |
| 120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 121 DCHECK_GE(received_content_length, 0); | 123 DCHECK_GE(received_content_length, 0); |
| 122 DCHECK_GE(original_content_length, 0); | 124 DCHECK_GE(original_content_length, 0); |
| 123 | 125 |
| 124 // Can be NULL in a unit test. | 126 // Can be NULL in a unit test. |
| 125 if (!g_browser_process) | 127 if (!g_browser_process) |
| 126 return; | 128 return; |
| 127 | 129 |
| 128 PrefService* prefs = g_browser_process->local_state(); | |
| 129 if (!prefs) | |
| 130 return; | |
| 131 | |
| 132 // Ignore off-the-record data. | 130 // Ignore off-the-record data. |
| 133 if (!g_browser_process->profile_manager()->IsValidProfile(profile) || | 131 if (!g_browser_process->profile_manager()->IsValidProfile(profile) || |
| 134 profile->IsOffTheRecord()) { | 132 profile->IsOffTheRecord()) { |
| 135 return; | 133 return; |
| 136 } | 134 } |
| 137 #if defined(OS_ANDROID) && defined(SPDY_PROXY_AUTH_ORIGIN) | 135 #if defined(OS_ANDROID) && defined(SPDY_PROXY_AUTH_ORIGIN) |
| 138 // If Android ever goes multi profile, the profile should be passed so that | 136 // If Android ever goes multi profile, the profile should be passed so that |
| 139 // the browser preference will be taken. | 137 // the browser preference will be taken. |
| 140 bool with_data_reduction_proxy_enabled = | 138 bool with_data_reduction_proxy_enabled = |
| 141 ProfileManager::GetActiveUserProfile()->GetPrefs()->GetBoolean( | 139 ProfileManager::GetActiveUserProfile()->GetPrefs()->GetBoolean( |
| 142 data_reduction_proxy::prefs::kDataReductionProxyEnabled); | 140 data_reduction_proxy::prefs::kDataReductionProxyEnabled); |
| 143 #else | 141 #else |
| 144 bool with_data_reduction_proxy_enabled = false; | 142 bool with_data_reduction_proxy_enabled = false; |
| 145 #endif | 143 #endif |
| 146 | 144 |
| 147 data_reduction_proxy::UpdateContentLengthPrefs(received_content_length, | 145 data_reduction_proxy::UpdateContentLengthPrefs( |
| 148 original_content_length, | 146 received_content_length, |
| 149 with_data_reduction_proxy_enabled, | 147 original_content_length, |
| 150 request_type, prefs); | 148 with_data_reduction_proxy_enabled, |
| 149 request_type, |
| 150 statistics_prefs); |
| 151 } | 151 } |
| 152 | 152 |
| 153 void StoreAccumulatedContentLength( | 153 void StoreAccumulatedContentLength( |
| 154 int received_content_length, | 154 int received_content_length, |
| 155 int original_content_length, | 155 int original_content_length, |
| 156 data_reduction_proxy::DataReductionProxyRequestType request_type, | 156 data_reduction_proxy::DataReductionProxyRequestType request_type, |
| 157 Profile* profile) { | 157 Profile* profile, |
| 158 data_reduction_proxy::DataReductionProxyStatisticsPrefs* statistics_prefs) { |
| 158 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 159 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 159 base::Bind(&UpdateContentLengthPrefs, | 160 base::Bind(&UpdateContentLengthPrefs, |
| 160 received_content_length, original_content_length, | 161 received_content_length, |
| 161 request_type, profile)); | 162 original_content_length, |
| 163 request_type, |
| 164 profile, |
| 165 statistics_prefs)); |
| 162 } | 166 } |
| 163 | 167 |
| 164 void RecordContentLengthHistograms( | 168 void RecordContentLengthHistograms( |
| 165 int64 received_content_length, | 169 int64 received_content_length, |
| 166 int64 original_content_length, | 170 int64 original_content_length, |
| 167 const base::TimeDelta& freshness_lifetime) { | 171 const base::TimeDelta& freshness_lifetime) { |
| 168 // Add the current resource to these histograms only when a valid | 172 // Add the current resource to these histograms only when a valid |
| 169 // X-Original-Content-Length header is present. | 173 // X-Original-Content-Length header is present. |
| 170 if (original_content_length >= 0) { | 174 if (original_content_length >= 0) { |
| 171 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthWithValidOCL", | 175 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthWithValidOCL", |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 #if defined(ENABLE_CONFIGURATION_POLICY) | 251 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 248 url_blacklist_manager_(NULL), | 252 url_blacklist_manager_(NULL), |
| 249 #endif | 253 #endif |
| 250 domain_reliability_monitor_(NULL), | 254 domain_reliability_monitor_(NULL), |
| 251 received_content_length_(0), | 255 received_content_length_(0), |
| 252 original_content_length_(0), | 256 original_content_length_(0), |
| 253 first_request_(true), | 257 first_request_(true), |
| 254 prerender_tracker_(NULL), | 258 prerender_tracker_(NULL), |
| 255 data_reduction_proxy_params_(NULL), | 259 data_reduction_proxy_params_(NULL), |
| 256 data_reduction_proxy_usage_stats_(NULL), | 260 data_reduction_proxy_usage_stats_(NULL), |
| 257 data_reduction_proxy_auth_request_handler_(NULL) { | 261 data_reduction_proxy_auth_request_handler_(NULL), |
| 262 data_reduction_proxy_statistics_prefs_(NULL) { |
| 258 DCHECK(enable_referrers); | 263 DCHECK(enable_referrers); |
| 259 extensions_delegate_.reset( | 264 extensions_delegate_.reset( |
| 260 ChromeExtensionsNetworkDelegate::Create(event_router)); | 265 ChromeExtensionsNetworkDelegate::Create(event_router)); |
| 261 } | 266 } |
| 262 | 267 |
| 263 ChromeNetworkDelegate::~ChromeNetworkDelegate() {} | 268 ChromeNetworkDelegate::~ChromeNetworkDelegate() {} |
| 264 | 269 |
| 265 void ChromeNetworkDelegate::set_extension_info_map( | 270 void ChromeNetworkDelegate::set_extension_info_map( |
| 266 extensions::InfoMap* extension_info_map) { | 271 extensions::InfoMap* extension_info_map) { |
| 267 extensions_delegate_->set_extension_info_map(extension_info_map); | 272 extensions_delegate_->set_extension_info_map(extension_info_map); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); | 321 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
| 317 } | 322 } |
| 318 } | 323 } |
| 319 | 324 |
| 320 // static | 325 // static |
| 321 void ChromeNetworkDelegate::AllowAccessToAllFiles() { | 326 void ChromeNetworkDelegate::AllowAccessToAllFiles() { |
| 322 g_allow_file_access_ = true; | 327 g_allow_file_access_ = true; |
| 323 } | 328 } |
| 324 | 329 |
| 325 // static | 330 // static |
| 331 // TODO(megjablon): Use data_reduction_proxy_delayed_pref_service to read prefs. |
| 332 // Until updated the pref values may be up to an hour behind on desktop. |
| 326 base::Value* ChromeNetworkDelegate::HistoricNetworkStatsInfoToValue() { | 333 base::Value* ChromeNetworkDelegate::HistoricNetworkStatsInfoToValue() { |
| 327 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 334 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 328 PrefService* prefs = g_browser_process->local_state(); | 335 PrefService* prefs = g_browser_process->local_state(); |
| 329 int64 total_received = prefs->GetInt64( | 336 int64 total_received = prefs->GetInt64( |
| 330 data_reduction_proxy::prefs::kHttpReceivedContentLength); | 337 data_reduction_proxy::prefs::kHttpReceivedContentLength); |
| 331 int64 total_original = prefs->GetInt64( | 338 int64 total_original = prefs->GetInt64( |
| 332 data_reduction_proxy::prefs::kHttpOriginalContentLength); | 339 data_reduction_proxy::prefs::kHttpOriginalContentLength); |
| 333 | 340 |
| 334 base::DictionaryValue* dict = new base::DictionaryValue(); | 341 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 335 // Use strings to avoid overflow. base::Value only supports 32-bit integers. | 342 // Use strings to avoid overflow. base::Value only supports 32-bit integers. |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 #endif | 821 #endif |
| 815 return net::OK; | 822 return net::OK; |
| 816 } | 823 } |
| 817 | 824 |
| 818 void ChromeNetworkDelegate::AccumulateContentLength( | 825 void ChromeNetworkDelegate::AccumulateContentLength( |
| 819 int64 received_content_length, | 826 int64 received_content_length, |
| 820 int64 original_content_length, | 827 int64 original_content_length, |
| 821 data_reduction_proxy::DataReductionProxyRequestType request_type) { | 828 data_reduction_proxy::DataReductionProxyRequestType request_type) { |
| 822 DCHECK_GE(received_content_length, 0); | 829 DCHECK_GE(received_content_length, 0); |
| 823 DCHECK_GE(original_content_length, 0); | 830 DCHECK_GE(original_content_length, 0); |
| 824 StoreAccumulatedContentLength(received_content_length, | 831 if (data_reduction_proxy_statistics_prefs_) { |
| 825 original_content_length, | 832 StoreAccumulatedContentLength(received_content_length, |
| 826 request_type, | 833 original_content_length, |
| 827 reinterpret_cast<Profile*>(profile_)); | 834 request_type, |
| 835 reinterpret_cast<Profile*>(profile_), |
| 836 data_reduction_proxy_statistics_prefs_); |
| 837 } |
| 828 received_content_length_ += received_content_length; | 838 received_content_length_ += received_content_length; |
| 829 original_content_length_ += original_content_length; | 839 original_content_length_ += original_content_length; |
| 830 } | 840 } |
| OLD | NEW |