| 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" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 void PluginInstanceThrottlerImpl::SetHiddenForPlaceholder(bool hidden) { | 103 void PluginInstanceThrottlerImpl::SetHiddenForPlaceholder(bool hidden) { |
| 104 is_hidden_for_placeholder_ = hidden; | 104 is_hidden_for_placeholder_ = hidden; |
| 105 FOR_EACH_OBSERVER(Observer, observer_list_, OnHiddenForPlaceholder(hidden)); | 105 FOR_EACH_OBSERVER(Observer, observer_list_, OnHiddenForPlaceholder(hidden)); |
| 106 } | 106 } |
| 107 | 107 |
| 108 blink::WebPlugin* PluginInstanceThrottlerImpl::GetWebPlugin() const { | 108 blink::WebPlugin* PluginInstanceThrottlerImpl::GetWebPlugin() const { |
| 109 DCHECK(web_plugin_); | 109 DCHECK(web_plugin_); |
| 110 return web_plugin_; | 110 return web_plugin_; |
| 111 } | 111 } |
| 112 | 112 |
| 113 const gfx::Size& PluginInstanceThrottlerImpl::GetSize() const { |
| 114 return initialized_size_; |
| 115 } |
| 116 |
| 113 void PluginInstanceThrottlerImpl::NotifyAudioThrottled() { | 117 void PluginInstanceThrottlerImpl::NotifyAudioThrottled() { |
| 114 audio_throttled_ = true; | 118 audio_throttled_ = true; |
| 115 audio_throttled_frame_timeout_.Reset(); | 119 audio_throttled_frame_timeout_.Reset(); |
| 116 } | 120 } |
| 117 | 121 |
| 118 void PluginInstanceThrottlerImpl::SetWebPlugin(blink::WebPlugin* web_plugin) { | 122 void PluginInstanceThrottlerImpl::SetWebPlugin(blink::WebPlugin* web_plugin) { |
| 119 DCHECK(!web_plugin_); | 123 DCHECK(!web_plugin_); |
| 120 web_plugin_ = web_plugin; | 124 web_plugin_ = web_plugin; |
| 121 } | 125 } |
| 122 | 126 |
| 123 void PluginInstanceThrottlerImpl::Initialize( | 127 void PluginInstanceThrottlerImpl::Initialize( |
| 124 RenderFrameImpl* frame, | 128 RenderFrameImpl* frame, |
| 125 const GURL& content_origin, | 129 const GURL& content_origin, |
| 126 const std::string& plugin_module_name, | 130 const std::string& plugin_module_name, |
| 127 const blink::WebRect& bounds) { | 131 const gfx::Size& size) { |
| 132 initialized_size_ = size; |
| 133 |
| 128 // |frame| may be nullptr in tests. | 134 // |frame| may be nullptr in tests. |
| 129 if (frame) { | 135 if (frame) { |
| 130 PluginPowerSaverHelper* helper = frame->plugin_power_saver_helper(); | 136 PluginPowerSaverHelper* helper = frame->plugin_power_saver_helper(); |
| 131 bool cross_origin_main_content = false; | 137 bool cross_origin_main_content = false; |
| 132 if (!helper->ShouldThrottleContent(content_origin, plugin_module_name, | 138 if (!helper->ShouldThrottleContent(content_origin, plugin_module_name, |
| 133 bounds.width, bounds.height, | 139 size.width(), size.height(), |
| 134 &cross_origin_main_content)) { | 140 &cross_origin_main_content)) { |
| 135 state_ = THROTTLER_STATE_MARKED_ESSENTIAL; | 141 state_ = THROTTLER_STATE_MARKED_ESSENTIAL; |
| 136 | 142 |
| 137 if (cross_origin_main_content) | 143 if (cross_origin_main_content) |
| 138 helper->WhitelistContentOrigin(content_origin); | 144 helper->WhitelistContentOrigin(content_origin); |
| 139 | 145 |
| 140 return; | 146 return; |
| 141 } | 147 } |
| 142 | 148 |
| 143 // To collect UMAs, register peripheral content even if power saver mode | 149 // To collect UMAs, register peripheral content even if power saver mode |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 | 210 |
| 205 // Release our reference to the underlying pixel data. | 211 // Release our reference to the underlying pixel data. |
| 206 last_received_frame_.reset(); | 212 last_received_frame_.reset(); |
| 207 } | 213 } |
| 208 | 214 |
| 209 state_ = THROTTLER_STATE_PLUGIN_THROTTLED; | 215 state_ = THROTTLER_STATE_PLUGIN_THROTTLED; |
| 210 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange()); | 216 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange()); |
| 211 } | 217 } |
| 212 | 218 |
| 213 } // namespace content | 219 } // namespace content |
| OLD | NEW |