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_RENDERER_PEPPER_PEPPER_PLUGIN_INSTANCE_THROTTLER_H_ |
6 #define CONTENT_RENDERER_PEPPER_PEPPER_PLUGIN_INSTANCE_THROTTLER_H_ | 6 #define CONTENT_RENDERER_PEPPER_PEPPER_PLUGIN_INSTANCE_THROTTLER_H_ |
7 | 7 |
8 #include "base/callback_forward.h" | 8 #include "base/callback.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/weak_ptr.h" |
| 11 #include "ppapi/shared_impl/ppb_view_shared.h" |
| 12 |
| 13 namespace blink { |
| 14 class WebInputEvent; |
| 15 } |
10 | 16 |
11 namespace content { | 17 namespace content { |
12 | 18 |
13 // Throttles Pepper Plugin instances in Power Saver mode. Currently just a | 19 class PepperPluginInstanceImpl; |
14 // stub implementation that engages throttling after a fixed timeout. | 20 |
15 // In the future, will examine plugin frames to find a suitable preview | 21 // Manages the Plugin Power Saver feature for a single Pepper plugin instance. |
16 // image before engaging throttling. | |
17 class PepperPluginInstanceThrottler { | 22 class PepperPluginInstanceThrottler { |
18 public: | 23 public: |
19 // |throttle_closure| is called to engage throttling. | 24 PepperPluginInstanceThrottler(PepperPluginInstanceImpl* instance, |
20 explicit PepperPluginInstanceThrottler(const base::Closure& throttle_closure); | 25 const base::Closure& throttle_change_callback); |
21 | 26 |
22 virtual ~PepperPluginInstanceThrottler(); | 27 virtual ~PepperPluginInstanceThrottler(); |
23 | 28 |
| 29 bool is_throttled() const { return plugin_throttled_; } |
| 30 const ppapi::ViewData& throttled_view_data() const { |
| 31 return empty_view_data_; |
| 32 } |
| 33 |
| 34 // Returns true if |event| was handled and shouldn't be further processed. |
| 35 bool ConsumeInputEvent(const blink::WebInputEvent& event); |
| 36 |
| 37 protected: |
| 38 // Used only for testing. |
| 39 PepperPluginInstanceThrottler(const base::Closure& throttle_change_callback, |
| 40 bool power_saver_enabled, |
| 41 bool is_peripheral_content); |
| 42 |
| 43 void SetPluginThrottled(bool throttled); |
| 44 void DisablePowerSaverByRetroactiveWhitelist(); |
| 45 |
24 private: | 46 private: |
| 47 // Called when the throttle state changes. |
| 48 base::Closure throttle_change_callback_; |
| 49 |
| 50 // Indicates whether this plugin may be throttled to reduce power consumption. |
| 51 // |power_saver_enabled_| implies |is_peripheral_content_|. |
| 52 bool power_saver_enabled_; |
| 53 |
| 54 // Indicates whether this plugin was found to be peripheral content. |
| 55 // This is separately tracked from |power_saver_enabled_| to collect UMAs. |
| 56 // Always true if |power_saver_enabled_| is true. |
| 57 bool is_peripheral_content_; |
| 58 |
| 59 // Indicates if the plugin is currently throttled. |
| 60 bool plugin_throttled_; |
| 61 |
| 62 // Fake view data used by the Power Saver feature to throttle plugins. |
| 63 const ppapi::ViewData empty_view_data_; |
| 64 |
| 65 base::WeakPtrFactory<PepperPluginInstanceThrottler> weak_factory_; |
| 66 |
25 DISALLOW_COPY_AND_ASSIGN(PepperPluginInstanceThrottler); | 67 DISALLOW_COPY_AND_ASSIGN(PepperPluginInstanceThrottler); |
26 }; | 68 }; |
27 } | 69 } |
28 | 70 |
29 #endif // CONTENT_RENDERER_PEPPER_PEPPER_PLUGIN_INSTANCE_THROTTLER_H_ | 71 #endif // CONTENT_RENDERER_PEPPER_PEPPER_PLUGIN_INSTANCE_THROTTLER_H_ |
OLD | NEW |