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 29 matching lines...) Expand all Loading... |
40 // To choose a representative keyframe, we first wait for a certain number of | 40 // To choose a representative keyframe, we first wait for a certain number of |
41 // "interesting" frames to be displayed by the plugin. A frame is called | 41 // "interesting" frames to be displayed by the plugin. A frame is called |
42 // interesting if it meets some heuristic. After we have seen a certain number | 42 // interesting if it meets some heuristic. After we have seen a certain number |
43 // of interesting frames, we throttle the plugin and use that frame as the | 43 // of interesting frames, we throttle the plugin and use that frame as the |
44 // representative keyframe. | 44 // representative keyframe. |
45 class CONTENT_EXPORT PluginInstanceThrottler { | 45 class CONTENT_EXPORT PluginInstanceThrottler { |
46 public: | 46 public: |
47 // How the throttled power saver is unthrottled, if ever. | 47 // How the throttled power saver is unthrottled, if ever. |
48 // These numeric values are used in UMA logs; do not change them. | 48 // These numeric values are used in UMA logs; do not change them. |
49 enum PowerSaverUnthrottleMethod { | 49 enum PowerSaverUnthrottleMethod { |
| 50 UNTHROTTLE_METHOD_DO_NOT_RECORD = -1, // Sentinel value to skip recording. |
50 UNTHROTTLE_METHOD_NEVER = 0, | 51 UNTHROTTLE_METHOD_NEVER = 0, |
51 UNTHROTTLE_METHOD_BY_CLICK = 1, | 52 UNTHROTTLE_METHOD_BY_CLICK = 1, |
52 UNTHROTTLE_METHOD_BY_WHITELIST = 2, | 53 UNTHROTTLE_METHOD_BY_WHITELIST = 2, |
53 UNTHROTTLE_METHOD_BY_AUDIO = 3, | 54 UNTHROTTLE_METHOD_BY_AUDIO = 3, |
54 UNTHROTTLE_METHOD_BY_SIZE_CHANGE = 4, | 55 UNTHROTTLE_METHOD_BY_SIZE_CHANGE = 4, |
55 UNTHROTTLE_METHOD_NUM_ITEMS | 56 UNTHROTTLE_METHOD_NUM_ITEMS |
56 }; | 57 }; |
57 | 58 |
58 class Observer { | 59 class Observer { |
59 public: | 60 public: |
60 // Guaranteed to be called before the throttle is engaged. | 61 // Guaranteed to be called before the throttle is engaged. |
61 virtual void OnKeyframeExtracted(const SkBitmap* bitmap) {} | 62 virtual void OnKeyframeExtracted(const SkBitmap* bitmap) {} |
62 | 63 |
63 virtual void OnThrottleStateChange() {} | 64 virtual void OnThrottleStateChange() {} |
64 | 65 |
65 virtual void OnPeripheralStateChange() {} | 66 virtual void OnPeripheralStateChange() {} |
66 | 67 |
67 // Called when the plugin should be hidden due to a placeholder. | 68 // Called when the plugin should be hidden due to a placeholder. |
68 virtual void OnHiddenForPlaceholder(bool hidden) {} | 69 virtual void OnHiddenForPlaceholder(bool hidden) {} |
69 | 70 |
70 virtual void OnThrottlerDestroyed() {} | 71 virtual void OnThrottlerDestroyed() {} |
71 }; | 72 }; |
72 | 73 |
73 static scoped_ptr<PluginInstanceThrottler> Create(); | 74 static scoped_ptr<PluginInstanceThrottler> Create(); |
74 | 75 |
75 static void RecordUnthrottleMethodMetric(PowerSaverUnthrottleMethod method); | 76 static void RecordUnthrottleMethodMetric(PowerSaverUnthrottleMethod method); |
76 | 77 |
77 // Returns true if content is considered "large", and thus essential. | |
78 // |width| and |height| are zoom and device scale independent logical pixels. | |
79 static bool IsLargeContent(int width, int height); | |
80 | |
81 virtual ~PluginInstanceThrottler() {} | 78 virtual ~PluginInstanceThrottler() {} |
82 | 79 |
83 virtual void AddObserver(Observer* observer) = 0; | 80 virtual void AddObserver(Observer* observer) = 0; |
84 virtual void RemoveObserver(Observer* observer) = 0; | 81 virtual void RemoveObserver(Observer* observer) = 0; |
85 | 82 |
86 virtual bool IsThrottled() const = 0; | 83 virtual bool IsThrottled() const = 0; |
87 virtual bool IsHiddenForPlaceholder() const = 0; | 84 virtual bool IsHiddenForPlaceholder() const = 0; |
88 | 85 |
89 // Marks the plugin as essential. Unthrottles the plugin if already throttled. | 86 // Marks the plugin as essential. Unthrottles the plugin if already throttled. |
90 virtual void MarkPluginEssential(PowerSaverUnthrottleMethod method) = 0; | 87 virtual void MarkPluginEssential(PowerSaverUnthrottleMethod method) = 0; |
(...skipping 12 matching lines...) Expand all Loading... |
103 | 100 |
104 protected: | 101 protected: |
105 PluginInstanceThrottler() {} | 102 PluginInstanceThrottler() {} |
106 | 103 |
107 private: | 104 private: |
108 DISALLOW_COPY_AND_ASSIGN(PluginInstanceThrottler); | 105 DISALLOW_COPY_AND_ASSIGN(PluginInstanceThrottler); |
109 }; | 106 }; |
110 } | 107 } |
111 | 108 |
112 #endif // CONTENT_PUBLIC_RENDERER_PLUGIN_INSTANCE_THROTTLER_H_ | 109 #endif // CONTENT_PUBLIC_RENDERER_PLUGIN_INSTANCE_THROTTLER_H_ |
OLD | NEW |