OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/thumbnails/thumbnail_tab_helper.h" | 5 #include "chrome/browser/thumbnails/thumbnail_tab_helper.h" |
6 | 6 |
7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/thumbnails/thumbnail_service.h" | 9 #include "chrome/browser/thumbnails/thumbnail_service.h" |
10 #include "chrome/browser/thumbnails/thumbnail_service_factory.h" | 10 #include "chrome/browser/thumbnails/thumbnail_service_factory.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 gfx::Image image = gfx::Image::CreateFrom1xBitmap(thumbnail); | 59 gfx::Image image = gfx::Image::CreateFrom1xBitmap(thumbnail); |
60 context.service->SetPageThumbnail(context, image); | 60 context.service->SetPageThumbnail(context, image); |
61 DVLOG(1) << "Thumbnail taken for " << context.url << ": " | 61 DVLOG(1) << "Thumbnail taken for " << context.url << ": " |
62 << context.score.ToString(); | 62 << context.score.ToString(); |
63 } | 63 } |
64 | 64 |
65 void ProcessCapturedBitmap(scoped_refptr<ThumbnailingContext> context, | 65 void ProcessCapturedBitmap(scoped_refptr<ThumbnailingContext> context, |
66 scoped_refptr<ThumbnailingAlgorithm> algorithm, | 66 scoped_refptr<ThumbnailingAlgorithm> algorithm, |
67 const SkBitmap& bitmap, | 67 const SkBitmap& bitmap, |
68 content::ReadbackResponse response) { | 68 content::ReadbackResponse response) { |
69 // Balance the IncrementCapturerCount() from UpdateThumbnailIfNecessary(). | |
70 context->web_contents->DecrementCapturerCount(); | |
71 | |
69 if (response != content::READBACK_SUCCESS) | 72 if (response != content::READBACK_SUCCESS) |
70 return; | 73 return; |
71 | 74 |
72 // On success, we must be on the UI thread (on failure because of shutdown we | 75 // On success, we must be on the UI thread (on failure because of shutdown we |
73 // are not on the UI thread). | 76 // are not on the UI thread). |
74 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 77 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
75 | 78 |
76 algorithm->ProcessBitmap(context, base::Bind(&UpdateThumbnail), bitmap); | 79 algorithm->ProcessBitmap(context, base::Bind(&UpdateThumbnail), bitmap); |
77 } | 80 } |
78 | 81 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 | 192 |
190 scoped_refptr<thumbnails::ThumbnailService> thumbnail_service = | 193 scoped_refptr<thumbnails::ThumbnailService> thumbnail_service = |
191 ThumbnailServiceFactory::GetForProfile(profile); | 194 ThumbnailServiceFactory::GetForProfile(profile); |
192 | 195 |
193 // Skip if we don't need to update the thumbnail. | 196 // Skip if we don't need to update the thumbnail. |
194 if (thumbnail_service.get() == NULL || | 197 if (thumbnail_service.get() == NULL || |
195 !thumbnail_service->ShouldAcquirePageThumbnail(url)) { | 198 !thumbnail_service->ShouldAcquirePageThumbnail(url)) { |
196 return; | 199 return; |
197 } | 200 } |
198 | 201 |
202 web_contents->IncrementCapturerCount(gfx::Size()); | |
203 | |
199 scoped_refptr<thumbnails::ThumbnailingAlgorithm> algorithm( | 204 scoped_refptr<thumbnails::ThumbnailingAlgorithm> algorithm( |
200 thumbnail_service->GetThumbnailingAlgorithm()); | 205 thumbnail_service->GetThumbnailingAlgorithm()); |
201 | 206 |
202 scoped_refptr<ThumbnailingContext> context(new ThumbnailingContext( | 207 scoped_refptr<ThumbnailingContext> context(new ThumbnailingContext( |
203 web_contents, thumbnail_service.get(), load_interrupted_)); | 208 web_contents, thumbnail_service.get(), load_interrupted_)); |
204 AsyncProcessThumbnail(web_contents, context, algorithm); | 209 AsyncProcessThumbnail(web_contents, context, algorithm); |
Lei Zhang
2015/10/07 17:55:20
Assuming having |web_contents| in |context| is saf
shrike
2015/10/07 18:06:34
Done.
| |
205 } | 210 } |
206 | 211 |
207 void ThumbnailTabHelper::RenderViewHostCreated( | 212 void ThumbnailTabHelper::RenderViewHostCreated( |
208 content::RenderViewHost* renderer) { | 213 content::RenderViewHost* renderer) { |
209 // NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED is really a new | 214 // NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED is really a new |
210 // RenderView, not RenderViewHost, and there is no good way to get | 215 // RenderView, not RenderViewHost, and there is no good way to get |
211 // notifications of RenderViewHosts. So just be tolerant of re-registrations. | 216 // notifications of RenderViewHosts. So just be tolerant of re-registrations. |
212 bool registered = registrar_.IsRegistered( | 217 bool registered = registrar_.IsRegistered( |
213 this, | 218 this, |
214 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, | 219 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, |
215 content::Source<RenderWidgetHost>(renderer)); | 220 content::Source<RenderWidgetHost>(renderer)); |
216 if (!registered) { | 221 if (!registered) { |
217 registrar_.Add( | 222 registrar_.Add( |
218 this, | 223 this, |
219 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, | 224 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, |
220 content::Source<RenderWidgetHost>(renderer)); | 225 content::Source<RenderWidgetHost>(renderer)); |
221 } | 226 } |
222 } | 227 } |
223 | 228 |
224 void ThumbnailTabHelper::WidgetHidden(RenderWidgetHost* widget) { | 229 void ThumbnailTabHelper::WidgetHidden(RenderWidgetHost* widget) { |
225 if (!enabled_) | 230 if (!enabled_) |
226 return; | 231 return; |
227 UpdateThumbnailIfNecessary(web_contents()); | 232 UpdateThumbnailIfNecessary(web_contents()); |
228 } | 233 } |
OLD | NEW |