| Index: chrome/browser/predictors/resource_prefetch_predictor.cc
|
| diff --git a/chrome/browser/predictors/resource_prefetch_predictor.cc b/chrome/browser/predictors/resource_prefetch_predictor.cc
|
| index 1812a87e01d92667795c0bbabd2464a426b925e3..d8c27221f179388194f1e0a509b37ef644a26bef 100644
|
| --- a/chrome/browser/predictors/resource_prefetch_predictor.cc
|
| +++ b/chrome/browser/predictors/resource_prefetch_predictor.cc
|
| @@ -67,28 +67,6 @@ float ComputeRedirectConfidence(const predictors::RedirectStat& redirect) {
|
| (redirect.number_of_hits() + redirect.number_of_misses());
|
| }
|
|
|
| -void UpdateOrAddToOrigins(
|
| - std::map<GURL, ResourcePrefetchPredictor::OriginRequestSummary>* summaries,
|
| - const ResourcePrefetchPredictor::URLRequestSummary& request_summary) {
|
| - const GURL& request_url = request_summary.request_url;
|
| - DCHECK(request_url.is_valid());
|
| - if (!request_url.is_valid())
|
| - return;
|
| -
|
| - GURL origin = request_url.GetOrigin();
|
| - auto it = summaries->find(origin);
|
| - if (it == summaries->end()) {
|
| - ResourcePrefetchPredictor::OriginRequestSummary summary;
|
| - summary.origin = origin;
|
| - summary.first_occurrence = summaries->size();
|
| - it = summaries->insert({origin, summary}).first;
|
| - }
|
| -
|
| - it->second.always_access_network |=
|
| - request_summary.always_revalidate || request_summary.is_no_store;
|
| - it->second.accessed_network |= request_summary.network_accessed;
|
| -}
|
| -
|
| void InitializeOriginStatFromOriginRequestSummary(
|
| OriginStat* origin,
|
| const ResourcePrefetchPredictor::OriginRequestSummary& summary) {
|
| @@ -413,70 +391,6 @@ void ResourcePrefetchPredictor::StartInitialization() {
|
| AsWeakPtr()));
|
| }
|
|
|
| -void ResourcePrefetchPredictor::RecordURLRequest(
|
| - const URLRequestSummary& request) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| - if (initialization_state_ != INITIALIZED)
|
| - return;
|
| -
|
| - CHECK_EQ(request.resource_type, content::RESOURCE_TYPE_MAIN_FRAME);
|
| - OnMainFrameRequest(request);
|
| -}
|
| -
|
| -void ResourcePrefetchPredictor::RecordURLResponse(
|
| - const URLRequestSummary& response) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| - if (initialization_state_ != INITIALIZED)
|
| - return;
|
| -
|
| - if (response.resource_type != content::RESOURCE_TYPE_MAIN_FRAME)
|
| - OnSubresourceResponse(response);
|
| -}
|
| -
|
| -void ResourcePrefetchPredictor::RecordURLRedirect(
|
| - const URLRequestSummary& response) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| - if (initialization_state_ != INITIALIZED)
|
| - return;
|
| -
|
| - if (response.resource_type == content::RESOURCE_TYPE_MAIN_FRAME)
|
| - OnMainFrameRedirect(response);
|
| - else
|
| - OnSubresourceRedirect(response);
|
| -}
|
| -
|
| -void ResourcePrefetchPredictor::RecordMainFrameLoadComplete(
|
| - const NavigationID& navigation_id) {
|
| - switch (initialization_state_) {
|
| - case NOT_INITIALIZED:
|
| - StartInitialization();
|
| - break;
|
| - case INITIALIZING:
|
| - break;
|
| - case INITIALIZED:
|
| - // WebContents can return an empty URL if the navigation entry
|
| - // corresponding to the navigation has not been created yet.
|
| - if (!navigation_id.main_frame_url.is_empty())
|
| - OnNavigationComplete(navigation_id);
|
| - break;
|
| - default:
|
| - NOTREACHED() << "Unexpected initialization_state_: "
|
| - << initialization_state_;
|
| - }
|
| -}
|
| -
|
| -void ResourcePrefetchPredictor::RecordFirstContentfulPaint(
|
| - const NavigationID& navigation_id,
|
| - const base::TimeTicks& first_contentful_paint) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| - if (initialization_state_ != INITIALIZED)
|
| - return;
|
| -
|
| - NavigationMap::iterator nav_it = inflight_navigations_.find(navigation_id);
|
| - if (nav_it != inflight_navigations_.end())
|
| - nav_it->second->first_contentful_paint = first_contentful_paint;
|
| -}
|
| -
|
| void ResourcePrefetchPredictor::OnPrefetchingFinished(
|
| const GURL& main_frame_url,
|
| std::unique_ptr<ResourcePrefetcher::PrefetcherStats> stats) {
|
| @@ -518,108 +432,8 @@ void ResourcePrefetchPredictor::Shutdown() {
|
| history_service_observer_.RemoveAll();
|
| }
|
|
|
| -void ResourcePrefetchPredictor::OnMainFrameRequest(
|
| - const URLRequestSummary& request) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| - DCHECK_EQ(INITIALIZED, initialization_state_);
|
| -
|
| - CleanupAbandonedNavigations(request.navigation_id);
|
| -
|
| - // New empty navigation entry.
|
| - const GURL& main_frame_url = request.navigation_id.main_frame_url;
|
| - inflight_navigations_.emplace(
|
| - request.navigation_id,
|
| - base::MakeUnique<PageRequestSummary>(main_frame_url));
|
| -}
|
| -
|
| -void ResourcePrefetchPredictor::OnMainFrameRedirect(
|
| - const URLRequestSummary& response) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| - DCHECK_EQ(INITIALIZED, initialization_state_);
|
| -
|
| - const GURL& main_frame_url = response.navigation_id.main_frame_url;
|
| - std::unique_ptr<PageRequestSummary> summary;
|
| - NavigationMap::iterator nav_it =
|
| - inflight_navigations_.find(response.navigation_id);
|
| - if (nav_it != inflight_navigations_.end()) {
|
| - summary = std::move(nav_it->second);
|
| - inflight_navigations_.erase(nav_it);
|
| - }
|
| -
|
| - // The redirect url may be empty if the URL was invalid.
|
| - if (response.redirect_url.is_empty())
|
| - return;
|
| -
|
| - // If we lost the information about the first hop for some reason.
|
| - if (!summary) {
|
| - summary = base::MakeUnique<PageRequestSummary>(main_frame_url);
|
| - }
|
| -
|
| - // A redirect will not lead to another OnMainFrameRequest call, so record the
|
| - // redirect url as a new navigation id and save the initial url.
|
| - NavigationID navigation_id(response.navigation_id);
|
| - navigation_id.main_frame_url = response.redirect_url;
|
| - summary->main_frame_url = response.redirect_url;
|
| - inflight_navigations_.emplace(navigation_id, std::move(summary));
|
| -}
|
| -
|
| -void ResourcePrefetchPredictor::OnSubresourceResponse(
|
| - const URLRequestSummary& response) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| - DCHECK_EQ(INITIALIZED, initialization_state_);
|
| -
|
| - NavigationMap::const_iterator nav_it =
|
| - inflight_navigations_.find(response.navigation_id);
|
| - if (nav_it == inflight_navigations_.end())
|
| - return;
|
| - auto& page_request_summary = *nav_it->second;
|
| -
|
| - if (!response.is_no_store)
|
| - page_request_summary.subresource_requests.push_back(response);
|
| -
|
| - if (config_.is_origin_learning_enabled)
|
| - UpdateOrAddToOrigins(&page_request_summary.origins, response);
|
| -}
|
| -
|
| -void ResourcePrefetchPredictor::OnSubresourceRedirect(
|
| - const URLRequestSummary& response) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| - DCHECK_EQ(INITIALIZED, initialization_state_);
|
| -
|
| - if (!config_.is_origin_learning_enabled)
|
| - return;
|
| -
|
| - NavigationMap::const_iterator nav_it =
|
| - inflight_navigations_.find(response.navigation_id);
|
| - if (nav_it == inflight_navigations_.end())
|
| - return;
|
| - auto& page_request_summary = *nav_it->second;
|
| - UpdateOrAddToOrigins(&page_request_summary.origins, response);
|
| -}
|
| -
|
| -void ResourcePrefetchPredictor::OnNavigationComplete(
|
| - const NavigationID& nav_id_without_timing_info) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| - DCHECK_EQ(INITIALIZED, initialization_state_);
|
| -
|
| - NavigationMap::iterator nav_it =
|
| - inflight_navigations_.find(nav_id_without_timing_info);
|
| - if (nav_it == inflight_navigations_.end())
|
| - return;
|
| -
|
| - // Remove the navigation from the inflight navigations.
|
| - std::unique_ptr<PageRequestSummary> summary = std::move(nav_it->second);
|
| - inflight_navigations_.erase(nav_it);
|
| -
|
| - // Set before_first_contentful paint for each resource.
|
| - for (auto& request_summary : summary->subresource_requests) {
|
| - request_summary.before_first_contentful_paint =
|
| - request_summary.response_time < summary->first_contentful_paint;
|
| - }
|
| -
|
| - if (stats_collector_)
|
| - stats_collector_->RecordPageRequestSummary(*summary);
|
| -
|
| +void ResourcePrefetchPredictor::HandlePageRequestSummary(
|
| + std::unique_ptr<PageRequestSummary> summary) {
|
| // Kick off history lookup to determine if we should record the URL.
|
| history::HistoryService* history_service =
|
| HistoryServiceFactory::GetForProfile(profile_,
|
| @@ -790,26 +604,6 @@ void ResourcePrefetchPredictor::OnHistoryAndCacheLoaded() {
|
| observer_->OnPredictorInitialized();
|
| }
|
|
|
| -void ResourcePrefetchPredictor::CleanupAbandonedNavigations(
|
| - const NavigationID& navigation_id) {
|
| - if (stats_collector_)
|
| - stats_collector_->CleanupAbandonedStats();
|
| -
|
| - static const base::TimeDelta max_navigation_age =
|
| - base::TimeDelta::FromSeconds(config_.max_navigation_lifetime_seconds);
|
| -
|
| - base::TimeTicks time_now = base::TimeTicks::Now();
|
| - for (NavigationMap::iterator it = inflight_navigations_.begin();
|
| - it != inflight_navigations_.end();) {
|
| - if ((it->first.tab_id == navigation_id.tab_id) ||
|
| - (time_now - it->first.creation_time > max_navigation_age)) {
|
| - inflight_navigations_.erase(it++);
|
| - } else {
|
| - ++it;
|
| - }
|
| - }
|
| -}
|
| -
|
| void ResourcePrefetchPredictor::DeleteAllUrls() {
|
| inflight_navigations_.clear();
|
|
|
|
|