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