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 "chrome/browser/predictors/resource_prefetch_predictor.h" | 5 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 PopulatePrefetcherRequest(iterator->second, prefetch_requests); | 700 PopulatePrefetcherRequest(iterator->second, prefetch_requests); |
701 } | 701 } |
702 } | 702 } |
703 | 703 |
704 return !prefetch_requests->empty(); | 704 return !prefetch_requests->empty(); |
705 } | 705 } |
706 | 706 |
707 void ResourcePrefetchPredictor::PopulatePrefetcherRequest( | 707 void ResourcePrefetchPredictor::PopulatePrefetcherRequest( |
708 const PrefetchData& data, | 708 const PrefetchData& data, |
709 ResourcePrefetcher::RequestVector* requests) { | 709 ResourcePrefetcher::RequestVector* requests) { |
710 for (ResourceRows::const_iterator it = data.resources.begin(); | 710 for (const ResourceRow& row : data.resources) { |
711 it != data.resources.end(); ++it) { | 711 float confidence = static_cast<float>(row.number_of_hits) / |
712 float confidence = static_cast<float>(it->number_of_hits) / | 712 (row.number_of_hits + row.number_of_misses); |
713 (it->number_of_hits + it->number_of_misses); | |
714 if (confidence < config_.min_resource_confidence_to_trigger_prefetch || | 713 if (confidence < config_.min_resource_confidence_to_trigger_prefetch || |
715 it->number_of_hits < config_.min_resource_hits_to_trigger_prefetch) { | 714 row.number_of_hits < config_.min_resource_hits_to_trigger_prefetch) { |
716 continue; | 715 continue; |
717 } | 716 } |
718 | 717 |
719 ResourcePrefetcher::Request* req = new ResourcePrefetcher::Request( | 718 ResourcePrefetcher::Request* req = |
720 it->resource_url); | 719 new ResourcePrefetcher::Request(row.resource_url); |
721 requests->push_back(req); | 720 requests->push_back(req); |
722 } | 721 } |
723 } | 722 } |
724 | 723 |
725 void ResourcePrefetchPredictor::StartPrefetching( | 724 void ResourcePrefetchPredictor::StartPrefetching( |
726 const NavigationID& navigation_id) { | 725 const NavigationID& navigation_id) { |
727 if (!prefetch_manager_.get()) // Prefetching not enabled. | 726 if (!prefetch_manager_.get()) // Prefetching not enabled. |
728 return; | 727 return; |
729 | 728 |
730 // Prefer URL based data first. | 729 // Prefer URL based data first. |
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1424 // HistoryService is already loaded. Continue with Initialization. | 1423 // HistoryService is already loaded. Continue with Initialization. |
1425 OnHistoryAndCacheLoaded(); | 1424 OnHistoryAndCacheLoaded(); |
1426 return; | 1425 return; |
1427 } | 1426 } |
1428 DCHECK(!history_service_observer_.IsObserving(history_service)); | 1427 DCHECK(!history_service_observer_.IsObserving(history_service)); |
1429 history_service_observer_.Add(history_service); | 1428 history_service_observer_.Add(history_service); |
1430 return; | 1429 return; |
1431 } | 1430 } |
1432 | 1431 |
1433 } // namespace predictors | 1432 } // namespace predictors |
OLD | NEW |