Chromium Code Reviews| 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 725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 736 void PrecacheFetcher::OnManifestFetchComplete(int64_t host_visits, | 736 void PrecacheFetcher::OnManifestFetchComplete(int64_t host_visits, |
| 737 const Fetcher& source) { | 737 const Fetcher& source) { |
| 738 DCHECK(unfinished_work_->has_config_settings()); | 738 DCHECK(unfinished_work_->has_config_settings()); |
| 739 UpdateStats(source.response_bytes(), source.network_response_bytes()); | 739 UpdateStats(source.response_bytes(), source.network_response_bytes()); |
| 740 if (source.network_url_fetcher() == nullptr) { | 740 if (source.network_url_fetcher() == nullptr) { |
| 741 pool_.DeleteAll(); // Cancel any other ongoing request. | 741 pool_.DeleteAll(); // Cancel any other ongoing request. |
| 742 } else { | 742 } else { |
| 743 PrecacheManifest manifest; | 743 PrecacheManifest manifest; |
| 744 | 744 |
| 745 if (ParseProtoFromFetchResponse(*source.network_url_fetcher(), &manifest)) { | 745 if (ParseProtoFromFetchResponse(*source.network_url_fetcher(), &manifest)) { |
| 746 const int32_t len = | |
| 747 std::min(manifest.resource_size(), | |
| 748 unfinished_work_->config_settings().top_resources_count()); | |
| 749 const uint64_t resource_bitset = | 746 const uint64_t resource_bitset = |
| 750 GetResourceBitset(manifest, experiment_id_); | 747 GetResourceBitset(manifest, experiment_id_); |
| 751 for (int i = 0; i < len; ++i) { | 748 const int32_t max_to_include = |
| 749 unfinished_work_->config_settings().top_resources_count(); | |
| 750 int32_t num_included = 0; | |
| 751 for (int i = 0; | |
| 752 i < manifest.resource_size() && num_included < max_to_include; ++i) { | |
| 752 if (((0x1ULL << i) & resource_bitset) && | 753 if (((0x1ULL << i) & resource_bitset) && |
| 753 manifest.resource(i).has_url()) { | 754 manifest.resource(i).has_url()) { |
| 754 GURL url(manifest.resource(i).url()); | 755 GURL url(manifest.resource(i).url()); |
| 755 if (url.is_valid()) { | 756 if (url.is_valid()) { |
| 756 double weight = ResourceWeight( | 757 double weight = ResourceWeight( |
| 757 unfinished_work_->config_settings().resource_weight_function(), | 758 unfinished_work_->config_settings().resource_weight_function(), |
| 758 manifest.resource(i).weight_ratio(), host_visits); | 759 manifest.resource(i).weight_ratio(), host_visits); |
| 759 if (weight >= unfinished_work_->config_settings().min_weight()) | 760 if (weight >= unfinished_work_->config_settings().min_weight()) { |
| 760 resources_to_rank_.emplace_back(url, source.referrer(), weight); | 761 resources_to_rank_.emplace_back(url, source.referrer(), weight); |
| 762 ++num_included; | |
|
bengr
2017/02/24 21:04:13
nit: I would be a bit clearer:
num_included -> inc
twifkak
2017/02/24 21:35:55
Done.
| |
| 763 } | |
| 761 } | 764 } |
| 762 } | 765 } |
| 763 } | 766 } |
| 764 db_task_runner_->PostTask( | 767 db_task_runner_->PostTask( |
| 765 FROM_HERE, base::Bind(&PrecacheDatabase::UpdatePrecacheReferrerHost, | 768 FROM_HERE, base::Bind(&PrecacheDatabase::UpdatePrecacheReferrerHost, |
| 766 precache_database_, source.referrer(), | 769 precache_database_, source.referrer(), |
| 767 manifest.id().id(), base::Time::Now())); | 770 manifest.id().id(), base::Time::Now())); |
| 768 } | 771 } |
| 769 } | 772 } |
| 770 | 773 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 843 remaining = 0; | 846 remaining = 0; |
| 844 quota_.set_remaining( | 847 quota_.set_remaining( |
| 845 used_bytes > quota_.remaining() ? 0U : quota_.remaining() - used_bytes); | 848 used_bytes > quota_.remaining() ? 0U : quota_.remaining() - used_bytes); |
| 846 db_task_runner_->PostTask( | 849 db_task_runner_->PostTask( |
| 847 FROM_HERE, | 850 FROM_HERE, |
| 848 base::Bind(&PrecacheDatabase::SaveQuota, precache_database_, quota_)); | 851 base::Bind(&PrecacheDatabase::SaveQuota, precache_database_, quota_)); |
| 849 } | 852 } |
| 850 } | 853 } |
| 851 | 854 |
| 852 } // namespace precache | 855 } // namespace precache |
| OLD | NEW |