| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/precache/core/precache_fetcher.h" | 5 #include "components/precache/core/precache_fetcher.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 base::Bind(&RetrieveQuotaInfo, precache_database_), | 713 base::Bind(&RetrieveQuotaInfo, precache_database_), |
| 714 base::Bind(&PrecacheFetcher::OnQuotaInfoRetrieved, AsWeakPtr())); | 714 base::Bind(&PrecacheFetcher::OnQuotaInfoRetrieved, AsWeakPtr())); |
| 715 } | 715 } |
| 716 | 716 |
| 717 void PrecacheFetcher::OnQuotaInfoRetrieved(const PrecacheQuota& quota) { | 717 void PrecacheFetcher::OnQuotaInfoRetrieved(const PrecacheQuota& quota) { |
| 718 quota_ = quota; | 718 quota_ = quota; |
| 719 base::Time time_now = base::Time::Now(); | 719 base::Time time_now = base::Time::Now(); |
| 720 if (IsQuotaTimeExpired(quota_, time_now)) { | 720 if (IsQuotaTimeExpired(quota_, time_now)) { |
| 721 // This is a new day. Update daily quota, that starts today and expires by | 721 // This is a new day. Update daily quota, that starts today and expires by |
| 722 // end of today. | 722 // end of today. |
| 723 |
| 724 // If a previous day existed, report its usage. |
| 725 if (quota_.has_start_time()) { |
| 726 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 727 "Precache.Fetch.ResponseBytes.Daily", |
| 728 unfinished_work_->config_settings().daily_quota_total() - |
| 729 quota_.remaining(), |
| 730 1, kMaxResponseBytes, 100); |
| 731 } |
| 732 |
| 723 quota_.set_start_time(time_now.LocalMidnight().ToInternalValue()); | 733 quota_.set_start_time(time_now.LocalMidnight().ToInternalValue()); |
| 724 quota_.set_remaining( | 734 quota_.set_remaining( |
| 725 unfinished_work_->config_settings().daily_quota_total()); | 735 unfinished_work_->config_settings().daily_quota_total()); |
| 726 db_task_runner_->PostTask( | 736 db_task_runner_->PostTask( |
| 727 FROM_HERE, | 737 FROM_HERE, |
| 728 base::Bind(&PrecacheDatabase::SaveQuota, precache_database_, quota_)); | 738 base::Bind(&PrecacheDatabase::SaveQuota, precache_database_, quota_)); |
| 729 } | 739 } |
| 730 StartNextFetch(); | 740 StartNextFetch(); |
| 731 } | 741 } |
| 732 | 742 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 remaining = 0; | 892 remaining = 0; |
| 883 quota_.set_remaining( | 893 quota_.set_remaining( |
| 884 used_bytes > quota_.remaining() ? 0U : quota_.remaining() - used_bytes); | 894 used_bytes > quota_.remaining() ? 0U : quota_.remaining() - used_bytes); |
| 885 db_task_runner_->PostTask( | 895 db_task_runner_->PostTask( |
| 886 FROM_HERE, | 896 FROM_HERE, |
| 887 base::Bind(&PrecacheDatabase::SaveQuota, precache_database_, quota_)); | 897 base::Bind(&PrecacheDatabase::SaveQuota, precache_database_, quota_)); |
| 888 } | 898 } |
| 889 } | 899 } |
| 890 | 900 |
| 891 } // namespace precache | 901 } // namespace precache |
| OLD | NEW |