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 class GURL; | 12 class GURL; |
| 13 class SkBitmap; |
13 | 14 |
14 namespace content { | 15 namespace content { |
15 | 16 |
16 class RenderFrame; | 17 class RenderFrame; |
17 | 18 |
18 // Plugin instances are "peripheral" if they are heuristically determined to be | 19 // Plugin instances are "peripheral" if they are heuristically determined to be |
19 // not "essential" to the web page content. See comments on | 20 // not "essential" to the web page content. See comments on |
20 // RenderFrame::ShouldThrottleContent for details on these heuristics. | 21 // RenderFrame::ShouldThrottleContent for details on these heuristics. |
21 enum PluginPowerSaverMode { | 22 enum PluginPowerSaverMode { |
22 // Plugin content is main content, and therefore never throttled. | 23 // Plugin content is main content, and therefore never throttled. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 enum PowerSaverUnthrottleMethod { | 55 enum PowerSaverUnthrottleMethod { |
55 UNTHROTTLE_METHOD_NEVER = 0, | 56 UNTHROTTLE_METHOD_NEVER = 0, |
56 UNTHROTTLE_METHOD_BY_CLICK = 1, | 57 UNTHROTTLE_METHOD_BY_CLICK = 1, |
57 UNTHROTTLE_METHOD_BY_WHITELIST = 2, | 58 UNTHROTTLE_METHOD_BY_WHITELIST = 2, |
58 UNTHROTTLE_METHOD_BY_AUDIO = 3, | 59 UNTHROTTLE_METHOD_BY_AUDIO = 3, |
59 UNTHROTTLE_METHOD_NUM_ITEMS | 60 UNTHROTTLE_METHOD_NUM_ITEMS |
60 }; | 61 }; |
61 | 62 |
62 class Observer { | 63 class Observer { |
63 public: | 64 public: |
64 virtual void OnThrottleStateChange() = 0; | 65 // Guaranteed to be called before the throttle is engaged. |
| 66 virtual void OnKeyframeExtracted(const SkBitmap* bitmap) {} |
| 67 |
| 68 virtual void OnThrottleStateChange() {} |
| 69 |
| 70 // Called when the plugin should be hidden due to a placeholder. |
| 71 virtual void OnHiddenForPlaceholder(bool hidden) {} |
| 72 |
| 73 virtual void OnThrottlerDestroyed() {} |
65 }; | 74 }; |
66 | 75 |
67 // Returns a nullptr if no throttler needed based on |power_saver_mode|. | 76 // Returns a nullptr if no throttler needed based on |power_saver_mode|. |
68 static scoped_ptr<PluginInstanceThrottler> Get( | 77 static scoped_ptr<PluginInstanceThrottler> Get( |
69 RenderFrame* frame, | 78 RenderFrame* frame, |
70 const GURL& plugin_url, | 79 const GURL& plugin_url, |
71 PluginPowerSaverMode power_saver_mode); | 80 PluginPowerSaverMode power_saver_mode); |
72 | 81 |
73 static void RecordUnthrottleMethodMetric(PowerSaverUnthrottleMethod method); | 82 static void RecordUnthrottleMethodMetric(PowerSaverUnthrottleMethod method); |
74 | 83 |
75 virtual ~PluginInstanceThrottler() {} | 84 virtual ~PluginInstanceThrottler() {} |
76 | 85 |
77 virtual void AddObserver(Observer* observer) = 0; | 86 virtual void AddObserver(Observer* observer) = 0; |
78 virtual void RemoveObserver(Observer* observer) = 0; | 87 virtual void RemoveObserver(Observer* observer) = 0; |
79 | 88 |
80 virtual bool IsThrottled() const = 0; | 89 virtual bool IsThrottled() const = 0; |
| 90 virtual bool IsHiddenForPlaceholder() const = 0; |
81 | 91 |
82 // Marks the plugin as essential. Unthrottles the plugin if already throttled. | 92 // Marks the plugin as essential. Unthrottles the plugin if already throttled. |
83 virtual void MarkPluginEssential(PowerSaverUnthrottleMethod method) = 0; | 93 virtual void MarkPluginEssential(PowerSaverUnthrottleMethod method) = 0; |
84 | 94 |
| 95 // Called by the placeholder when the plugin should temporarily be hidden. |
| 96 virtual void SetHiddenForPlaceholder(bool hidden) = 0; |
| 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 |