Commit e54c55a9 authored by jam's avatar jam Committed by Commit bot

Fix early prerender cancellation not working with PlzNavigate.

With PlzNavigate the navigation starts in the browser, so LaunchAppWithUrl cancels the prerender before we get the PrerenderHostMsg_AddLinkRelPrerender IPC from the renderer. Fix this by noticing that the prerender was already cancelled when the IPC arrives.

This fixes
PlatformAppUrlRedirectorBrowserTest.PrerenderedClickInTabIntercepted
with PlzNavigate.

BUG=504347

Review-Url: https://codereview.chromium.org/2554573012
Cr-Commit-Position: refs/heads/master@{#437633}
parent 72c1b445
...@@ -235,6 +235,10 @@ class PrerenderContents : public content::NotificationObserver, ...@@ -235,6 +235,10 @@ class PrerenderContents : public content::NotificationObserver,
// Increments the number of bytes fetched over the network for this prerender. // Increments the number of bytes fetched over the network for this prerender.
void AddNetworkBytes(int64_t bytes); void AddNetworkBytes(int64_t bytes);
bool prerendering_has_been_cancelled() const {
return prerendering_has_been_cancelled_;
}
protected: protected:
PrerenderContents(PrerenderManager* prerender_manager, PrerenderContents(PrerenderManager* prerender_manager,
Profile* profile, Profile* profile,
...@@ -263,10 +267,6 @@ class PrerenderContents : public content::NotificationObserver, ...@@ -263,10 +267,6 @@ class PrerenderContents : public content::NotificationObserver,
return notification_registrar_; return notification_registrar_;
} }
bool prerendering_has_been_cancelled() const {
return prerendering_has_been_cancelled_;
}
content::WebContents* CreateWebContents( content::WebContents* CreateWebContents(
content::SessionStorageNamespace* session_storage_namespace); content::SessionStorageNamespace* session_storage_namespace);
......
...@@ -48,7 +48,8 @@ void PrerenderHandle::OnCancel() { ...@@ -48,7 +48,8 @@ void PrerenderHandle::OnCancel() {
bool PrerenderHandle::IsPrerendering() const { bool PrerenderHandle::IsPrerendering() const {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
return prerender_data_.get() != nullptr; return prerender_data_.get() != nullptr &&
!prerender_data_->contents()->prerendering_has_been_cancelled();
} }
bool PrerenderHandle::IsFinishedLoading() const { bool PrerenderHandle::IsFinishedLoading() const {
......
...@@ -392,16 +392,20 @@ void PrerenderLinkManager::StartPrerenders() { ...@@ -392,16 +392,20 @@ void PrerenderLinkManager::StartPrerenders() {
continue; continue;
} }
// We have successfully started a new prerender. if (handle->IsPrerendering()) {
(*i)->handle = handle.release(); // We have successfully started a new prerender.
++total_started_prerender_count; (*i)->handle = handle.release();
(*i)->handle->SetObserver(this); ++total_started_prerender_count;
if ((*i)->handle->IsPrerendering()) (*i)->handle->SetObserver(this);
OnPrerenderStart((*i)->handle); OnPrerenderStart((*i)->handle);
RecordLinkManagerStarting((*i)->rel_types); RecordLinkManagerStarting((*i)->rel_types);
running_launcher_and_render_view_routes.insert(
running_launcher_and_render_view_routes.insert( launcher_and_render_view_route);
launcher_and_render_view_route); } else {
Send((*i)->launcher_child_id,
new PrerenderMsg_OnPrerenderStop((*i)->prerender_id));
prerenders_.erase(*i);
}
} }
} }
...@@ -522,7 +526,7 @@ void PrerenderLinkManager::OnPrerenderStop( ...@@ -522,7 +526,7 @@ void PrerenderLinkManager::OnPrerenderStop(
return; return;
Send(prerender->launcher_child_id, Send(prerender->launcher_child_id,
new PrerenderMsg_OnPrerenderStop(prerender->prerender_id)); new PrerenderMsg_OnPrerenderStop(prerender->prerender_id));
RemovePrerender(prerender); RemovePrerender(prerender);
StartPrerenders(); StartPrerenders();
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment