Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: components/data_reduction_proxy/browser/data_reduction_proxy_metrics.cc

Issue 382313003: Add data reduction functionality to all platforms. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove incorrect DCHECK from drp_statistics_prefs.cc Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
10 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings. h" 11 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings. h"
11 #include "components/data_reduction_proxy/browser/data_reduction_proxy_statistic s_prefs.h" 12 #include "components/data_reduction_proxy/browser/data_reduction_proxy_statistic s_prefs.h"
12 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h" 13 #include "components/data_reduction_proxy/common/data_reduction_proxy_headers.h"
13 #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"
14 #include "net/base/host_port_pair.h" 15 #include "net/base/host_port_pair.h"
15 #include "net/http/http_response_headers.h" 16 #include "net/http/http_response_headers.h"
16 #include "net/proxy/proxy_retry_info.h" 17 #include "net/proxy/proxy_retry_info.h"
17 #include "net/proxy/proxy_service.h" 18 #include "net/proxy/proxy_service.h"
18 #include "net/url_request/url_request_context.h" 19 #include "net/url_request/url_request_context.h"
19 20
20 namespace data_reduction_proxy { 21 namespace data_reduction_proxy {
21 22
22 namespace { 23 namespace {
23 24
24 #if defined(SPDY_PROXY_AUTH_ORIGIN)
25 // 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.
26 const int kLongBypassDelayInSeconds = 30 * 60; 26 const int kLongBypassDelayInSeconds = 30 * 60;
27 #endif
28 27
29 // 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
30 // 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
31 // number. 30 // number.
32 void AddInt64ToListPref(size_t index, 31 void AddInt64ToListPref(size_t index,
33 int64 length, 32 int64 length,
34 base::ListValue* list_update) { 33 base::ListValue* list_update) {
35 int64 value = 0; 34 int64 value = 0;
36 std::string old_string_value; 35 std::string old_string_value;
37 bool rv = list_update->GetString(index, &old_string_value); 36 bool rv = list_update->GetString(index, &old_string_value);
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 } // namespace 291 } // namespace
293 292
294 DataReductionProxyRequestType GetDataReductionProxyRequestType( 293 DataReductionProxyRequestType GetDataReductionProxyRequestType(
295 const net::URLRequest* request) { 294 const net::URLRequest* request) {
296 if (request->url().SchemeIs("https")) 295 if (request->url().SchemeIs("https"))
297 return HTTPS; 296 return HTTPS;
298 if (!request->url().SchemeIs("http")) { 297 if (!request->url().SchemeIs("http")) {
299 NOTREACHED(); 298 NOTREACHED();
300 return UNKNOWN_TYPE; 299 return UNKNOWN_TYPE;
301 } 300 }
302 #if defined(SPDY_PROXY_AUTH_ORIGIN)
303 DataReductionProxyParams params( 301 DataReductionProxyParams params(
304 DataReductionProxyParams::kAllowed | 302 DataReductionProxyParams::kAllowed |
305 DataReductionProxyParams::kFallbackAllowed | 303 DataReductionProxyParams::kFallbackAllowed |
306 DataReductionProxyParams::kPromoAllowed); 304 DataReductionProxyParams::kPromoAllowed);
307 base::TimeDelta bypass_delay; 305 base::TimeDelta bypass_delay;
308 if (params.AreDataReductionProxiesBypassed(*request, &bypass_delay)) { 306 if (params.AreDataReductionProxiesBypassed(*request, &bypass_delay)) {
309 if (bypass_delay > base::TimeDelta::FromSeconds(kLongBypassDelayInSeconds)) 307 if (bypass_delay > base::TimeDelta::FromSeconds(kLongBypassDelayInSeconds))
310 return LONG_BYPASS; 308 return LONG_BYPASS;
311 return SHORT_BYPASS; 309 return SHORT_BYPASS;
312 } 310 }
313 #endif
314 if (request->response_info().headers.get() && 311 if (request->response_info().headers.get() &&
315 HasDataReductionProxyViaHeader(request->response_info().headers.get(), 312 HasDataReductionProxyViaHeader(request->response_info().headers.get(),
316 NULL)) { 313 NULL)) {
317 return VIA_DATA_REDUCTION_PROXY; 314 return VIA_DATA_REDUCTION_PROXY;
318 } 315 }
319 return UNKNOWN_TYPE; 316 return UNKNOWN_TYPE;
320 } 317 }
321 318
322 int64 GetAdjustedOriginalContentLength( 319 int64 GetAdjustedOriginalContentLength(
323 DataReductionProxyRequestType request_type, 320 DataReductionProxyRequestType request_type,
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 https.GetListPrefValue(kNumDaysInHistory - 2), 460 https.GetListPrefValue(kNumDaysInHistory - 2),
464 short_bypass.GetListPrefValue(kNumDaysInHistory - 2), 461 short_bypass.GetListPrefValue(kNumDaysInHistory - 2),
465 long_bypass.GetListPrefValue(kNumDaysInHistory - 2), 462 long_bypass.GetListPrefValue(kNumDaysInHistory - 2),
466 unknown.GetListPrefValue(kNumDaysInHistory - 2)); 463 unknown.GetListPrefValue(kNumDaysInHistory - 2));
467 } 464 }
468 } 465 }
469 } 466 }
470 467
471 void UpdateContentLengthPrefs(int received_content_length, 468 void UpdateContentLengthPrefs(int received_content_length,
472 int original_content_length, 469 int original_content_length,
473 bool with_data_reduction_proxy_enabled, 470 PrefService* profile_prefs,
474 DataReductionProxyRequestType request_type, 471 DataReductionProxyRequestType request_type,
475 DataReductionProxyStatisticsPrefs* prefs) { 472 DataReductionProxyStatisticsPrefs* prefs) {
476 int64 total_received = prefs->GetInt64( 473 int64 total_received = prefs->GetInt64(
477 data_reduction_proxy::prefs::kHttpReceivedContentLength); 474 data_reduction_proxy::prefs::kHttpReceivedContentLength);
478 int64 total_original = prefs->GetInt64( 475 int64 total_original = prefs->GetInt64(
479 data_reduction_proxy::prefs::kHttpOriginalContentLength); 476 data_reduction_proxy::prefs::kHttpOriginalContentLength);
480 total_received += received_content_length; 477 total_received += received_content_length;
481 total_original += original_content_length; 478 total_original += original_content_length;
482 prefs->SetInt64(data_reduction_proxy::prefs::kHttpReceivedContentLength, 479 prefs->SetInt64(
483 total_received); 480 data_reduction_proxy::prefs::kHttpReceivedContentLength,
484 prefs->SetInt64(data_reduction_proxy::prefs::kHttpOriginalContentLength, 481 total_received);
485 total_original); 482 prefs->SetInt64(
483 data_reduction_proxy::prefs::kHttpOriginalContentLength,
484 total_original);
486 485
486 bool with_data_reduction_proxy_enabled =
487 profile_prefs->GetBoolean(
488 data_reduction_proxy::prefs::kDataReductionProxyEnabled);
487 UpdateContentLengthPrefsForDataReductionProxy( 489 UpdateContentLengthPrefsForDataReductionProxy(
488 received_content_length, 490 received_content_length,
489 original_content_length, 491 original_content_length,
490 with_data_reduction_proxy_enabled, 492 with_data_reduction_proxy_enabled,
491 request_type, 493 request_type,
492 base::Time::Now(), 494 base::Time::Now(),
493 prefs); 495 prefs);
494 } 496 }
495 497
496 } // namespace data_reduction_proxy 498 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698