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_frame.h" | 10 #include "content/public/renderer/render_frame.h" |
11 #include "content/public/renderer/render_thread.h" | 11 #include "content/public/renderer/render_thread.h" |
12 #include "third_party/WebKit/public/web/WebInputEvent.h" | 12 #include "third_party/WebKit/public/web/WebInputEvent.h" |
13 #include "ui/gfx/color_utils.h" | 13 #include "ui/gfx/color_utils.h" |
14 #include "url/gurl.h" | 14 #include "url/gurl.h" |
15 | 15 |
16 namespace content { | 16 namespace content { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 const char kPowerSaverUnthrottleHistogram[] = "Plugin.PowerSaver.Unthrottle"; | |
21 | |
22 void RecordUnthrottleMethodMetric( | |
23 PluginInstanceThrottlerImpl::PowerSaverUnthrottleMethod method) { | |
24 UMA_HISTOGRAM_ENUMERATION( | |
25 kPowerSaverUnthrottleHistogram, method, | |
26 PluginInstanceThrottler::UNTHROTTLE_METHOD_NUM_ITEMS); | |
27 } | |
28 | |
29 // When we give up waiting for a suitable preview frame, and simply suspend | 20 // When we give up waiting for a suitable preview frame, and simply suspend |
30 // the plugin where it's at. In milliseconds. | 21 // the plugin where it's at. In milliseconds. |
31 const int kThrottleTimeout = 5000; | 22 const int kThrottleTimeout = 5000; |
32 | 23 |
33 // Threshold for 'boring' score to accept a frame as good enough to be a | 24 // Threshold for 'boring' score to accept a frame as good enough to be a |
34 // representative keyframe. Units are the ratio of all pixels that are within | 25 // representative keyframe. Units are the ratio of all pixels that are within |
35 // the most common luma bin. The same threshold is used for history thumbnails. | 26 // the most common luma bin. The same threshold is used for history thumbnails. |
36 const double kAcceptableFrameMaximumBoringness = 0.94; | 27 const double kAcceptableFrameMaximumBoringness = 0.94; |
37 | 28 |
38 const int kMinimumConsecutiveInterestingFrames = 4; | 29 const int kMinimumConsecutiveInterestingFrames = 4; |
39 | 30 |
40 } // namespace | 31 } // namespace |
41 | 32 |
| 33 // static |
| 34 scoped_ptr<PluginInstanceThrottler> PluginInstanceThrottler::Get( |
| 35 RenderFrame* frame, |
| 36 const GURL& plugin_url, |
| 37 PluginPowerSaverMode power_saver_mode) { |
| 38 if (power_saver_mode == PluginPowerSaverMode::POWER_SAVER_MODE_ESSENTIAL) |
| 39 return nullptr; |
| 40 |
| 41 bool power_saver_enabled = |
| 42 power_saver_mode == |
| 43 PluginPowerSaverMode::POWER_SAVER_MODE_PERIPHERAL_THROTTLED; |
| 44 return make_scoped_ptr( |
| 45 new PluginInstanceThrottlerImpl(frame, plugin_url, power_saver_enabled)); |
| 46 } |
| 47 |
| 48 // static |
| 49 void PluginInstanceThrottler::RecordUnthrottleMethodMetric( |
| 50 PluginInstanceThrottlerImpl::PowerSaverUnthrottleMethod method) { |
| 51 UMA_HISTOGRAM_ENUMERATION( |
| 52 "Plugin.PowerSaver.Unthrottle", method, |
| 53 PluginInstanceThrottler::UNTHROTTLE_METHOD_NUM_ITEMS); |
| 54 } |
| 55 |
42 PluginInstanceThrottlerImpl::PluginInstanceThrottlerImpl( | 56 PluginInstanceThrottlerImpl::PluginInstanceThrottlerImpl( |
43 RenderFrame* frame, | 57 RenderFrame* frame, |
44 const GURL& plugin_url, | 58 const GURL& plugin_url, |
45 bool power_saver_enabled) | 59 bool power_saver_enabled) |
46 : state_(power_saver_enabled ? POWER_SAVER_ENABLED_AWAITING_KEYFRAME | 60 : state_(power_saver_enabled ? POWER_SAVER_ENABLED_AWAITING_KEYFRAME |
47 : POWER_SAVER_DISABLED), | 61 : POWER_SAVER_DISABLED), |
48 consecutive_interesting_frames_(0), | 62 consecutive_interesting_frames_(0), |
49 weak_factory_(this) { | 63 weak_factory_(this) { |
50 // To collect UMAs, register peripheral content even if power saver disabled. | 64 // To collect UMAs, register peripheral content even if power saver disabled. |
51 if (frame) { | 65 if (frame) { |
52 frame->RegisterPeripheralPlugin( | 66 frame->RegisterPeripheralPlugin( |
53 plugin_url.GetOrigin(), | 67 plugin_url.GetOrigin(), |
54 base::Bind(&PluginInstanceThrottlerImpl::MarkPluginEssential, | 68 base::Bind(&PluginInstanceThrottlerImpl::MarkPluginEssential, |
55 weak_factory_.GetWeakPtr(), UNTHROTTLE_METHOD_BY_WHITELIST)); | 69 weak_factory_.GetWeakPtr(), UNTHROTTLE_METHOD_BY_WHITELIST)); |
56 } | 70 } |
57 | 71 |
58 if (power_saver_enabled) { | 72 if (power_saver_enabled) { |
59 base::MessageLoop::current()->PostDelayedTask( | 73 base::MessageLoop::current()->PostDelayedTask( |
60 FROM_HERE, base::Bind(&PluginInstanceThrottlerImpl::EngageThrottle, | 74 FROM_HERE, base::Bind(&PluginInstanceThrottlerImpl::EngageThrottle, |
61 weak_factory_.GetWeakPtr()), | 75 weak_factory_.GetWeakPtr()), |
62 base::TimeDelta::FromMilliseconds(kThrottleTimeout)); | 76 base::TimeDelta::FromMilliseconds(kThrottleTimeout)); |
63 } | 77 } |
64 } | 78 } |
65 | 79 |
66 PluginInstanceThrottlerImpl::~PluginInstanceThrottlerImpl() { | 80 PluginInstanceThrottlerImpl::~PluginInstanceThrottlerImpl() { |
| 81 if (state_ != PLUGIN_INSTANCE_MARKED_ESSENTIAL) |
| 82 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_NEVER); |
67 } | 83 } |
68 | 84 |
69 void PluginInstanceThrottlerImpl::AddObserver(Observer* observer) { | 85 void PluginInstanceThrottlerImpl::AddObserver(Observer* observer) { |
70 observer_list_.AddObserver(observer); | 86 observer_list_.AddObserver(observer); |
71 } | 87 } |
72 | 88 |
73 void PluginInstanceThrottlerImpl::RemoveObserver(Observer* observer) { | 89 void PluginInstanceThrottlerImpl::RemoveObserver(Observer* observer) { |
74 observer_list_.RemoveObserver(observer); | 90 observer_list_.RemoveObserver(observer); |
75 } | 91 } |
76 | 92 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 | 144 |
129 void PluginInstanceThrottlerImpl::EngageThrottle() { | 145 void PluginInstanceThrottlerImpl::EngageThrottle() { |
130 if (state_ != POWER_SAVER_ENABLED_AWAITING_KEYFRAME) | 146 if (state_ != POWER_SAVER_ENABLED_AWAITING_KEYFRAME) |
131 return; | 147 return; |
132 | 148 |
133 state_ = POWER_SAVER_ENABLED_PLUGIN_THROTTLED; | 149 state_ = POWER_SAVER_ENABLED_PLUGIN_THROTTLED; |
134 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange()); | 150 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange()); |
135 } | 151 } |
136 | 152 |
137 } // namespace content | 153 } // namespace content |
OLD | NEW |