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 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 void PrecacheFetcher::OnManifestFetchComplete(int64_t host_visits, | 757 void PrecacheFetcher::OnManifestFetchComplete(int64_t host_visits, |
758 const Fetcher& source) { | 758 const Fetcher& source) { |
759 DCHECK(unfinished_work_->has_config_settings()); | 759 DCHECK(unfinished_work_->has_config_settings()); |
760 UpdateStats(source.response_bytes(), source.network_response_bytes()); | 760 UpdateStats(source.response_bytes(), source.network_response_bytes()); |
761 if (source.network_url_fetcher() == nullptr) { | 761 if (source.network_url_fetcher() == nullptr) { |
762 pool_.DeleteAll(); // Cancel any other ongoing request. | 762 pool_.DeleteAll(); // Cancel any other ongoing request. |
763 } else { | 763 } else { |
764 PrecacheManifest manifest; | 764 PrecacheManifest manifest; |
765 | 765 |
766 if (ParseProtoFromFetchResponse(*source.network_url_fetcher(), &manifest)) { | 766 if (ParseProtoFromFetchResponse(*source.network_url_fetcher(), &manifest)) { |
767 const int32_t len = | |
768 std::min(manifest.resource_size(), | |
769 unfinished_work_->config_settings().top_resources_count()); | |
770 const base::Optional<std::vector<bool>> resource_bitset = | 767 const base::Optional<std::vector<bool>> resource_bitset = |
771 GetResourceBitset(manifest, experiment_id_); | 768 GetResourceBitset(manifest, experiment_id_); |
772 for (int i = 0; i < len; ++i) { | 769 const int32_t included_resources_max = |
| 770 unfinished_work_->config_settings().top_resources_count(); |
| 771 int32_t included_resources = 0; |
| 772 for (int i = 0; i < manifest.resource_size() && |
| 773 included_resources < included_resources_max; |
| 774 ++i) { |
773 if ((!resource_bitset.has_value() || resource_bitset.value()[i]) && | 775 if ((!resource_bitset.has_value() || resource_bitset.value()[i]) && |
774 manifest.resource(i).has_url()) { | 776 manifest.resource(i).has_url()) { |
775 GURL url(manifest.resource(i).url()); | 777 GURL url(manifest.resource(i).url()); |
776 if (url.is_valid()) { | 778 if (url.is_valid()) { |
777 double weight = ResourceWeight( | 779 double weight = ResourceWeight( |
778 unfinished_work_->config_settings().resource_weight_function(), | 780 unfinished_work_->config_settings().resource_weight_function(), |
779 manifest.resource(i).weight_ratio(), host_visits); | 781 manifest.resource(i).weight_ratio(), host_visits); |
780 if (weight >= unfinished_work_->config_settings().min_weight()) | 782 if (weight >= unfinished_work_->config_settings().min_weight()) { |
781 resources_to_rank_.emplace_back(url, source.referrer(), weight); | 783 resources_to_rank_.emplace_back(url, source.referrer(), weight); |
| 784 ++included_resources; |
| 785 } |
782 } | 786 } |
783 } | 787 } |
784 } | 788 } |
785 db_task_runner_->PostTask( | 789 db_task_runner_->PostTask( |
786 FROM_HERE, base::Bind(&PrecacheDatabase::UpdatePrecacheReferrerHost, | 790 FROM_HERE, base::Bind(&PrecacheDatabase::UpdatePrecacheReferrerHost, |
787 precache_database_, source.referrer(), | 791 precache_database_, source.referrer(), |
788 manifest.id().id(), base::Time::Now())); | 792 manifest.id().id(), base::Time::Now())); |
789 } | 793 } |
790 } | 794 } |
791 | 795 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
864 remaining = 0; | 868 remaining = 0; |
865 quota_.set_remaining( | 869 quota_.set_remaining( |
866 used_bytes > quota_.remaining() ? 0U : quota_.remaining() - used_bytes); | 870 used_bytes > quota_.remaining() ? 0U : quota_.remaining() - used_bytes); |
867 db_task_runner_->PostTask( | 871 db_task_runner_->PostTask( |
868 FROM_HERE, | 872 FROM_HERE, |
869 base::Bind(&PrecacheDatabase::SaveQuota, precache_database_, quota_)); | 873 base::Bind(&PrecacheDatabase::SaveQuota, precache_database_, quota_)); |
870 } | 874 } |
871 } | 875 } |
872 | 876 |
873 } // namespace precache | 877 } // namespace precache |
OLD | NEW |