Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(326)

Side by Side Diff: chrome/browser/predictors/resource_prefetch_predictor.cc

Issue 2923813002: predictors: Don't call IsUrlPrefetchable twice. (Closed)
Patch Set: . Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 std::unique_ptr<ResourcePrefetcher::PrefetcherStats> stats) { 577 std::unique_ptr<ResourcePrefetcher::PrefetcherStats> stats) {
578 if (observer_) 578 if (observer_)
579 observer_->OnPrefetchingFinished(main_frame_url); 579 observer_->OnPrefetchingFinished(main_frame_url);
580 580
581 if (stats_collector_) 581 if (stats_collector_)
582 stats_collector_->RecordPrefetcherStats(std::move(stats)); 582 stats_collector_->RecordPrefetcherStats(std::move(stats));
583 } 583 }
584 584
585 bool ResourcePrefetchPredictor::IsUrlPrefetchable( 585 bool ResourcePrefetchPredictor::IsUrlPrefetchable(
586 const GURL& main_frame_url) const { 586 const GURL& main_frame_url) const {
587 DCHECK_CURRENTLY_ON(BrowserThread::UI);
588 if (initialization_state_ != INITIALIZED)
589 return false;
590
591 return GetPrefetchData(main_frame_url, nullptr); 587 return GetPrefetchData(main_frame_url, nullptr);
592 } 588 }
593 589
594 bool ResourcePrefetchPredictor::IsResourcePrefetchable( 590 bool ResourcePrefetchPredictor::IsResourcePrefetchable(
595 const ResourceData& resource) const { 591 const ResourceData& resource) const {
596 float confidence = static_cast<float>(resource.number_of_hits()) / 592 float confidence = static_cast<float>(resource.number_of_hits()) /
597 (resource.number_of_hits() + resource.number_of_misses()); 593 (resource.number_of_hits() + resource.number_of_misses());
598 return confidence >= config_.min_resource_confidence_to_trigger_prefetch && 594 return confidence >= config_.min_resource_confidence_to_trigger_prefetch &&
599 resource.number_of_hits() >= 595 resource.number_of_hits() >=
600 config_.min_resource_hits_to_trigger_prefetch; 596 config_.min_resource_hits_to_trigger_prefetch;
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 history_service->TopHosts( 732 history_service->TopHosts(
737 kNumSampleHosts, 733 kNumSampleHosts,
738 base::Bind(&ResourcePrefetchPredictor::ReportDatabaseReadiness, 734 base::Bind(&ResourcePrefetchPredictor::ReportDatabaseReadiness,
739 AsWeakPtr())); 735 AsWeakPtr()));
740 } 736 }
741 } 737 }
742 738
743 bool ResourcePrefetchPredictor::GetPrefetchData( 739 bool ResourcePrefetchPredictor::GetPrefetchData(
744 const GURL& main_frame_url, 740 const GURL& main_frame_url,
745 ResourcePrefetchPredictor::Prediction* prediction) const { 741 ResourcePrefetchPredictor::Prediction* prediction) const {
742 DCHECK_CURRENTLY_ON(BrowserThread::UI);
743 if (initialization_state_ != INITIALIZED)
744 return false;
745
746 std::vector<GURL>* urls = 746 std::vector<GURL>* urls =
747 prediction ? &prediction->subresource_urls : nullptr; 747 prediction ? &prediction->subresource_urls : nullptr;
748 DCHECK(!urls || urls->empty()); 748 DCHECK(!urls || urls->empty());
749 749
750 // Fetch resources using URL-keyed data first. 750 // Fetch resources using URL-keyed data first.
751 std::string redirect_endpoint; 751 std::string redirect_endpoint;
752 const std::string& main_frame_url_spec = main_frame_url.spec(); 752 const std::string& main_frame_url_spec = main_frame_url.spec();
753 if (config_.is_url_learning_enabled && 753 if (config_.is_url_learning_enabled &&
754 GetRedirectEndpoint(main_frame_url_spec, *url_redirect_data_, 754 GetRedirectEndpoint(main_frame_url_spec, *url_redirect_data_,
755 &redirect_endpoint) && 755 &redirect_endpoint) &&
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
1390 if (!history_service) 1390 if (!history_service)
1391 return; 1391 return;
1392 DCHECK(!history_service_observer_.IsObserving(history_service)); 1392 DCHECK(!history_service_observer_.IsObserving(history_service));
1393 history_service_observer_.Add(history_service); 1393 history_service_observer_.Add(history_service);
1394 if (history_service->BackendLoaded()) { 1394 if (history_service->BackendLoaded()) {
1395 // HistoryService is already loaded. Continue with Initialization. 1395 // HistoryService is already loaded. Continue with Initialization.
1396 OnHistoryAndCacheLoaded(); 1396 OnHistoryAndCacheLoaded();
1397 } 1397 }
1398 } 1398 }
1399 1399
1400 void ResourcePrefetchPredictor::StartPrefetching(const GURL& url) { 1400 void ResourcePrefetchPredictor::StartPrefetching(
1401 const GURL& url,
1402 const ResourcePrefetchPredictor::Prediction& prediction) {
1401 TRACE_EVENT1("browser", "ResourcePrefetchPredictor::StartPrefetching", "url", 1403 TRACE_EVENT1("browser", "ResourcePrefetchPredictor::StartPrefetching", "url",
1402 url.spec()); 1404 url.spec());
1403 if (!prefetch_manager_.get()) // Not enabled. 1405 if (!prefetch_manager_.get()) // Not enabled.
1404 return; 1406 return;
1405 1407
1406 ResourcePrefetchPredictor::Prediction prediction;
1407 bool has_data = GetPrefetchData(url, &prediction);
1408 DCHECK(has_data);
1409
1410 BrowserThread::PostTask( 1408 BrowserThread::PostTask(
1411 BrowserThread::IO, FROM_HERE, 1409 BrowserThread::IO, FROM_HERE,
1412 base::BindOnce(&ResourcePrefetcherManager::MaybeAddPrefetch, 1410 base::BindOnce(&ResourcePrefetcherManager::MaybeAddPrefetch,
1413 prefetch_manager_, url, prediction.subresource_urls)); 1411 prefetch_manager_, url, prediction.subresource_urls));
1414 1412
1415 if (observer_) 1413 if (observer_)
1416 observer_->OnPrefetchingStarted(url); 1414 observer_->OnPrefetchingStarted(url);
1417 } 1415 }
1418 1416
1419 void ResourcePrefetchPredictor::StopPrefetching(const GURL& url) { 1417 void ResourcePrefetchPredictor::StopPrefetching(const GURL& url) {
(...skipping 17 matching lines...) Expand all
1437 TestObserver::~TestObserver() { 1435 TestObserver::~TestObserver() {
1438 predictor_->SetObserverForTesting(nullptr); 1436 predictor_->SetObserverForTesting(nullptr);
1439 } 1437 }
1440 1438
1441 TestObserver::TestObserver(ResourcePrefetchPredictor* predictor) 1439 TestObserver::TestObserver(ResourcePrefetchPredictor* predictor)
1442 : predictor_(predictor) { 1440 : predictor_(predictor) {
1443 predictor_->SetObserverForTesting(this); 1441 predictor_->SetObserverForTesting(this);
1444 } 1442 }
1445 1443
1446 } // namespace predictors 1444 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698