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

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

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

Powered by Google App Engine
This is Rietveld 408576698