Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(524)

Side by Side Diff: content/renderer/pepper/pepper_plugin_instance_throttler.h

Issue 707113002: Plugin Power Saver: Refactor Plugin Instance Throttling code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@0190-plugin-power-saver-add-some-umas
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
14 namespace blink {
15 class WebInputEvent;
16 }
10 17
11 namespace content { 18 namespace content {
12 19
13 // Throttles Pepper Plugin instances in Power Saver mode. Currently just a 20 class PepperPluginInstanceImpl;
14 // stub implementation that engages throttling after a fixed timeout. 21
15 // In the future, will examine plugin frames to find a suitable preview 22 // Manages the Plugin Power Saver feature for a single Pepper plugin instance.
16 // image before engaging throttling. 23 class CONTENT_EXPORT PepperPluginInstanceThrottler {
17 class PepperPluginInstanceThrottler {
18 public: 24 public:
19 // |throttle_closure| is called to engage throttling. 25 PepperPluginInstanceThrottler(PepperPluginInstanceImpl* instance,
20 explicit PepperPluginInstanceThrottler(const base::Closure& throttle_closure); 26 const base::Closure& throttle_change_callback);
21 27
22 virtual ~PepperPluginInstanceThrottler(); 28 virtual ~PepperPluginInstanceThrottler();
23 29
30 bool is_throttled() const { return plugin_throttled_; }
31 const ppapi::ViewData& throttled_view_data() const {
32 return empty_view_data_;
33 }
34
35 // Returns true if |event| was handled and shouldn't be further processed.
36 bool ConsumeInputEvent(const blink::WebInputEvent& event);
37
38 protected:
39 // Used only for testing.
40 PepperPluginInstanceThrottler(const base::Closure& throttle_change_callback,
41 bool power_saver_enabled,
42 bool is_peripheral_content);
43
44 void SetPluginThrottled(bool throttled);
45 void DisablePowerSaverByRetroactiveWhitelist();
46
24 private: 47 private:
48 PepperPluginInstanceImpl* instance_;
49
50 // Called when the throttle state changes.
51 base::Closure throttle_change_callback_;
52
53 // Set to true first time plugin is clicked. Used to collect metrics.
54 bool has_been_clicked_;
55
56 // Indicates whether this plugin may be throttled to reduce power consumption.
57 // |power_saver_enabled_| implies |is_peripheral_content_|.
58 bool power_saver_enabled_;
59
60 // Indicates whether this plugin was found to be peripheral content.
61 // This is separately tracked from |power_saver_enabled_| to collect UMAs.
62 // Always true if |power_saver_enabled_| is true.
63 bool is_peripheral_content_;
64
65 // Indicates if the plugin is currently throttled.
66 bool plugin_throttled_;
67
68 // Fake view data used by the Power Saver feature to throttle plugins.
69 const ppapi::ViewData empty_view_data_;
70
71 base::WeakPtrFactory<PepperPluginInstanceThrottler> weak_factory_;
72
25 DISALLOW_COPY_AND_ASSIGN(PepperPluginInstanceThrottler); 73 DISALLOW_COPY_AND_ASSIGN(PepperPluginInstanceThrottler);
26 }; 74 };
27 } 75 }
28 76
29 #endif // CONTENT_RENDERER_PEPPER_PEPPER_PLUGIN_INSTANCE_THROTTLER_H_ 77 #endif // CONTENT_RENDERER_PEPPER_PEPPER_PLUGIN_INSTANCE_THROTTLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698