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

Unified Diff: chrome/browser/thumbnails/thumbnail_tab_helper.cc

Issue 1348833003: Fix NTP thumbnail generation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Watch for destruction of web_contents. Created 5 years, 2 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/thumbnails/thumbnail_tab_helper.cc
diff --git a/chrome/browser/thumbnails/thumbnail_tab_helper.cc b/chrome/browser/thumbnails/thumbnail_tab_helper.cc
index f8322e76f9a2d9573939dea942a32fe342b8bffb..c26fd5febe4dbb083576383c474ae1a90ec35269 100644
--- a/chrome/browser/thumbnails/thumbnail_tab_helper.cc
+++ b/chrome/browser/thumbnails/thumbnail_tab_helper.cc
@@ -66,6 +66,13 @@ void ProcessCapturedBitmap(scoped_refptr<ThumbnailingContext> context,
scoped_refptr<ThumbnailingAlgorithm> algorithm,
const SkBitmap& bitmap,
content::ReadbackResponse response) {
+ // Was the web contents destroyed before the thumbnail could be generated?
+ if (!context->web_contents())
+ return;
+
+ // Balance the IncrementCapturerCount() from UpdateThumbnailIfNecessary().
+ context->web_contents()->DecrementCapturerCount();
+
if (response != content::READBACK_SUCCESS)
return;
@@ -76,11 +83,11 @@ void ProcessCapturedBitmap(scoped_refptr<ThumbnailingContext> context,
algorithm->ProcessBitmap(context, base::Bind(&UpdateThumbnail), bitmap);
}
-void AsyncProcessThumbnail(content::WebContents* web_contents,
- scoped_refptr<ThumbnailingContext> context,
+void AsyncProcessThumbnail(scoped_refptr<ThumbnailingContext> context,
scoped_refptr<ThumbnailingAlgorithm> algorithm) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- RenderWidgetHost* render_widget_host = web_contents->GetRenderViewHost();
+ RenderWidgetHost* render_widget_host =
+ context->web_contents()->GetRenderViewHost();
content::RenderWidgetHostView* view = render_widget_host->GetView();
if (!view)
return;
@@ -196,12 +203,14 @@ void ThumbnailTabHelper::UpdateThumbnailIfNecessary(
return;
}
+ web_contents->IncrementCapturerCount(gfx::Size());
+
scoped_refptr<thumbnails::ThumbnailingAlgorithm> algorithm(
thumbnail_service->GetThumbnailingAlgorithm());
scoped_refptr<ThumbnailingContext> context(new ThumbnailingContext(
web_contents, thumbnail_service.get(), load_interrupted_));
- AsyncProcessThumbnail(web_contents, context, algorithm);
+ AsyncProcessThumbnail(context, algorithm);
}
void ThumbnailTabHelper::RenderViewHostCreated(
« no previous file with comments | « no previous file | chrome/browser/thumbnails/thumbnailing_context.h » ('j') | chrome/browser/thumbnails/thumbnailing_context.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698