| 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" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 // How the throttled power saver is unthrottled, if ever. | 52 // How the throttled power saver is unthrottled, if ever. |
| 53 // These numeric values are used in UMA logs; do not change them. | 53 // These numeric values are used in UMA logs; do not change them. |
| 54 enum PowerSaverUnthrottleMethod { | 54 enum PowerSaverUnthrottleMethod { |
| 55 UNTHROTTLE_METHOD_NEVER = 0, | 55 UNTHROTTLE_METHOD_NEVER = 0, |
| 56 UNTHROTTLE_METHOD_BY_CLICK = 1, | 56 UNTHROTTLE_METHOD_BY_CLICK = 1, |
| 57 UNTHROTTLE_METHOD_BY_WHITELIST = 2, | 57 UNTHROTTLE_METHOD_BY_WHITELIST = 2, |
| 58 UNTHROTTLE_METHOD_BY_AUDIO = 3, | 58 UNTHROTTLE_METHOD_BY_AUDIO = 3, |
| 59 UNTHROTTLE_METHOD_NUM_ITEMS | 59 UNTHROTTLE_METHOD_NUM_ITEMS |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 enum PowerSaverState { |
| 63 // Initial state if Power Saver is disabled. We are just collecting metrics. |
| 64 POWER_SAVER_DISABLED, |
| 65 // Initial state if Power Saver is enabled. Waiting for a keyframe. |
| 66 POWER_SAVER_ENABLED_AWAITING_KEYFRAME, |
| 67 // We've chosen a keyframe and the plug-in is throttled. |
| 68 POWER_SAVER_ENABLED_PLUGIN_THROTTLED, |
| 69 // Plugin instance is no longer considered peripheral. This can happen from |
| 70 // a user click, whitelisting, or some other reason. We can end up in this |
| 71 // state regardless of whether power saver is enabled. |
| 72 POWER_SAVER_MARKED_ESSENTIAL |
| 73 }; |
| 74 |
| 62 class Observer { | 75 class Observer { |
| 63 public: | 76 public: |
| 64 virtual void OnThrottleStateChange() = 0; | 77 virtual void OnPowerSaverStateChange(PowerSaverState state) = 0; |
| 65 }; | 78 }; |
| 66 | 79 |
| 67 // Returns a nullptr if no throttler needed based on |power_saver_mode|. | 80 // Returns a nullptr if no throttler needed based on |power_saver_mode|. |
| 68 static scoped_ptr<PluginInstanceThrottler> Get( | 81 static scoped_ptr<PluginInstanceThrottler> Get( |
| 69 RenderFrame* frame, | 82 RenderFrame* frame, |
| 70 const GURL& plugin_url, | 83 const GURL& plugin_url, |
| 71 PluginPowerSaverMode power_saver_mode); | 84 PluginPowerSaverMode power_saver_mode); |
| 72 | 85 |
| 73 static void RecordUnthrottleMethodMetric(PowerSaverUnthrottleMethod method); | 86 static void RecordUnthrottleMethodMetric(PowerSaverUnthrottleMethod method); |
| 74 | 87 |
| 75 virtual ~PluginInstanceThrottler() {} | 88 virtual ~PluginInstanceThrottler() {} |
| 76 | 89 |
| 77 virtual void AddObserver(Observer* observer) = 0; | 90 virtual void AddObserver(Observer* observer) = 0; |
| 78 virtual void RemoveObserver(Observer* observer) = 0; | 91 virtual void RemoveObserver(Observer* observer) = 0; |
| 79 | 92 |
| 80 virtual bool IsThrottled() const = 0; | 93 virtual bool IsThrottled() const = 0; |
| 81 | 94 |
| 82 // Marks the plugin as essential. Unthrottles the plugin if already throttled. | 95 // Marks the plugin as essential. Unthrottles the plugin if already throttled. |
| 83 virtual void MarkPluginEssential(PowerSaverUnthrottleMethod method) = 0; | 96 virtual void MarkPluginEssential(PowerSaverUnthrottleMethod method) = 0; |
| 84 | 97 |
| 85 protected: | 98 protected: |
| 86 PluginInstanceThrottler() {} | 99 PluginInstanceThrottler() {} |
| 87 | 100 |
| 88 private: | 101 private: |
| 89 DISALLOW_COPY_AND_ASSIGN(PluginInstanceThrottler); | 102 DISALLOW_COPY_AND_ASSIGN(PluginInstanceThrottler); |
| 90 }; | 103 }; |
| 91 } | 104 } |
| 92 | 105 |
| 93 #endif // CONTENT_PUBLIC_RENDERER_PLUGIN_INSTANCE_THROTTLER_H_ | 106 #endif // CONTENT_PUBLIC_RENDERER_PLUGIN_INSTANCE_THROTTLER_H_ |
| OLD | NEW |