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

Side by Side Diff: chrome/browser/thumbnails/thumbnail_tab_helper.cc

Issue 2093113003: Clean up the RWHVMac to ui::Compositor interface (phase 1 of 2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove hack Created 4 years, 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | content/browser/renderer_host/browser_compositor_view_mac.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "build/build_config.h" 7 #include "build/build_config.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/thumbnails/thumbnail_service.h" 10 #include "chrome/browser/thumbnails/thumbnail_service.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 } 103 }
104 104
105 void ThumbnailTabHelper::NavigationStopped() { 105 void ThumbnailTabHelper::NavigationStopped() {
106 // This function gets called when the page loading is interrupted by the 106 // This function gets called when the page loading is interrupted by the
107 // stop button. 107 // stop button.
108 load_interrupted_ = true; 108 load_interrupted_ = true;
109 } 109 }
110 110
111 void ThumbnailTabHelper::UpdateThumbnailIfNecessary() { 111 void ThumbnailTabHelper::UpdateThumbnailIfNecessary() {
112 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 112 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
113 // Ignore thumbnail update requests if one is already in progress. This can 113 // Ignore thumbnail update requests if one is already in progress.
114 // happen at the end of thumbnail generation when
115 // CleanUpFromThumbnailGeneration() calls DecrementCapturerCount(), triggering
116 // a call to content::WebContentsImpl::WasHidden() which eventually calls
117 // ThumbnailTabHelper::UpdateThumbnailIfNecessary().
118 if (thumbnailing_context_) { 114 if (thumbnailing_context_) {
119 return; 115 return;
120 } 116 }
121 117
122 // Destroying a WebContents may trigger it to be hidden, prompting a snapshot 118 // Destroying a WebContents may trigger it to be hidden, prompting a snapshot
123 // which would be unwise to attempt <http://crbug.com/130097>. If the 119 // which would be unwise to attempt <http://crbug.com/130097>. If the
124 // WebContents is in the middle of destruction, do not risk it. 120 // WebContents is in the middle of destruction, do not risk it.
125 if (!web_contents() || web_contents()->IsBeingDestroyed()) 121 if (!web_contents() || web_contents()->IsBeingDestroyed())
126 return; 122 return;
127 // Skip if a pending entry exists. WidgetHidden can be called while navigating 123 // Skip if a pending entry exists. WidgetHidden can be called while navigating
128 // pages and this is not a time when thumbnails should be generated. 124 // pages and this is not a time when thumbnails should be generated.
129 if (web_contents()->GetController().GetPendingEntry()) 125 if (web_contents()->GetController().GetPendingEntry())
130 return; 126 return;
131 const GURL& url = web_contents()->GetURL(); 127 const GURL& url = web_contents()->GetURL();
132 Profile* profile = 128 Profile* profile =
133 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 129 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
134 130
135 scoped_refptr<thumbnails::ThumbnailService> thumbnail_service = 131 scoped_refptr<thumbnails::ThumbnailService> thumbnail_service =
136 ThumbnailServiceFactory::GetForProfile(profile); 132 ThumbnailServiceFactory::GetForProfile(profile);
137 133
138 // Skip if we don't need to update the thumbnail. 134 // Skip if we don't need to update the thumbnail.
139 if (thumbnail_service.get() == NULL || 135 if (thumbnail_service.get() == NULL ||
140 !thumbnail_service->ShouldAcquirePageThumbnail(url)) { 136 !thumbnail_service->ShouldAcquirePageThumbnail(url)) {
141 return; 137 return;
142 } 138 }
143 139
144 // Prevent the web contents from disappearing before the async thumbnail
145 // generation code executes. See https://crbug.com/530707 .
146 web_contents()->IncrementCapturerCount(gfx::Size());
147
148 AsyncProcessThumbnail(thumbnail_service); 140 AsyncProcessThumbnail(thumbnail_service);
149 } 141 }
150 142
151 void ThumbnailTabHelper::AsyncProcessThumbnail( 143 void ThumbnailTabHelper::AsyncProcessThumbnail(
152 scoped_refptr<thumbnails::ThumbnailService> thumbnail_service) { 144 scoped_refptr<thumbnails::ThumbnailService> thumbnail_service) {
153 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 145 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
154 RenderWidgetHost* render_widget_host = 146 RenderWidgetHost* render_widget_host =
155 web_contents()->GetRenderViewHost()->GetWidget(); 147 web_contents()->GetRenderViewHost()->GetWidget();
156 content::RenderWidgetHostView* view = render_widget_host->GetView(); 148 content::RenderWidgetHostView* view = render_widget_host->GetView();
157 if (!view || !view->IsSurfaceAvailableForCopy()) { 149 if (!view || !view->IsSurfaceAvailableForCopy()) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 // that cleanup happens on that thread. 201 // that cleanup happens on that thread.
210 content::BrowserThread::PostTask( 202 content::BrowserThread::PostTask(
211 content::BrowserThread::UI, 203 content::BrowserThread::UI,
212 FROM_HERE, 204 FROM_HERE,
213 base::Bind(&ThumbnailTabHelper::CleanUpFromThumbnailGeneration, 205 base::Bind(&ThumbnailTabHelper::CleanUpFromThumbnailGeneration,
214 weak_factory_.GetWeakPtr())); 206 weak_factory_.GetWeakPtr()));
215 } 207 }
216 } 208 }
217 209
218 void ThumbnailTabHelper::CleanUpFromThumbnailGeneration() { 210 void ThumbnailTabHelper::CleanUpFromThumbnailGeneration() {
219 if (web_contents()) {
220 // Balance the call to IncrementCapturerCount() made in
221 // UpdateThumbnailIfNecessary().
222 web_contents()->DecrementCapturerCount();
223 }
224
225 // Make a note that thumbnail generation is complete. 211 // Make a note that thumbnail generation is complete.
226 thumbnailing_context_ = nullptr; 212 thumbnailing_context_ = nullptr;
227 } 213 }
228 214
229 void ThumbnailTabHelper::UpdateThumbnail( 215 void ThumbnailTabHelper::UpdateThumbnail(
230 const thumbnails::ThumbnailingContext& context, 216 const thumbnails::ThumbnailingContext& context,
231 const SkBitmap& thumbnail) { 217 const SkBitmap& thumbnail) {
232 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 218 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
233 // Feed the constructed thumbnail to the thumbnail service. 219 // Feed the constructed thumbnail to the thumbnail service.
234 gfx::Image image = gfx::Image::CreateFrom1xBitmap(thumbnail); 220 gfx::Image image = gfx::Image::CreateFrom1xBitmap(thumbnail);
(...skipping 14 matching lines...) Expand all
249 content::Source<RenderWidgetHost>(renderer->GetWidget())); 235 content::Source<RenderWidgetHost>(renderer->GetWidget()));
250 if (!registered) { 236 if (!registered) {
251 registrar_.Add(this, content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, 237 registrar_.Add(this, content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED,
252 content::Source<RenderWidgetHost>(renderer->GetWidget())); 238 content::Source<RenderWidgetHost>(renderer->GetWidget()));
253 } 239 }
254 } 240 }
255 241
256 void ThumbnailTabHelper::WidgetHidden(RenderWidgetHost* widget) { 242 void ThumbnailTabHelper::WidgetHidden(RenderWidgetHost* widget) {
257 UpdateThumbnailIfNecessary(); 243 UpdateThumbnailIfNecessary();
258 } 244 }
OLDNEW
« no previous file with comments | « no previous file | content/browser/renderer_host/browser_compositor_view_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698