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" |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 const int kMaxDaysSinceUnixEpoch = 365 * 1000; // 1000 years. | 389 const int kMaxDaysSinceUnixEpoch = 365 * 1000; // 1000 years. |
390 if (time_since_unix_epoch.InDays() < kMinDaysSinceUnixEpoch || | 390 if (time_since_unix_epoch.InDays() < kMinDaysSinceUnixEpoch || |
391 time_since_unix_epoch.InDays() > kMaxDaysSinceUnixEpoch) { | 391 time_since_unix_epoch.InDays() > kMaxDaysSinceUnixEpoch) { |
392 return; | 392 return; |
393 } | 393 } |
394 | 394 |
395 // Determine how many days it has been since the last update. | 395 // Determine how many days it has been since the last update. |
396 int64 then_internal = prefs->GetInt64( | 396 int64 then_internal = prefs->GetInt64( |
397 data_reduction_proxy::prefs::kDailyHttpContentLengthLastUpdateDate); | 397 data_reduction_proxy::prefs::kDailyHttpContentLengthLastUpdateDate); |
398 | 398 |
399 #if defined(OS_WIN) | 399 // Local midnight could have been shifted due to time zone change. |
| 400 // If time is null then don't care if midnight will be wrong shifted due to |
| 401 // time zone change because it's still too much time ago. |
400 base::Time then_midnight = base::Time::FromInternalValue(then_internal); | 402 base::Time then_midnight = base::Time::FromInternalValue(then_internal); |
401 base::Time midnight = | 403 if (!then_midnight.is_null()) { |
402 base::Time::FromInternalValue( | 404 then_midnight = then_midnight.LocalMidnight(); |
403 (now.ToInternalValue() / base::Time::kMicrosecondsPerDay) * | 405 } |
404 base::Time::kMicrosecondsPerDay); | |
405 #else | |
406 // Local midnight could have been shifted due to time zone change. | |
407 base::Time then_midnight = | |
408 base::Time::FromInternalValue(then_internal).LocalMidnight(); | |
409 base::Time midnight = now.LocalMidnight(); | 406 base::Time midnight = now.LocalMidnight(); |
410 #endif | |
411 | 407 |
412 int days_since_last_update = (midnight - then_midnight).InDays(); | 408 int days_since_last_update = (midnight - then_midnight).InDays(); |
413 | 409 |
414 // Each day, we calculate the total number of bytes received and the total | 410 // Each day, we calculate the total number of bytes received and the total |
415 // size of all corresponding resources before any data-reducing recompression | 411 // size of all corresponding resources before any data-reducing recompression |
416 // is applied. These values are used to compute the data savings realized | 412 // is applied. These values are used to compute the data savings realized |
417 // by applying our compression techniques. Totals for the last | 413 // by applying our compression techniques. Totals for the last |
418 // |kNumDaysInHistory| days are maintained. | 414 // |kNumDaysInHistory| days are maintained. |
419 DailyDataSavingUpdate total( | 415 DailyDataSavingUpdate total( |
420 data_reduction_proxy::prefs::kDailyHttpOriginalContentLength, | 416 data_reduction_proxy::prefs::kDailyHttpOriginalContentLength, |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 UpdateContentLengthPrefsForDataReductionProxy( | 530 UpdateContentLengthPrefsForDataReductionProxy( |
535 received_content_length, | 531 received_content_length, |
536 original_content_length, | 532 original_content_length, |
537 with_data_reduction_proxy_enabled, | 533 with_data_reduction_proxy_enabled, |
538 request_type, | 534 request_type, |
539 base::Time::Now(), | 535 base::Time::Now(), |
540 prefs); | 536 prefs); |
541 } | 537 } |
542 | 538 |
543 } // namespace data_reduction_proxy | 539 } // namespace data_reduction_proxy |
OLD | NEW |