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

Side by Side Diff: chrome/browser/tab_contents/thumbnail_generator.cc

Issue 6010004: Refactor RenderWidgetHost::set_paint_observer() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added comments Created 10 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/tab_contents/thumbnail_generator.h" 5 #include "chrome/browser/tab_contents/thumbnail_generator.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 9
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 NotificationService::AllSources()); 165 NotificationService::AllSources());
166 registrar_.Add(this, NotificationType::RENDER_WIDGET_VISIBILITY_CHANGED, 166 registrar_.Add(this, NotificationType::RENDER_WIDGET_VISIBILITY_CHANGED,
167 NotificationService::AllSources()); 167 NotificationService::AllSources());
168 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED, 168 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
169 NotificationService::AllSources()); 169 NotificationService::AllSources());
170 registrar_.Add(this, NotificationType::TAB_CONTENTS_DISCONNECTED, 170 registrar_.Add(this, NotificationType::TAB_CONTENTS_DISCONNECTED,
171 NotificationService::AllSources()); 171 NotificationService::AllSources());
172 } 172 }
173 } 173 }
174 174
175 void ThumbnailGenerator::MonitorRenderer(
176 RenderWidgetHost* renderer,
brettw 2011/01/03 19:48:30 This should fit on the previous line, I think. (Th
DaveMoore 2011/01/07 19:04:05 Done.
177 bool monitor) {
178 Source<RenderWidgetHost> renderer_source = Source<RenderWidgetHost>(renderer);
179 bool currently_monitored =
180 registrar_.IsRegistered(
181 this,
182 NotificationType::RENDER_WIDGET_HOST_WILL_DESTROY_BACKING_STORE,
183 renderer_source);
184 if (monitor |= currently_monitored) {
185 if (monitor) {
186 registrar_.Add(
187 this,
188 NotificationType::RENDER_WIDGET_HOST_WILL_DESTROY_BACKING_STORE,
189 renderer_source);
190 registrar_.Add(
191 this,
192 NotificationType::RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE,
193 renderer_source);
194 registrar_.Add(
195 this,
196 NotificationType::RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK,
197 renderer_source);
198 } else {
199 registrar_.Remove(
200 this,
201 NotificationType::RENDER_WIDGET_HOST_WILL_DESTROY_BACKING_STORE,
202 renderer_source);
203 registrar_.Remove(
204 this,
205 NotificationType::RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE,
206 renderer_source);
207 registrar_.Remove(
208 this,
209 NotificationType::RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK,
210 renderer_source);
211 }
212 }
213 }
214
175 void ThumbnailGenerator::AskForSnapshot(RenderWidgetHost* renderer, 215 void ThumbnailGenerator::AskForSnapshot(RenderWidgetHost* renderer,
176 bool prefer_backing_store, 216 bool prefer_backing_store,
177 ThumbnailReadyCallback* callback, 217 ThumbnailReadyCallback* callback,
178 gfx::Size page_size, 218 gfx::Size page_size,
179 gfx::Size desired_size) { 219 gfx::Size desired_size) {
180 if (prefer_backing_store) { 220 if (prefer_backing_store) {
181 BackingStore* backing_store = renderer->GetBackingStore(false); 221 BackingStore* backing_store = renderer->GetBackingStore(false);
182 if (backing_store) { 222 if (backing_store) {
183 // We were able to find a non-null backing store for this renderer, so 223 // We were able to find a non-null backing store for this renderer, so
184 // we'll go with it. 224 // we'll go with it.
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 } 389 }
350 } 390 }
351 391
352 void ThumbnailGenerator::Observe(NotificationType type, 392 void ThumbnailGenerator::Observe(NotificationType type,
353 const NotificationSource& source, 393 const NotificationSource& source,
354 const NotificationDetails& details) { 394 const NotificationDetails& details) {
355 switch (type.value) { 395 switch (type.value) {
356 case NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB: { 396 case NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB: {
357 // Install our observer for all new RVHs. 397 // Install our observer for all new RVHs.
358 RenderViewHost* renderer = Details<RenderViewHost>(details).ptr(); 398 RenderViewHost* renderer = Details<RenderViewHost>(details).ptr();
359 renderer->set_painting_observer(this); 399 MonitorRenderer(renderer, true);
360 break; 400 break;
361 } 401 }
362 402
363 case NotificationType::RENDER_WIDGET_VISIBILITY_CHANGED: 403 case NotificationType::RENDER_WIDGET_VISIBILITY_CHANGED:
364 if (*Details<bool>(details).ptr()) 404 if (*Details<bool>(details).ptr())
365 WidgetShown(Source<RenderWidgetHost>(source).ptr()); 405 WidgetShown(Source<RenderWidgetHost>(source).ptr());
366 else 406 else
367 WidgetHidden(Source<RenderWidgetHost>(source).ptr()); 407 WidgetHidden(Source<RenderWidgetHost>(source).ptr());
368 break; 408 break;
369 409
370 case NotificationType::RENDER_WIDGET_HOST_DESTROYED: 410 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
371 WidgetDestroyed(Source<RenderWidgetHost>(source).ptr()); 411 WidgetDestroyed(Source<RenderWidgetHost>(source).ptr());
372 break; 412 break;
373 413
414 case NotificationType::RENDER_WIDGET_HOST_WILL_DESTROY_BACKING_STORE:
415 WidgetWillDestroyBackingStore(
416 Source<RenderWidgetHost>(source).ptr(),
417 Details<BackingStore>(details).ptr());
418 break;
419
420 case NotificationType::RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE:
421 WidgetDidUpdateBackingStore(Source<RenderWidgetHost>(source).ptr());
422 break;
423
424 case NotificationType::RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK: {
425 RenderWidgetHost::PaintAtSizeAckDetails* size_ack_details =
426 Details<RenderWidgetHost::PaintAtSizeAckDetails>(details).ptr();
427 WidgetDidReceivePaintAtSizeAck(
428 Source<RenderWidgetHost>(source).ptr(),
429 size_ack_details->tag,
430 size_ack_details->size);
431 break;
432 }
433
374 case NotificationType::TAB_CONTENTS_DISCONNECTED: 434 case NotificationType::TAB_CONTENTS_DISCONNECTED:
375 TabContentsDisconnected(Source<TabContents>(source).ptr()); 435 TabContentsDisconnected(Source<TabContents>(source).ptr());
376 break; 436 break;
377 437
378 default: 438 default:
379 NOTREACHED(); 439 NOTREACHED();
380 } 440 }
381 } 441 }
382 442
383 void ThumbnailGenerator::WidgetShown(RenderWidgetHost* widget) { 443 void ThumbnailGenerator::WidgetShown(RenderWidgetHost* widget) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 &ThumbnailGenerator::ShownDelayHandler); 528 &ThumbnailGenerator::ShownDelayHandler);
469 } 529 }
470 } 530 }
471 531
472 void ThumbnailGenerator::EraseHostFromShownList(RenderWidgetHost* widget) { 532 void ThumbnailGenerator::EraseHostFromShownList(RenderWidgetHost* widget) {
473 std::vector<RenderWidgetHost*>::iterator found = 533 std::vector<RenderWidgetHost*>::iterator found =
474 std::find(shown_hosts_.begin(), shown_hosts_.end(), widget); 534 std::find(shown_hosts_.begin(), shown_hosts_.end(), widget);
475 if (found != shown_hosts_.end()) 535 if (found != shown_hosts_.end())
476 shown_hosts_.erase(found); 536 shown_hosts_.erase(found);
477 } 537 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698