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

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

Issue 6459005: Cancel prerender when we discover a download starting from a page we are prer... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Changed source of notification and now notify on all entry points for download initiation. Created 9 years, 10 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_contents.cc
===================================================================
--- chrome/browser/prerender/prerender_contents.cc (revision 74377)
+++ chrome/browser/prerender/prerender_contents.cc (working copy)
@@ -82,6 +82,10 @@
registrar_.Add(this, NotificationType::AUTH_CANCELLED,
NotificationService::AllSources());
+ // Register all responses to see if we should cancel.
+ registrar_.Add(this, NotificationType::DOWNLOAD_INITIATED,
+ NotificationService::AllSources());
+
DCHECK(load_start_time_.is_null());
load_start_time_ = base::TimeTicks::Now();
@@ -95,6 +99,7 @@
void PrerenderContents::set_final_status(FinalStatus final_status) {
DCHECK(final_status >= FINAL_STATUS_USED && final_status < FINAL_STATUS_MAX);
DCHECK_EQ(FINAL_STATUS_MAX, final_status_);
+
final_status_ = final_status;
}
@@ -186,6 +191,7 @@
case NotificationType::PROFILE_DESTROYED:
Destroy(FINAL_STATUS_PROFILE_DESTROYED);
return;
+
case NotificationType::APP_TERMINATING:
Destroy(FINAL_STATUS_APP_TERMINATING);
return;
@@ -201,11 +207,26 @@
LoginHandler* handler = details_ptr->handler();
DCHECK(handler != NULL);
RenderViewHostDelegate* delegate = handler->GetRenderViewHostDelegate();
- if (controller == NULL && delegate == this)
+ if (controller == NULL && delegate == this) {
Destroy(FINAL_STATUS_AUTH_NEEDED);
+ return;
+ }
break;
}
+ case NotificationType::DOWNLOAD_INITIATED: {
+ // If the download is started from a RenderViewHost that we are
+ // delegating, kill the prerender. This cancels any pending requests
+ // though the download never actually started thanks to the
+ // DownloadRequestLimiter.
+ DCHECK(details == NotificationService::NoDetails());
+ RenderViewHost* rvh = Source<RenderViewHost>(source).ptr();
+ if (rvh->delegate() == this) {
cbentzel 2011/02/10 19:32:18 May not hurt to be defensive and check that rvh is
dominich 2011/02/10 20:02:17 Done.
+ Destroy(FINAL_STATUS_DOWNLOAD);
+ }
+ return;
cbentzel 2011/02/10 19:32:18 move return next to Destroy and make this break, t
dominich 2011/02/10 20:02:17 Done.
+ }
+
default:
NOTREACHED() << "Unexpected notification sent.";
break;

Powered by Google App Engine
This is Rietveld 408576698