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 #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" |
11 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 11 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
12 #include "content/renderer/peripheral_content_heuristic.h" | |
13 #include "content/renderer/render_frame_impl.h" | 12 #include "content/renderer/render_frame_impl.h" |
14 #include "ppapi/shared_impl/ppapi_constants.h" | 13 #include "ppapi/shared_impl/ppapi_constants.h" |
15 #include "third_party/WebKit/public/platform/WebRect.h" | 14 #include "third_party/WebKit/public/platform/WebRect.h" |
16 #include "third_party/WebKit/public/web/WebInputEvent.h" | 15 #include "third_party/WebKit/public/web/WebInputEvent.h" |
17 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 16 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
18 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 17 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
19 #include "third_party/WebKit/public/web/WebPluginParams.h" | 18 #include "third_party/WebKit/public/web/WebPluginParams.h" |
20 #include "third_party/WebKit/public/web/WebView.h" | 19 #include "third_party/WebKit/public/web/WebView.h" |
21 #include "ui/gfx/color_utils.h" | 20 #include "ui/gfx/color_utils.h" |
22 #include "url/origin.h" | 21 #include "url/origin.h" |
(...skipping 23 matching lines...) Expand all Loading... |
46 } | 45 } |
47 | 46 |
48 // static | 47 // static |
49 void PluginInstanceThrottler::RecordUnthrottleMethodMetric( | 48 void PluginInstanceThrottler::RecordUnthrottleMethodMetric( |
50 PluginInstanceThrottlerImpl::PowerSaverUnthrottleMethod method) { | 49 PluginInstanceThrottlerImpl::PowerSaverUnthrottleMethod method) { |
51 UMA_HISTOGRAM_ENUMERATION( | 50 UMA_HISTOGRAM_ENUMERATION( |
52 "Plugin.PowerSaver.Unthrottle", method, | 51 "Plugin.PowerSaver.Unthrottle", method, |
53 PluginInstanceThrottler::UNTHROTTLE_METHOD_NUM_ITEMS); | 52 PluginInstanceThrottler::UNTHROTTLE_METHOD_NUM_ITEMS); |
54 } | 53 } |
55 | 54 |
56 // static | |
57 bool PluginInstanceThrottler::IsLargeContent(int width, int height) { | |
58 return PeripheralContentHeuristic::IsLargeContent(width, height); | |
59 } | |
60 | |
61 PluginInstanceThrottlerImpl::PluginInstanceThrottlerImpl() | 55 PluginInstanceThrottlerImpl::PluginInstanceThrottlerImpl() |
62 : state_(THROTTLER_STATE_AWAITING_KEYFRAME), | 56 : state_(THROTTLER_STATE_AWAITING_KEYFRAME), |
63 is_hidden_for_placeholder_(false), | 57 is_hidden_for_placeholder_(false), |
64 web_plugin_(nullptr), | 58 web_plugin_(nullptr), |
65 frames_examined_(0), | 59 frames_examined_(0), |
66 audio_throttled_(false), | 60 audio_throttled_(false), |
67 audio_throttled_frame_timeout_( | 61 audio_throttled_frame_timeout_( |
68 FROM_HERE, | 62 FROM_HERE, |
69 base::TimeDelta::FromMilliseconds( | 63 base::TimeDelta::FromMilliseconds( |
70 kAudioThrottledFrameTimeoutMilliseconds), | 64 kAudioThrottledFrameTimeoutMilliseconds), |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 void PluginInstanceThrottlerImpl::Initialize( | 132 void PluginInstanceThrottlerImpl::Initialize( |
139 RenderFrameImpl* frame, | 133 RenderFrameImpl* frame, |
140 const url::Origin& content_origin, | 134 const url::Origin& content_origin, |
141 const std::string& plugin_module_name, | 135 const std::string& plugin_module_name, |
142 const gfx::Size& unobscured_size) { | 136 const gfx::Size& unobscured_size) { |
143 DCHECK(unobscured_size_.IsEmpty()); | 137 DCHECK(unobscured_size_.IsEmpty()); |
144 unobscured_size_ = unobscured_size; | 138 unobscured_size_ = unobscured_size; |
145 | 139 |
146 // |frame| may be nullptr in tests. | 140 // |frame| may be nullptr in tests. |
147 if (frame) { | 141 if (frame) { |
148 PluginPowerSaverHelper* helper = frame->plugin_power_saver_helper(); | |
149 bool cross_origin_main_content = false; | 142 bool cross_origin_main_content = false; |
150 float zoom_factor = GetWebPlugin()->container()->pageZoomFactor(); | 143 float zoom_factor = GetWebPlugin()->container()->pageZoomFactor(); |
151 if (!helper->ShouldThrottleContent( | 144 if (!frame->ShouldThrottleContent( |
152 frame->GetWebFrame()->top()->securityOrigin(), content_origin, | 145 frame->GetWebFrame()->top()->securityOrigin(), content_origin, |
153 plugin_module_name, roundf(unobscured_size.width() / zoom_factor), | 146 plugin_module_name, roundf(unobscured_size.width() / zoom_factor), |
154 roundf(unobscured_size.height() / zoom_factor), | 147 roundf(unobscured_size.height() / zoom_factor), |
155 &cross_origin_main_content)) { | 148 &cross_origin_main_content)) { |
156 DCHECK_NE(THROTTLER_STATE_MARKED_ESSENTIAL, state_); | 149 DCHECK_NE(THROTTLER_STATE_MARKED_ESSENTIAL, state_); |
157 state_ = THROTTLER_STATE_MARKED_ESSENTIAL; | 150 state_ = THROTTLER_STATE_MARKED_ESSENTIAL; |
158 FOR_EACH_OBSERVER(Observer, observer_list_, OnPeripheralStateChange()); | 151 FOR_EACH_OBSERVER(Observer, observer_list_, OnPeripheralStateChange()); |
159 | 152 |
160 if (cross_origin_main_content) | 153 if (cross_origin_main_content) |
161 helper->WhitelistContentOrigin(content_origin); | 154 frame->WhitelistContentOrigin(content_origin); |
162 | 155 |
163 return; | 156 return; |
164 } | 157 } |
165 | 158 |
166 // To collect UMAs, register peripheral content even if power saver mode | 159 // To collect UMAs, register peripheral content even if power saver mode |
167 // is disabled. | 160 // is disabled. |
168 helper->RegisterPeripheralPlugin( | 161 frame->RegisterPeripheralPlugin( |
169 content_origin, | 162 content_origin, |
170 base::Bind(&PluginInstanceThrottlerImpl::MarkPluginEssential, | 163 base::Bind(&PluginInstanceThrottlerImpl::MarkPluginEssential, |
171 weak_factory_.GetWeakPtr(), UNTHROTTLE_METHOD_BY_WHITELIST)); | 164 weak_factory_.GetWeakPtr(), UNTHROTTLE_METHOD_BY_WHITELIST)); |
172 } | 165 } |
173 } | 166 } |
174 | 167 |
175 void PluginInstanceThrottlerImpl::OnImageFlush(const SkBitmap* bitmap) { | 168 void PluginInstanceThrottlerImpl::OnImageFlush(const SkBitmap* bitmap) { |
176 DCHECK(needs_representative_keyframe()); | 169 DCHECK(needs_representative_keyframe()); |
177 if (!bitmap) | 170 if (!bitmap) |
178 return; | 171 return; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 | 215 |
223 // Release our reference to the underlying pixel data. | 216 // Release our reference to the underlying pixel data. |
224 last_received_frame_.reset(); | 217 last_received_frame_.reset(); |
225 } | 218 } |
226 | 219 |
227 state_ = THROTTLER_STATE_PLUGIN_THROTTLED; | 220 state_ = THROTTLER_STATE_PLUGIN_THROTTLED; |
228 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange()); | 221 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange()); |
229 } | 222 } |
230 | 223 |
231 } // namespace content | 224 } // namespace content |
OLD | NEW |