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

Unified Diff: chrome/browser/predictors/resource_prefetch_predictor.cc

Issue 2755093002: predictors: Mark before_first_contentful_paint for resources fetched before fcp. (Closed)
Patch Set: before_first_contentful_paint browser_test Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
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 58d01b5df36a23eabb6ebf86be8c50d4a700047b..3ff92fe15c30be1cf49f8565f0c50573359aa7b0 100644
--- a/chrome/browser/predictors/resource_prefetch_predictor.cc
+++ b/chrome/browser/predictors/resource_prefetch_predictor.cc
@@ -469,6 +469,8 @@ ResourcePrefetchPredictor::OriginRequestSummary::~OriginRequestSummary() {}
ResourcePrefetchPredictor::URLRequestSummary::URLRequestSummary()
: resource_type(content::RESOURCE_TYPE_LAST_TYPE),
priority(net::IDLE),
+ response_time(base::TimeTicks()),
+ before_first_contentful_paint(false),
was_cached(false),
has_validators(false),
always_revalidate(false),
@@ -490,6 +492,7 @@ bool ResourcePrefetchPredictor::URLRequestSummary::SummarizeResponse(
if (!request_info)
return false;
+ summary->response_time = base::TimeTicks::Now();
summary->resource_url = request.original_url();
summary->request_url = request.url();
content::ResourceType resource_type_from_request =
@@ -517,7 +520,9 @@ bool ResourcePrefetchPredictor::URLRequestSummary::SummarizeResponse(
ResourcePrefetchPredictor::PageRequestSummary::PageRequestSummary(
const GURL& i_main_frame_url)
- : main_frame_url(i_main_frame_url), initial_url(i_main_frame_url) {}
+ : main_frame_url(i_main_frame_url),
+ initial_url(i_main_frame_url),
+ first_contentful_paint(base::TimeTicks::Max()) {}
ResourcePrefetchPredictor::PageRequestSummary::PageRequestSummary(
const PageRequestSummary& other) = default;
@@ -645,6 +650,15 @@ void ResourcePrefetchPredictor::RecordMainFrameLoadComplete(
}
}
+void ResourcePrefetchPredictor::RecordFirstContentfulPaint(
+ const NavigationID& navigation_id,
+ const base::TimeTicks& first_contentful_paint) {
alexilin 2017/04/21 13:49:05 Please add following lines to the beginning of the
trevordixon 2017/04/25 12:46:09 Done.
+ NavigationMap::iterator nav_it = inflight_navigations_.find(navigation_id);
+ if (nav_it != inflight_navigations_.end()) {
alexilin 2017/04/21 13:49:05 very tiny nit: You could omit curly braces.
trevordixon 2017/04/25 12:46:09 OK.
+ nav_it->second->first_contentful_paint = first_contentful_paint;
+ }
+}
+
void ResourcePrefetchPredictor::StartPrefetching(const GURL& url,
PrefetchOrigin origin) {
TRACE_EVENT1("browser", "ResourcePrefetchPredictor::StartPrefetching", "url",
@@ -844,6 +858,12 @@ void ResourcePrefetchPredictor::OnNavigationComplete(
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;
+ }
+
const GURL& initial_url = summary->initial_url;
ResourcePrefetchPredictor::Prediction prediction;
bool has_data = GetPrefetchData(initial_url, &prediction);
@@ -1419,6 +1439,8 @@ void ResourcePrefetchPredictor::LearnNavigation(
resource_to_add->set_average_position(i + 1);
resource_to_add->set_priority(
static_cast<ResourceData::Priority>(summary.priority));
+ resource_to_add->set_before_first_contentful_paint(
+ summary.before_first_contentful_paint);
resource_to_add->set_has_validators(new_resources[i].has_validators);
resource_to_add->set_always_revalidate(
new_resources[i].always_revalidate);

Powered by Google App Engine
This is Rietveld 408576698