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

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

Issue 274453011: Revert of Collect data reduction proxy UMA on all platforms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 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/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_pref_names .h" 13 #include "components/data_reduction_proxy/common/data_reduction_proxy_pref_names .h"
14 #include "net/base/host_port_pair.h" 14 #include "net/base/host_port_pair.h"
15 #include "net/http/http_response_headers.h" 15 #include "net/http/http_response_headers.h"
16 #include "net/proxy/proxy_retry_info.h" 16 #include "net/proxy/proxy_retry_info.h"
17 #include "net/proxy/proxy_service.h" 17 #include "net/proxy/proxy_service.h"
18 #include "net/url_request/url_request_context.h" 18 #include "net/url_request/url_request_context.h"
19 19
20 namespace data_reduction_proxy { 20 namespace data_reduction_proxy {
21 21
22 namespace { 22 namespace {
23 23
24 // A bypass delay more than this is treated as a long delay. 24 // A bypass delay more than this is treated as a long delay.
25 const int kLongBypassDelayInSeconds = 30 * 60; 25 const int kLongBypassDelayInSeconds = 30 * 60;
26 26
27 #if defined(OS_ANDROID) || defined(OS_IOS)
28
27 // Increments an int64, stored as a string, in a ListPref at the specified 29 // Increments an int64, stored as a string, in a ListPref at the specified
28 // index. The value must already exist and be a string representation of a 30 // index. The value must already exist and be a string representation of a
29 // number. 31 // number.
30 void AddInt64ToListPref(size_t index, 32 void AddInt64ToListPref(size_t index,
31 int64 length, 33 int64 length,
32 base::ListValue* list_update) { 34 base::ListValue* list_update) {
33 int64 value = 0; 35 int64 value = 0;
34 std::string old_string_value; 36 std::string old_string_value;
35 bool rv = list_update->GetString(index, &old_string_value); 37 bool rv = list_update->GetString(index, &old_string_value);
36 DCHECK(rv); 38 DCHECK(rv);
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 } 291 }
290 int64 GetReceivedListPrefValue(size_t index) { 292 int64 GetReceivedListPrefValue(size_t index) {
291 return received_.GetListPrefValue(index); 293 return received_.GetListPrefValue(index);
292 } 294 }
293 295
294 private: 296 private:
295 DailyContentLengthUpdate original_; 297 DailyContentLengthUpdate original_;
296 DailyContentLengthUpdate received_; 298 DailyContentLengthUpdate received_;
297 }; 299 };
298 300
301 #endif // defined(OS_ANDROID) || defined(OS_IOS)
302
299 // Returns true if the request is bypassed by all configured data reduction 303 // Returns true if the request is bypassed by all configured data reduction
300 // proxies. It returns the bypass delay in delay_seconds (if not NULL). If 304 // proxies. It returns the bypass delay in delay_seconds (if not NULL). If
301 // the request is bypassed by more than one proxy, delay_seconds returns 305 // the request is bypassed by more than one proxy, delay_seconds returns
302 // shortest delay. 306 // shortest delay.
303 bool IsBypassRequest(const net::URLRequest* request, int64* delay_seconds) { 307 bool IsBypassRequest(const net::URLRequest* request, int64* delay_seconds) {
308 #if defined(OS_ANDROID) || defined(OS_IOS)
304 DataReductionProxySettings::DataReductionProxyList proxies = 309 DataReductionProxySettings::DataReductionProxyList proxies =
305 DataReductionProxySettings::GetDataReductionProxies(); 310 DataReductionProxySettings::GetDataReductionProxies();
306 if (proxies.size() == 0) 311 if (proxies.size() == 0)
307 return false; 312 return false;
308 313
309 if (request == NULL || request->context() == NULL || 314 if (request == NULL || request->context() == NULL ||
310 request->context()->proxy_service() == NULL) { 315 request->context()->proxy_service() == NULL) {
311 return false; 316 return false;
312 } 317 }
313 318
(...skipping 14 matching lines...) Expand all
328 if (found == retry_map.end()) 333 if (found == retry_map.end())
329 return false; 334 return false;
330 if (shortest_delay == 0 || 335 if (shortest_delay == 0 ||
331 shortest_delay > found->second.current_delay.InSeconds()) { 336 shortest_delay > found->second.current_delay.InSeconds()) {
332 shortest_delay = found->second.current_delay.InSeconds(); 337 shortest_delay = found->second.current_delay.InSeconds();
333 } 338 }
334 } 339 }
335 if (delay_seconds != NULL) 340 if (delay_seconds != NULL)
336 *delay_seconds = shortest_delay; 341 *delay_seconds = shortest_delay;
337 return true; 342 return true;
343 #else
344 return false;
345 #endif // defined(OS_ANDROID) || defined(OS_IOS)
338 } 346 }
339 347
340 } // namespace 348 } // namespace
341 349
342 DataReductionProxyRequestType GetDataReductionProxyRequestType( 350 DataReductionProxyRequestType GetDataReductionProxyRequestType(
343 const net::URLRequest* request) { 351 const net::URLRequest* request) {
344 if (request->url().SchemeIs("https")) 352 if (request->url().SchemeIs("https"))
345 return HTTPS; 353 return HTTPS;
346 if (!request->url().SchemeIs("http")) { 354 if (!request->url().SchemeIs("http")) {
347 NOTREACHED(); 355 NOTREACHED();
348 return UNKNOWN_TYPE; 356 return UNKNOWN_TYPE;
349 } 357 }
350 int64 bypass_delay = 0; 358 int64 bypass_delay = 0;
351 if (IsBypassRequest(request, &bypass_delay)) { 359 if (IsBypassRequest(request, &bypass_delay)) {
352 return (bypass_delay > kLongBypassDelayInSeconds) ? 360 return (bypass_delay > kLongBypassDelayInSeconds) ?
353 LONG_BYPASS : SHORT_BYPASS; 361 LONG_BYPASS : SHORT_BYPASS;
354 } 362 }
363 #if defined(SPDY_PROXY_AUTH_ORIGIN)
355 if (request->response_info().headers && 364 if (request->response_info().headers &&
356 request->response_info().headers->IsDataReductionProxyResponse()) { 365 request->response_info().headers->IsDataReductionProxyResponse()) {
357 return VIA_DATA_REDUCTION_PROXY; 366 return VIA_DATA_REDUCTION_PROXY;
358 } 367 }
368 #endif
359 return UNKNOWN_TYPE; 369 return UNKNOWN_TYPE;
360 } 370 }
361 371
362 int64 GetAdjustedOriginalContentLength( 372 int64 GetAdjustedOriginalContentLength(
363 DataReductionProxyRequestType request_type, 373 DataReductionProxyRequestType request_type,
364 int64 original_content_length, 374 int64 original_content_length,
365 int64 received_content_length) { 375 int64 received_content_length) {
366 // Since there was no indication of the original content length, presume 376 // Since there was no indication of the original content length, presume
367 // it is no different from the number of bytes read. 377 // it is no different from the number of bytes read.
368 if (original_content_length == -1 || 378 if (original_content_length == -1 ||
369 request_type != VIA_DATA_REDUCTION_PROXY) { 379 request_type != VIA_DATA_REDUCTION_PROXY) {
370 return received_content_length; 380 return received_content_length;
371 } 381 }
372 return original_content_length; 382 return original_content_length;
373 } 383 }
374 384
385 #if defined(OS_ANDROID) || defined(OS_IOS)
375 void UpdateContentLengthPrefsForDataReductionProxy( 386 void UpdateContentLengthPrefsForDataReductionProxy(
376 int received_content_length, 387 int received_content_length,
377 int original_content_length, 388 int original_content_length,
378 bool with_data_reduction_proxy_enabled, 389 bool with_data_reduction_proxy_enabled,
379 DataReductionProxyRequestType request_type, 390 DataReductionProxyRequestType request_type,
380 base::Time now, PrefService* prefs) { 391 base::Time now, PrefService* prefs) {
381 // TODO(bengr): Remove this check once the underlying cause of 392 // TODO(bengr): Remove this check once the underlying cause of
382 // http://crbug.com/287821 is fixed. For now, only continue if the current 393 // http://crbug.com/287821 is fixed. For now, only continue if the current
383 // year is reported as being between 1972 and 2970. 394 // year is reported as being between 1972 and 2970.
384 base::TimeDelta time_since_unix_epoch = now - base::Time::UnixEpoch(); 395 base::TimeDelta time_since_unix_epoch = now - base::Time::UnixEpoch();
385 const int kMinDaysSinceUnixEpoch = 365 * 2; // 2 years. 396 const int kMinDaysSinceUnixEpoch = 365 * 2; // 2 years.
386 const int kMaxDaysSinceUnixEpoch = 365 * 1000; // 1000 years. 397 const int kMaxDaysSinceUnixEpoch = 365 * 1000; // 1000 years.
387 if (time_since_unix_epoch.InDays() < kMinDaysSinceUnixEpoch || 398 if (time_since_unix_epoch.InDays() < kMinDaysSinceUnixEpoch ||
388 time_since_unix_epoch.InDays() > kMaxDaysSinceUnixEpoch) { 399 time_since_unix_epoch.InDays() > kMaxDaysSinceUnixEpoch) {
389 return; 400 return;
390 } 401 }
391 402
392 // Determine how many days it has been since the last update. 403 // Determine how many days it has been since the last update.
393 int64 then_internal = prefs->GetInt64( 404 int64 then_internal = prefs->GetInt64(
394 data_reduction_proxy::prefs::kDailyHttpContentLengthLastUpdateDate); 405 data_reduction_proxy::prefs::kDailyHttpContentLengthLastUpdateDate);
395
396 #if defined(OS_WIN)
397 base::Time then_midnight = base::Time::FromInternalValue(then_internal);
398 base::Time midnight =
399 base::Time::FromInternalValue(
400 (now.ToInternalValue() / base::Time::kMicrosecondsPerDay) *
401 base::Time::kMicrosecondsPerDay);
402 #else
403 // Local midnight could have been shifted due to time zone change. 406 // Local midnight could have been shifted due to time zone change.
404 base::Time then_midnight = 407 base::Time then_midnight =
405 base::Time::FromInternalValue(then_internal).LocalMidnight(); 408 base::Time::FromInternalValue(then_internal).LocalMidnight();
406 base::Time midnight = now.LocalMidnight(); 409 base::Time midnight = now.LocalMidnight();
407 #endif
408
409 int days_since_last_update = (midnight - then_midnight).InDays(); 410 int days_since_last_update = (midnight - then_midnight).InDays();
410 411
411 // Each day, we calculate the total number of bytes received and the total 412 // Each day, we calculate the total number of bytes received and the total
412 // size of all corresponding resources before any data-reducing recompression 413 // size of all corresponding resources before any data-reducing recompression
413 // is applied. These values are used to compute the data savings realized 414 // is applied. These values are used to compute the data savings realized
414 // by applying our compression techniques. Totals for the last 415 // by applying our compression techniques. Totals for the last
415 // |kNumDaysInHistory| days are maintained. 416 // |kNumDaysInHistory| days are maintained.
416 DailyDataSavingUpdate total( 417 DailyDataSavingUpdate total(
417 data_reduction_proxy::prefs::kDailyHttpOriginalContentLength, 418 data_reduction_proxy::prefs::kDailyHttpOriginalContentLength,
418 data_reduction_proxy::prefs::kDailyHttpReceivedContentLength, 419 data_reduction_proxy::prefs::kDailyHttpReceivedContentLength,
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 proxy_enabled.GetReceivedListPrefValue(kNumDaysInHistory - 2), 504 proxy_enabled.GetReceivedListPrefValue(kNumDaysInHistory - 2),
504 via_proxy.GetOriginalListPrefValue(kNumDaysInHistory - 2), 505 via_proxy.GetOriginalListPrefValue(kNumDaysInHistory - 2),
505 via_proxy.GetReceivedListPrefValue(kNumDaysInHistory - 2), 506 via_proxy.GetReceivedListPrefValue(kNumDaysInHistory - 2),
506 https.GetListPrefValue(kNumDaysInHistory - 2), 507 https.GetListPrefValue(kNumDaysInHistory - 2),
507 short_bypass.GetListPrefValue(kNumDaysInHistory - 2), 508 short_bypass.GetListPrefValue(kNumDaysInHistory - 2),
508 long_bypass.GetListPrefValue(kNumDaysInHistory - 2), 509 long_bypass.GetListPrefValue(kNumDaysInHistory - 2),
509 unknown.GetListPrefValue(kNumDaysInHistory - 2)); 510 unknown.GetListPrefValue(kNumDaysInHistory - 2));
510 } 511 }
511 } 512 }
512 } 513 }
514 #endif // defined(OS_ANDROID) || defined(OS_IOS)
513 515
514 void UpdateContentLengthPrefs( 516 void UpdateContentLengthPrefs(
515 int received_content_length, 517 int received_content_length,
516 int original_content_length, 518 int original_content_length,
517 bool with_data_reduction_proxy_enabled, 519 bool with_data_reduction_proxy_enabled,
518 DataReductionProxyRequestType request_type, 520 DataReductionProxyRequestType request_type,
519 PrefService* prefs) { 521 PrefService* prefs) {
520 int64 total_received = prefs->GetInt64( 522 int64 total_received = prefs->GetInt64(
521 data_reduction_proxy::prefs::kHttpReceivedContentLength); 523 data_reduction_proxy::prefs::kHttpReceivedContentLength);
522 int64 total_original = prefs->GetInt64( 524 int64 total_original = prefs->GetInt64(
523 data_reduction_proxy::prefs::kHttpOriginalContentLength); 525 data_reduction_proxy::prefs::kHttpOriginalContentLength);
524 total_received += received_content_length; 526 total_received += received_content_length;
525 total_original += original_content_length; 527 total_original += original_content_length;
526 prefs->SetInt64(data_reduction_proxy::prefs::kHttpReceivedContentLength, 528 prefs->SetInt64(data_reduction_proxy::prefs::kHttpReceivedContentLength,
527 total_received); 529 total_received);
528 prefs->SetInt64(data_reduction_proxy::prefs::kHttpOriginalContentLength, 530 prefs->SetInt64(data_reduction_proxy::prefs::kHttpOriginalContentLength,
529 total_original); 531 total_original);
530 532
533 #if defined(OS_ANDROID) || defined(OS_IOS)
531 UpdateContentLengthPrefsForDataReductionProxy( 534 UpdateContentLengthPrefsForDataReductionProxy(
532 received_content_length, 535 received_content_length,
533 original_content_length, 536 original_content_length,
534 with_data_reduction_proxy_enabled, 537 with_data_reduction_proxy_enabled,
535 request_type, 538 request_type,
536 base::Time::Now(), 539 base::Time::Now(),
537 prefs); 540 prefs);
541 #endif // defined(OS_ANDROID) || defined(OS_IOS)
542
538 } 543 }
539 544
540 } // namespace data_reduction_proxy 545 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698