Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 CONTENT_PUBLIC_RENDERER_PLUGIN_INSTANCE_THROTTLER_H_ | 5 #ifndef CONTENT_PUBLIC_RENDERER_PLUGIN_INSTANCE_THROTTLER_H_ |
| 6 #define CONTENT_PUBLIC_RENDERER_PLUGIN_INSTANCE_THROTTLER_H_ | 6 #define CONTENT_PUBLIC_RENDERER_PLUGIN_INSTANCE_THROTTLER_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "content/common/content_export.h" | 10 #include "content/common/content_export.h" |
| 11 | 11 |
| 12 namespace blink { | |
| 13 struct WebPluginParams; | |
| 14 } | |
| 15 | |
| 12 class GURL; | 16 class GURL; |
| 13 class SkBitmap; | 17 class SkBitmap; |
| 14 | 18 |
| 15 namespace content { | 19 namespace content { |
| 16 | 20 |
| 17 class RenderFrame; | |
| 18 | |
| 19 // Plugin instances are "peripheral" if they are heuristically determined to be | |
| 20 // not "essential" to the web page content. See comments on | |
| 21 // RenderFrame::ShouldThrottleContent for details on these heuristics. | |
| 22 enum PluginPowerSaverMode { | |
| 23 // Plugin content is main content, and therefore never throttled. | |
| 24 POWER_SAVER_MODE_ESSENTIAL = 0, | |
| 25 // Plugin content is peripheral, but throttling is disabled. | |
| 26 POWER_SAVER_MODE_PERIPHERAL_UNTHROTTLED = 1, | |
| 27 // Plugin content is peripheral, and throttling is enabled. | |
| 28 POWER_SAVER_MODE_PERIPHERAL_THROTTLED = 2 | |
| 29 }; | |
| 30 | |
| 31 // This class manages the metric collection, throttling, and unthrottling of a | 21 // This class manages the metric collection, throttling, and unthrottling of a |
| 32 // single peripheral plugin instance. If the Power Saver feature is disabled, | 22 // single peripheral plugin instance. If the Power Saver feature is disabled, |
| 33 // the plugin instance will never actually be throttled, but still collects | 23 // the plugin instance will never actually be throttled, but still collects |
| 34 // user interaction metrics. | 24 // user interaction metrics. |
| 35 // | 25 // |
| 36 // The process for throttling a plugin is as follows: | 26 // The process for throttling a plugin is as follows: |
| 37 // 1) Attempt to find a representative keyframe to display as a placeholder for | 27 // 1) Attempt to find a representative keyframe to display as a placeholder for |
| 38 // the plugin. | 28 // the plugin. |
| 39 // 2) a) If a representative keyframe is found, throttle the plugin at that | 29 // 2) a) If a representative keyframe is found, throttle the plugin at that |
| 40 // keyframe. | 30 // keyframe. |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 66 virtual void OnKeyframeExtracted(const SkBitmap* bitmap) {} | 56 virtual void OnKeyframeExtracted(const SkBitmap* bitmap) {} |
| 67 | 57 |
| 68 virtual void OnThrottleStateChange() {} | 58 virtual void OnThrottleStateChange() {} |
| 69 | 59 |
| 70 // Called when the plugin should be hidden due to a placeholder. | 60 // Called when the plugin should be hidden due to a placeholder. |
| 71 virtual void OnHiddenForPlaceholder(bool hidden) {} | 61 virtual void OnHiddenForPlaceholder(bool hidden) {} |
| 72 | 62 |
| 73 virtual void OnThrottlerDestroyed() {} | 63 virtual void OnThrottlerDestroyed() {} |
| 74 }; | 64 }; |
| 75 | 65 |
| 76 // Returns a nullptr if no throttler needed based on |power_saver_mode|. | 66 static scoped_ptr<PluginInstanceThrottler> Create(bool power_saver_enabled); |
| 77 static scoped_ptr<PluginInstanceThrottler> Get( | 67 |
| 78 RenderFrame* frame, | 68 static GURL GetPluginInstancePosterImage(const blink::WebPluginParams& params, |
| 79 const GURL& plugin_url, | 69 const GURL& page_base_url); |
|
piman
2015/02/06 22:13:12
Why is this even here? It doesn't need anything fr
tommycli
2015/02/06 22:57:10
Done. It was to support a unit test. But I think t
| |
| 80 PluginPowerSaverMode power_saver_mode); | |
| 81 | 70 |
| 82 static void RecordUnthrottleMethodMetric(PowerSaverUnthrottleMethod method); | 71 static void RecordUnthrottleMethodMetric(PowerSaverUnthrottleMethod method); |
| 83 | 72 |
| 84 virtual ~PluginInstanceThrottler() {} | 73 virtual ~PluginInstanceThrottler() {} |
| 85 | 74 |
| 86 virtual void AddObserver(Observer* observer) = 0; | 75 virtual void AddObserver(Observer* observer) = 0; |
| 87 virtual void RemoveObserver(Observer* observer) = 0; | 76 virtual void RemoveObserver(Observer* observer) = 0; |
| 88 | 77 |
| 89 virtual bool IsThrottled() const = 0; | 78 virtual bool IsThrottled() const = 0; |
| 90 virtual bool IsHiddenForPlaceholder() const = 0; | 79 virtual bool IsHiddenForPlaceholder() const = 0; |
| 91 | 80 |
| 92 // Marks the plugin as essential. Unthrottles the plugin if already throttled. | 81 // Marks the plugin as essential. Unthrottles the plugin if already throttled. |
| 93 virtual void MarkPluginEssential(PowerSaverUnthrottleMethod method) = 0; | 82 virtual void MarkPluginEssential(PowerSaverUnthrottleMethod method) = 0; |
| 94 | 83 |
| 95 // Called by the placeholder when the plugin should temporarily be hidden. | 84 // Called by the placeholder when the plugin should temporarily be hidden. |
| 96 virtual void SetHiddenForPlaceholder(bool hidden) = 0; | 85 virtual void SetHiddenForPlaceholder(bool hidden) = 0; |
| 97 | 86 |
| 98 protected: | 87 protected: |
| 99 PluginInstanceThrottler() {} | 88 PluginInstanceThrottler() {} |
| 100 | 89 |
| 101 private: | 90 private: |
| 102 DISALLOW_COPY_AND_ASSIGN(PluginInstanceThrottler); | 91 DISALLOW_COPY_AND_ASSIGN(PluginInstanceThrottler); |
| 103 }; | 92 }; |
| 104 } | 93 } |
| 105 | 94 |
| 106 #endif // CONTENT_PUBLIC_RENDERER_PLUGIN_INSTANCE_THROTTLER_H_ | 95 #endif // CONTENT_PUBLIC_RENDERER_PLUGIN_INSTANCE_THROTTLER_H_ |
| OLD | NEW |