| 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 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 | 539 |
| 540 ResourcePrefetchPredictor::Prediction::Prediction( | 540 ResourcePrefetchPredictor::Prediction::Prediction( |
| 541 const ResourcePrefetchPredictor::Prediction& other) = default; | 541 const ResourcePrefetchPredictor::Prediction& other) = default; |
| 542 | 542 |
| 543 ResourcePrefetchPredictor::Prediction::~Prediction() = default; | 543 ResourcePrefetchPredictor::Prediction::~Prediction() = default; |
| 544 | 544 |
| 545 //////////////////////////////////////////////////////////////////////////////// | 545 //////////////////////////////////////////////////////////////////////////////// |
| 546 // ResourcePrefetchPredictor. | 546 // ResourcePrefetchPredictor. |
| 547 | 547 |
| 548 ResourcePrefetchPredictor::ResourcePrefetchPredictor( | 548 ResourcePrefetchPredictor::ResourcePrefetchPredictor( |
| 549 const ResourcePrefetchPredictorConfig& config, | 549 const LoadingPredictorConfig& config, |
| 550 Profile* profile) | 550 Profile* profile) |
| 551 : profile_(profile), | 551 : profile_(profile), |
| 552 observer_(nullptr), | 552 observer_(nullptr), |
| 553 config_(config), | 553 config_(config), |
| 554 initialization_state_(NOT_INITIALIZED), | 554 initialization_state_(NOT_INITIALIZED), |
| 555 tables_(PredictorDatabaseFactory::GetForProfile(profile) | 555 tables_(PredictorDatabaseFactory::GetForProfile(profile) |
| 556 ->resource_prefetch_tables()), | 556 ->resource_prefetch_tables()), |
| 557 history_service_observer_(this) { | 557 history_service_observer_(this) { |
| 558 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 558 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 559 | 559 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 662 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 663 if (initialization_state_ != INITIALIZED) | 663 if (initialization_state_ != INITIALIZED) |
| 664 return; | 664 return; |
| 665 | 665 |
| 666 NavigationMap::iterator nav_it = inflight_navigations_.find(navigation_id); | 666 NavigationMap::iterator nav_it = inflight_navigations_.find(navigation_id); |
| 667 if (nav_it != inflight_navigations_.end()) | 667 if (nav_it != inflight_navigations_.end()) |
| 668 nav_it->second->first_contentful_paint = first_contentful_paint; | 668 nav_it->second->first_contentful_paint = first_contentful_paint; |
| 669 } | 669 } |
| 670 | 670 |
| 671 void ResourcePrefetchPredictor::StartPrefetching(const GURL& url, | 671 void ResourcePrefetchPredictor::StartPrefetching(const GURL& url, |
| 672 PrefetchOrigin origin) { | 672 HintOrigin origin) { |
| 673 TRACE_EVENT1("browser", "ResourcePrefetchPredictor::StartPrefetching", "url", | 673 TRACE_EVENT1("browser", "ResourcePrefetchPredictor::StartPrefetching", "url", |
| 674 url.spec()); | 674 url.spec()); |
| 675 // Save prefetch start time to report prefetching duration. | 675 // Save prefetch start time to report prefetching duration. |
| 676 if (inflight_prefetches_.find(url) == inflight_prefetches_.end() && | 676 if (inflight_prefetches_.find(url) == inflight_prefetches_.end() && |
| 677 IsUrlPrefetchable(url)) { | 677 IsUrlPrefetchable(url)) { |
| 678 inflight_prefetches_.insert(std::make_pair(url, base::TimeTicks::Now())); | 678 inflight_prefetches_.insert(std::make_pair(url, base::TimeTicks::Now())); |
| 679 } | 679 } |
| 680 | 680 |
| 681 if (!prefetch_manager_.get()) // Prefetching not enabled. | 681 if (!prefetch_manager_.get()) // Prefetching not enabled. |
| 682 return; | 682 return; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 } | 755 } |
| 756 history_service_observer_.RemoveAll(); | 756 history_service_observer_.RemoveAll(); |
| 757 } | 757 } |
| 758 | 758 |
| 759 void ResourcePrefetchPredictor::OnMainFrameRequest( | 759 void ResourcePrefetchPredictor::OnMainFrameRequest( |
| 760 const URLRequestSummary& request) { | 760 const URLRequestSummary& request) { |
| 761 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 761 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 762 DCHECK_EQ(INITIALIZED, initialization_state_); | 762 DCHECK_EQ(INITIALIZED, initialization_state_); |
| 763 | 763 |
| 764 const GURL& main_frame_url = request.navigation_id.main_frame_url; | 764 const GURL& main_frame_url = request.navigation_id.main_frame_url; |
| 765 StartPrefetching(main_frame_url, PrefetchOrigin::NAVIGATION); | 765 StartPrefetching(main_frame_url, HintOrigin::NAVIGATION); |
| 766 | 766 |
| 767 CleanupAbandonedNavigations(request.navigation_id); | 767 CleanupAbandonedNavigations(request.navigation_id); |
| 768 | 768 |
| 769 // New empty navigation entry. | 769 // New empty navigation entry. |
| 770 inflight_navigations_.insert( | 770 inflight_navigations_.insert( |
| 771 std::make_pair(request.navigation_id, | 771 std::make_pair(request.navigation_id, |
| 772 base::MakeUnique<PageRequestSummary>(main_frame_url))); | 772 base::MakeUnique<PageRequestSummary>(main_frame_url))); |
| 773 } | 773 } |
| 774 | 774 |
| 775 void ResourcePrefetchPredictor::OnMainFrameResponse( | 775 void ResourcePrefetchPredictor::OnMainFrameResponse( |
| (...skipping 1075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1851 TestObserver::~TestObserver() { | 1851 TestObserver::~TestObserver() { |
| 1852 predictor_->SetObserverForTesting(nullptr); | 1852 predictor_->SetObserverForTesting(nullptr); |
| 1853 } | 1853 } |
| 1854 | 1854 |
| 1855 TestObserver::TestObserver(ResourcePrefetchPredictor* predictor) | 1855 TestObserver::TestObserver(ResourcePrefetchPredictor* predictor) |
| 1856 : predictor_(predictor) { | 1856 : predictor_(predictor) { |
| 1857 predictor_->SetObserverForTesting(this); | 1857 predictor_->SetObserverForTesting(this); |
| 1858 } | 1858 } |
| 1859 | 1859 |
| 1860 } // namespace predictors | 1860 } // namespace predictors |
| OLD | NEW |