OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/linked_ptr.h" | 15 #include "base/linked_ptr.h" |
16 #include "base/lock.h" | 16 #include "base/lock.h" |
17 #include "base/timer.h" | 17 #include "base/timer.h" |
18 #include "chrome/browser/renderer_host/render_widget_host_painting_observer.h" | 18 #include "chrome/browser/renderer_host/backing_store.h" |
19 #include "chrome/common/notification_observer.h" | 19 #include "chrome/common/notification_observer.h" |
20 #include "chrome/common/notification_registrar.h" | 20 #include "chrome/common/notification_registrar.h" |
21 | 21 |
22 class RenderWidgetHost; | 22 class RenderWidgetHost; |
23 class SkBitmap; | 23 class SkBitmap; |
24 class TabContents; | 24 class TabContents; |
25 | 25 |
26 // This class MUST be destroyed after the RenderWidgetHosts, since it installs | 26 class ThumbnailGenerator : NotificationObserver { |
27 // a painting observer that is not removed. | |
28 class ThumbnailGenerator : public RenderWidgetHostPaintingObserver, | |
29 public NotificationObserver { | |
30 public: | 27 public: |
31 typedef Callback1<const SkBitmap&>::Type ThumbnailReadyCallback; | 28 typedef Callback1<const SkBitmap&>::Type ThumbnailReadyCallback; |
32 // This class will do nothing until you call StartThumbnailing. | 29 // This class will do nothing until you call StartThumbnailing. |
33 ThumbnailGenerator(); | 30 ThumbnailGenerator(); |
34 ~ThumbnailGenerator(); | 31 ~ThumbnailGenerator(); |
35 | 32 |
36 // Ensures that we're properly hooked in to generated thumbnails. This can | 33 // Ensures that we're properly hooked in to generated thumbnails. This can |
37 // be called repeatedly and with wild abandon to no ill effect. | 34 // be called repeatedly and with wild abandon to no ill effect. |
38 void StartThumbnailing(); | 35 void StartThumbnailing(); |
39 | 36 |
(...skipping 17 matching lines...) Expand all Loading... |
57 void AskForSnapshot(RenderWidgetHost* renderer, | 54 void AskForSnapshot(RenderWidgetHost* renderer, |
58 bool prefer_backing_store, | 55 bool prefer_backing_store, |
59 ThumbnailReadyCallback* callback, | 56 ThumbnailReadyCallback* callback, |
60 gfx::Size page_size, | 57 gfx::Size page_size, |
61 gfx::Size desired_size); | 58 gfx::Size desired_size); |
62 | 59 |
63 // This returns a thumbnail of a fixed, small size for the given | 60 // This returns a thumbnail of a fixed, small size for the given |
64 // renderer. | 61 // renderer. |
65 SkBitmap GetThumbnailForRenderer(RenderWidgetHost* renderer) const; | 62 SkBitmap GetThumbnailForRenderer(RenderWidgetHost* renderer) const; |
66 | 63 |
| 64 // Start or stop monitoring notifications for |renderer| based on the value |
| 65 // of |monitor|. |
| 66 void MonitorRenderer(RenderWidgetHost* renderer, bool monitor); |
| 67 |
67 #ifdef UNIT_TEST | 68 #ifdef UNIT_TEST |
68 // When true, the class will not use a timeout to do the expiration. This | 69 // When true, the class will not use a timeout to do the expiration. This |
69 // will cause expiration to happen on the next run of the message loop. | 70 // will cause expiration to happen on the next run of the message loop. |
70 // Unit tests case use this to test expiration by choosing when the message | 71 // Unit tests case use this to test expiration by choosing when the message |
71 // loop runs. | 72 // loop runs. |
72 void set_no_timeout(bool no_timeout) { no_timeout_ = no_timeout; } | 73 void set_no_timeout(bool no_timeout) { no_timeout_ = no_timeout; } |
73 #endif | 74 #endif |
74 | 75 |
75 private: | 76 private: |
76 // RenderWidgetHostPaintingObserver implementation. | 77 // RenderWidgetHostPaintingObserver implementation. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 // Map of callback objects by sequence number. | 122 // Map of callback objects by sequence number. |
122 struct AsyncRequestInfo; | 123 struct AsyncRequestInfo; |
123 typedef std::map<int, | 124 typedef std::map<int, |
124 linked_ptr<AsyncRequestInfo> > ThumbnailCallbackMap; | 125 linked_ptr<AsyncRequestInfo> > ThumbnailCallbackMap; |
125 ThumbnailCallbackMap callback_map_; | 126 ThumbnailCallbackMap callback_map_; |
126 | 127 |
127 DISALLOW_COPY_AND_ASSIGN(ThumbnailGenerator); | 128 DISALLOW_COPY_AND_ASSIGN(ThumbnailGenerator); |
128 }; | 129 }; |
129 | 130 |
130 #endif // CHROME_BROWSER_TAB_CONTENTS_THUMBNAIL_GENERATOR_H_ | 131 #endif // CHROME_BROWSER_TAB_CONTENTS_THUMBNAIL_GENERATOR_H_ |
OLD | NEW |