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/pepper/pepper_webplugin_impl.h" | |
13 #include "content/renderer/render_frame_impl.h" | 12 #include "content/renderer/render_frame_impl.h" |
14 #include "ppapi/shared_impl/ppapi_constants.h" | 13 #include "ppapi/shared_impl/ppapi_constants.h" |
15 #include "ppapi/shared_impl/scoped_pp_var.h" | |
16 #include "ppapi/shared_impl/var.h" | |
17 #include "third_party/WebKit/public/platform/WebRect.h" | 14 #include "third_party/WebKit/public/platform/WebRect.h" |
18 #include "third_party/WebKit/public/web/WebInputEvent.h" | 15 #include "third_party/WebKit/public/web/WebInputEvent.h" |
19 #include "third_party/WebKit/public/web/WebPluginParams.h" | 16 #include "third_party/WebKit/public/web/WebPluginParams.h" |
20 #include "ui/gfx/color_utils.h" | 17 #include "ui/gfx/color_utils.h" |
21 #include "url/gurl.h" | 18 #include "url/gurl.h" |
22 | 19 |
23 namespace content { | 20 namespace content { |
24 | 21 |
25 namespace { | 22 namespace { |
26 | 23 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 88 |
92 void PluginInstanceThrottlerImpl::MarkPluginEssential( | 89 void PluginInstanceThrottlerImpl::MarkPluginEssential( |
93 PowerSaverUnthrottleMethod method) { | 90 PowerSaverUnthrottleMethod method) { |
94 if (state_ == THROTTLER_STATE_MARKED_ESSENTIAL) | 91 if (state_ == THROTTLER_STATE_MARKED_ESSENTIAL) |
95 return; | 92 return; |
96 | 93 |
97 bool was_throttled = IsThrottled(); | 94 bool was_throttled = IsThrottled(); |
98 state_ = THROTTLER_STATE_MARKED_ESSENTIAL; | 95 state_ = THROTTLER_STATE_MARKED_ESSENTIAL; |
99 RecordUnthrottleMethodMetric(method); | 96 RecordUnthrottleMethodMetric(method); |
100 | 97 |
| 98 FOR_EACH_OBSERVER(Observer, observer_list_, OnPeripheralStateChange()); |
| 99 |
101 if (was_throttled) | 100 if (was_throttled) |
102 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange()); | 101 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange()); |
103 | |
104 // Notify the Power Saver test plugin of a peripheral status change. | |
105 if (web_plugin_ && web_plugin_->instance() && | |
106 plugin_module_name_ == ppapi::kPowerSaverTestPluginName) { | |
107 web_plugin_->instance()->HandleMessage(ppapi::ScopedPPVar( | |
108 ppapi::ScopedPPVar::PassRef(), | |
109 ppapi::StringVar::StringToPPVar("peripheralStatusChange"))); | |
110 } | |
111 } | 102 } |
112 | 103 |
113 void PluginInstanceThrottlerImpl::SetHiddenForPlaceholder(bool hidden) { | 104 void PluginInstanceThrottlerImpl::SetHiddenForPlaceholder(bool hidden) { |
114 is_hidden_for_placeholder_ = hidden; | 105 is_hidden_for_placeholder_ = hidden; |
115 FOR_EACH_OBSERVER(Observer, observer_list_, OnHiddenForPlaceholder(hidden)); | 106 FOR_EACH_OBSERVER(Observer, observer_list_, OnHiddenForPlaceholder(hidden)); |
116 } | 107 } |
117 | 108 |
118 blink::WebPlugin* PluginInstanceThrottlerImpl::GetWebPlugin() const { | 109 PepperWebPluginImpl* PluginInstanceThrottlerImpl::GetWebPlugin() const { |
119 DCHECK(web_plugin_); | 110 DCHECK(web_plugin_); |
120 return web_plugin_; | 111 return web_plugin_; |
121 } | 112 } |
122 | 113 |
123 const gfx::Size& PluginInstanceThrottlerImpl::GetSize() const { | 114 const gfx::Size& PluginInstanceThrottlerImpl::GetSize() const { |
124 return unobscured_size_; | 115 return unobscured_size_; |
125 } | 116 } |
126 | 117 |
127 void PluginInstanceThrottlerImpl::NotifyAudioThrottled() { | 118 void PluginInstanceThrottlerImpl::NotifyAudioThrottled() { |
128 audio_throttled_ = true; | 119 audio_throttled_ = true; |
129 audio_throttled_frame_timeout_.Reset(); | 120 audio_throttled_frame_timeout_.Reset(); |
130 } | 121 } |
131 | 122 |
132 void PluginInstanceThrottlerImpl::SetWebPlugin( | 123 void PluginInstanceThrottlerImpl::SetWebPlugin( |
133 PepperWebPluginImpl* web_plugin) { | 124 PepperWebPluginImpl* web_plugin) { |
134 DCHECK(!web_plugin_); | 125 DCHECK(!web_plugin_); |
135 web_plugin_ = web_plugin; | 126 web_plugin_ = web_plugin; |
136 } | 127 } |
137 | 128 |
138 void PluginInstanceThrottlerImpl::Initialize( | 129 void PluginInstanceThrottlerImpl::Initialize( |
139 RenderFrameImpl* frame, | 130 RenderFrameImpl* frame, |
140 const GURL& content_origin, | 131 const GURL& content_origin, |
141 const std::string& plugin_module_name, | 132 const std::string& plugin_module_name, |
142 const gfx::Size& unobscured_size) { | 133 const gfx::Size& unobscured_size) { |
143 plugin_module_name_ = plugin_module_name; | 134 DCHECK(unobscured_size_.IsEmpty()); |
144 unobscured_size_ = unobscured_size; | 135 unobscured_size_ = unobscured_size; |
145 | 136 |
146 // |frame| may be nullptr in tests. | 137 // |frame| may be nullptr in tests. |
147 if (frame) { | 138 if (frame) { |
148 PluginPowerSaverHelper* helper = frame->plugin_power_saver_helper(); | 139 PluginPowerSaverHelper* helper = frame->plugin_power_saver_helper(); |
149 bool cross_origin_main_content = false; | 140 bool cross_origin_main_content = false; |
150 if (!helper->ShouldThrottleContent(content_origin, plugin_module_name, | 141 if (!helper->ShouldThrottleContent(content_origin, plugin_module_name, |
151 unobscured_size.width(), | 142 unobscured_size.width(), |
152 unobscured_size.height(), | 143 unobscured_size.height(), |
153 &cross_origin_main_content)) { | 144 &cross_origin_main_content)) { |
| 145 DCHECK_NE(THROTTLER_STATE_MARKED_ESSENTIAL, state_); |
154 state_ = THROTTLER_STATE_MARKED_ESSENTIAL; | 146 state_ = THROTTLER_STATE_MARKED_ESSENTIAL; |
| 147 FOR_EACH_OBSERVER(Observer, observer_list_, OnPeripheralStateChange()); |
155 | 148 |
156 if (cross_origin_main_content) | 149 if (cross_origin_main_content) |
157 helper->WhitelistContentOrigin(content_origin); | 150 helper->WhitelistContentOrigin(content_origin); |
158 | 151 |
159 return; | 152 return; |
160 } | 153 } |
161 | 154 |
162 // To collect UMAs, register peripheral content even if power saver mode | 155 // To collect UMAs, register peripheral content even if power saver mode |
163 // is disabled. | 156 // is disabled. |
164 helper->RegisterPeripheralPlugin( | 157 helper->RegisterPeripheralPlugin( |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 | 211 |
219 // Release our reference to the underlying pixel data. | 212 // Release our reference to the underlying pixel data. |
220 last_received_frame_.reset(); | 213 last_received_frame_.reset(); |
221 } | 214 } |
222 | 215 |
223 state_ = THROTTLER_STATE_PLUGIN_THROTTLED; | 216 state_ = THROTTLER_STATE_PLUGIN_THROTTLED; |
224 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange()); | 217 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange()); |
225 } | 218 } |
226 | 219 |
227 } // namespace content | 220 } // namespace content |
OLD | NEW |