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" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.
h" | 12 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.
h" |
13 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" | 13 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" |
14 #include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names
.h" | 14 #include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names
.h" |
15 #include "net/base/host_port_pair.h" | 15 #include "net/base/host_port_pair.h" |
16 #include "net/http/http_response_headers.h" | 16 #include "net/http/http_response_headers.h" |
17 #include "net/proxy/proxy_retry_info.h" | 17 #include "net/proxy/proxy_retry_info.h" |
18 #include "net/proxy/proxy_service.h" | 18 #include "net/proxy/proxy_service.h" |
19 #include "net/url_request/url_request_context.h" | 19 #include "net/url_request/url_request_context.h" |
20 | 20 |
21 namespace data_reduction_proxy { | 21 namespace data_reduction_proxy { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 #if defined(SPDY_PROXY_AUTH_ORIGIN) | |
26 // A bypass delay more than this is treated as a long delay. | 25 // A bypass delay more than this is treated as a long delay. |
27 const int kLongBypassDelayInSeconds = 30 * 60; | 26 const int kLongBypassDelayInSeconds = 30 * 60; |
28 #endif | |
29 | 27 |
30 // Increments an int64, stored as a string, in a ListPref at the specified | 28 // Increments an int64, stored as a string, in a ListPref at the specified |
31 // index. The value must already exist and be a string representation of a | 29 // index. The value must already exist and be a string representation of a |
32 // number. | 30 // number. |
33 void AddInt64ToListPref(size_t index, | 31 void AddInt64ToListPref(size_t index, |
34 int64 length, | 32 int64 length, |
35 base::ListValue* list_update) { | 33 base::ListValue* list_update) { |
36 int64 value = 0; | 34 int64 value = 0; |
37 std::string old_string_value; | 35 std::string old_string_value; |
38 bool rv = list_update->GetString(index, &old_string_value); | 36 bool rv = list_update->GetString(index, &old_string_value); |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 } // namespace | 293 } // namespace |
296 | 294 |
297 DataReductionProxyRequestType GetDataReductionProxyRequestType( | 295 DataReductionProxyRequestType GetDataReductionProxyRequestType( |
298 const net::URLRequest* request) { | 296 const net::URLRequest* request) { |
299 if (request->url().SchemeIs("https")) | 297 if (request->url().SchemeIs("https")) |
300 return HTTPS; | 298 return HTTPS; |
301 if (!request->url().SchemeIs("http")) { | 299 if (!request->url().SchemeIs("http")) { |
302 NOTREACHED(); | 300 NOTREACHED(); |
303 return UNKNOWN_TYPE; | 301 return UNKNOWN_TYPE; |
304 } | 302 } |
305 #if defined(SPDY_PROXY_AUTH_ORIGIN) | |
306 DataReductionProxyParams params( | 303 DataReductionProxyParams params( |
307 DataReductionProxyParams::kAllowed | | 304 DataReductionProxyParams::kAllowed | |
308 DataReductionProxyParams::kFallbackAllowed | | 305 DataReductionProxyParams::kFallbackAllowed | |
309 DataReductionProxyParams::kPromoAllowed); | 306 DataReductionProxyParams::kPromoAllowed); |
310 base::TimeDelta bypass_delay; | 307 base::TimeDelta bypass_delay; |
311 if (params.AreDataReductionProxiesBypassed(*request, &bypass_delay)) { | 308 if (params.AreDataReductionProxiesBypassed(*request, &bypass_delay)) { |
312 if (bypass_delay > base::TimeDelta::FromSeconds(kLongBypassDelayInSeconds)) | 309 if (bypass_delay > base::TimeDelta::FromSeconds(kLongBypassDelayInSeconds)) |
313 return LONG_BYPASS; | 310 return LONG_BYPASS; |
314 return SHORT_BYPASS; | 311 return SHORT_BYPASS; |
315 } | 312 } |
316 #endif | |
317 if (request->response_info().headers.get() && | 313 if (request->response_info().headers.get() && |
318 HasDataReductionProxyViaHeader(request->response_info().headers.get(), | 314 HasDataReductionProxyViaHeader(request->response_info().headers.get(), |
319 NULL)) { | 315 NULL)) { |
320 return VIA_DATA_REDUCTION_PROXY; | 316 return VIA_DATA_REDUCTION_PROXY; |
321 } | 317 } |
322 return UNKNOWN_TYPE; | 318 return UNKNOWN_TYPE; |
323 } | 319 } |
324 | 320 |
325 int64 GetAdjustedOriginalContentLength( | 321 int64 GetAdjustedOriginalContentLength( |
326 DataReductionProxyRequestType request_type, | 322 DataReductionProxyRequestType request_type, |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 UpdateContentLengthPrefsForDataReductionProxy( | 486 UpdateContentLengthPrefsForDataReductionProxy( |
491 received_content_length, | 487 received_content_length, |
492 original_content_length, | 488 original_content_length, |
493 with_data_reduction_proxy_enabled, | 489 with_data_reduction_proxy_enabled, |
494 request_type, | 490 request_type, |
495 base::Time::Now(), | 491 base::Time::Now(), |
496 prefs); | 492 prefs); |
497 } | 493 } |
498 | 494 |
499 } // namespace data_reduction_proxy | 495 } // namespace data_reduction_proxy |
OLD | NEW |