| 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_macros.h" | 8 #include "base/metrics/histogram_macros.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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 audio_throttled_(false), | 64 audio_throttled_(false), |
| 65 audio_throttled_frame_timeout_( | 65 audio_throttled_frame_timeout_( |
| 66 FROM_HERE, | 66 FROM_HERE, |
| 67 base::TimeDelta::FromMilliseconds( | 67 base::TimeDelta::FromMilliseconds( |
| 68 kAudioThrottledFrameTimeoutMilliseconds), | 68 kAudioThrottledFrameTimeoutMilliseconds), |
| 69 this, | 69 this, |
| 70 &PluginInstanceThrottlerImpl::EngageThrottle), | 70 &PluginInstanceThrottlerImpl::EngageThrottle), |
| 71 weak_factory_(this) {} | 71 weak_factory_(this) {} |
| 72 | 72 |
| 73 PluginInstanceThrottlerImpl::~PluginInstanceThrottlerImpl() { | 73 PluginInstanceThrottlerImpl::~PluginInstanceThrottlerImpl() { |
| 74 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottlerDestroyed()); | 74 for (auto& observer : observer_list_) |
| 75 observer.OnThrottlerDestroyed(); |
| 75 if (state_ != THROTTLER_STATE_MARKED_ESSENTIAL) | 76 if (state_ != THROTTLER_STATE_MARKED_ESSENTIAL) |
| 76 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_NEVER); | 77 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_NEVER); |
| 77 } | 78 } |
| 78 | 79 |
| 79 void PluginInstanceThrottlerImpl::AddObserver(Observer* observer) { | 80 void PluginInstanceThrottlerImpl::AddObserver(Observer* observer) { |
| 80 observer_list_.AddObserver(observer); | 81 observer_list_.AddObserver(observer); |
| 81 } | 82 } |
| 82 | 83 |
| 83 void PluginInstanceThrottlerImpl::RemoveObserver(Observer* observer) { | 84 void PluginInstanceThrottlerImpl::RemoveObserver(Observer* observer) { |
| 84 observer_list_.RemoveObserver(observer); | 85 observer_list_.RemoveObserver(observer); |
| 85 } | 86 } |
| 86 | 87 |
| 87 bool PluginInstanceThrottlerImpl::IsThrottled() const { | 88 bool PluginInstanceThrottlerImpl::IsThrottled() const { |
| 88 return state_ == THROTTLER_STATE_PLUGIN_THROTTLED; | 89 return state_ == THROTTLER_STATE_PLUGIN_THROTTLED; |
| 89 } | 90 } |
| 90 | 91 |
| 91 bool PluginInstanceThrottlerImpl::IsHiddenForPlaceholder() const { | 92 bool PluginInstanceThrottlerImpl::IsHiddenForPlaceholder() const { |
| 92 return is_hidden_for_placeholder_; | 93 return is_hidden_for_placeholder_; |
| 93 } | 94 } |
| 94 | 95 |
| 95 void PluginInstanceThrottlerImpl::MarkPluginEssential( | 96 void PluginInstanceThrottlerImpl::MarkPluginEssential( |
| 96 PowerSaverUnthrottleMethod method) { | 97 PowerSaverUnthrottleMethod method) { |
| 97 if (state_ == THROTTLER_STATE_MARKED_ESSENTIAL) | 98 if (state_ == THROTTLER_STATE_MARKED_ESSENTIAL) |
| 98 return; | 99 return; |
| 99 | 100 |
| 100 bool was_throttled = IsThrottled(); | 101 bool was_throttled = IsThrottled(); |
| 101 state_ = THROTTLER_STATE_MARKED_ESSENTIAL; | 102 state_ = THROTTLER_STATE_MARKED_ESSENTIAL; |
| 102 RecordUnthrottleMethodMetric(method); | 103 RecordUnthrottleMethodMetric(method); |
| 103 | 104 |
| 104 FOR_EACH_OBSERVER(Observer, observer_list_, OnPeripheralStateChange()); | 105 for (auto& observer : observer_list_) |
| 106 observer.OnPeripheralStateChange(); |
| 105 | 107 |
| 106 if (was_throttled) | 108 if (was_throttled) { |
| 107 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange()); | 109 for (auto& observer : observer_list_) |
| 110 observer.OnThrottleStateChange(); |
| 111 } |
| 108 } | 112 } |
| 109 | 113 |
| 110 void PluginInstanceThrottlerImpl::SetHiddenForPlaceholder(bool hidden) { | 114 void PluginInstanceThrottlerImpl::SetHiddenForPlaceholder(bool hidden) { |
| 111 is_hidden_for_placeholder_ = hidden; | 115 is_hidden_for_placeholder_ = hidden; |
| 112 FOR_EACH_OBSERVER(Observer, observer_list_, OnHiddenForPlaceholder(hidden)); | 116 for (auto& observer : observer_list_) |
| 117 observer.OnHiddenForPlaceholder(hidden); |
| 113 } | 118 } |
| 114 | 119 |
| 115 PepperWebPluginImpl* PluginInstanceThrottlerImpl::GetWebPlugin() const { | 120 PepperWebPluginImpl* PluginInstanceThrottlerImpl::GetWebPlugin() const { |
| 116 DCHECK(web_plugin_); | 121 DCHECK(web_plugin_); |
| 117 return web_plugin_; | 122 return web_plugin_; |
| 118 } | 123 } |
| 119 | 124 |
| 120 const gfx::Size& PluginInstanceThrottlerImpl::GetSize() const { | 125 const gfx::Size& PluginInstanceThrottlerImpl::GetSize() const { |
| 121 return unobscured_size_; | 126 return unobscured_size_; |
| 122 } | 127 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 144 if (frame) { | 149 if (frame) { |
| 145 float zoom_factor = GetWebPlugin()->container()->pageZoomFactor(); | 150 float zoom_factor = GetWebPlugin()->container()->pageZoomFactor(); |
| 146 auto status = frame->GetPeripheralContentStatus( | 151 auto status = frame->GetPeripheralContentStatus( |
| 147 frame->GetWebFrame()->top()->getSecurityOrigin(), content_origin, | 152 frame->GetWebFrame()->top()->getSecurityOrigin(), content_origin, |
| 148 gfx::Size(roundf(unobscured_size.width() / zoom_factor), | 153 gfx::Size(roundf(unobscured_size.width() / zoom_factor), |
| 149 roundf(unobscured_size.height() / zoom_factor)), | 154 roundf(unobscured_size.height() / zoom_factor)), |
| 150 record_decision_); | 155 record_decision_); |
| 151 if (status != RenderFrame::CONTENT_STATUS_PERIPHERAL) { | 156 if (status != RenderFrame::CONTENT_STATUS_PERIPHERAL) { |
| 152 DCHECK_NE(THROTTLER_STATE_MARKED_ESSENTIAL, state_); | 157 DCHECK_NE(THROTTLER_STATE_MARKED_ESSENTIAL, state_); |
| 153 state_ = THROTTLER_STATE_MARKED_ESSENTIAL; | 158 state_ = THROTTLER_STATE_MARKED_ESSENTIAL; |
| 154 FOR_EACH_OBSERVER(Observer, observer_list_, OnPeripheralStateChange()); | 159 for (auto& observer : observer_list_) |
| 160 observer.OnPeripheralStateChange(); |
| 155 | 161 |
| 156 if (status == RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_BIG) | 162 if (status == RenderFrame::CONTENT_STATUS_ESSENTIAL_CROSS_ORIGIN_BIG) |
| 157 frame->WhitelistContentOrigin(content_origin); | 163 frame->WhitelistContentOrigin(content_origin); |
| 158 | 164 |
| 159 return; | 165 return; |
| 160 } | 166 } |
| 161 | 167 |
| 162 // To collect UMAs, register peripheral content even if power saver mode | 168 // To collect UMAs, register peripheral content even if power saver mode |
| 163 // is disabled. | 169 // is disabled. |
| 164 frame->RegisterPeripheralPlugin( | 170 frame->RegisterPeripheralPlugin( |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 } | 212 } |
| 207 | 213 |
| 208 return IsThrottled(); | 214 return IsThrottled(); |
| 209 } | 215 } |
| 210 | 216 |
| 211 void PluginInstanceThrottlerImpl::EngageThrottle() { | 217 void PluginInstanceThrottlerImpl::EngageThrottle() { |
| 212 if (state_ != THROTTLER_STATE_AWAITING_KEYFRAME) | 218 if (state_ != THROTTLER_STATE_AWAITING_KEYFRAME) |
| 213 return; | 219 return; |
| 214 | 220 |
| 215 if (!last_received_frame_.empty()) { | 221 if (!last_received_frame_.empty()) { |
| 216 FOR_EACH_OBSERVER(Observer, observer_list_, | 222 for (auto& observer : observer_list_) |
| 217 OnKeyframeExtracted(&last_received_frame_)); | 223 observer.OnKeyframeExtracted(&last_received_frame_); |
| 218 | 224 |
| 219 // Release our reference to the underlying pixel data. | 225 // Release our reference to the underlying pixel data. |
| 220 last_received_frame_.reset(); | 226 last_received_frame_.reset(); |
| 221 } | 227 } |
| 222 | 228 |
| 223 state_ = THROTTLER_STATE_PLUGIN_THROTTLED; | 229 state_ = THROTTLER_STATE_PLUGIN_THROTTLED; |
| 224 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange()); | 230 for (auto& observer : observer_list_) |
| 231 observer.OnThrottleStateChange(); |
| 225 } | 232 } |
| 226 | 233 |
| 227 } // namespace content | 234 } // namespace content |
| OLD | NEW |