OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/data_reduction_proxy/browser/data_reduction_proxy_metrics.h
" | 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_metrics.h
" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/prefs/scoped_user_pref_update.h" | 9 #include "base/prefs/scoped_user_pref_update.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 } | 283 } |
284 int64 GetReceivedListPrefValue(size_t index) { | 284 int64 GetReceivedListPrefValue(size_t index) { |
285 return received_.GetListPrefValue(index); | 285 return received_.GetListPrefValue(index); |
286 } | 286 } |
287 | 287 |
288 private: | 288 private: |
289 DailyContentLengthUpdate original_; | 289 DailyContentLengthUpdate original_; |
290 DailyContentLengthUpdate received_; | 290 DailyContentLengthUpdate received_; |
291 }; | 291 }; |
292 | 292 |
293 // Returns true if the request is bypassed by all configured data reduction | |
294 // proxies. It returns the bypass delay in delay_seconds (if not NULL). If | |
295 // the request is bypassed by more than one proxy, delay_seconds returns | |
296 // shortest delay. | |
297 bool IsBypassRequest(const net::URLRequest* request, int64* delay_seconds) { | |
298 // TODO(bengr): Add support for other data reduction proxy configurations. | |
299 #if defined(SPDY_PROXY_AUTH_ORIGIN) | |
300 DataReductionProxyParams params( | |
301 DataReductionProxyParams::kAllowed | | |
302 DataReductionProxyParams::kFallbackAllowed | | |
303 DataReductionProxyParams::kPromoAllowed); | |
304 DataReductionProxyParams::DataReductionProxyList proxies = | |
305 params.GetAllowedProxies(); | |
306 if (proxies.size() == 0) | |
307 return false; | |
308 | |
309 if (request == NULL || request->context() == NULL || | |
310 request->context()->proxy_service() == NULL) { | |
311 return false; | |
312 } | |
313 | |
314 const net::ProxyRetryInfoMap& retry_map = | |
315 request->context()->proxy_service()->proxy_retry_info(); | |
316 if (retry_map.size() == 0) | |
317 return false; | |
318 | |
319 int64 shortest_delay = 0; | |
320 // The request is bypassed if all configured proxies are in the retry map. | |
321 for (size_t i = 0; i < proxies.size(); ++i) { | |
322 std::string proxy = net::HostPortPair::FromURL(proxies[i]).ToString(); | |
323 // The retry list has the scheme prefix for https but not for http. | |
324 if (proxies[i].SchemeIs("https")) | |
325 proxy = std::string("https://") + proxy; | |
326 | |
327 net::ProxyRetryInfoMap::const_iterator found = retry_map.find(proxy); | |
328 if (found == retry_map.end()) | |
329 return false; | |
330 if (shortest_delay == 0 || | |
331 shortest_delay > found->second.current_delay.InSeconds()) { | |
332 shortest_delay = found->second.current_delay.InSeconds(); | |
333 } | |
334 } | |
335 if (delay_seconds != NULL) | |
336 *delay_seconds = shortest_delay; | |
337 return true; | |
338 #else | |
339 return false; | |
340 #endif | |
341 } | |
342 | |
343 } // namespace | 293 } // namespace |
344 | 294 |
345 DataReductionProxyRequestType GetDataReductionProxyRequestType( | 295 DataReductionProxyRequestType GetDataReductionProxyRequestType( |
346 const net::URLRequest* request) { | 296 const net::URLRequest* request) { |
347 if (request->url().SchemeIs("https")) | 297 if (request->url().SchemeIs("https")) |
348 return HTTPS; | 298 return HTTPS; |
349 if (!request->url().SchemeIs("http")) { | 299 if (!request->url().SchemeIs("http")) { |
350 NOTREACHED(); | 300 NOTREACHED(); |
351 return UNKNOWN_TYPE; | 301 return UNKNOWN_TYPE; |
352 } | 302 } |
| 303 DataReductionProxyParams params( |
| 304 DataReductionProxyParams::kAllowed | |
| 305 DataReductionProxyParams::kFallbackAllowed | |
| 306 DataReductionProxyParams::kPromoAllowed); |
353 int64 bypass_delay = 0; | 307 int64 bypass_delay = 0; |
354 if (IsBypassRequest(request, &bypass_delay)) { | 308 if (params.WereDataReductionProxiesBypassed(request, &bypass_delay)) { |
355 return (bypass_delay > kLongBypassDelayInSeconds) ? | 309 return (bypass_delay > kLongBypassDelayInSeconds) ? |
356 LONG_BYPASS : SHORT_BYPASS; | 310 LONG_BYPASS : SHORT_BYPASS; |
357 } | 311 } |
358 if (request->response_info().headers && | 312 if (request->response_info().headers && |
359 HasDataReductionProxyViaHeader(request->response_info().headers)) { | 313 HasDataReductionProxyViaHeader(request->response_info().headers)) { |
360 return VIA_DATA_REDUCTION_PROXY; | 314 return VIA_DATA_REDUCTION_PROXY; |
361 } | 315 } |
362 return UNKNOWN_TYPE; | 316 return UNKNOWN_TYPE; |
363 } | 317 } |
364 | 318 |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 UpdateContentLengthPrefsForDataReductionProxy( | 488 UpdateContentLengthPrefsForDataReductionProxy( |
535 received_content_length, | 489 received_content_length, |
536 original_content_length, | 490 original_content_length, |
537 with_data_reduction_proxy_enabled, | 491 with_data_reduction_proxy_enabled, |
538 request_type, | 492 request_type, |
539 base::Time::Now(), | 493 base::Time::Now(), |
540 prefs); | 494 prefs); |
541 } | 495 } |
542 | 496 |
543 } // namespace data_reduction_proxy | 497 } // namespace data_reduction_proxy |
OLD | NEW |