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

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

Issue 904913003: Plugin Power Saver: Fix implicitly sized and below the fold plugins. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move Get Poster call to anon namespace Created 5 years, 10 months 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_PLUGIN_INSTANCE_THROTTLER_IMPL_H_ 5 #ifndef CONTENT_RENDERER_PEPPER_PLUGIN_INSTANCE_THROTTLER_IMPL_H_
6 #define CONTENT_RENDERER_PEPPER_PLUGIN_INSTANCE_THROTTLER_IMPL_H_ 6 #define CONTENT_RENDERER_PEPPER_PLUGIN_INSTANCE_THROTTLER_IMPL_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/observer_list.h" 10 #include "base/observer_list.h"
11 #include "content/common/content_export.h" 11 #include "content/common/content_export.h"
12 #include "content/public/renderer/plugin_instance_throttler.h" 12 #include "content/public/renderer/plugin_instance_throttler.h"
13 #include "ppapi/shared_impl/ppb_view_shared.h" 13 #include "ppapi/shared_impl/ppb_view_shared.h"
14 #include "third_party/WebKit/public/platform/WebRect.h"
15 14
16 namespace blink { 15 namespace blink {
17 class WebInputEvent; 16 class WebInputEvent;
17 struct WebRect;
18 } 18 }
19 19
20 class SkBitmap; 20 namespace content {
21 21
22 namespace content { 22 class RenderFrameImpl;
23 23
24 class CONTENT_EXPORT PluginInstanceThrottlerImpl 24 class CONTENT_EXPORT PluginInstanceThrottlerImpl
25 : public PluginInstanceThrottler { 25 : public PluginInstanceThrottler {
26 public: 26 public:
27 PluginInstanceThrottlerImpl(RenderFrame* frame, 27 // Maximum number of frames to examine for a suitable keyframe. After that, we
28 const GURL& plugin_url, 28 // simply suspend the plugin where it's at. Chosen arbitrarily.
29 bool power_saver_enabled); 29 static const int kMaximumFramesToExamine;
Bernhard Bauer 2015/02/09 11:52:27 Make this private, seeing that it's only used outs
tommycli 2015/02/09 19:22:11 Done.
30
31 PluginInstanceThrottlerImpl(bool power_saver_enabled);
30 32
31 ~PluginInstanceThrottlerImpl() override; 33 ~PluginInstanceThrottlerImpl() override;
32 34
33 // PluginInstanceThrottler implementation: 35 // PluginInstanceThrottler implementation:
34 void AddObserver(Observer* observer) override; 36 void AddObserver(Observer* observer) override;
35 void RemoveObserver(Observer* observer) override; 37 void RemoveObserver(Observer* observer) override;
36 bool IsThrottled() const override; 38 bool IsThrottled() const override;
37 bool IsHiddenForPlaceholder() const override; 39 bool IsHiddenForPlaceholder() const override;
38 void MarkPluginEssential(PowerSaverUnthrottleMethod method) override; 40 void MarkPluginEssential(PowerSaverUnthrottleMethod method) override;
39 void SetHiddenForPlaceholder(bool hidden) override; 41 void SetHiddenForPlaceholder(bool hidden) override;
40 42
41 bool needs_representative_keyframe() const { 43 bool needs_representative_keyframe() const {
42 return state_ == POWER_SAVER_ENABLED_AWAITING_KEYFRAME; 44 return state_ == THROTTLER_STATE_AWAITING_KEYFRAME;
43 } 45 }
44 46
45 bool power_saver_enabled() const { 47 bool power_saver_enabled() const {
46 return state_ == POWER_SAVER_ENABLED_AWAITING_KEYFRAME || 48 return state_ == THROTTLER_STATE_AWAITING_KEYFRAME ||
47 state_ == POWER_SAVER_ENABLED_PLUGIN_THROTTLED; 49 state_ == THROTTLER_STATE_PLUGIN_THROTTLED;
48 } 50 }
49 51
52 // Throttler needs to be initialized with the real plugin's view bounds.
53 void Initialize(RenderFrameImpl* frame,
54 const GURL& content_origin,
55 const std::string& plugin_module_name,
56 const blink::WebRect& bounds);
57
50 // Called when the plugin flushes it's graphics context. Supplies the 58 // Called when the plugin flushes it's graphics context. Supplies the
51 // throttler with a candidate to use as the representative keyframe. 59 // throttler with a candidate to use as the representative keyframe.
52 void OnImageFlush(const SkBitmap* bitmap); 60 void OnImageFlush(const SkBitmap* bitmap);
53 61
54 // Returns true if |event| was handled and shouldn't be further processed. 62 // Returns true if |event| was handled and shouldn't be further processed.
55 bool ConsumeInputEvent(const blink::WebInputEvent& event); 63 bool ConsumeInputEvent(const blink::WebInputEvent& event);
56 64
57 private: 65 private:
58 friend class PluginInstanceThrottlerImplTest; 66 friend class PluginInstanceThrottlerImplTest;
59 67
60 enum State { 68 enum ThrottlerState {
61 // Initial state if Power Saver is disabled. We are just collecting metrics. 69 // Power saver is disabled, but the plugin instance is still peripheral.
62 POWER_SAVER_DISABLED, 70 THROTTLER_STATE_POWER_SAVER_DISABLED,
63 // Initial state if Power Saver is enabled. Waiting for a keyframe. 71 // Plugin has been found to be peripheral, Plugin Power Saver is enabled,
64 POWER_SAVER_ENABLED_AWAITING_KEYFRAME, 72 // and throttler is awaiting a representative keyframe.
65 // We've chosen a keyframe and the plug-in is throttled. 73 THROTTLER_STATE_AWAITING_KEYFRAME,
66 POWER_SAVER_ENABLED_PLUGIN_THROTTLED, 74 // A representative keyframe has been chosen and the plugin is throttled.
67 // Plugin instance is no longer considered peripheral. This can happen from 75 THROTTLER_STATE_PLUGIN_THROTTLED,
68 // a user click, whitelisting, or some other reason. We can end up in this 76 // Plugin instance has been marked essential.
69 // state regardless of whether power saver is enabled. 77 THROTTLER_STATE_MARKED_ESSENTIAL,
70 PLUGIN_INSTANCE_MARKED_ESSENTIAL
71 }; 78 };
72 79
73 void EngageThrottle(); 80 void EngageThrottle();
74 81
75 void TimeoutKeyframeExtraction(); 82 ThrottlerState state_;
76
77 State state_;
78 83
79 bool is_hidden_for_placeholder_; 84 bool is_hidden_for_placeholder_;
80 85
81 // Number of consecutive interesting frames we've encountered. 86 // Number of consecutive interesting frames we've encountered.
82 int consecutive_interesting_frames_; 87 int consecutive_interesting_frames_;
83 88
84 // If true, take the next frame as the keyframe regardless of interestingness. 89 // Number of frames we've examined to find a keyframe.
85 bool keyframe_extraction_timed_out_; 90 int frames_examined_;
86 91
87 ObserverList<Observer> observer_list_; 92 ObserverList<Observer> observer_list_;
88 93
89 base::WeakPtrFactory<PluginInstanceThrottlerImpl> weak_factory_; 94 base::WeakPtrFactory<PluginInstanceThrottlerImpl> weak_factory_;
90 95
91 DISALLOW_COPY_AND_ASSIGN(PluginInstanceThrottlerImpl); 96 DISALLOW_COPY_AND_ASSIGN(PluginInstanceThrottlerImpl);
92 }; 97 };
93 } 98 }
94 99
95 #endif // CONTENT_RENDERER_PEPPER_PLUGIN_INSTANCE_THROTTLER_IMPL_H_ 100 #endif // CONTENT_RENDERER_PEPPER_PLUGIN_INSTANCE_THROTTLER_IMPL_H_
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_plugin_instance_impl.cc ('k') | content/renderer/pepper/plugin_instance_throttler_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698