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

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: Remove helper classes per review Created 9 years, 11 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 | 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(RenderWidgetHost* renderer,
176 bool monitor) {
177 Source<RenderWidgetHost> renderer_source = Source<RenderWidgetHost>(renderer);
178 bool currently_monitored =
179 registrar_.IsRegistered(
180 this,
181 NotificationType::RENDER_WIDGET_HOST_WILL_DESTROY_BACKING_STORE,
182 renderer_source);
183 if (monitor |= currently_monitored) {
Nico 2011/01/18 00:39:52 Is this supposed to be != (it's currently |=)? Th
184 if (monitor) {
185 registrar_.Add(
186 this,
187 NotificationType::RENDER_WIDGET_HOST_WILL_DESTROY_BACKING_STORE,
188 renderer_source);
189 registrar_.Add(
190 this,
191 NotificationType::RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE,
192 renderer_source);
193 registrar_.Add(
194 this,
195 NotificationType::RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK,
196 renderer_source);
197 } else {
198 registrar_.Remove(
199 this,
200 NotificationType::RENDER_WIDGET_HOST_WILL_DESTROY_BACKING_STORE,
201 renderer_source);
202 registrar_.Remove(
203 this,
204 NotificationType::RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE,
205 renderer_source);
206 registrar_.Remove(
207 this,
208 NotificationType::RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK,
209 renderer_source);
210 }
211 }
212 }
213
175 void ThumbnailGenerator::AskForSnapshot(RenderWidgetHost* renderer, 214 void ThumbnailGenerator::AskForSnapshot(RenderWidgetHost* renderer,
176 bool prefer_backing_store, 215 bool prefer_backing_store,
177 ThumbnailReadyCallback* callback, 216 ThumbnailReadyCallback* callback,
178 gfx::Size page_size, 217 gfx::Size page_size,
179 gfx::Size desired_size) { 218 gfx::Size desired_size) {
180 if (prefer_backing_store) { 219 if (prefer_backing_store) {
181 BackingStore* backing_store = renderer->GetBackingStore(false); 220 BackingStore* backing_store = renderer->GetBackingStore(false);
182 if (backing_store) { 221 if (backing_store) {
183 // We were able to find a non-null backing store for this renderer, so 222 // We were able to find a non-null backing store for this renderer, so
184 // we'll go with it. 223 // we'll go with it.
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 } 388 }
350 } 389 }
351 390
352 void ThumbnailGenerator::Observe(NotificationType type, 391 void ThumbnailGenerator::Observe(NotificationType type,
353 const NotificationSource& source, 392 const NotificationSource& source,
354 const NotificationDetails& details) { 393 const NotificationDetails& details) {
355 switch (type.value) { 394 switch (type.value) {
356 case NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB: { 395 case NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB: {
357 // Install our observer for all new RVHs. 396 // Install our observer for all new RVHs.
358 RenderViewHost* renderer = Details<RenderViewHost>(details).ptr(); 397 RenderViewHost* renderer = Details<RenderViewHost>(details).ptr();
359 renderer->set_painting_observer(this); 398 MonitorRenderer(renderer, true);
360 break; 399 break;
361 } 400 }
362 401
363 case NotificationType::RENDER_WIDGET_VISIBILITY_CHANGED: 402 case NotificationType::RENDER_WIDGET_VISIBILITY_CHANGED:
364 if (*Details<bool>(details).ptr()) 403 if (*Details<bool>(details).ptr())
365 WidgetShown(Source<RenderWidgetHost>(source).ptr()); 404 WidgetShown(Source<RenderWidgetHost>(source).ptr());
366 else 405 else
367 WidgetHidden(Source<RenderWidgetHost>(source).ptr()); 406 WidgetHidden(Source<RenderWidgetHost>(source).ptr());
368 break; 407 break;
369 408
370 case NotificationType::RENDER_WIDGET_HOST_DESTROYED: 409 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
371 WidgetDestroyed(Source<RenderWidgetHost>(source).ptr()); 410 WidgetDestroyed(Source<RenderWidgetHost>(source).ptr());
372 break; 411 break;
373 412
413 case NotificationType::RENDER_WIDGET_HOST_WILL_DESTROY_BACKING_STORE:
414 WidgetWillDestroyBackingStore(
415 Source<RenderWidgetHost>(source).ptr(),
416 Details<BackingStore>(details).ptr());
417 break;
418
419 case NotificationType::RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE:
420 WidgetDidUpdateBackingStore(Source<RenderWidgetHost>(source).ptr());
421 break;
422
423 case NotificationType::RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK: {
424 RenderWidgetHost::PaintAtSizeAckDetails* size_ack_details =
425 Details<RenderWidgetHost::PaintAtSizeAckDetails>(details).ptr();
426 WidgetDidReceivePaintAtSizeAck(
427 Source<RenderWidgetHost>(source).ptr(),
428 size_ack_details->tag,
429 size_ack_details->size);
430 break;
431 }
432
374 case NotificationType::TAB_CONTENTS_DISCONNECTED: 433 case NotificationType::TAB_CONTENTS_DISCONNECTED:
375 TabContentsDisconnected(Source<TabContents>(source).ptr()); 434 TabContentsDisconnected(Source<TabContents>(source).ptr());
376 break; 435 break;
377 436
378 default: 437 default:
379 NOTREACHED(); 438 NOTREACHED();
380 } 439 }
381 } 440 }
382 441
383 void ThumbnailGenerator::WidgetShown(RenderWidgetHost* widget) { 442 void ThumbnailGenerator::WidgetShown(RenderWidgetHost* widget) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 &ThumbnailGenerator::ShownDelayHandler); 527 &ThumbnailGenerator::ShownDelayHandler);
469 } 528 }
470 } 529 }
471 530
472 void ThumbnailGenerator::EraseHostFromShownList(RenderWidgetHost* widget) { 531 void ThumbnailGenerator::EraseHostFromShownList(RenderWidgetHost* widget) {
473 std::vector<RenderWidgetHost*>::iterator found = 532 std::vector<RenderWidgetHost*>::iterator found =
474 std::find(shown_hosts_.begin(), shown_hosts_.end(), widget); 533 std::find(shown_hosts_.begin(), shown_hosts_.end(), widget);
475 if (found != shown_hosts_.end()) 534 if (found != shown_hosts_.end())
476 shown_hosts_.erase(found); 535 shown_hosts_.erase(found);
477 } 536 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698