1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_PUBLIC_RENDERER_PLUGIN_INSTANCE_THROTTLER_H_
6 #define CONTENT_PUBLIC_RENDERER_PLUGIN_INSTANCE_THROTTLER_H_
8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "content/common/content_export.h"
14 struct WebPluginParams
;
25 // This class manages the metric collection, throttling, and unthrottling of a
26 // single peripheral plugin instance. If the Power Saver feature is disabled,
27 // the plugin instance will never actually be throttled, but still collects
28 // user interaction metrics.
30 // The process for throttling a plugin is as follows:
31 // 1) Attempt to find a representative keyframe to display as a placeholder for
33 // 2) a) If a representative keyframe is found, throttle the plugin at that
35 // b) If a representative keyframe is not found, throttle the plugin after a
36 // certain period of time.
38 // The plugin will then be unthrottled by receiving a mouse click from the user.
40 // To choose a representative keyframe, we first wait for a certain number of
41 // "interesting" frames to be displayed by the plugin. A frame is called
42 // interesting if it meets some heuristic. After we have seen a certain number
43 // of interesting frames, we throttle the plugin and use that frame as the
44 // representative keyframe.
45 class CONTENT_EXPORT PluginInstanceThrottler
{
47 // How the throttled power saver is unthrottled, if ever.
48 // These numeric values are used in UMA logs; do not change them.
49 enum PowerSaverUnthrottleMethod
{
50 UNTHROTTLE_METHOD_NEVER
= 0,
51 UNTHROTTLE_METHOD_BY_CLICK
= 1,
52 UNTHROTTLE_METHOD_BY_WHITELIST
= 2,
53 UNTHROTTLE_METHOD_BY_AUDIO
= 3,
54 UNTHROTTLE_METHOD_BY_SIZE_CHANGE
= 4,
55 UNTHROTTLE_METHOD_NUM_ITEMS
60 // Guaranteed to be called before the throttle is engaged.
61 virtual void OnKeyframeExtracted(const SkBitmap
* bitmap
) {}
63 virtual void OnThrottleStateChange() {}
65 virtual void OnPeripheralStateChange() {}
67 // Called when the plugin should be hidden due to a placeholder.
68 virtual void OnHiddenForPlaceholder(bool hidden
) {}
70 virtual void OnThrottlerDestroyed() {}
73 static scoped_ptr
<PluginInstanceThrottler
> Create();
75 static void RecordUnthrottleMethodMetric(PowerSaverUnthrottleMethod method
);
77 // Returns true if content is considered "large", and thus essential.
78 // |width| and |height| are zoom and device scale independent logical pixels.
79 static bool IsLargeContent(int width
, int height
);
81 virtual ~PluginInstanceThrottler() {}
83 virtual void AddObserver(Observer
* observer
) = 0;
84 virtual void RemoveObserver(Observer
* observer
) = 0;
86 virtual bool IsThrottled() const = 0;
87 virtual bool IsHiddenForPlaceholder() const = 0;
89 // Marks the plugin as essential. Unthrottles the plugin if already throttled.
90 virtual void MarkPluginEssential(PowerSaverUnthrottleMethod method
) = 0;
92 // Called by the placeholder when the plugin should temporarily be hidden.
93 virtual void SetHiddenForPlaceholder(bool hidden
) = 0;
95 virtual blink::WebPlugin
* GetWebPlugin() const = 0;
97 // Gets the throttler's best estimate of the plugin's visible dimensions.
98 virtual const gfx::Size
& GetSize() const = 0;
100 // Throttler needs to know when the plugin audio is throttled, as this may
101 // prevent the plugin from generating new frames.
102 virtual void NotifyAudioThrottled() = 0;
105 PluginInstanceThrottler() {}
108 DISALLOW_COPY_AND_ASSIGN(PluginInstanceThrottler
);
112 #endif // CONTENT_PUBLIC_RENDERER_PLUGIN_INSTANCE_THROTTLER_H_