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 "content/common/content_export.h" |
| 12 #include "ppapi/shared_impl/ppb_view_shared.h" |
| 13 #include "third_party/WebKit/public/platform/WebRect.h" |
| 14 |
| 15 namespace blink { |
| 16 class WebInputEvent; |
| 17 } |
| 18 |
| 19 class GURL; |
10 | 20 |
11 namespace content { | 21 namespace content { |
12 | 22 |
13 // Throttles Pepper Plugin instances in Power Saver mode. Currently just a | 23 class PluginPowerSaverHelper; |
14 // stub implementation that engages throttling after a fixed timeout. | 24 |
15 // In the future, will examine plugin frames to find a suitable preview | 25 // Manages the Plugin Power Saver feature for a single Pepper plugin instance. |
16 // image before engaging throttling. | 26 class CONTENT_EXPORT PepperPluginInstanceThrottler { |
17 class PepperPluginInstanceThrottler { | |
18 public: | 27 public: |
19 // |throttle_closure| is called to engage throttling. | 28 PepperPluginInstanceThrottler(PluginPowerSaverHelper* power_saver_helper, |
20 explicit PepperPluginInstanceThrottler(const base::Closure& throttle_closure); | 29 const blink::WebRect& bounds, |
| 30 const std::string& module_name, |
| 31 const GURL& plugin_url, |
| 32 const base::Closure& throttle_change_callback); |
21 | 33 |
22 virtual ~PepperPluginInstanceThrottler(); | 34 virtual ~PepperPluginInstanceThrottler(); |
23 | 35 |
| 36 bool is_throttled() const { return plugin_throttled_; } |
| 37 const ppapi::ViewData& throttled_view_data() const { |
| 38 return empty_view_data_; |
| 39 } |
| 40 |
| 41 // Returns true if |event| was handled and shouldn't be further processed. |
| 42 bool ConsumeInputEvent(const blink::WebInputEvent& event); |
| 43 |
24 private: | 44 private: |
| 45 friend class PepperPluginInstanceThrottlerTest; |
| 46 |
| 47 void SetPluginThrottled(bool throttled); |
| 48 void DisablePowerSaverByRetroactiveWhitelist(); |
| 49 |
| 50 // Plugin's bounds in view space. |
| 51 blink::WebRect bounds_; |
| 52 |
| 53 // Called when the throttle state changes. |
| 54 base::Closure throttle_change_callback_; |
| 55 |
| 56 bool is_flash_plugin_; |
| 57 |
| 58 // Set to true first time plugin is clicked. Used to collect metrics. |
| 59 bool has_been_clicked_; |
| 60 |
| 61 // Indicates whether this plugin may be throttled to reduce power consumption. |
| 62 // |power_saver_enabled_| implies |is_peripheral_content_|. |
| 63 bool power_saver_enabled_; |
| 64 |
| 65 // Indicates whether this plugin was found to be peripheral content. |
| 66 // This is separately tracked from |power_saver_enabled_| to collect UMAs. |
| 67 // Always true if |power_saver_enabled_| is true. |
| 68 bool is_peripheral_content_; |
| 69 |
| 70 // Indicates if the plugin is currently throttled. |
| 71 bool plugin_throttled_; |
| 72 |
| 73 // Fake view data used by the Power Saver feature to throttle plugins. |
| 74 const ppapi::ViewData empty_view_data_; |
| 75 |
| 76 base::WeakPtrFactory<PepperPluginInstanceThrottler> weak_factory_; |
| 77 |
25 DISALLOW_COPY_AND_ASSIGN(PepperPluginInstanceThrottler); | 78 DISALLOW_COPY_AND_ASSIGN(PepperPluginInstanceThrottler); |
26 }; | 79 }; |
27 } | 80 } |
28 | 81 |
29 #endif // CONTENT_RENDERER_PEPPER_PEPPER_PLUGIN_INSTANCE_THROTTLER_H_ | 82 #endif // CONTENT_RENDERER_PEPPER_PEPPER_PLUGIN_INSTANCE_THROTTLER_H_ |
OLD | NEW |