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

Unified Diff: chrome/browser/prerender/prerender_manager.cc

Issue 6625066: Add pending preloads indexed by routing id. Start preloading once we navigate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing leak by checking for a valid Prerender source Created 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/prerender/prerender_manager.cc
diff --git a/chrome/browser/prerender/prerender_manager.cc b/chrome/browser/prerender/prerender_manager.cc
index d30bc9135c9e81f2c3f35701dae39a972a8a6b4c..dedfdf223ec3eebdfcbf37e6f7750cc535c60365 100644
--- a/chrome/browser/prerender/prerender_manager.cc
+++ b/chrome/browser/prerender/prerender_manager.cc
@@ -53,6 +53,17 @@ struct PrerenderManager::PrerenderContentsData {
}
};
+struct PrerenderManager::PendingContentsData {
+ PendingContentsData(const GURL& url, const std::vector<GURL>& alias_urls,
+ const GURL& referrer)
+ : url_(url), alias_urls_(alias_urls), referrer_(referrer) { }
+ ~PendingContentsData() {}
+ GURL url_;
+ std::vector<GURL> alias_urls_;
+ GURL referrer_;
+};
+
+
PrerenderManager::PrerenderManager(Profile* profile)
: profile_(profile),
max_prerender_age_(base::TimeDelta::FromSeconds(
@@ -107,6 +118,46 @@ bool PrerenderManager::AddPreload(const GURL& url,
return true;
}
+void PrerenderManager::AddPendingPreload(
+ const std::pair<int,int>& child_route_id_pair,
+ const GURL& url,
+ const std::vector<GURL>& alias_urls,
+ const GURL& referrer) {
+ // Check if this is coming from a valid prerender rvh.
+ bool is_valid_prerender = false;
+ for (std::list<PrerenderContentsData>::iterator it = prerender_list_.begin();
+ it != prerender_list_.end(); ++it) {
cbentzel 2011/03/18 18:35:43 This is a pretty subtle case. Could you add a test
dominich 2011/03/21 16:36:11 Done.
+ PrerenderContents* pc = it->contents_;
+ const RenderViewHost* rvh = pc->render_view_host();
+ if (rvh &&
+ rvh->process() &&
cbentzel 2011/03/18 18:35:43 You don't check for process() in RemovePendingPrel
dominich 2011/03/21 16:36:11 Actually no - I checked that when I wrote RemovePe
+ rvh->process()->id() == child_route_id_pair.first &&
+ rvh->routing_id() == child_route_id_pair.second) {
+ is_valid_prerender = true;
+ break;
+ }
+ }
+
+ // If not, we could check to see if the RenderViewHost specified by the
+ // child_route_id_pair exists and if so just start prerendering, as this
+ // suggests that the link was clicked, though this might prerender something
+ // that the user has already navigated away from. For now, we'll be
+ // conservative and skip the prerender which will mean some prerender requests
+ // from prerendered pages will be missed if the user navigates quickly.
cbentzel 2011/03/18 18:35:43 Should you add a FINAL_STATUS entry here? This is
dominich 2011/03/21 16:36:11 I thought about it, but we're not creating the pre
+ if (!is_valid_prerender)
cbentzel 2011/03/18 18:35:43 Thanks for the comment here.
+ return;
+
+ PendingPrerenderList::iterator it =
+ pending_prerender_list_.find(child_route_id_pair);
+ if (it == pending_prerender_list_.end()) {
+ PendingPrerenderList::value_type el = std::make_pair(child_route_id_pair,
+ std::vector<PendingContentsData>());
+ it = pending_prerender_list_.insert(el).first;
+ }
+
+ it->second.push_back(PendingContentsData(url, alias_urls, referrer));
+}
+
void PrerenderManager::DeleteOldEntries() {
while (!prerender_list_.empty()) {
PrerenderContentsData data = prerender_list_.front();
@@ -155,6 +206,22 @@ bool PrerenderManager::MaybeUsePreloadedPage(TabContents* tc, const GURL& url) {
tc->SwapInRenderViewHost(rvh);
MarkTabContentsAsPrerendered(tc);
+ // See if we have any pending prerender requests for this routing id and start
+ // the preload if we do.
+ std::pair<int, int> child_route_pair = std::make_pair(rvh->process()->id(),
+ rvh->routing_id());
+ PendingPrerenderList::iterator pending_it =
+ pending_prerender_list_.find(child_route_pair);
+ if (pending_it != pending_prerender_list_.end()) {
+ for (std::vector<PendingContentsData>::iterator content_it =
+ pending_it->second.begin();
+ content_it != pending_it->second.end(); ++content_it) {
+ AddPreload(content_it->url_, content_it->alias_urls_,
+ content_it->referrer_);
+ }
+ pending_prerender_list_.erase(pending_it);
+ }
+
ViewHostMsg_FrameNavigate_Params* p = pc->navigate_params();
if (p != NULL)
tc->DidNavigate(rvh, *p);
@@ -179,6 +246,7 @@ void PrerenderManager::RemoveEntry(PrerenderContents* entry) {
it != prerender_list_.end();
++it) {
if (it->contents_ == entry) {
+ RemovePendingPreload(entry);
prerender_list_.erase(it);
break;
}
@@ -241,6 +309,23 @@ PrerenderContents* PrerenderManager::FindEntry(const GURL& url) {
return NULL;
}
+PrerenderManager::PendingContentsData*
+ PrerenderManager::FindPendingEntry(const GURL& url) {
+ for (PendingPrerenderList::iterator map_it = pending_prerender_list_.begin();
+ map_it != pending_prerender_list_.end();
+ ++map_it) {
+ for (std::vector<PendingContentsData>::iterator content_it =
+ map_it->second.begin();
+ content_it != map_it->second.end();
+ ++content_it) {
+ if (content_it->url_ == url)
+ return &(*content_it);
+ }
+ }
+
+ return NULL;
+}
+
// static
void PrerenderManager::RecordPrefetchTagObserved() {
// Ensure that we are in the UI thread, and post to the UI thread if
@@ -267,6 +352,19 @@ void PrerenderManager::RecordPrefetchTagObservedOnUIThread() {
last_prefetch_seen_time_ = base::TimeTicks::Now();
}
+void PrerenderManager::RemovePendingPreload(PrerenderContents* entry) {
cbentzel 2011/03/18 18:35:43 can |entry| be const?
dominich 2011/03/21 16:36:11 no - render_view_host() is not const. Is there pr
+ RenderViewHost* rvh = entry->render_view_host();
+
+ // If the entry doesn't have a RenderViewHost then it didn't start
+ // prerendering and there shouldn't be any pending preloads to remove.
+ if (rvh == NULL)
+ return;
+
+ std::pair<int, int> child_route_pair = std::make_pair(rvh->process()->id(),
+ rvh->routing_id());
+ pending_prerender_list_.erase(child_route_pair);
+}
+
// static
bool PrerenderManager::ShouldRecordWindowedPPLT() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));

Powered by Google App Engine
This is Rietveld 408576698