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

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

Issue 703453004: Plugin Power Saver: Add some UMAs to test plugins in wild. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/pepper_plugin_instance_impl.h" 5 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/linked_ptr.h" 12 #include "base/memory/linked_ptr.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/metrics/histogram.h"
14 #include "base/stl_util.h" 15 #include "base/stl_util.h"
15 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
16 #include "base/strings/utf_offset_string_conversions.h" 17 #include "base/strings/utf_offset_string_conversions.h"
17 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
18 #include "base/time/time.h" 19 #include "base/time/time.h"
19 #include "cc/base/latency_info_swap_promise.h" 20 #include "cc/base/latency_info_swap_promise.h"
20 #include "cc/blink/web_layer_impl.h" 21 #include "cc/blink/web_layer_impl.h"
21 #include "cc/layers/texture_layer.h" 22 #include "cc/layers/texture_layer.h"
22 #include "cc/trees/layer_tree_host.h" 23 #include "cc/trees/layer_tree_host.h"
23 #include "content/common/content_constants_internal.h" 24 #include "content/common/content_constants_internal.h"
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 input_sequence); 384 input_sequence);
384 new_latency->TraceEventType(WebInputEventTraits::GetName(type)); 385 new_latency->TraceEventType(WebInputEventTraits::GetName(type));
385 if (old_latency) { 386 if (old_latency) {
386 new_latency->CopyLatencyFrom(*old_latency, 387 new_latency->CopyLatencyFrom(*old_latency,
387 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT); 388 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT);
388 new_latency->CopyLatencyFrom(*old_latency, 389 new_latency->CopyLatencyFrom(*old_latency,
389 ui::INPUT_EVENT_LATENCY_UI_COMPONENT); 390 ui::INPUT_EVENT_LATENCY_UI_COMPONENT);
390 } 391 }
391 } 392 }
392 393
394 // How the throttled power saver is unthrottled, if ever.
395 // These numeric values are used in UMA logs; do not change them.
396 enum PowerSaverUnthrottleMethod {
397 UNTHROTTLE_METHOD_NEVER = 0,
398 UNTHROTTLE_METHOD_BY_CLICK = 1,
399 UNTHROTTLE_METHOD_BY_WHITELIST = 2,
400 UNTHROTTLE_METHOD_NUM_ITEMS
401 };
402
403 const char kPowerSaverUnthrottleHistogram[] = "Plugin.PowerSaverUnthrottle";
404
405 void RecordUnthrottleMethodMetric(PowerSaverUnthrottleMethod method) {
406 UMA_HISTOGRAM_ENUMERATION(kPowerSaverUnthrottleHistogram, method,
407 UNTHROTTLE_METHOD_NUM_ITEMS);
408 }
409
393 bool IsFlashPlugin(PluginModule* module) { 410 bool IsFlashPlugin(PluginModule* module) {
394 return module->name() == kFlashPluginName; 411 return module->name() == kFlashPluginName;
395 } 412 }
396 413
397 } // namespace 414 } // namespace
398 415
399 // static 416 // static
400 PepperPluginInstanceImpl* PepperPluginInstanceImpl::Create( 417 PepperPluginInstanceImpl* PepperPluginInstanceImpl::Create(
401 RenderFrameImpl* render_frame, 418 RenderFrameImpl* render_frame,
402 PluginModule* module, 419 PluginModule* module,
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 : RenderFrameObserver(render_frame), 505 : RenderFrameObserver(render_frame),
489 render_frame_(render_frame), 506 render_frame_(render_frame),
490 module_(module), 507 module_(module),
491 instance_interface_(instance_interface), 508 instance_interface_(instance_interface),
492 pp_instance_(0), 509 pp_instance_(0),
493 container_(container), 510 container_(container),
494 layer_bound_to_fullscreen_(false), 511 layer_bound_to_fullscreen_(false),
495 layer_is_hardware_(false), 512 layer_is_hardware_(false),
496 plugin_url_(plugin_url), 513 plugin_url_(plugin_url),
497 power_saver_enabled_(false), 514 power_saver_enabled_(false),
515 is_peripheral_content_(false),
498 plugin_throttled_(false), 516 plugin_throttled_(false),
499 full_frame_(false), 517 full_frame_(false),
500 sent_initial_did_change_view_(false), 518 sent_initial_did_change_view_(false),
501 bound_graphics_2d_platform_(NULL), 519 bound_graphics_2d_platform_(NULL),
502 bound_compositor_(NULL), 520 bound_compositor_(NULL),
503 has_webkit_focus_(false), 521 has_webkit_focus_(false),
504 has_content_area_focus_(false), 522 has_content_area_focus_(false),
505 find_identifier_(-1), 523 find_identifier_(-1),
506 plugin_find_interface_(NULL), 524 plugin_find_interface_(NULL),
507 plugin_input_event_interface_(NULL), 525 plugin_input_event_interface_(NULL),
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 609
592 if (IsFlashPlugin(module_.get())) { 610 if (IsFlashPlugin(module_.get())) {
593 RenderThread::Get()->RecordAction( 611 RenderThread::Get()->RecordAction(
594 base::UserMetricsAction("Flash.PluginInstanceCreated")); 612 base::UserMetricsAction("Flash.PluginInstanceCreated"));
595 } 613 }
596 } 614 }
597 615
598 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() { 616 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() {
599 DCHECK(!fullscreen_container_); 617 DCHECK(!fullscreen_container_);
600 618
619 if (plugin_throttled_)
620 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_NEVER);
621
601 // Notify all the plugin objects of deletion. This will prevent blink from 622 // Notify all the plugin objects of deletion. This will prevent blink from
602 // calling into the plugin any more. 623 // calling into the plugin any more.
603 // 624 //
604 // Swap out the set so we can delete from it (the objects will try to 625 // Swap out the set so we can delete from it (the objects will try to
605 // unregister themselves inside the delete call). 626 // unregister themselves inside the delete call).
606 PluginObjectSet plugin_object_copy; 627 PluginObjectSet plugin_object_copy;
607 live_plugin_objects_.swap(plugin_object_copy); 628 live_plugin_objects_.swap(plugin_object_copy);
608 for (PluginObjectSet::iterator i = plugin_object_copy.begin(); 629 for (PluginObjectSet::iterator i = plugin_object_copy.begin();
609 i != plugin_object_copy.end(); 630 i != plugin_object_copy.end();
610 ++i) { 631 ++i) {
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 bool full_frame) { 870 bool full_frame) {
850 if (!render_frame_) 871 if (!render_frame_)
851 return false; 872 return false;
852 873
853 PluginPowerSaverHelper* power_saver_helper = 874 PluginPowerSaverHelper* power_saver_helper =
854 render_frame_->plugin_power_saver_helper(); 875 render_frame_->plugin_power_saver_helper();
855 GURL content_origin = plugin_url_.GetOrigin(); 876 GURL content_origin = plugin_url_.GetOrigin();
856 blink::WebRect bounds = container_->element().boundsInViewportSpace(); 877 blink::WebRect bounds = container_->element().boundsInViewportSpace();
857 878
858 bool cross_origin = false; 879 bool cross_origin = false;
859 power_saver_enabled_ = 880 is_peripheral_content_ =
860 CommandLine::ForCurrentProcess()->HasSwitch(
861 switches::kEnablePluginPowerSaver) &&
862 IsFlashPlugin(module_.get()) && 881 IsFlashPlugin(module_.get()) &&
863 power_saver_helper->ShouldThrottleContent( 882 power_saver_helper->ShouldThrottleContent(content_origin, bounds.width,
864 content_origin, bounds.width, bounds.height, &cross_origin); 883 bounds.height, &cross_origin);
865 884
866 if (power_saver_enabled_) { 885 power_saver_enabled_ = is_peripheral_content_ &&
886 base::CommandLine::ForCurrentProcess()->HasSwitch(
887 switches::kEnablePluginPowerSaver);
888
889 if (is_peripheral_content_) {
890 // To collect UMAs, register peripheral content even if we don't throttle.
867 power_saver_helper->RegisterPeripheralPlugin( 891 power_saver_helper->RegisterPeripheralPlugin(
868 content_origin, 892 content_origin,
869 base::Bind(&PepperPluginInstanceImpl::DisablePowerSaverAndUnthrottle, 893 base::Bind(
870 weak_factory_.GetWeakPtr())); 894 &PepperPluginInstanceImpl::DisablePowerSaverByRetroactiveWhitelist,
895 weak_factory_.GetWeakPtr()));
871 896
872 throttler_.reset(new PepperPluginInstanceThrottler( 897 if (power_saver_enabled_) {
873 base::Bind(&PepperPluginInstanceImpl::SetPluginThrottled, 898 throttler_.reset(new PepperPluginInstanceThrottler(
874 weak_factory_.GetWeakPtr(), true /* throttled */))); 899 base::Bind(&PepperPluginInstanceImpl::SetPluginThrottled,
900 weak_factory_.GetWeakPtr(), true /* throttled */)));
901 }
875 } else if (cross_origin) { 902 } else if (cross_origin) {
876 power_saver_helper->WhitelistContentOrigin(content_origin); 903 power_saver_helper->WhitelistContentOrigin(content_origin);
877 } 904 }
878 905
879 message_channel_ = MessageChannel::Create(this, &message_channel_object_); 906 message_channel_ = MessageChannel::Create(this, &message_channel_object_);
880 907
881 full_frame_ = full_frame; 908 full_frame_ = full_frame;
882 909
883 UpdateTouchEventRequest(); 910 UpdateTouchEventRequest();
884 container_->setWantsWheelEvents(IsAcceptingWheelEvents()); 911 container_->setWantsWheelEvents(IsAcceptingWheelEvents());
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 gfx::Rect caret(text_input_caret_); 1151 gfx::Rect caret(text_input_caret_);
1125 caret.Offset(view_data_.rect.point.x, view_data_.rect.point.y); 1152 caret.Offset(view_data_.rect.point.x, view_data_.rect.point.y);
1126 return caret; 1153 return caret;
1127 } 1154 }
1128 1155
1129 bool PepperPluginInstanceImpl::HandleInputEvent( 1156 bool PepperPluginInstanceImpl::HandleInputEvent(
1130 const blink::WebInputEvent& event, 1157 const blink::WebInputEvent& event,
1131 WebCursorInfo* cursor_info) { 1158 WebCursorInfo* cursor_info) {
1132 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleInputEvent"); 1159 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleInputEvent");
1133 1160
1134 if (event.type == blink::WebInputEvent::MouseUp && power_saver_enabled_) 1161 if (event.type == blink::WebInputEvent::MouseUp && is_peripheral_content_) {
1162 is_peripheral_content_ = false;
1135 power_saver_enabled_ = false; 1163 power_saver_enabled_ = false;
1136 1164
1137 if (plugin_throttled_) { 1165 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_BY_CLICK);
1138 if (event.type == blink::WebInputEvent::MouseUp) 1166
1167 if (plugin_throttled_) {
raymes 2014/11/06 22:24:48 I'm not sure if this is correct anymore. Before th
tommycli 2014/11/06 22:33:36 I think this is okay, as the body of SetPluginThro
raymes 2014/11/06 22:37:45 Ok yep I think I agree! Please still do add a test
1139 SetPluginThrottled(false /* throttled */); 1168 SetPluginThrottled(false /* throttled */);
1140 1169 return true;
1141 return true; 1170 }
1142 } 1171 }
1143 1172
1144 if (!render_frame_) 1173 if (!render_frame_)
1145 return false; 1174 return false;
1146 if (WebInputEvent::isMouseEventType(event.type)) { 1175 if (WebInputEvent::isMouseEventType(event.type)) {
1147 render_frame_->PepperDidReceiveMouseEvent(this); 1176 render_frame_->PepperDidReceiveMouseEvent(this);
1148 } 1177 }
1149 1178
1150 // Don't dispatch input events to crashed plugins. 1179 // Don't dispatch input events to crashed plugins.
1151 if (module()->is_crashed()) 1180 if (module()->is_crashed())
(...skipping 2173 matching lines...) Expand 10 before | Expand all | Expand 10 after
3325 3354
3326 void PepperPluginInstanceImpl::SetPluginThrottled(bool throttled) { 3355 void PepperPluginInstanceImpl::SetPluginThrottled(bool throttled) {
3327 // Do not throttle if we've already disabled power saver. 3356 // Do not throttle if we've already disabled power saver.
3328 if (!power_saver_enabled_ && throttled) 3357 if (!power_saver_enabled_ && throttled)
3329 return; 3358 return;
3330 3359
3331 plugin_throttled_ = throttled; 3360 plugin_throttled_ = throttled;
3332 SendDidChangeView(); 3361 SendDidChangeView();
3333 } 3362 }
3334 3363
3335 void PepperPluginInstanceImpl::DisablePowerSaverAndUnthrottle() { 3364 void PepperPluginInstanceImpl::DisablePowerSaverByRetroactiveWhitelist() {
3336 DCHECK(power_saver_enabled_); 3365 if (!is_peripheral_content_)
3366 return;
3367
3368 is_peripheral_content_ = false;
3337 power_saver_enabled_ = false; 3369 power_saver_enabled_ = false;
3338 SetPluginThrottled(false); 3370 SetPluginThrottled(false);
3371
3372 RecordUnthrottleMethodMetric(UNTHROTTLE_METHOD_BY_WHITELIST);
3339 } 3373 }
3340 3374
3341 } // namespace content 3375 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698