OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/prerender/prerender_manager.h" | 5 #include "chrome/browser/prerender/prerender_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <functional> | 10 #include <functional> |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
568 redirect_count); | 568 redirect_count); |
569 } | 569 } |
570 | 570 |
571 void PrerenderManager::RecordNoStateFirstContentfulPaint(const GURL& url, | 571 void PrerenderManager::RecordNoStateFirstContentfulPaint(const GURL& url, |
572 bool is_no_store, | 572 bool is_no_store, |
573 bool was_hidden, | 573 bool was_hidden, |
574 base::TimeDelta time) { | 574 base::TimeDelta time) { |
575 base::TimeDelta prefetch_age; | 575 base::TimeDelta prefetch_age; |
576 Origin origin; | 576 Origin origin; |
577 GetPrefetchInformation(url, &prefetch_age, &origin); | 577 GetPrefetchInformation(url, &prefetch_age, &origin); |
578 OnPrefetchUsed(url); | |
578 | 579 |
579 histograms_->RecordPrefetchFirstContentfulPaintTime( | 580 histograms_->RecordPrefetchFirstContentfulPaintTime( |
580 origin, is_no_store, was_hidden, time, prefetch_age); | 581 origin, is_no_store, was_hidden, time, prefetch_age); |
581 | 582 |
582 for (auto& observer : observers_) { | 583 for (auto& observer : observers_) { |
583 observer->OnFirstContentfulPaint(); | 584 observer->OnFirstContentfulPaint(); |
584 } | 585 } |
585 } | 586 } |
586 | 587 |
587 void PrerenderManager::RecordPrerenderFirstContentfulPaint( | 588 void PrerenderManager::RecordPrerenderFirstContentfulPaint( |
588 const GURL& url, | 589 const GURL& url, |
589 content::WebContents* web_contents, | 590 content::WebContents* web_contents, |
590 bool is_no_store, | 591 bool is_no_store, |
591 bool was_hidden, | 592 bool was_hidden, |
592 base::TimeTicks first_contentful_paint) { | 593 base::TimeTicks first_contentful_paint) { |
593 DCHECK(!first_contentful_paint.is_null()); | 594 DCHECK(!first_contentful_paint.is_null()); |
594 | 595 |
595 PrerenderTabHelper* tab_helper = | 596 PrerenderTabHelper* tab_helper = |
596 PrerenderTabHelper::FromWebContents(web_contents); | 597 PrerenderTabHelper::FromWebContents(web_contents); |
597 DCHECK(tab_helper); | 598 DCHECK(tab_helper); |
598 | 599 |
599 base::TimeDelta prefetch_age; | 600 base::TimeDelta prefetch_age; |
600 // The origin at prefetch is superceeded by the tab_helper origin for the | 601 // The origin at prefetch is superceeded by the tab_helper origin for the |
601 // histogram recording, below. | 602 // histogram recording, below. |
602 Origin unused_origin; | 603 Origin unused_origin; |
603 GetPrefetchInformation(url, &prefetch_age, &unused_origin); | 604 GetPrefetchInformation(url, &prefetch_age, &unused_origin); |
605 OnPrefetchUsed(url); | |
604 | 606 |
605 base::TimeTicks swap_ticks = tab_helper->swap_ticks(); | 607 base::TimeTicks swap_ticks = tab_helper->swap_ticks(); |
606 bool fcp_recorded = false; | 608 bool fcp_recorded = false; |
607 if (!swap_ticks.is_null() && !first_contentful_paint.is_null()) { | 609 if (!swap_ticks.is_null() && !first_contentful_paint.is_null()) { |
608 histograms_->RecordPrefetchFirstContentfulPaintTime( | 610 histograms_->RecordPrefetchFirstContentfulPaintTime( |
609 tab_helper->origin(), is_no_store, was_hidden, | 611 tab_helper->origin(), is_no_store, was_hidden, |
610 first_contentful_paint - swap_ticks, prefetch_age); | 612 first_contentful_paint - swap_ticks, prefetch_age); |
611 fcp_recorded = true; | 613 fcp_recorded = true; |
612 } | 614 } |
613 histograms_->RecordPerceivedFirstContentfulPaintStatus( | 615 histograms_->RecordPerceivedFirstContentfulPaintStatus( |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
932 if (prerendering_status != NetworkPredictionStatus::ENABLED) { | 934 if (prerendering_status != NetworkPredictionStatus::ENABLED) { |
933 FinalStatus final_status = | 935 FinalStatus final_status = |
934 prerendering_status == NetworkPredictionStatus::DISABLED_DUE_TO_NETWORK | 936 prerendering_status == NetworkPredictionStatus::DISABLED_DUE_TO_NETWORK |
935 ? FINAL_STATUS_CELLULAR_NETWORK | 937 ? FINAL_STATUS_CELLULAR_NETWORK |
936 : FINAL_STATUS_PRERENDERING_DISABLED; | 938 : FINAL_STATUS_PRERENDERING_DISABLED; |
937 RecordFinalStatusWithoutCreatingPrerenderContents(url, origin, | 939 RecordFinalStatusWithoutCreatingPrerenderContents(url, origin, |
938 final_status); | 940 final_status); |
939 return nullptr; | 941 return nullptr; |
940 } | 942 } |
941 | 943 |
942 if (PrerenderData* preexisting_prerender_data = | 944 if (IsNoStatePrefetch(origin)) { |
943 FindPrerenderData(url, session_storage_namespace)) { | 945 base::TimeDelta prefetch_age; |
946 Origin origin; | |
pasko
2017/01/04 15:00:45
overriding |origin| in this local scope looks dang
| |
947 GetPrefetchInformation(url, &prefetch_age, &origin); | |
948 if (!prefetch_age.is_zero() && prefetch_age < config_.time_to_live) { | |
949 RecordFinalStatusWithoutCreatingPrerenderContents(url, origin, | |
pasko
2017/01/04 15:00:45
this should register the origin from the AddPreren
droger
2017/01/04 15:14:48
This is a bug, good catch.
The local variable shou
| |
950 FINAL_STATUS_DUPLICATE); | |
951 return nullptr; | |
952 } | |
953 } else if (PrerenderData* preexisting_prerender_data = | |
954 FindPrerenderData(url, session_storage_namespace)) { | |
944 RecordFinalStatusWithoutCreatingPrerenderContents( | 955 RecordFinalStatusWithoutCreatingPrerenderContents( |
945 url, origin, FINAL_STATUS_DUPLICATE); | 956 url, origin, FINAL_STATUS_DUPLICATE); |
946 return base::WrapUnique(new PrerenderHandle(preexisting_prerender_data)); | 957 return base::WrapUnique(new PrerenderHandle(preexisting_prerender_data)); |
947 } | 958 } |
948 | 959 |
949 // Do not prerender if there are too many render processes, and we would | 960 // Do not prerender if there are too many render processes, and we would |
950 // have to use an existing one. We do not want prerendering to happen in | 961 // have to use an existing one. We do not want prerendering to happen in |
951 // a shared process, so that we can always reliably lower the CPU | 962 // a shared process, so that we can always reliably lower the CPU |
952 // priority for prerendering. | 963 // priority for prerendering. |
953 // In single-process mode, ShouldTryToUseExistingProcessHost() always returns | 964 // In single-process mode, ShouldTryToUseExistingProcessHost() always returns |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1197 | 1208 |
1198 *prefetch_age = base::TimeDelta(); | 1209 *prefetch_age = base::TimeDelta(); |
1199 *origin = ORIGIN_NONE; | 1210 *origin = ORIGIN_NONE; |
1200 for (auto it = prefetches_.crbegin(); it != prefetches_.crend(); ++it) { | 1211 for (auto it = prefetches_.crbegin(); it != prefetches_.crend(); ++it) { |
1201 if (it->url == url) { | 1212 if (it->url == url) { |
1202 *prefetch_age = GetCurrentTimeTicks() - it->time; | 1213 *prefetch_age = GetCurrentTimeTicks() - it->time; |
1203 *origin = it->origin; | 1214 *origin = it->origin; |
1204 break; | 1215 break; |
1205 } | 1216 } |
1206 } | 1217 } |
1218 } | |
1207 | 1219 |
1220 void PrerenderManager::OnPrefetchUsed(const GURL& url) { | |
1208 // Loading a prefetched URL resets the revalidation bypass. Remove all | 1221 // Loading a prefetched URL resets the revalidation bypass. Remove all |
1209 // matching urls from the prefetch list for more accurate metrics. | 1222 // matching urls from the prefetch list for more accurate metrics. |
1210 prefetches_.erase( | 1223 prefetches_.erase( |
1211 std::remove_if(prefetches_.begin(), prefetches_.end(), | 1224 std::remove_if(prefetches_.begin(), prefetches_.end(), |
1212 [url](const NavigationRecord& r) { return r.url == url; }), | 1225 [url](const NavigationRecord& r) { return r.url == url; }), |
1213 prefetches_.end()); | 1226 prefetches_.end()); |
1214 } | 1227 } |
1215 | 1228 |
1216 void PrerenderManager::CleanUpOldNavigations( | 1229 void PrerenderManager::CleanUpOldNavigations( |
1217 std::vector<NavigationRecord>* navigations, | 1230 std::vector<NavigationRecord>* navigations, |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1422 return weak_factory_.GetWeakPtr(); | 1435 return weak_factory_.GetWeakPtr(); |
1423 } | 1436 } |
1424 | 1437 |
1425 void PrerenderManager::SetPrerenderContentsFactoryForTest( | 1438 void PrerenderManager::SetPrerenderContentsFactoryForTest( |
1426 PrerenderContents::Factory* prerender_contents_factory) { | 1439 PrerenderContents::Factory* prerender_contents_factory) { |
1427 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1440 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1428 prerender_contents_factory_.reset(prerender_contents_factory); | 1441 prerender_contents_factory_.reset(prerender_contents_factory); |
1429 } | 1442 } |
1430 | 1443 |
1431 } // namespace prerender | 1444 } // namespace prerender |
OLD | NEW |