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

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

Issue 2755093002: predictors: Mark before_first_contentful_paint for resources fetched before fcp. (Closed)
Patch Set: Mark before_first_contentful_paint. Created 3 years, 9 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 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 // corresponding to the navigation has not been created yet. 571 // corresponding to the navigation has not been created yet.
572 if (!navigation_id.main_frame_url.is_empty()) 572 if (!navigation_id.main_frame_url.is_empty())
573 OnNavigationComplete(navigation_id); 573 OnNavigationComplete(navigation_id);
574 break; 574 break;
575 default: 575 default:
576 NOTREACHED() << "Unexpected initialization_state_: " 576 NOTREACHED() << "Unexpected initialization_state_: "
577 << initialization_state_; 577 << initialization_state_;
578 } 578 }
579 } 579 }
580 580
581 void ResourcePrefetchPredictor::RecordFirstContentfulPaint(
582 const NavigationID navigation_id) {
583 NavigationMap::iterator nav_it =
584 inflight_navigations_.find(navigation_id);
585 if (nav_it == inflight_navigations_.end()) return;
alexilin 2017/03/17 14:46:46 nit: Return statement should occupy a separate lin
trevordixon 2017/03/27 12:30:08 Done.
586
587 for (auto& request_summary : nav_it->second->subresource_requests) {
588 request_summary.before_first_contentful_paint = true;
alexilin 2017/03/17 14:46:46 You can't assume that Observer gets an event at th
trevordixon 2017/03/27 12:30:08 Maybe fixed. How likely is it that OnFirstContentf
alexilin 2017/03/27 15:31:59 Well, it's definitely not rare for "fast" pages fo
589 }
590 }
591
592
581 void ResourcePrefetchPredictor::StartPrefetching(const GURL& url, 593 void ResourcePrefetchPredictor::StartPrefetching(const GURL& url,
582 PrefetchOrigin origin) { 594 PrefetchOrigin origin) {
583 TRACE_EVENT1("browser", "ResourcePrefetchPredictor::StartPrefetching", "url", 595 TRACE_EVENT1("browser", "ResourcePrefetchPredictor::StartPrefetching", "url",
584 url.spec()); 596 url.spec());
585 // Save prefetch start time to report prefetching duration. 597 // Save prefetch start time to report prefetching duration.
586 if (inflight_prefetches_.find(url) == inflight_prefetches_.end() && 598 if (inflight_prefetches_.find(url) == inflight_prefetches_.end() &&
587 IsUrlPrefetchable(url)) { 599 IsUrlPrefetchable(url)) {
588 inflight_prefetches_.insert(std::make_pair(url, base::TimeTicks::Now())); 600 inflight_prefetches_.insert(std::make_pair(url, base::TimeTicks::Now()));
589 } 601 }
590 602
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 data.set_primary_key(key); 1151 data.set_primary_key(key);
1140 data.set_last_visit_time(base::Time::Now().ToInternalValue()); 1152 data.set_last_visit_time(base::Time::Now().ToInternalValue());
1141 size_t new_resources_size = new_resources.size(); 1153 size_t new_resources_size = new_resources.size();
1142 std::set<GURL> resources_seen; 1154 std::set<GURL> resources_seen;
1143 for (size_t i = 0; i < new_resources_size; ++i) { 1155 for (size_t i = 0; i < new_resources_size; ++i) {
1144 const URLRequestSummary& summary = new_resources[i]; 1156 const URLRequestSummary& summary = new_resources[i];
1145 if (resources_seen.find(summary.resource_url) != resources_seen.end()) 1157 if (resources_seen.find(summary.resource_url) != resources_seen.end())
1146 continue; 1158 continue;
1147 1159
1148 ResourceData* resource_to_add = data.add_resources(); 1160 ResourceData* resource_to_add = data.add_resources();
1161 resource_to_add->set_before_first_contentful_paint(
1162 summary.before_first_contentful_paint);
1149 resource_to_add->set_resource_url(summary.resource_url.spec()); 1163 resource_to_add->set_resource_url(summary.resource_url.spec());
1150 resource_to_add->set_resource_type( 1164 resource_to_add->set_resource_type(
1151 static_cast<ResourceData::ResourceType>(summary.resource_type)); 1165 static_cast<ResourceData::ResourceType>(summary.resource_type));
1152 resource_to_add->set_number_of_hits(1); 1166 resource_to_add->set_number_of_hits(1);
1153 resource_to_add->set_average_position(i + 1); 1167 resource_to_add->set_average_position(i + 1);
1154 resource_to_add->set_priority( 1168 resource_to_add->set_priority(
1155 static_cast<ResourceData::Priority>(summary.priority)); 1169 static_cast<ResourceData::Priority>(summary.priority));
1156 resource_to_add->set_has_validators(summary.has_validators); 1170 resource_to_add->set_has_validators(summary.has_validators);
1157 resource_to_add->set_always_revalidate(summary.always_revalidate); 1171 resource_to_add->set_always_revalidate(summary.always_revalidate);
1158 1172
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
1432 TestObserver::~TestObserver() { 1446 TestObserver::~TestObserver() {
1433 predictor_->SetObserverForTesting(nullptr); 1447 predictor_->SetObserverForTesting(nullptr);
1434 } 1448 }
1435 1449
1436 TestObserver::TestObserver(ResourcePrefetchPredictor* predictor) 1450 TestObserver::TestObserver(ResourcePrefetchPredictor* predictor)
1437 : predictor_(predictor) { 1451 : predictor_(predictor) {
1438 predictor_->SetObserverForTesting(this); 1452 predictor_->SetObserverForTesting(this);
1439 } 1453 }
1440 1454
1441 } // namespace predictors 1455 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698