Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(339)

Side by Side Diff: content/renderer/pepper/plugin_instance_throttler_impl.cc

Issue 1088763002: Plugin Power Saver: Add comprehensive browser tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@0260-plugins-overhaul-prerender-tests
Patch Set: add back PostMessage undef Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
12 #include "content/renderer/pepper/pepper_webplugin_impl.h"
11 #include "content/renderer/render_frame_impl.h" 13 #include "content/renderer/render_frame_impl.h"
14 #include "ppapi/shared_impl/ppapi_constants.h"
15 #include "ppapi/shared_impl/scoped_pp_var.h"
16 #include "ppapi/shared_impl/var.h"
12 #include "third_party/WebKit/public/platform/WebRect.h" 17 #include "third_party/WebKit/public/platform/WebRect.h"
13 #include "third_party/WebKit/public/web/WebInputEvent.h" 18 #include "third_party/WebKit/public/web/WebInputEvent.h"
14 #include "third_party/WebKit/public/web/WebPluginParams.h" 19 #include "third_party/WebKit/public/web/WebPluginParams.h"
15 #include "ui/gfx/color_utils.h" 20 #include "ui/gfx/color_utils.h"
16 #include "url/gurl.h" 21 #include "url/gurl.h"
17 22
18 namespace content { 23 namespace content {
19 24
20 namespace { 25 namespace {
21 26
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 PowerSaverUnthrottleMethod method) { 96 PowerSaverUnthrottleMethod method) {
92 if (state_ == THROTTLER_STATE_MARKED_ESSENTIAL) 97 if (state_ == THROTTLER_STATE_MARKED_ESSENTIAL)
93 return; 98 return;
94 99
95 bool was_throttled = IsThrottled(); 100 bool was_throttled = IsThrottled();
96 state_ = THROTTLER_STATE_MARKED_ESSENTIAL; 101 state_ = THROTTLER_STATE_MARKED_ESSENTIAL;
97 RecordUnthrottleMethodMetric(method); 102 RecordUnthrottleMethodMetric(method);
98 103
99 if (was_throttled) 104 if (was_throttled)
100 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange()); 105 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange());
106
107 // Notify the Power Saver test plugin of a peripheral status change.
108 if (web_plugin_ && web_plugin_->instance() &&
109 plugin_module_name_ == ppapi::kPowerSaverTestPluginName) {
110 web_plugin_->instance()->HandleMessage(ppapi::ScopedPPVar(
111 ppapi::ScopedPPVar::PassRef(),
112 ppapi::StringVar::StringToPPVar("peripheralStatusChange")));
113 }
101 } 114 }
102 115
103 void PluginInstanceThrottlerImpl::SetHiddenForPlaceholder(bool hidden) { 116 void PluginInstanceThrottlerImpl::SetHiddenForPlaceholder(bool hidden) {
104 is_hidden_for_placeholder_ = hidden; 117 is_hidden_for_placeholder_ = hidden;
105 FOR_EACH_OBSERVER(Observer, observer_list_, OnHiddenForPlaceholder(hidden)); 118 FOR_EACH_OBSERVER(Observer, observer_list_, OnHiddenForPlaceholder(hidden));
106 } 119 }
107 120
108 blink::WebPlugin* PluginInstanceThrottlerImpl::GetWebPlugin() const { 121 blink::WebPlugin* PluginInstanceThrottlerImpl::GetWebPlugin() const {
109 DCHECK(web_plugin_); 122 DCHECK(web_plugin_);
110 return web_plugin_; 123 return web_plugin_;
111 } 124 }
112 125
113 const gfx::Size& PluginInstanceThrottlerImpl::GetSize() const { 126 const gfx::Size& PluginInstanceThrottlerImpl::GetSize() const {
114 return unobscured_size_; 127 return unobscured_size_;
115 } 128 }
116 129
117 void PluginInstanceThrottlerImpl::NotifyAudioThrottled() { 130 void PluginInstanceThrottlerImpl::NotifyAudioThrottled() {
118 audio_throttled_ = true; 131 audio_throttled_ = true;
119 audio_throttled_frame_timeout_.Reset(); 132 audio_throttled_frame_timeout_.Reset();
120 } 133 }
121 134
122 void PluginInstanceThrottlerImpl::SetWebPlugin(blink::WebPlugin* web_plugin) { 135 void PluginInstanceThrottlerImpl::SetWebPlugin(
136 PepperWebPluginImpl* web_plugin) {
123 DCHECK(!web_plugin_); 137 DCHECK(!web_plugin_);
124 web_plugin_ = web_plugin; 138 web_plugin_ = web_plugin;
125 } 139 }
126 140
127 void PluginInstanceThrottlerImpl::Initialize( 141 void PluginInstanceThrottlerImpl::Initialize(
128 RenderFrameImpl* frame, 142 RenderFrameImpl* frame,
129 const GURL& content_origin, 143 const GURL& content_origin,
130 const std::string& plugin_module_name, 144 const std::string& plugin_module_name,
131 const gfx::Size& unobscured_size) { 145 const gfx::Size& unobscured_size) {
146 plugin_module_name_ = plugin_module_name;
132 unobscured_size_ = unobscured_size; 147 unobscured_size_ = unobscured_size;
133 148
134 // |frame| may be nullptr in tests. 149 // |frame| may be nullptr in tests.
135 if (frame) { 150 if (frame) {
136 PluginPowerSaverHelper* helper = frame->plugin_power_saver_helper(); 151 PluginPowerSaverHelper* helper = frame->plugin_power_saver_helper();
137 bool cross_origin_main_content = false; 152 bool cross_origin_main_content = false;
138 if (!helper->ShouldThrottleContent(content_origin, plugin_module_name, 153 if (!helper->ShouldThrottleContent(content_origin, plugin_module_name,
139 unobscured_size.width(), 154 unobscured_size.width(),
140 unobscured_size.height(), 155 unobscured_size.height(),
141 &cross_origin_main_content)) { 156 &cross_origin_main_content)) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 226
212 // Release our reference to the underlying pixel data. 227 // Release our reference to the underlying pixel data.
213 last_received_frame_.reset(); 228 last_received_frame_.reset();
214 } 229 }
215 230
216 state_ = THROTTLER_STATE_PLUGIN_THROTTLED; 231 state_ = THROTTLER_STATE_PLUGIN_THROTTLED;
217 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange()); 232 FOR_EACH_OBSERVER(Observer, observer_list_, OnThrottleStateChange());
218 } 233 }
219 234
220 } // namespace content 235 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698