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/render_frame_impl.h" | 12 #include "content/renderer/render_frame_impl.h" |
13 #include "ppapi/shared_impl/ppapi_constants.h" | 13 #include "ppapi/shared_impl/ppapi_constants.h" |
14 #include "third_party/WebKit/public/platform/WebRect.h" | 14 #include "third_party/WebKit/public/platform/WebRect.h" |
15 #include "third_party/WebKit/public/web/WebInputEvent.h" | 15 #include "third_party/WebKit/public/web/WebInputEvent.h" |
16 #include "third_party/WebKit/public/web/WebPluginParams.h" | 16 #include "third_party/WebKit/public/web/WebPluginParams.h" |
17 #include "ui/gfx/color_utils.h" | 17 #include "ui/gfx/color_utils.h" |
18 #include "url/gurl.h" | 18 #include "url/gurl.h" |
19 | 19 |
20 namespace content { | 20 namespace content { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
| 24 // Maximum dimensions plugin content may have while still being considered |
| 25 // peripheral content. |
| 26 const int kPeripheralContentMaxWidth = 398; |
| 27 const int kPeripheralContentMaxHeight = 298; |
| 28 |
24 // Threshold for 'boring' score to accept a frame as good enough to be a | 29 // Threshold for 'boring' score to accept a frame as good enough to be a |
25 // representative keyframe. Units are the ratio of all pixels that are within | 30 // representative keyframe. Units are the ratio of all pixels that are within |
26 // the most common luma bin. The same threshold is used for history thumbnails. | 31 // the most common luma bin. The same threshold is used for history thumbnails. |
27 const double kAcceptableFrameMaximumBoringness = 0.94; | 32 const double kAcceptableFrameMaximumBoringness = 0.94; |
28 | 33 |
29 // When plugin audio is throttled, the plugin will sometimes stop generating | 34 // When plugin audio is throttled, the plugin will sometimes stop generating |
30 // video frames. We use this timeout to prevent waiting forever for a good | 35 // video frames. We use this timeout to prevent waiting forever for a good |
31 // poster image. Chosen arbitrarily. | 36 // poster image. Chosen arbitrarily. |
32 const int kAudioThrottledFrameTimeoutMilliseconds = 500; | 37 const int kAudioThrottledFrameTimeoutMilliseconds = 500; |
33 | 38 |
34 } // namespace | 39 } // namespace |
35 | 40 |
36 // static | 41 // static |
37 const int PluginInstanceThrottlerImpl::kMaximumFramesToExamine = 150; | 42 const int PluginInstanceThrottlerImpl::kMaximumFramesToExamine = 150; |
38 | 43 |
39 // static | 44 // static |
40 scoped_ptr<PluginInstanceThrottler> PluginInstanceThrottler::Create() { | 45 scoped_ptr<PluginInstanceThrottler> PluginInstanceThrottler::Create() { |
41 return make_scoped_ptr(new PluginInstanceThrottlerImpl); | 46 return make_scoped_ptr(new PluginInstanceThrottlerImpl); |
42 } | 47 } |
43 | 48 |
44 // static | 49 // static |
45 void PluginInstanceThrottler::RecordUnthrottleMethodMetric( | 50 void PluginInstanceThrottler::RecordUnthrottleMethodMetric( |
46 PluginInstanceThrottlerImpl::PowerSaverUnthrottleMethod method) { | 51 PluginInstanceThrottlerImpl::PowerSaverUnthrottleMethod method) { |
47 UMA_HISTOGRAM_ENUMERATION( | 52 UMA_HISTOGRAM_ENUMERATION( |
48 "Plugin.PowerSaver.Unthrottle", method, | 53 "Plugin.PowerSaver.Unthrottle", method, |
49 PluginInstanceThrottler::UNTHROTTLE_METHOD_NUM_ITEMS); | 54 PluginInstanceThrottler::UNTHROTTLE_METHOD_NUM_ITEMS); |
50 } | 55 } |
51 | 56 |
| 57 // static |
| 58 bool PluginInstanceThrottler::IsLargeContent(int width, int height) { |
| 59 return width >= kPeripheralContentMaxWidth && |
| 60 height >= kPeripheralContentMaxHeight; |
| 61 } |
| 62 |
52 PluginInstanceThrottlerImpl::PluginInstanceThrottlerImpl() | 63 PluginInstanceThrottlerImpl::PluginInstanceThrottlerImpl() |
53 : state_(THROTTLER_STATE_AWAITING_KEYFRAME), | 64 : state_(THROTTLER_STATE_AWAITING_KEYFRAME), |
54 is_hidden_for_placeholder_(false), | 65 is_hidden_for_placeholder_(false), |
55 web_plugin_(nullptr), | 66 web_plugin_(nullptr), |
56 frames_examined_(0), | 67 frames_examined_(0), |
57 audio_throttled_(false), | 68 audio_throttled_(false), |
58 audio_throttled_frame_timeout_( | 69 audio_throttled_frame_timeout_( |
59 FROM_HERE, | 70 FROM_HERE, |
60 base::TimeDelta::FromMilliseconds( | 71 base::TimeDelta::FromMilliseconds( |
61 kAudioThrottledFrameTimeoutMilliseconds), | 72 kAudioThrottledFrameTimeoutMilliseconds), |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 | 222 |
212 // Release our reference to the underlying pixel data. | 223 // Release our reference to the underlying pixel data. |
213 last_received_frame_.reset(); | 224 last_received_frame_.reset(); |
214 } | 225 } |
215 | 226 |
216 state_ = THROTTLER_STATE_PLUGIN_THROTTLED; | 227 state_ = THROTTLER_STATE_PLUGIN_THROTTLED; |
217 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange()); | 228 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange()); |
218 } | 229 } |
219 | 230 |
220 } // namespace content | 231 } // namespace content |
OLD | NEW |