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

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

Issue 949533004: Rename DataReductionProxyStatisticsPrefs to DataReductionProxyCompressionStats (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 8 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/core/browser/data_reduction_proxy_metr ics.h" 5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_metr ics.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/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_comp ression_stats.h"
11 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf ig.h" 12 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf ig.h"
12 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.h" 13 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.h"
13 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_stat istics_prefs.h"
14 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h" 14 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h"
15 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h" 15 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h"
16 #include "net/base/host_port_pair.h" 16 #include "net/base/host_port_pair.h"
17 #include "net/base/load_flags.h" 17 #include "net/base/load_flags.h"
18 #include "net/http/http_response_headers.h" 18 #include "net/http/http_response_headers.h"
19 #include "net/proxy/proxy_config.h" 19 #include "net/proxy/proxy_config.h"
20 #include "net/proxy/proxy_retry_info.h" 20 #include "net/proxy/proxy_retry_info.h"
21 #include "net/proxy/proxy_server.h" 21 #include "net/proxy/proxy_server.h"
22 #include "net/proxy/proxy_service.h" 22 #include "net/proxy/proxy_service.h"
23 #include "net/url_request/url_request.h" 23 #include "net/url_request/url_request.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 list->AppendString(base::Int64ToString(0)); 190 list->AppendString(base::Int64ToString(0));
191 DCHECK_EQ(length, list->GetSize()); 191 DCHECK_EQ(length, list->GetSize());
192 } 192 }
193 193
194 // DailyContentLengthUpdate maintains a data saving pref. The pref is a list 194 // DailyContentLengthUpdate maintains a data saving pref. The pref is a list
195 // of |kNumDaysInHistory| elements of daily total content lengths for the past 195 // of |kNumDaysInHistory| elements of daily total content lengths for the past
196 // |kNumDaysInHistory| days. 196 // |kNumDaysInHistory| days.
197 class DailyContentLengthUpdate { 197 class DailyContentLengthUpdate {
198 public: 198 public:
199 DailyContentLengthUpdate(const char* pref, 199 DailyContentLengthUpdate(const char* pref,
200 DataReductionProxyStatisticsPrefs* pref_service) 200 DataReductionProxyCompressionStats* pref_service)
201 : update_(pref_service->GetList(pref)) { 201 : update_(pref_service->GetList(pref)) {}
202 }
203 202
204 void UpdateForDataChange(int days_since_last_update) { 203 void UpdateForDataChange(int days_since_last_update) {
205 // New empty lists may have been created. Maintain the invariant that 204 // New empty lists may have been created. Maintain the invariant that
206 // there should be exactly |kNumDaysInHistory| days in the histories. 205 // there should be exactly |kNumDaysInHistory| days in the histories.
207 MaintainContentLengthPrefsWindow(update_, kNumDaysInHistory); 206 MaintainContentLengthPrefsWindow(update_, kNumDaysInHistory);
208 if (days_since_last_update) { 207 if (days_since_last_update) {
209 MaintainContentLengthPrefForDateChange(days_since_last_update); 208 MaintainContentLengthPrefForDateChange(days_since_last_update);
210 } 209 }
211 } 210 }
212 211
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 258
260 // DailyDataSavingUpdate maintains a pair of data saving prefs, original_update_ 259 // DailyDataSavingUpdate maintains a pair of data saving prefs, original_update_
261 // and received_update_. pref_original is a list of |kNumDaysInHistory| elements 260 // and received_update_. pref_original is a list of |kNumDaysInHistory| elements
262 // of daily total original content lengths for the past |kNumDaysInHistory| 261 // of daily total original content lengths for the past |kNumDaysInHistory|
263 // days. pref_received is the corresponding list of the daily total received 262 // days. pref_received is the corresponding list of the daily total received
264 // content lengths. 263 // content lengths.
265 class DailyDataSavingUpdate { 264 class DailyDataSavingUpdate {
266 public: 265 public:
267 DailyDataSavingUpdate(const char* pref_original, 266 DailyDataSavingUpdate(const char* pref_original,
268 const char* pref_received, 267 const char* pref_received,
269 DataReductionProxyStatisticsPrefs* prefs) 268 DataReductionProxyCompressionStats* compression_stats)
270 : original_(pref_original, prefs), 269 : original_(pref_original, compression_stats),
271 received_(pref_received, prefs) { 270 received_(pref_received, compression_stats) {}
272 }
273 271
274 void UpdateForDataChange(int days_since_last_update) { 272 void UpdateForDataChange(int days_since_last_update) {
275 original_.UpdateForDataChange(days_since_last_update); 273 original_.UpdateForDataChange(days_since_last_update);
276 received_.UpdateForDataChange(days_since_last_update); 274 received_.UpdateForDataChange(days_since_last_update);
277 } 275 }
278 276
279 // Update the lengths for the current day. 277 // Update the lengths for the current day.
280 void Add(int original_content_length, int received_content_length) { 278 void Add(int original_content_length, int received_content_length) {
281 original_.Add(original_content_length); 279 original_.Add(original_content_length);
282 received_.Add(received_content_length); 280 received_.Add(received_content_length);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 } 349 }
352 return original_content_length; 350 return original_content_length;
353 } 351 }
354 352
355 void UpdateContentLengthPrefsForDataReductionProxy( 353 void UpdateContentLengthPrefsForDataReductionProxy(
356 int received_content_length, 354 int received_content_length,
357 int original_content_length, 355 int original_content_length,
358 bool with_data_reduction_proxy_enabled, 356 bool with_data_reduction_proxy_enabled,
359 DataReductionProxyRequestType request_type, 357 DataReductionProxyRequestType request_type,
360 base::Time now, 358 base::Time now,
361 DataReductionProxyStatisticsPrefs* prefs) { 359 DataReductionProxyCompressionStats* compression_stats) {
362 // TODO(bengr): Remove this check once the underlying cause of 360 // TODO(bengr): Remove this check once the underlying cause of
363 // http://crbug.com/287821 is fixed. For now, only continue if the current 361 // http://crbug.com/287821 is fixed. For now, only continue if the current
364 // year is reported as being between 1972 and 2970. 362 // year is reported as being between 1972 and 2970.
365 base::TimeDelta time_since_unix_epoch = now - base::Time::UnixEpoch(); 363 base::TimeDelta time_since_unix_epoch = now - base::Time::UnixEpoch();
366 const int kMinDaysSinceUnixEpoch = 365 * 2; // 2 years. 364 const int kMinDaysSinceUnixEpoch = 365 * 2; // 2 years.
367 const int kMaxDaysSinceUnixEpoch = 365 * 1000; // 1000 years. 365 const int kMaxDaysSinceUnixEpoch = 365 * 1000; // 1000 years.
368 if (time_since_unix_epoch.InDays() < kMinDaysSinceUnixEpoch || 366 if (time_since_unix_epoch.InDays() < kMinDaysSinceUnixEpoch ||
369 time_since_unix_epoch.InDays() > kMaxDaysSinceUnixEpoch) { 367 time_since_unix_epoch.InDays() > kMaxDaysSinceUnixEpoch) {
370 return; 368 return;
371 } 369 }
372 370
373 // Determine how many days it has been since the last update. 371 // Determine how many days it has been since the last update.
374 int64 then_internal = prefs->GetInt64( 372 int64 then_internal = compression_stats->GetInt64(
375 data_reduction_proxy::prefs::kDailyHttpContentLengthLastUpdateDate); 373 data_reduction_proxy::prefs::kDailyHttpContentLengthLastUpdateDate);
376 374
377 // Local midnight could have been shifted due to time zone change. 375 // Local midnight could have been shifted due to time zone change.
378 // If time is null then don't care if midnight will be wrong shifted due to 376 // If time is null then don't care if midnight will be wrong shifted due to
379 // time zone change because it's still too much time ago. 377 // time zone change because it's still too much time ago.
380 base::Time then_midnight = base::Time::FromInternalValue(then_internal); 378 base::Time then_midnight = base::Time::FromInternalValue(then_internal);
381 if (!then_midnight.is_null()) { 379 if (!then_midnight.is_null()) {
382 then_midnight = then_midnight.LocalMidnight(); 380 then_midnight = then_midnight.LocalMidnight();
383 } 381 }
384 base::Time midnight = now.LocalMidnight(); 382 base::Time midnight = now.LocalMidnight();
385 383
386 int days_since_last_update = (midnight - then_midnight).InDays(); 384 int days_since_last_update = (midnight - then_midnight).InDays();
387 385
388 // Each day, we calculate the total number of bytes received and the total 386 // Each day, we calculate the total number of bytes received and the total
389 // size of all corresponding resources before any data-reducing recompression 387 // size of all corresponding resources before any data-reducing recompression
390 // is applied. These values are used to compute the data savings realized 388 // is applied. These values are used to compute the data savings realized
391 // by applying our compression techniques. Totals for the last 389 // by applying our compression techniques. Totals for the last
392 // |kNumDaysInHistory| days are maintained. 390 // |kNumDaysInHistory| days are maintained.
393 DailyDataSavingUpdate total( 391 DailyDataSavingUpdate total(
394 data_reduction_proxy::prefs::kDailyHttpOriginalContentLength, 392 data_reduction_proxy::prefs::kDailyHttpOriginalContentLength,
395 data_reduction_proxy::prefs::kDailyHttpReceivedContentLength, 393 data_reduction_proxy::prefs::kDailyHttpReceivedContentLength,
396 prefs); 394 compression_stats);
397 total.UpdateForDataChange(days_since_last_update); 395 total.UpdateForDataChange(days_since_last_update);
398 396
399 DailyDataSavingUpdate proxy_enabled( 397 DailyDataSavingUpdate proxy_enabled(
400 data_reduction_proxy::prefs:: 398 data_reduction_proxy::prefs::
401 kDailyOriginalContentLengthWithDataReductionProxyEnabled, 399 kDailyOriginalContentLengthWithDataReductionProxyEnabled,
402 data_reduction_proxy::prefs:: 400 data_reduction_proxy::prefs::
403 kDailyContentLengthWithDataReductionProxyEnabled, 401 kDailyContentLengthWithDataReductionProxyEnabled,
404 prefs); 402 compression_stats);
405 proxy_enabled.UpdateForDataChange(days_since_last_update); 403 proxy_enabled.UpdateForDataChange(days_since_last_update);
406 404
407 DailyDataSavingUpdate via_proxy( 405 DailyDataSavingUpdate via_proxy(
408 data_reduction_proxy::prefs:: 406 data_reduction_proxy::prefs::
409 kDailyOriginalContentLengthViaDataReductionProxy, 407 kDailyOriginalContentLengthViaDataReductionProxy,
410 data_reduction_proxy::prefs:: 408 data_reduction_proxy::prefs::
411 kDailyContentLengthViaDataReductionProxy, 409 kDailyContentLengthViaDataReductionProxy,
412 prefs); 410 compression_stats);
413 via_proxy.UpdateForDataChange(days_since_last_update); 411 via_proxy.UpdateForDataChange(days_since_last_update);
414 412
415 DailyContentLengthUpdate https( 413 DailyContentLengthUpdate https(
416 data_reduction_proxy::prefs:: 414 data_reduction_proxy::prefs::
417 kDailyContentLengthHttpsWithDataReductionProxyEnabled, 415 kDailyContentLengthHttpsWithDataReductionProxyEnabled,
418 prefs); 416 compression_stats);
419 https.UpdateForDataChange(days_since_last_update); 417 https.UpdateForDataChange(days_since_last_update);
420 418
421 DailyContentLengthUpdate short_bypass( 419 DailyContentLengthUpdate short_bypass(
422 data_reduction_proxy::prefs:: 420 data_reduction_proxy::prefs::
423 kDailyContentLengthShortBypassWithDataReductionProxyEnabled, 421 kDailyContentLengthShortBypassWithDataReductionProxyEnabled,
424 prefs); 422 compression_stats);
425 short_bypass.UpdateForDataChange(days_since_last_update); 423 short_bypass.UpdateForDataChange(days_since_last_update);
426 424
427 DailyContentLengthUpdate long_bypass( 425 DailyContentLengthUpdate long_bypass(
428 data_reduction_proxy::prefs:: 426 data_reduction_proxy::prefs::
429 kDailyContentLengthLongBypassWithDataReductionProxyEnabled, 427 kDailyContentLengthLongBypassWithDataReductionProxyEnabled,
430 prefs); 428 compression_stats);
431 long_bypass.UpdateForDataChange(days_since_last_update); 429 long_bypass.UpdateForDataChange(days_since_last_update);
432 430
433 DailyContentLengthUpdate unknown( 431 DailyContentLengthUpdate unknown(
434 data_reduction_proxy::prefs:: 432 data_reduction_proxy::prefs::
435 kDailyContentLengthUnknownWithDataReductionProxyEnabled, 433 kDailyContentLengthUnknownWithDataReductionProxyEnabled,
436 prefs); 434 compression_stats);
437 unknown.UpdateForDataChange(days_since_last_update); 435 unknown.UpdateForDataChange(days_since_last_update);
438 436
439 total.Add(original_content_length, received_content_length); 437 total.Add(original_content_length, received_content_length);
440 if (with_data_reduction_proxy_enabled) { 438 if (with_data_reduction_proxy_enabled) {
441 proxy_enabled.Add(original_content_length, received_content_length); 439 proxy_enabled.Add(original_content_length, received_content_length);
442 // Ignore data source cases, if exist, when 440 // Ignore data source cases, if exist, when
443 // "with_data_reduction_proxy_enabled == false" 441 // "with_data_reduction_proxy_enabled == false"
444 switch (request_type) { 442 switch (request_type) {
445 case VIA_DATA_REDUCTION_PROXY: 443 case VIA_DATA_REDUCTION_PROXY:
446 via_proxy.Add(original_content_length, received_content_length); 444 via_proxy.Add(original_content_length, received_content_length);
447 break; 445 break;
448 case HTTPS: 446 case HTTPS:
449 https.Add(received_content_length); 447 https.Add(received_content_length);
450 break; 448 break;
451 case SHORT_BYPASS: 449 case SHORT_BYPASS:
452 short_bypass.Add(received_content_length); 450 short_bypass.Add(received_content_length);
453 break; 451 break;
454 case LONG_BYPASS: 452 case LONG_BYPASS:
455 long_bypass.Add(received_content_length); 453 long_bypass.Add(received_content_length);
456 break; 454 break;
457 case UNKNOWN_TYPE: 455 case UNKNOWN_TYPE:
458 unknown.Add(received_content_length); 456 unknown.Add(received_content_length);
459 break; 457 break;
460 } 458 }
461 } 459 }
462 460
463 if (days_since_last_update) { 461 if (days_since_last_update) {
464 // Record the last update time in microseconds in UTC. 462 // Record the last update time in microseconds in UTC.
465 prefs->SetInt64( 463 compression_stats->SetInt64(
466 data_reduction_proxy::prefs::kDailyHttpContentLengthLastUpdateDate, 464 data_reduction_proxy::prefs::kDailyHttpContentLengthLastUpdateDate,
467 midnight.ToInternalValue()); 465 midnight.ToInternalValue());
468 466
469 // A new day. Report the previous day's data if exists. We'll lose usage 467 // A new day. Report the previous day's data if exists. We'll lose usage
470 // data if the last time Chrome was run was more than a day ago. 468 // data if the last time Chrome was run was more than a day ago.
471 // Here, we prefer collecting less data but the collected data is 469 // Here, we prefer collecting less data but the collected data is
472 // associated with an accurate date. 470 // associated with an accurate date.
473 if (days_since_last_update == 1) { 471 if (days_since_last_update == 1) {
474 // The previous day's data point is the second one from the tail. 472 // The previous day's data point is the second one from the tail.
475 // Therefore (kNumDaysInHistory - 2) below. 473 // Therefore (kNumDaysInHistory - 2) below.
476 RecordDailyContentLengthHistograms( 474 RecordDailyContentLengthHistograms(
477 total.GetOriginalListPrefValue(kNumDaysInHistory - 2), 475 total.GetOriginalListPrefValue(kNumDaysInHistory - 2),
478 total.GetReceivedListPrefValue(kNumDaysInHistory - 2), 476 total.GetReceivedListPrefValue(kNumDaysInHistory - 2),
479 proxy_enabled.GetOriginalListPrefValue(kNumDaysInHistory - 2), 477 proxy_enabled.GetOriginalListPrefValue(kNumDaysInHistory - 2),
480 proxy_enabled.GetReceivedListPrefValue(kNumDaysInHistory - 2), 478 proxy_enabled.GetReceivedListPrefValue(kNumDaysInHistory - 2),
481 via_proxy.GetOriginalListPrefValue(kNumDaysInHistory - 2), 479 via_proxy.GetOriginalListPrefValue(kNumDaysInHistory - 2),
482 via_proxy.GetReceivedListPrefValue(kNumDaysInHistory - 2), 480 via_proxy.GetReceivedListPrefValue(kNumDaysInHistory - 2),
483 https.GetListPrefValue(kNumDaysInHistory - 2), 481 https.GetListPrefValue(kNumDaysInHistory - 2),
484 short_bypass.GetListPrefValue(kNumDaysInHistory - 2), 482 short_bypass.GetListPrefValue(kNumDaysInHistory - 2),
485 long_bypass.GetListPrefValue(kNumDaysInHistory - 2), 483 long_bypass.GetListPrefValue(kNumDaysInHistory - 2),
486 unknown.GetListPrefValue(kNumDaysInHistory - 2)); 484 unknown.GetListPrefValue(kNumDaysInHistory - 2));
487 } 485 }
488 } 486 }
489 } 487 }
490 488
491 } // namespace data_reduction_proxy 489 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698