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/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 13 matching lines...) Expand all Loading... | |
| 24 #include "chrome/browser/net/chrome_extensions_network_delegate.h" | 24 #include "chrome/browser/net/chrome_extensions_network_delegate.h" |
| 25 #include "chrome/browser/net/client_hints.h" | 25 #include "chrome/browser/net/client_hints.h" |
| 26 #include "chrome/browser/net/connect_interceptor.h" | 26 #include "chrome/browser/net/connect_interceptor.h" |
| 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_delayed_p ref_service.h" | |
| 34 #include "components/data_reduction_proxy/browser/data_reduction_proxy_metrics.h " | 35 #include "components/data_reduction_proxy/browser/data_reduction_proxy_metrics.h " |
| 35 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" | 36 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" |
| 36 #include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol. h" | 37 #include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol. 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" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 int rv) { | 108 int rv) { |
| 108 if (rv == net::OK && new_url->is_empty()) | 109 if (rv == net::OK && new_url->is_empty()) |
| 109 safe_search_util::ForceGoogleSafeSearch(request, new_url); | 110 safe_search_util::ForceGoogleSafeSearch(request, new_url); |
| 110 callback.Run(rv); | 111 callback.Run(rv); |
| 111 } | 112 } |
| 112 | 113 |
| 113 void UpdateContentLengthPrefs( | 114 void UpdateContentLengthPrefs( |
| 114 int received_content_length, | 115 int received_content_length, |
| 115 int original_content_length, | 116 int original_content_length, |
| 116 data_reduction_proxy::DataReductionProxyRequestType request_type, | 117 data_reduction_proxy::DataReductionProxyRequestType request_type, |
| 117 Profile* profile) { | 118 Profile* profile, |
| 119 data_reduction_proxy::DataReductionProxyDelayedPrefService* pref_service) { | |
|
bengr
2014/08/14 17:39:41
DCHECK(pref_service)
Also, after the class renami
megjablon
2014/08/26 19:28:40
Done.
| |
| 118 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 119 DCHECK_GE(received_content_length, 0); | 121 DCHECK_GE(received_content_length, 0); |
| 120 DCHECK_GE(original_content_length, 0); | 122 DCHECK_GE(original_content_length, 0); |
| 121 | 123 |
| 122 // Can be NULL in a unit test. | 124 // Can be NULL in a unit test. |
| 123 if (!g_browser_process) | 125 if (!g_browser_process) |
| 124 return; | 126 return; |
| 125 | 127 |
| 126 PrefService* prefs = g_browser_process->local_state(); | 128 if (!pref_service) |
|
bengr
2014/08/14 17:39:41
Why would this ever be null?
megjablon
2014/08/26 19:28:40
Done.
| |
| 127 if (!prefs) | |
| 128 return; | 129 return; |
| 129 | 130 |
| 130 // Ignore off-the-record data. | 131 // Ignore off-the-record data. |
| 131 if (!g_browser_process->profile_manager()->IsValidProfile(profile) || | 132 if (!g_browser_process->profile_manager()->IsValidProfile(profile) || |
| 132 profile->IsOffTheRecord()) { | 133 profile->IsOffTheRecord()) { |
| 133 return; | 134 return; |
| 134 } | 135 } |
| 135 #if defined(OS_ANDROID) | 136 #if defined(OS_ANDROID) |
| 136 // If Android ever goes multi profile, the profile should be passed so that | 137 // If Android ever goes multi profile, the profile should be passed so that |
| 137 // the browser preference will be taken. | 138 // the browser preference will be taken. |
| 138 bool with_data_reduction_proxy_enabled = | 139 bool with_data_reduction_proxy_enabled = |
| 139 ProfileManager::GetActiveUserProfile()->GetPrefs()->GetBoolean( | 140 ProfileManager::GetActiveUserProfile()->GetPrefs()->GetBoolean( |
| 140 data_reduction_proxy::prefs::kDataReductionProxyEnabled); | 141 data_reduction_proxy::prefs::kDataReductionProxyEnabled); |
| 141 #else | 142 #else |
| 142 bool with_data_reduction_proxy_enabled = false; | 143 bool with_data_reduction_proxy_enabled = false; |
| 143 #endif | 144 #endif |
| 144 | 145 |
| 145 data_reduction_proxy::UpdateContentLengthPrefs(received_content_length, | 146 data_reduction_proxy::UpdateContentLengthPrefs( |
| 146 original_content_length, | 147 received_content_length, |
| 147 with_data_reduction_proxy_enabled, | 148 original_content_length, |
| 148 request_type, prefs); | 149 with_data_reduction_proxy_enabled, |
| 150 request_type, | |
| 151 pref_service); | |
| 149 } | 152 } |
| 150 | 153 |
| 151 void StoreAccumulatedContentLength( | 154 void StoreAccumulatedContentLength( |
| 152 int received_content_length, | 155 int received_content_length, |
| 153 int original_content_length, | 156 int original_content_length, |
| 154 data_reduction_proxy::DataReductionProxyRequestType request_type, | 157 data_reduction_proxy::DataReductionProxyRequestType request_type, |
| 155 Profile* profile) { | 158 Profile* profile, |
| 159 data_reduction_proxy::DataReductionProxyDelayedPrefService* pref_service) { | |
| 156 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 160 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 157 base::Bind(&UpdateContentLengthPrefs, | 161 base::Bind(&UpdateContentLengthPrefs, |
| 158 received_content_length, original_content_length, | 162 received_content_length, original_content_length, |
| 159 request_type, profile)); | 163 request_type, profile, pref_service)); |
| 160 } | 164 } |
| 161 | 165 |
| 162 void RecordContentLengthHistograms( | 166 void RecordContentLengthHistograms( |
| 163 int64 received_content_length, | 167 int64 received_content_length, |
| 164 int64 original_content_length, | 168 int64 original_content_length, |
| 165 const base::TimeDelta& freshness_lifetime) { | 169 const base::TimeDelta& freshness_lifetime) { |
| 166 // Add the current resource to these histograms only when a valid | 170 // Add the current resource to these histograms only when a valid |
| 167 // X-Original-Content-Length header is present. | 171 // X-Original-Content-Length header is present. |
| 168 if (original_content_length >= 0) { | 172 if (original_content_length >= 0) { |
| 169 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthWithValidOCL", | 173 UMA_HISTOGRAM_COUNTS("Net.HttpContentLengthWithValidOCL", |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 #if defined(ENABLE_CONFIGURATION_POLICY) | 249 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 246 url_blacklist_manager_(NULL), | 250 url_blacklist_manager_(NULL), |
| 247 #endif | 251 #endif |
| 248 domain_reliability_monitor_(NULL), | 252 domain_reliability_monitor_(NULL), |
| 249 received_content_length_(0), | 253 received_content_length_(0), |
| 250 original_content_length_(0), | 254 original_content_length_(0), |
| 251 first_request_(true), | 255 first_request_(true), |
| 252 prerender_tracker_(NULL), | 256 prerender_tracker_(NULL), |
| 253 data_reduction_proxy_params_(NULL), | 257 data_reduction_proxy_params_(NULL), |
| 254 data_reduction_proxy_usage_stats_(NULL), | 258 data_reduction_proxy_usage_stats_(NULL), |
| 255 data_reduction_proxy_auth_request_handler_(NULL) { | 259 data_reduction_proxy_auth_request_handler_(NULL), |
| 260 data_reduction_proxy_delayed_pref_service_(NULL) { | |
| 256 DCHECK(enable_referrers); | 261 DCHECK(enable_referrers); |
| 257 extensions_delegate_.reset( | 262 extensions_delegate_.reset( |
| 258 ChromeExtensionsNetworkDelegate::Create(event_router)); | 263 ChromeExtensionsNetworkDelegate::Create(event_router)); |
| 259 } | 264 } |
| 260 | 265 |
| 261 ChromeNetworkDelegate::~ChromeNetworkDelegate() {} | 266 ChromeNetworkDelegate::~ChromeNetworkDelegate() {} |
| 262 | 267 |
| 263 void ChromeNetworkDelegate::set_extension_info_map( | 268 void ChromeNetworkDelegate::set_extension_info_map( |
| 264 extensions::InfoMap* extension_info_map) { | 269 extensions::InfoMap* extension_info_map) { |
| 265 extensions_delegate_->set_extension_info_map(extension_info_map); | 270 extensions_delegate_->set_extension_info_map(extension_info_map); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); | 319 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
| 315 } | 320 } |
| 316 } | 321 } |
| 317 | 322 |
| 318 // static | 323 // static |
| 319 void ChromeNetworkDelegate::AllowAccessToAllFiles() { | 324 void ChromeNetworkDelegate::AllowAccessToAllFiles() { |
| 320 g_allow_file_access_ = true; | 325 g_allow_file_access_ = true; |
| 321 } | 326 } |
| 322 | 327 |
| 323 // static | 328 // static |
| 329 // TODO(megjablon): Use data_reduction_proxy_delayed_pref_service to read prefs. | |
| 330 // Until updated the pref values may be up to an hour behind. | |
|
bengr
2014/08/14 17:39:41
Please file a bug to fix this.
megjablon
2014/08/26 19:28:40
Done.
| |
| 324 base::Value* ChromeNetworkDelegate::HistoricNetworkStatsInfoToValue() { | 331 base::Value* ChromeNetworkDelegate::HistoricNetworkStatsInfoToValue() { |
| 325 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 332 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 326 PrefService* prefs = g_browser_process->local_state(); | 333 PrefService* prefs = g_browser_process->local_state(); |
| 327 int64 total_received = prefs->GetInt64( | 334 int64 total_received = prefs->GetInt64( |
| 328 data_reduction_proxy::prefs::kHttpReceivedContentLength); | 335 data_reduction_proxy::prefs::kHttpReceivedContentLength); |
| 329 int64 total_original = prefs->GetInt64( | 336 int64 total_original = prefs->GetInt64( |
| 330 data_reduction_proxy::prefs::kHttpOriginalContentLength); | 337 data_reduction_proxy::prefs::kHttpOriginalContentLength); |
| 331 | 338 |
| 332 base::DictionaryValue* dict = new base::DictionaryValue(); | 339 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 333 // Use strings to avoid overflow. base::Value only supports 32-bit integers. | 340 // Use strings to avoid overflow. base::Value only supports 32-bit integers. |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 794 #endif | 801 #endif |
| 795 return net::OK; | 802 return net::OK; |
| 796 } | 803 } |
| 797 | 804 |
| 798 void ChromeNetworkDelegate::AccumulateContentLength( | 805 void ChromeNetworkDelegate::AccumulateContentLength( |
| 799 int64 received_content_length, | 806 int64 received_content_length, |
| 800 int64 original_content_length, | 807 int64 original_content_length, |
| 801 data_reduction_proxy::DataReductionProxyRequestType request_type) { | 808 data_reduction_proxy::DataReductionProxyRequestType request_type) { |
| 802 DCHECK_GE(received_content_length, 0); | 809 DCHECK_GE(received_content_length, 0); |
| 803 DCHECK_GE(original_content_length, 0); | 810 DCHECK_GE(original_content_length, 0); |
| 804 StoreAccumulatedContentLength(received_content_length, | 811 if (data_reduction_proxy_delayed_pref_service_) { |
| 805 original_content_length, | 812 StoreAccumulatedContentLength(received_content_length, |
| 806 request_type, | 813 original_content_length, |
| 807 reinterpret_cast<Profile*>(profile_)); | 814 request_type, |
| 815 reinterpret_cast<Profile*>(profile_), | |
| 816 data_reduction_proxy_delayed_pref_service_); | |
| 817 } | |
| 808 received_content_length_ += received_content_length; | 818 received_content_length_ += received_content_length; |
| 809 original_content_length_ += original_content_length; | 819 original_content_length_ += original_content_length; |
| 810 } | 820 } |
| OLD | NEW |