| OLD | NEW |
| 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 #ifndef CHROME_BROWSER_TAB_CONTENTS_THUMBNAIL_GENERATOR_H_ | 5 #ifndef CHROME_BROWSER_TAB_CONTENTS_THUMBNAIL_GENERATOR_H_ |
| 6 #define CHROME_BROWSER_TAB_CONTENTS_THUMBNAIL_GENERATOR_H_ | 6 #define CHROME_BROWSER_TAB_CONTENTS_THUMBNAIL_GENERATOR_H_ |
| 7 | 7 |
| 8 #include <map> |
| 9 #include <utility> |
| 8 #include <vector> | 10 #include <vector> |
| 9 | 11 |
| 10 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/callback.h" |
| 14 #include "base/linked_ptr.h" |
| 15 #include "base/lock.h" |
| 11 #include "base/timer.h" | 16 #include "base/timer.h" |
| 12 #include "chrome/browser/renderer_host/render_widget_host_painting_observer.h" | 17 #include "chrome/browser/renderer_host/render_widget_host_painting_observer.h" |
| 13 #include "chrome/common/notification_observer.h" | 18 #include "chrome/common/notification_observer.h" |
| 14 #include "chrome/common/notification_registrar.h" | 19 #include "chrome/common/notification_registrar.h" |
| 15 | 20 |
| 21 class RenderViewHost; |
| 16 class RenderWidgetHost; | 22 class RenderWidgetHost; |
| 17 class SkBitmap; | 23 class SkBitmap; |
| 24 class TabContents; |
| 18 | 25 |
| 19 // This class MUST be destroyed after the RenderWidgetHosts, since it installs | 26 // This class MUST be destroyed after the RenderWidgetHosts, since it installs |
| 20 // a painting observer that is not removed. | 27 // a painting observer that is not removed. |
| 21 class ThumbnailGenerator : public RenderWidgetHostPaintingObserver, | 28 class ThumbnailGenerator : public RenderWidgetHostPaintingObserver, |
| 22 public NotificationObserver { | 29 public NotificationObserver { |
| 23 public: | 30 public: |
| 31 typedef Callback1<const SkBitmap&>::Type ThumbnailReadyCallback; |
| 24 // This class will do nothing until you call StartThumbnailing. | 32 // This class will do nothing until you call StartThumbnailing. |
| 25 ThumbnailGenerator(); | 33 ThumbnailGenerator(); |
| 26 ~ThumbnailGenerator(); | 34 ~ThumbnailGenerator(); |
| 27 | 35 |
| 28 // Ensures that we're properly hooked in to generated thumbnails. This can | 36 // Ensures that we're properly hooked in to generated thumbnails. This can |
| 29 // be called repeatedly and with wild abandon to no ill effect. | 37 // be called repeatedly and with wild abandon to no ill effect. |
| 30 void StartThumbnailing(); | 38 void StartThumbnailing(); |
| 31 | 39 |
| 40 // This registers a callback that can receive the resulting SkBitmap |
| 41 // from the renderer when it is done rendering it. This differs |
| 42 // from GetThumbnailForRenderer in that it is asynchronous, and |
| 43 // because it will also fetch the bitmap even if the tab is hidden. |
| 44 // In addition, if the renderer has to be invoked, the scaling of |
| 45 // the thumbnail happens on the rendering thread. Takes ownership |
| 46 // of the callback object. |
| 47 void AskForThumbnail(RenderWidgetHost* renderer, |
| 48 ThumbnailReadyCallback* callback, |
| 49 gfx::Size size); |
| 50 |
| 32 SkBitmap GetThumbnailForRenderer(RenderWidgetHost* renderer) const; | 51 SkBitmap GetThumbnailForRenderer(RenderWidgetHost* renderer) const; |
| 33 | 52 |
| 34 #ifdef UNIT_TEST | 53 #ifdef UNIT_TEST |
| 35 // When true, the class will not use a timeout to do the expiration. This | 54 // When true, the class will not use a timeout to do the expiration. This |
| 36 // will cause expiration to happen on the next run of the message loop. | 55 // will cause expiration to happen on the next run of the message loop. |
| 37 // Unit tests case use this to test expiration by choosing when the message | 56 // Unit tests case use this to test expiration by choosing when the message |
| 38 // loop runs. | 57 // loop runs. |
| 39 void set_no_timeout(bool no_timeout) { no_timeout_ = no_timeout; } | 58 void set_no_timeout(bool no_timeout) { no_timeout_ = no_timeout; } |
| 40 #endif | 59 #endif |
| 41 | 60 |
| 42 private: | 61 private: |
| 43 // RenderWidgetHostPaintingObserver implementation. | 62 // RenderWidgetHostPaintingObserver implementation. |
| 44 virtual void WidgetWillDestroyBackingStore(RenderWidgetHost* widget, | 63 virtual void WidgetWillDestroyBackingStore(RenderWidgetHost* widget, |
| 45 BackingStore* backing_store); | 64 BackingStore* backing_store); |
| 46 virtual void WidgetDidUpdateBackingStore(RenderWidgetHost* widget); | 65 virtual void WidgetDidUpdateBackingStore(RenderWidgetHost* widget); |
| 47 | 66 |
| 67 virtual void WidgetDidReceivePaintAtSizeAck( |
| 68 RenderWidgetHost* widget, |
| 69 const TransportDIB::Handle& dib_handle, |
| 70 const gfx::Size& size); |
| 71 |
| 48 // NotificationObserver interface. | 72 // NotificationObserver interface. |
| 49 virtual void Observe(NotificationType type, | 73 virtual void Observe(NotificationType type, |
| 50 const NotificationSource& source, | 74 const NotificationSource& source, |
| 51 const NotificationDetails& details); | 75 const NotificationDetails& details); |
| 52 | 76 |
| 53 // Indicates that the given widget has changed is visibility. | 77 // Indicates that the given widget has changed is visibility. |
| 54 void WidgetShown(RenderWidgetHost* widget); | 78 void WidgetShown(RenderWidgetHost* widget); |
| 55 void WidgetHidden(RenderWidgetHost* widget); | 79 void WidgetHidden(RenderWidgetHost* widget); |
| 56 | 80 |
| 57 // Called when the given widget is destroyed. | 81 // Called when the given widget is destroyed. |
| 58 void WidgetDestroyed(RenderWidgetHost* widget); | 82 void WidgetDestroyed(RenderWidgetHost* widget); |
| 59 | 83 |
| 84 // Called when the given tab contents are disconnected (either |
| 85 // through being closed, or because the renderer is no longer there). |
| 86 void TabContentsDisconnected(TabContents* contents); |
| 87 |
| 60 // Timer function called on a delay after a tab has been shown. It will | 88 // Timer function called on a delay after a tab has been shown. It will |
| 61 // invalidate the thumbnail for hosts with expired thumbnails in shown_hosts_. | 89 // invalidate the thumbnail for hosts with expired thumbnails in shown_hosts_. |
| 62 void ShownDelayHandler(); | 90 void ShownDelayHandler(); |
| 63 | 91 |
| 64 // Removes the given host from the shown_hosts_ list, if it is there. | 92 // Removes the given host from the shown_hosts_ list, if it is there. |
| 65 void EraseHostFromShownList(RenderWidgetHost* host); | 93 void EraseHostFromShownList(RenderWidgetHost* host); |
| 66 | 94 |
| 67 NotificationRegistrar registrar_; | 95 NotificationRegistrar registrar_; |
| 68 | 96 |
| 69 base::OneShotTimer<ThumbnailGenerator> timer_; | 97 base::OneShotTimer<ThumbnailGenerator> timer_; |
| 70 | 98 |
| 71 // A list of all RWHs that have been shown and need to have their thumbnail | 99 // A list of all RWHs that have been shown and need to have their thumbnail |
| 72 // expired at some time in the future with the "slop" time has elapsed. This | 100 // expired at some time in the future with the "slop" time has elapsed. This |
| 73 // list will normally have 0 or 1 items in it. | 101 // list will normally have 0 or 1 items in it. |
| 74 std::vector<RenderWidgetHost*> shown_hosts_; | 102 std::vector<RenderWidgetHost*> shown_hosts_; |
| 75 | 103 |
| 76 // See the setter above. | 104 // See the setter above. |
| 77 bool no_timeout_; | 105 bool no_timeout_; |
| 78 | 106 |
| 107 // Map of callback objects by TransportDIB::Handle. |
| 108 struct AsyncRequestInfo; |
| 109 typedef std::map<TransportDIB::Handle, |
| 110 linked_ptr<AsyncRequestInfo> > ThumbnailCallbackMap; |
| 111 ThumbnailCallbackMap callback_map_; |
| 112 |
| 79 DISALLOW_COPY_AND_ASSIGN(ThumbnailGenerator); | 113 DISALLOW_COPY_AND_ASSIGN(ThumbnailGenerator); |
| 80 }; | 114 }; |
| 81 | 115 |
| 82 #endif // CHROME_BROWSER_TAB_CONTENTS_THUMBNAIL_GENERATOR_H_ | 116 #endif // CHROME_BROWSER_TAB_CONTENTS_THUMBNAIL_GENERATOR_H_ |
| OLD | NEW |