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

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

Issue 1015023002: Plugin Power Saver: Throttle 'large' plugins that appear small. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 #include "content/renderer/pepper/plugin_instance_throttler_impl.h" 5 #include "content/renderer/pepper/plugin_instance_throttler_impl.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "content/public/common/content_constants.h" 9 #include "content/public/common/content_constants.h"
10 #include "content/public/renderer/render_thread.h" 10 #include "content/public/renderer/render_thread.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 } 46 }
47 47
48 PluginInstanceThrottlerImpl::PluginInstanceThrottlerImpl( 48 PluginInstanceThrottlerImpl::PluginInstanceThrottlerImpl(
49 bool power_saver_enabled) 49 bool power_saver_enabled)
50 : state_(power_saver_enabled ? THROTTLER_STATE_AWAITING_KEYFRAME 50 : state_(power_saver_enabled ? THROTTLER_STATE_AWAITING_KEYFRAME
51 : THROTTLER_STATE_POWER_SAVER_DISABLED), 51 : THROTTLER_STATE_POWER_SAVER_DISABLED),
52 is_hidden_for_placeholder_(false), 52 is_hidden_for_placeholder_(false),
53 web_plugin_(nullptr), 53 web_plugin_(nullptr),
54 consecutive_interesting_frames_(0), 54 consecutive_interesting_frames_(0),
55 frames_examined_(0), 55 frames_examined_(0),
56 initialized_width_(0),
57 initialized_height_(0),
56 weak_factory_(this) { 58 weak_factory_(this) {
57 } 59 }
58 60
59 PluginInstanceThrottlerImpl::~PluginInstanceThrottlerImpl() { 61 PluginInstanceThrottlerImpl::~PluginInstanceThrottlerImpl() {
60 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottlerDestroyed()); 62 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottlerDestroyed());
61 if (state_ != THROTTLER_STATE_MARKED_ESSENTIAL) 63 if (state_ != THROTTLER_STATE_MARKED_ESSENTIAL)
62 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_NEVER); 64 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_NEVER);
63 } 65 }
64 66
65 void PluginInstanceThrottlerImpl::AddObserver(Observer* observer) { 67 void PluginInstanceThrottlerImpl::AddObserver(Observer* observer) {
(...skipping 28 matching lines...) Expand all
94 void PluginInstanceThrottlerImpl::SetHiddenForPlaceholder(bool hidden) { 96 void PluginInstanceThrottlerImpl::SetHiddenForPlaceholder(bool hidden) {
95 is_hidden_for_placeholder_ = hidden; 97 is_hidden_for_placeholder_ = hidden;
96 FOR_EACH_OBSERVER(Observer, observer_list_, OnHiddenForPlaceholder(hidden)); 98 FOR_EACH_OBSERVER(Observer, observer_list_, OnHiddenForPlaceholder(hidden));
97 } 99 }
98 100
99 blink::WebPlugin* PluginInstanceThrottlerImpl::GetWebPlugin() const { 101 blink::WebPlugin* PluginInstanceThrottlerImpl::GetWebPlugin() const {
100 DCHECK(web_plugin_); 102 DCHECK(web_plugin_);
101 return web_plugin_; 103 return web_plugin_;
102 } 104 }
103 105
106 int PluginInstanceThrottlerImpl::GetWidth() const {
107 return initialized_width_;
108 }
109
110 int PluginInstanceThrottlerImpl::GetHeight() const {
111 return initialized_height_;
112 }
113
104 void PluginInstanceThrottlerImpl::SetWebPlugin(blink::WebPlugin* web_plugin) { 114 void PluginInstanceThrottlerImpl::SetWebPlugin(blink::WebPlugin* web_plugin) {
105 DCHECK(!web_plugin_); 115 DCHECK(!web_plugin_);
106 web_plugin_ = web_plugin; 116 web_plugin_ = web_plugin;
107 } 117 }
108 118
109 void PluginInstanceThrottlerImpl::Initialize( 119 void PluginInstanceThrottlerImpl::Initialize(
110 RenderFrameImpl* frame, 120 RenderFrameImpl* frame,
111 const GURL& content_origin, 121 const GURL& content_origin,
112 const std::string& plugin_module_name, 122 const std::string& plugin_module_name,
113 const blink::WebRect& bounds) { 123 int width,
124 int height) {
125 initialized_width_ = width;
126 initialized_height_ = height;
127
114 // |frame| may be nullptr in tests. 128 // |frame| may be nullptr in tests.
115 if (frame) { 129 if (frame) {
116 PluginPowerSaverHelper* helper = frame->plugin_power_saver_helper(); 130 PluginPowerSaverHelper* helper = frame->plugin_power_saver_helper();
117 bool cross_origin_main_content = false; 131 bool cross_origin_main_content = false;
118 if (!helper->ShouldThrottleContent(content_origin, plugin_module_name, 132 if (!helper->ShouldThrottleContent(content_origin, plugin_module_name,
119 bounds.width, bounds.height, 133 width, height,
120 &cross_origin_main_content)) { 134 &cross_origin_main_content)) {
121 state_ = THROTTLER_STATE_MARKED_ESSENTIAL; 135 state_ = THROTTLER_STATE_MARKED_ESSENTIAL;
122 136
123 if (cross_origin_main_content) 137 if (cross_origin_main_content)
124 helper->WhitelistContentOrigin(content_origin); 138 helper->WhitelistContentOrigin(content_origin);
125 139
126 return; 140 return;
127 } 141 }
128 142
129 // To collect UMAs, register peripheral content even if power saver mode 143 // To collect UMAs, register peripheral content even if power saver mode
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 191
178 void PluginInstanceThrottlerImpl::EngageThrottle() { 192 void PluginInstanceThrottlerImpl::EngageThrottle() {
179 if (state_ != THROTTLER_STATE_AWAITING_KEYFRAME) 193 if (state_ != THROTTLER_STATE_AWAITING_KEYFRAME)
180 return; 194 return;
181 195
182 state_ = THROTTLER_STATE_PLUGIN_THROTTLED; 196 state_ = THROTTLER_STATE_PLUGIN_THROTTLED;
183 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange()); 197 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange());
184 } 198 }
185 199
186 } // namespace content 200 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698