Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_RENDERER_PEPPER_PEPPER_PLUGIN_INSTANCE_THROTTLER_H_ | 5 #ifndef CONTENT_PUBLIC_RENDERER_PLUGIN_INSTANCE_THROTTLER_H_ |
| 6 #define CONTENT_RENDERER_PEPPER_PEPPER_PLUGIN_INSTANCE_THROTTLER_H_ | 6 #define CONTENT_PUBLIC_RENDERER_PLUGIN_INSTANCE_THROTTLER_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/observer_list.h" | |
| 11 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
| 12 #include "content/public/renderer/render_frame.h" | |
| 13 #include "ppapi/shared_impl/ppb_view_shared.h" | 13 #include "ppapi/shared_impl/ppb_view_shared.h" |
| 14 #include "third_party/WebKit/public/platform/WebRect.h" | 14 #include "third_party/WebKit/public/platform/WebRect.h" |
| 15 | 15 |
| 16 namespace blink { | 16 namespace blink { |
| 17 class WebInputEvent; | 17 class WebInputEvent; |
| 18 } | 18 } |
| 19 | 19 |
| 20 class GURL; | 20 class GURL; |
| 21 class SkBitmap; | 21 class SkBitmap; |
| 22 | 22 |
| 23 namespace content { | 23 namespace content { |
| 24 | 24 |
| 25 class RenderFrame; | |
| 26 | |
| 25 // Manages the Plugin Power Saver feature for a single Pepper plugin instance. | 27 // Manages the Plugin Power Saver feature for a single Pepper plugin instance. |
| 26 // | 28 // |
| 27 // A plugin must meet certain criteria in order to be throttled (e.g. it must | 29 // A plugin must meet certain criteria in order to be throttled (e.g. it must |
| 28 // be a Flash plugin, it must meet certain size criteria, etc.). The process | 30 // be a Flash plugin, it must meet certain size criteria, etc.). The process |
| 29 // for throttling a plugin is as follows: | 31 // for throttling a plugin is as follows: |
| 30 // 1) Attempt to find a representative keyframe to display as a placeholder for | 32 // 1) Attempt to find a representative keyframe to display as a placeholder for |
| 31 // the plugin. | 33 // the plugin. |
| 32 // 2) a) If a representative keyframe is found, throttle the plugin at that | 34 // 2) a) If a representative keyframe is found, throttle the plugin at that |
| 33 // keyframe. | 35 // keyframe. |
| 34 // b) If a representative keyframe is not found, throttle the plugin after a | 36 // b) If a representative keyframe is not found, throttle the plugin after a |
| 35 // certain period of time. | 37 // certain period of time. |
| 36 // | 38 // |
| 37 // The plugin will then be unthrottled by receiving a mouse click from the user. | 39 // The plugin will then be unthrottled by receiving a mouse click from the user. |
| 38 // | 40 // |
| 39 // To choose a representative keyframe, we first wait for a certain number of | 41 // To choose a representative keyframe, we first wait for a certain number of |
| 40 // "interesting" frames to be displayed by the plugin. A frame is called | 42 // "interesting" frames to be displayed by the plugin. A frame is called |
| 41 // interesting if it meets some heuristic. After we have seen a certain number | 43 // interesting if it meets some heuristic. After we have seen a certain number |
| 42 // of interesting frames, we throttle the plugin and use that frame as the | 44 // of interesting frames, we throttle the plugin and use that frame as the |
| 43 // representative keyframe. | 45 // representative keyframe. |
| 44 class CONTENT_EXPORT PepperPluginInstanceThrottler { | 46 class CONTENT_EXPORT PluginInstanceThrottler { |
| 45 public: | 47 public: |
| 48 enum PluginPowerSaverMode { | |
| 49 // Plugin content is main content, and therefore never throttled. | |
| 50 POWER_SAVER_MODE_ESSENTIAL = 0, | |
| 51 // Plugin content is peripheral, but throttling is disabled. | |
| 52 POWER_SAVER_MODE_PERIPHERAL_UNTHROTTLED = 1, | |
| 53 // Plugin content is peripheral, and throttling is enabled. | |
| 54 POWER_SAVER_MODE_PERIPHERAL_THROTTLED = 2 | |
| 55 }; | |
| 56 | |
| 46 // How the throttled power saver is unthrottled, if ever. | 57 // How the throttled power saver is unthrottled, if ever. |
| 47 // These numeric values are used in UMA logs; do not change them. | 58 // These numeric values are used in UMA logs; do not change them. |
| 48 enum PowerSaverUnthrottleMethod { | 59 enum PowerSaverUnthrottleMethod { |
| 49 UNTHROTTLE_METHOD_NEVER = 0, | 60 UNTHROTTLE_METHOD_NEVER = 0, |
| 50 UNTHROTTLE_METHOD_BY_CLICK = 1, | 61 UNTHROTTLE_METHOD_BY_CLICK = 1, |
| 51 UNTHROTTLE_METHOD_BY_WHITELIST = 2, | 62 UNTHROTTLE_METHOD_BY_WHITELIST = 2, |
| 52 UNTHROTTLE_METHOD_BY_AUDIO = 3, | 63 UNTHROTTLE_METHOD_BY_AUDIO = 3, |
| 53 UNTHROTTLE_METHOD_NUM_ITEMS | 64 UNTHROTTLE_METHOD_NUM_ITEMS |
| 54 }; | 65 }; |
| 55 | 66 |
| 56 PepperPluginInstanceThrottler( | 67 class Observer { |
| 57 RenderFrame* frame, | 68 public: |
| 58 const blink::WebRect& bounds, | 69 virtual void OnThrottleStateChange() = 0; |
| 59 bool is_flash_plugin, | 70 }; |
| 60 const GURL& plugin_url, | |
| 61 RenderFrame::PluginPowerSaverMode power_saver_mode, | |
| 62 const base::Closure& throttle_change_callback); | |
| 63 | 71 |
| 64 virtual ~PepperPluginInstanceThrottler(); | 72 PluginInstanceThrottler(RenderFrame* frame, |
| 73 const GURL& plugin_url, | |
| 74 PluginPowerSaverMode power_saver_mode); | |
| 75 | |
| 76 virtual ~PluginInstanceThrottler(); | |
| 77 | |
| 78 void AddObserver(Observer* observer); | |
| 79 void RemoveObserver(Observer* observer); | |
| 65 | 80 |
| 66 bool needs_representative_keyframe() const { | 81 bool needs_representative_keyframe() const { |
| 67 return needs_representative_keyframe_; | 82 return needs_representative_keyframe_; |
| 68 } | 83 } |
| 69 | 84 |
| 70 bool power_saver_enabled() const { | 85 bool power_saver_enabled() const { return power_saver_enabled_; } |
| 71 return power_saver_enabled_; | |
| 72 } | |
| 73 | 86 |
| 74 // Called when the plugin flushes it's graphics context. Supplies the | 87 // Called when the plugin flushes it's graphics context. Supplies the |
| 75 // throttler with a candidate to use as the representative keyframe. | 88 // throttler with a candidate to use as the representative keyframe. |
| 76 void OnImageFlush(const SkBitmap* bitmap); | 89 void OnImageFlush(const SkBitmap* bitmap); |
|
piman
2015/01/14 00:09:32
Are you actually going to call this and other conc
tommycli
2015/01/14 01:44:59
Done.
| |
| 77 | 90 |
| 78 bool is_throttled() const { return plugin_throttled_; } | 91 bool is_throttled() const { return plugin_throttled_; } |
| 79 | 92 |
| 80 // Returns true if |event| was handled and shouldn't be further processed. | 93 // Returns true if |event| was handled and shouldn't be further processed. |
| 81 bool ConsumeInputEvent(const blink::WebInputEvent& event); | 94 bool ConsumeInputEvent(const blink::WebInputEvent& event); |
| 82 | 95 |
| 83 // Disables Power Saver and unthrottles the plugin if already throttled. | 96 // Disables Power Saver and unthrottles the plugin if already throttled. |
| 84 void DisablePowerSaver(PowerSaverUnthrottleMethod method); | 97 void DisablePowerSaver(PowerSaverUnthrottleMethod method); |
| 85 | 98 |
| 86 private: | 99 private: |
| 87 friend class PepperPluginInstanceThrottlerTest; | 100 friend class PluginInstanceThrottlerTest; |
| 88 | 101 |
| 89 void SetPluginThrottled(bool throttled); | 102 void SetPluginThrottled(bool throttled); |
| 90 | 103 |
| 91 // Plugin's bounds in view space. | |
| 92 blink::WebRect bounds_; | |
| 93 | |
| 94 // Called when the throttle state changes. | |
| 95 base::Closure throttle_change_callback_; | |
| 96 | |
| 97 bool is_flash_plugin_; | |
| 98 | |
| 99 // True if throttler is still waiting to find a representative keyframe. | 104 // True if throttler is still waiting to find a representative keyframe. |
| 100 bool needs_representative_keyframe_; | 105 bool needs_representative_keyframe_; |
| 101 | 106 |
| 102 // Number of consecutive interesting frames we've encountered. | 107 // Number of consecutive interesting frames we've encountered. |
| 103 int consecutive_interesting_frames_; | 108 int consecutive_interesting_frames_; |
| 104 | 109 |
| 105 // Set to true first time plugin is clicked. Used to collect metrics. | |
| 106 bool has_been_clicked_; | |
| 107 | |
| 108 // Indicates whether this plugin may be throttled to reduce power consumption. | 110 // Indicates whether this plugin may be throttled to reduce power consumption. |
| 109 // |power_saver_enabled_| implies |is_peripheral_content_|. | 111 // |power_saver_enabled_| implies |is_peripheral_content_|. |
| 110 bool power_saver_enabled_; | 112 bool power_saver_enabled_; |
| 111 | 113 |
| 112 // Indicates whether this plugin was found to be peripheral content. | 114 // Indicates whether this plugin was found to be peripheral content. |
| 113 // This is separately tracked from |power_saver_enabled_| to collect UMAs. | 115 // This is separately tracked from |power_saver_enabled_| to collect UMAs. |
| 114 // Always true if |power_saver_enabled_| is true. | 116 // Always true if |power_saver_enabled_| is true. |
| 115 bool is_peripheral_content_; | 117 bool is_peripheral_content_; |
| 116 | 118 |
| 117 // Indicates if the plugin is currently throttled. | 119 // Indicates if the plugin is currently throttled. |
| 118 bool plugin_throttled_; | 120 bool plugin_throttled_; |
| 119 | 121 |
| 120 base::WeakPtrFactory<PepperPluginInstanceThrottler> weak_factory_; | 122 ObserverList<Observer> observer_list_; |
| 121 | 123 |
| 122 DISALLOW_COPY_AND_ASSIGN(PepperPluginInstanceThrottler); | 124 base::WeakPtrFactory<PluginInstanceThrottler> weak_factory_; |
| 125 | |
| 126 DISALLOW_COPY_AND_ASSIGN(PluginInstanceThrottler); | |
| 123 }; | 127 }; |
| 124 } | 128 } |
| 125 | 129 |
| 126 #endif // CONTENT_RENDERER_PEPPER_PEPPER_PLUGIN_INSTANCE_THROTTLER_H_ | 130 #endif // CONTENT_PUBLIC_RENDERER_PLUGIN_INSTANCE_THROTTLER_H_ |
| OLD | NEW |