| 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/render_widget_snapshot_taker.h" | 9 #include "chrome/browser/thumbnails/render_widget_snapshot_taker.h" |
| 10 #include "chrome/browser/thumbnails/thumbnail_service.h" | 10 #include "chrome/browser/thumbnails/thumbnail_service.h" |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 if (web_contents->GetController().GetPendingEntry()) | 199 if (web_contents->GetController().GetPendingEntry()) |
| 200 return; | 200 return; |
| 201 const GURL& url = web_contents->GetURL(); | 201 const GURL& url = web_contents->GetURL(); |
| 202 Profile* profile = | 202 Profile* profile = |
| 203 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 203 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 204 | 204 |
| 205 scoped_refptr<thumbnails::ThumbnailService> thumbnail_service = | 205 scoped_refptr<thumbnails::ThumbnailService> thumbnail_service = |
| 206 ThumbnailServiceFactory::GetForProfile(profile); | 206 ThumbnailServiceFactory::GetForProfile(profile); |
| 207 | 207 |
| 208 // Skip if we don't need to update the thumbnail. | 208 // Skip if we don't need to update the thumbnail. |
| 209 if (thumbnail_service == NULL || | 209 if (thumbnail_service.get() == NULL || |
| 210 !thumbnail_service->ShouldAcquirePageThumbnail(url)) { | 210 !thumbnail_service->ShouldAcquirePageThumbnail(url)) { |
| 211 return; | 211 return; |
| 212 } | 212 } |
| 213 | 213 |
| 214 scoped_refptr<thumbnails::ThumbnailingAlgorithm> algorithm( | 214 scoped_refptr<thumbnails::ThumbnailingAlgorithm> algorithm( |
| 215 thumbnail_service->GetThumbnailingAlgorithm()); | 215 thumbnail_service->GetThumbnailingAlgorithm()); |
| 216 | 216 |
| 217 scoped_refptr<ThumbnailingContext> context( | 217 scoped_refptr<ThumbnailingContext> context(new ThumbnailingContext( |
| 218 new ThumbnailingContext(web_contents, | 218 web_contents, thumbnail_service.get(), load_interrupted_)); |
| 219 thumbnail_service, | |
| 220 load_interrupted_)); | |
| 221 AsyncProcessThumbnail(web_contents, context, algorithm); | 219 AsyncProcessThumbnail(web_contents, context, algorithm); |
| 222 } | 220 } |
| 223 | 221 |
| 224 void ThumbnailTabHelper::RenderViewHostCreated( | 222 void ThumbnailTabHelper::RenderViewHostCreated( |
| 225 content::RenderViewHost* renderer) { | 223 content::RenderViewHost* renderer) { |
| 226 // NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED is really a new | 224 // NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED is really a new |
| 227 // RenderView, not RenderViewHost, and there is no good way to get | 225 // RenderView, not RenderViewHost, and there is no good way to get |
| 228 // notifications of RenderViewHosts. So just be tolerant of re-registrations. | 226 // notifications of RenderViewHosts. So just be tolerant of re-registrations. |
| 229 bool registered = registrar_.IsRegistered( | 227 bool registered = registrar_.IsRegistered( |
| 230 this, | 228 this, |
| 231 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, | 229 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, |
| 232 content::Source<RenderWidgetHost>(renderer)); | 230 content::Source<RenderWidgetHost>(renderer)); |
| 233 if (!registered) { | 231 if (!registered) { |
| 234 registrar_.Add( | 232 registrar_.Add( |
| 235 this, | 233 this, |
| 236 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, | 234 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, |
| 237 content::Source<RenderWidgetHost>(renderer)); | 235 content::Source<RenderWidgetHost>(renderer)); |
| 238 } | 236 } |
| 239 } | 237 } |
| 240 | 238 |
| 241 void ThumbnailTabHelper::WidgetHidden(RenderWidgetHost* widget) { | 239 void ThumbnailTabHelper::WidgetHidden(RenderWidgetHost* widget) { |
| 242 if (!enabled_) | 240 if (!enabled_) |
| 243 return; | 241 return; |
| 244 UpdateThumbnailIfNecessary(web_contents()); | 242 UpdateThumbnailIfNecessary(web_contents()); |
| 245 } | 243 } |
| 246 | 244 |
| OLD | NEW |