blob: 499c2d64c4e21ef3c3c4de757a806ecda4d0e5b9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_TAB_CONTENTS_THUMBNAIL_GENERATOR_H_
#define CHROME_BROWSER_TAB_CONTENTS_THUMBNAIL_GENERATOR_H_
#include <vector>
#include "base/basictypes.h"
#include "base/timer.h"
#include "chrome/browser/renderer_host/render_widget_host_painting_observer.h"
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_registrar.h"
class RenderWidgetHost;
class SkBitmap;
// This class MUST be destroyed after the RenderWidgetHosts, since it installs
// a painting observer that is not removed.
class ThumbnailGenerator : public RenderWidgetHostPaintingObserver,
public NotificationObserver {
public:
// This class will do nothing until you call StartThumbnailing.
ThumbnailGenerator();
~ThumbnailGenerator();
// Ensures that we're properly hooked in to generated thumbnails. This can
// be called repeatedly and with wild abandon to no ill effect.
void StartThumbnailing();
SkBitmap GetThumbnailForRenderer(RenderWidgetHost* renderer) const;
#ifdef UNIT_TEST
// When true, the class will not use a timeout to do the expiration. This
// will cause expiration to happen on the next run of the message loop.
// Unit tests case use this to test expiration by choosing when the message
// loop runs.
void set_no_timeout(bool no_timeout) { no_timeout_ = no_timeout; }
#endif
private:
// RenderWidgetHostPaintingObserver implementation.
virtual void WidgetWillDestroyBackingStore(RenderWidgetHost* widget,
BackingStore* backing_store);
virtual void WidgetDidUpdateBackingStore(RenderWidgetHost* widget);
// NotificationObserver interface.
virtual void Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details);
// Indicates that the given widget has changed is visibility.
void WidgetShown(RenderWidgetHost* widget);
void WidgetHidden(RenderWidgetHost* widget);
// Called when the given widget is destroyed.
void WidgetDestroyed(RenderWidgetHost* widget);
// Timer function called on a delay after a tab has been shown. It will
// invalidate the thumbnail for hosts with expired thumbnails in shown_hosts_.
void ShownDelayHandler();
// Removes the given host from the shown_hosts_ list, if it is there.
void EraseHostFromShownList(RenderWidgetHost* host);
NotificationRegistrar registrar_;
base::OneShotTimer<ThumbnailGenerator> timer_;
// A list of all RWHs that have been shown and need to have their thumbnail
// expired at some time in the future with the "slop" time has elapsed. This
// list will normally have 0 or 1 items in it.
std::vector<RenderWidgetHost*> shown_hosts_;
// See the setter above.
bool no_timeout_;
DISALLOW_COPY_AND_ASSIGN(ThumbnailGenerator);
};
#endif // CHROME_BROWSER_TAB_CONTENTS_THUMBNAIL_GENERATOR_H_
|