| 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_PLUGIN_INSTANCE_THROTTLER_IMPL_H_ | 5 #ifndef CONTENT_RENDERER_PEPPER_PLUGIN_INSTANCE_THROTTLER_IMPL_H_ |
| 6 #define CONTENT_RENDERER_PEPPER_PLUGIN_INSTANCE_THROTTLER_IMPL_H_ | 6 #define CONTENT_RENDERER_PEPPER_PLUGIN_INSTANCE_THROTTLER_IMPL_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
| 11 #include "base/timer/timer.h" |
| 11 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
| 12 #include "content/public/renderer/plugin_instance_throttler.h" | 13 #include "content/public/renderer/plugin_instance_throttler.h" |
| 13 #include "ppapi/shared_impl/ppb_view_shared.h" | 14 #include "ppapi/shared_impl/ppb_view_shared.h" |
| 15 #include "third_party/skia/include/core/SkBitmap.h" |
| 14 | 16 |
| 15 namespace blink { | 17 namespace blink { |
| 16 class WebInputEvent; | 18 class WebInputEvent; |
| 17 struct WebRect; | 19 struct WebRect; |
| 18 } | 20 } |
| 19 | 21 |
| 20 namespace content { | 22 namespace content { |
| 21 | 23 |
| 22 class RenderFrameImpl; | 24 class RenderFrameImpl; |
| 23 | 25 |
| 24 class CONTENT_EXPORT PluginInstanceThrottlerImpl | 26 class CONTENT_EXPORT PluginInstanceThrottlerImpl |
| 25 : public PluginInstanceThrottler { | 27 : public PluginInstanceThrottler { |
| 26 public: | 28 public: |
| 27 PluginInstanceThrottlerImpl(bool power_saver_enabled); | 29 PluginInstanceThrottlerImpl(bool power_saver_enabled); |
| 28 | 30 |
| 29 ~PluginInstanceThrottlerImpl() override; | 31 ~PluginInstanceThrottlerImpl() override; |
| 30 | 32 |
| 31 // PluginInstanceThrottler implementation: | 33 // PluginInstanceThrottler implementation: |
| 32 void AddObserver(Observer* observer) override; | 34 void AddObserver(Observer* observer) override; |
| 33 void RemoveObserver(Observer* observer) override; | 35 void RemoveObserver(Observer* observer) override; |
| 34 bool IsThrottled() const override; | 36 bool IsThrottled() const override; |
| 35 bool IsHiddenForPlaceholder() const override; | 37 bool IsHiddenForPlaceholder() const override; |
| 36 void MarkPluginEssential(PowerSaverUnthrottleMethod method) override; | 38 void MarkPluginEssential(PowerSaverUnthrottleMethod method) override; |
| 37 void SetHiddenForPlaceholder(bool hidden) override; | 39 void SetHiddenForPlaceholder(bool hidden) override; |
| 38 blink::WebPlugin* GetWebPlugin() const override; | 40 blink::WebPlugin* GetWebPlugin() const override; |
| 41 void NotifyAudioThrottled() override; |
| 39 | 42 |
| 40 void SetWebPlugin(blink::WebPlugin* web_plugin); | 43 void SetWebPlugin(blink::WebPlugin* web_plugin); |
| 41 | 44 |
| 42 bool needs_representative_keyframe() const { | 45 bool needs_representative_keyframe() const { |
| 43 return state_ == THROTTLER_STATE_AWAITING_KEYFRAME; | 46 return state_ == THROTTLER_STATE_AWAITING_KEYFRAME; |
| 44 } | 47 } |
| 45 | 48 |
| 46 bool power_saver_enabled() const { | 49 bool power_saver_enabled() const { |
| 47 return state_ == THROTTLER_STATE_AWAITING_KEYFRAME || | 50 return state_ == THROTTLER_STATE_AWAITING_KEYFRAME || |
| 48 state_ == THROTTLER_STATE_PLUGIN_THROTTLED; | 51 state_ == THROTTLER_STATE_PLUGIN_THROTTLED; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 73 // A representative keyframe has been chosen and the plugin is throttled. | 76 // A representative keyframe has been chosen and the plugin is throttled. |
| 74 THROTTLER_STATE_PLUGIN_THROTTLED, | 77 THROTTLER_STATE_PLUGIN_THROTTLED, |
| 75 // Plugin instance has been marked essential. | 78 // Plugin instance has been marked essential. |
| 76 THROTTLER_STATE_MARKED_ESSENTIAL, | 79 THROTTLER_STATE_MARKED_ESSENTIAL, |
| 77 }; | 80 }; |
| 78 | 81 |
| 79 // Maximum number of frames to examine for a suitable keyframe. After that, we | 82 // Maximum number of frames to examine for a suitable keyframe. After that, we |
| 80 // simply suspend the plugin where it's at. Chosen arbitrarily. | 83 // simply suspend the plugin where it's at. Chosen arbitrarily. |
| 81 static const int kMaximumFramesToExamine; | 84 static const int kMaximumFramesToExamine; |
| 82 | 85 |
| 86 void AudioThrottledFrameTimeout(); |
| 83 void EngageThrottle(); | 87 void EngageThrottle(); |
| 84 | 88 |
| 85 ThrottlerState state_; | 89 ThrottlerState state_; |
| 86 | 90 |
| 87 bool is_hidden_for_placeholder_; | 91 bool is_hidden_for_placeholder_; |
| 88 | 92 |
| 89 blink::WebPlugin* web_plugin_; | 93 blink::WebPlugin* web_plugin_; |
| 90 | 94 |
| 95 // Holds a reference to the last received frame. This doesn't actually copy |
| 96 // the pixel data, but rather increments the reference count to the pixels. |
| 97 SkBitmap last_received_frame_; |
| 98 |
| 91 // Number of consecutive interesting frames we've encountered. | 99 // Number of consecutive interesting frames we've encountered. |
| 92 int consecutive_interesting_frames_; | 100 int consecutive_interesting_frames_; |
| 93 | 101 |
| 94 // Number of frames we've examined to find a keyframe. | 102 // Number of frames we've examined to find a keyframe. |
| 95 int frames_examined_; | 103 int frames_examined_; |
| 96 | 104 |
| 105 // Video plugins with throttled audio often stop generating frames. |
| 106 // This timer is so we don't wait forever for candidate poster frames. |
| 107 bool audio_throttled_; |
| 108 base::DelayTimer<PluginInstanceThrottlerImpl> audio_throttled_frame_timeout_; |
| 109 |
| 97 ObserverList<Observer> observer_list_; | 110 ObserverList<Observer> observer_list_; |
| 98 | 111 |
| 99 base::WeakPtrFactory<PluginInstanceThrottlerImpl> weak_factory_; | 112 base::WeakPtrFactory<PluginInstanceThrottlerImpl> weak_factory_; |
| 100 | 113 |
| 101 DISALLOW_COPY_AND_ASSIGN(PluginInstanceThrottlerImpl); | 114 DISALLOW_COPY_AND_ASSIGN(PluginInstanceThrottlerImpl); |
| 102 }; | 115 }; |
| 103 } | 116 } |
| 104 | 117 |
| 105 #endif // CONTENT_RENDERER_PEPPER_PLUGIN_INSTANCE_THROTTLER_IMPL_H_ | 118 #endif // CONTENT_RENDERER_PEPPER_PLUGIN_INSTANCE_THROTTLER_IMPL_H_ |
| OLD | NEW |