| 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/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "content/public/common/content_constants.h" | 10 #include "content/public/common/content_constants.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 // video frames. We use this timeout to prevent waiting forever for a good | 34 // video frames. We use this timeout to prevent waiting forever for a good |
| 35 // poster image. Chosen arbitrarily. | 35 // poster image. Chosen arbitrarily. |
| 36 const int kAudioThrottledFrameTimeoutMilliseconds = 500; | 36 const int kAudioThrottledFrameTimeoutMilliseconds = 500; |
| 37 | 37 |
| 38 } // namespace | 38 } // namespace |
| 39 | 39 |
| 40 // static | 40 // static |
| 41 const int PluginInstanceThrottlerImpl::kMaximumFramesToExamine = 150; | 41 const int PluginInstanceThrottlerImpl::kMaximumFramesToExamine = 150; |
| 42 | 42 |
| 43 // static | 43 // static |
| 44 std::unique_ptr<PluginInstanceThrottler> PluginInstanceThrottler::Create() { | 44 std::unique_ptr<PluginInstanceThrottler> PluginInstanceThrottler::Create( |
| 45 return base::WrapUnique(new PluginInstanceThrottlerImpl); | 45 RenderFrame::RecordPeripheralDecision record_decision) { |
| 46 return base::WrapUnique(new PluginInstanceThrottlerImpl(record_decision)); |
| 46 } | 47 } |
| 47 | 48 |
| 48 // static | 49 // static |
| 49 void PluginInstanceThrottler::RecordUnthrottleMethodMetric( | 50 void PluginInstanceThrottler::RecordUnthrottleMethodMetric( |
| 50 PluginInstanceThrottlerImpl::PowerSaverUnthrottleMethod method) { | 51 PluginInstanceThrottlerImpl::PowerSaverUnthrottleMethod method) { |
| 51 UMA_HISTOGRAM_ENUMERATION( | 52 UMA_HISTOGRAM_ENUMERATION( |
| 52 "Plugin.PowerSaver.Unthrottle", method, | 53 "Plugin.PowerSaver.Unthrottle", method, |
| 53 PluginInstanceThrottler::UNTHROTTLE_METHOD_NUM_ITEMS); | 54 PluginInstanceThrottler::UNTHROTTLE_METHOD_NUM_ITEMS); |
| 54 } | 55 } |
| 55 | 56 |
| 56 PluginInstanceThrottlerImpl::PluginInstanceThrottlerImpl() | 57 PluginInstanceThrottlerImpl::PluginInstanceThrottlerImpl( |
| 57 : state_(THROTTLER_STATE_AWAITING_KEYFRAME), | 58 content::RenderFrame::RecordPeripheralDecision record_decision) |
| 59 : record_decision_(record_decision), |
| 60 state_(THROTTLER_STATE_AWAITING_KEYFRAME), |
| 58 is_hidden_for_placeholder_(false), | 61 is_hidden_for_placeholder_(false), |
| 59 web_plugin_(nullptr), | 62 web_plugin_(nullptr), |
| 60 frames_examined_(0), | 63 frames_examined_(0), |
| 61 audio_throttled_(false), | 64 audio_throttled_(false), |
| 62 audio_throttled_frame_timeout_( | 65 audio_throttled_frame_timeout_( |
| 63 FROM_HERE, | 66 FROM_HERE, |
| 64 base::TimeDelta::FromMilliseconds( | 67 base::TimeDelta::FromMilliseconds( |
| 65 kAudioThrottledFrameTimeoutMilliseconds), | 68 kAudioThrottledFrameTimeoutMilliseconds), |
| 66 this, | 69 this, |
| 67 &PluginInstanceThrottlerImpl::EngageThrottle), | 70 &PluginInstanceThrottlerImpl::EngageThrottle), |
| 68 weak_factory_(this) { | 71 weak_factory_(this) {} |
| 69 } | |
| 70 | 72 |
| 71 PluginInstanceThrottlerImpl::~PluginInstanceThrottlerImpl() { | 73 PluginInstanceThrottlerImpl::~PluginInstanceThrottlerImpl() { |
| 72 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottlerDestroyed()); | 74 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottlerDestroyed()); |
| 73 if (state_ != THROTTLER_STATE_MARKED_ESSENTIAL) | 75 if (state_ != THROTTLER_STATE_MARKED_ESSENTIAL) |
| 74 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_NEVER); | 76 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_NEVER); |
| 75 } | 77 } |
| 76 | 78 |
| 77 void PluginInstanceThrottlerImpl::AddObserver(Observer* observer) { | 79 void PluginInstanceThrottlerImpl::AddObserver(Observer* observer) { |
| 78 observer_list_.AddObserver(observer); | 80 observer_list_.AddObserver(observer); |
| 79 } | 81 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 const gfx::Size& unobscured_size) { | 139 const gfx::Size& unobscured_size) { |
| 138 DCHECK(unobscured_size_.IsEmpty()); | 140 DCHECK(unobscured_size_.IsEmpty()); |
| 139 unobscured_size_ = unobscured_size; | 141 unobscured_size_ = unobscured_size; |
| 140 | 142 |
| 141 // |frame| may be nullptr in tests. | 143 // |frame| may be nullptr in tests. |
| 142 if (frame) { | 144 if (frame) { |
| 143 float zoom_factor = GetWebPlugin()->container()->pageZoomFactor(); | 145 float zoom_factor = GetWebPlugin()->container()->pageZoomFactor(); |
| 144 auto status = frame->GetPeripheralContentStatus( | 146 auto status = frame->GetPeripheralContentStatus( |
| 145 frame->GetWebFrame()->top()->getSecurityOrigin(), content_origin, | 147 frame->GetWebFrame()->top()->getSecurityOrigin(), content_origin, |
| 146 gfx::Size(roundf(unobscured_size.width() / zoom_factor), | 148 gfx::Size(roundf(unobscured_size.width() / zoom_factor), |
| 147 roundf(unobscured_size.height() / zoom_factor))); | 149 roundf(unobscured_size.height() / zoom_factor)), |
| 150 record_decision_); |
| 148 if (status != RenderFrame::CONTENT_STATUS_PERIPHERAL) { | 151 if (status != RenderFrame::CONTENT_STATUS_PERIPHERAL) { |
| 149 DCHECK_NE(THROTTLER_STATE_MARKED_ESSENTIAL, state_); | 152 DCHECK_NE(THROTTLER_STATE_MARKED_ESSENTIAL, state_); |
| 150 state_ = THROTTLER_STATE_MARKED_ESSENTIAL; | 153 state_ = THROTTLER_STATE_MARKED_ESSENTIAL; |
| 151 FOR_EACH_OBSERVER(Observer, observer_list_, OnPeripheralStateChange()); | 154 FOR_EACH_OBSERVER(Observer, observer_list_, OnPeripheralStateChange()); |
| 152 | 155 |
| 153 if (status == RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_BIG) | 156 if (status == RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_BIG) |
| 154 frame->WhitelistContentOrigin(content_origin); | 157 frame->WhitelistContentOrigin(content_origin); |
| 155 | 158 |
| 156 return; | 159 return; |
| 157 } | 160 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 | 218 |
| 216 // Release our reference to the underlying pixel data. | 219 // Release our reference to the underlying pixel data. |
| 217 last_received_frame_.reset(); | 220 last_received_frame_.reset(); |
| 218 } | 221 } |
| 219 | 222 |
| 220 state_ = THROTTLER_STATE_PLUGIN_THROTTLED; | 223 state_ = THROTTLER_STATE_PLUGIN_THROTTLED; |
| 221 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange()); | 224 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange()); |
| 222 } | 225 } |
| 223 | 226 |
| 224 } // namespace content | 227 } // namespace content |
| OLD | NEW |