Index: chrome/browser/prerender/prerender_local_predictor.cc |
diff --git a/chrome/browser/prerender/prerender_local_predictor.cc b/chrome/browser/prerender/prerender_local_predictor.cc |
index fea2cafb090a314d5f4edad011f8e296b1e7815a..36ad713f48d45e132c1113620d86f386f73c1695 100644 |
--- a/chrome/browser/prerender/prerender_local_predictor.cc |
+++ b/chrome/browser/prerender/prerender_local_predictor.cc |
@@ -455,24 +455,55 @@ class PrerenderLocalPredictor::PrefetchList { |
return_value = true; |
} |
// If the item has been seen in both the history and in tab contents, |
- // erase it from the map to make room for new prefetches. |
- if (it->second->seen_tabcontents_ && it->second->seen_history_) |
+ // and the page load time has been recorded, erase it from the map to |
+ // make room for new prefetches. |
+ if (it->second->seen_tabcontents_ && it->second->seen_history_ && |
+ it->second->plt_recorded_) { |
entries_.erase(url.spec().c_str()); |
+ } |
return return_value; |
} |
+ // To be called when a PLT was seen for a given URL. |
+ // Returns true iff: |
+ // - There is an entry of a prefetch for the URL provided. |
+ // - The prefetch was started before the page load was started (based on the |
+ // plt). |
+ // - The prefetch entry has not been returned "true" for as a result of a call |
+ // to this method previously. |
+ bool SeenPLTForURL(const GURL& url, base::TimeDelta plt) { |
jkarlin
2014/08/21 14:34:14
Rename to MarkPLTSeen? Then reformat the comments
tburkard
2014/08/21 15:28:11
Done.
|
+ ExpireOldItems(); |
+ base::hash_map<string, ListEntry*>::iterator it = |
+ entries_.find(url.spec().c_str()); |
+ if (it == entries_.end() || it->second->plt_recorded_ || |
+ it->second->add_time_ > GetCurrentTime() - plt) { |
+ return false; |
+ } |
+ it->second->plt_recorded_ = true; |
+ // If the item has been seen in both the history and in tab contents, |
+ // and the page load time has been recorded, erase it from the map to |
+ // make room for new prefetches. |
+ if (it->second->seen_tabcontents_ && it->second->seen_history_ && |
+ it->second->plt_recorded_) { |
+ entries_.erase(url.spec().c_str()); |
+ } |
+ return true; |
+ } |
+ |
private: |
struct ListEntry { |
explicit ListEntry(const string& url) |
: url_(url), |
add_time_(GetCurrentTime()), |
seen_tabcontents_(false), |
- seen_history_(false) { |
+ seen_history_(false), |
+ plt_recorded_(false) { |
} |
std::string url_; |
base::Time add_time_; |
bool seen_tabcontents_; |
bool seen_history_; |
+ bool plt_recorded_; |
jkarlin
2014/08/21 14:34:14
Why not seen_plt_ like the other members? Prefetc
tburkard
2014/08/21 15:28:11
Done.
|
}; |
void ExpireOldItems() { |
@@ -1119,6 +1150,14 @@ void PrerenderLocalPredictor::Init() { |
void PrerenderLocalPredictor::OnPLTEventForURL(const GURL& url, |
base::TimeDelta page_load_time) { |
+ if (prefetch_list_->SeenPLTForURL(url, page_load_time)) { |
+ UMA_HISTOGRAM_CUSTOM_TIMES("Prerender.LocalPredictorPrefetchMatchPLT", |
+ page_load_time, |
+ base::TimeDelta::FromMilliseconds(10), |
+ base::TimeDelta::FromSeconds(60), |
+ 100); |
+ } |
+ |
scoped_ptr<PrerenderProperties> prerender; |
if (DoesPrerenderMatchPLTRecord(last_swapped_in_prerender_.get(), |
url, page_load_time)) { |
@@ -1338,8 +1377,19 @@ void PrerenderLocalPredictor::IssuePrerender( |
CandidatePrerenderInfo* info, |
LocalPredictorURLInfo* url_info) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- if (prefetch_list_->AddURL(url_info->url)) |
+ if (prefetch_list_->AddURL(url_info->url)) { |
RecordEvent(EVENT_PREFETCH_LIST_ADDED); |
+ // If we are prefetching rather than prerendering, now is the time to launch |
+ // the prefetch. |
+ if (IsLocalPredictorPrerenderPrefetchEnabled()) { |
+ // Obtain the render frame host that caused this prefetch. |
+ RenderFrameHost* rfh = RenderFrameHost::FromID(info->render_process_id_, |
+ info->render_frame_id_); |
+ // If it is still alive, launch the prefresh. |
+ if (rfh) |
+ rfh->Send(new PrefetchMsg_Prefetch(rfh->GetRoutingID(), url_info->url)); |
+ } |
+ } |
PrerenderProperties* prerender_properties = |
GetIssuedPrerenderSlotForPriority(url_info->url, url_info->priority); |
if (!prerender_properties) { |
@@ -1395,16 +1445,6 @@ void PrerenderLocalPredictor::IssuePrerender( |
new_prerender_handle->OnCancel(); |
RecordEvent(EVENT_ISSUE_PRERENDER_CANCELLED_OLD_PRERENDER); |
} |
- // If we are prefetching rather than prerendering, now is the time to launch |
- // the prefetch. |
- if (IsLocalPredictorPrerenderPrefetchEnabled()) { |
- // Obtain the render frame host that caused this prefetch. |
- RenderFrameHost* rfh = RenderFrameHost::FromID(info->render_process_id_, |
- info->render_frame_id_); |
- // If it is still alive, launch the prefresh. |
- if (rfh) |
- rfh->Send(new PrefetchMsg_Prefetch(rfh->GetRoutingID(), url)); |
- } |
} |
RecordEvent(EVENT_ADD_VISIT_PRERENDERING); |