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

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"
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 : RenderFrameObserver(render_frame), 488 : RenderFrameObserver(render_frame),
489 render_frame_(render_frame), 489 render_frame_(render_frame),
490 module_(module), 490 module_(module),
491 instance_interface_(instance_interface), 491 instance_interface_(instance_interface),
492 pp_instance_(0), 492 pp_instance_(0),
493 container_(container), 493 container_(container),
494 layer_bound_to_fullscreen_(false), 494 layer_bound_to_fullscreen_(false),
495 layer_is_hardware_(false), 495 layer_is_hardware_(false),
496 plugin_url_(plugin_url), 496 plugin_url_(plugin_url),
497 power_saver_enabled_(false), 497 power_saver_enabled_(false),
498 is_peripheral_content_(false),
498 plugin_throttled_(false), 499 plugin_throttled_(false),
499 full_frame_(false), 500 full_frame_(false),
500 sent_initial_did_change_view_(false), 501 sent_initial_did_change_view_(false),
501 bound_graphics_2d_platform_(NULL), 502 bound_graphics_2d_platform_(NULL),
502 bound_compositor_(NULL), 503 bound_compositor_(NULL),
503 has_webkit_focus_(false), 504 has_webkit_focus_(false),
504 has_content_area_focus_(false), 505 has_content_area_focus_(false),
505 find_identifier_(-1), 506 find_identifier_(-1),
506 plugin_find_interface_(NULL), 507 plugin_find_interface_(NULL),
507 plugin_input_event_interface_(NULL), 508 plugin_input_event_interface_(NULL),
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 container_->element().document().url(), 581 container_->element().document().url(),
581 GetPluginURL()); 582 GetPluginURL());
582 } 583 }
583 584
584 PluginPowerSaverHelper* power_saver_helper = 585 PluginPowerSaverHelper* power_saver_helper =
585 render_frame_->plugin_power_saver_helper(); 586 render_frame_->plugin_power_saver_helper();
586 GURL content_origin = plugin_url_.GetOrigin(); 587 GURL content_origin = plugin_url_.GetOrigin();
587 blink::WebRect bounds = container_->element().boundsInViewportSpace(); 588 blink::WebRect bounds = container_->element().boundsInViewportSpace();
588 589
589 bool cross_origin = false; 590 bool cross_origin = false;
590 power_saver_enabled_ = 591 is_peripheral_content_ =
591 CommandLine::ForCurrentProcess()->HasSwitch(
592 switches::kEnablePluginPowerSaver) &&
593 IsFlashPlugin(module_.get()) && 592 IsFlashPlugin(module_.get()) &&
594 power_saver_helper->ShouldThrottleContent( 593 power_saver_helper->ShouldThrottleContent(content_origin, bounds.width,
595 content_origin, bounds.width, bounds.height, &cross_origin); 594 bounds.height, &cross_origin);
596 595
597 if (power_saver_enabled_) { 596 power_saver_enabled_ = is_peripheral_content_ &&
597 CommandLine::ForCurrentProcess()->HasSwitch(
598 switches::kEnablePluginPowerSaver);
599
600 if (IsFlashPlugin(module_.get())) {
601 RenderThread::Get()->RecordAction(
602 base::UserMetricsAction("Flash.PluginInstanceCreated"));
603 }
604
605 if (is_peripheral_content_) {
606 // To collect UMAs, register peripheral content even if we don't throttle.
598 power_saver_helper->RegisterPeripheralPlugin( 607 power_saver_helper->RegisterPeripheralPlugin(
599 content_origin, 608 content_origin,
600 base::Bind(&PepperPluginInstanceImpl::DisablePowerSaverAndUnthrottle, 609 base::Bind(&PepperPluginInstanceImpl::
610 DisablePowerSaverByRetroactiveWhitelist,
601 weak_factory_.GetWeakPtr())); 611 weak_factory_.GetWeakPtr()));
602 612
603 throttler_.reset(new PepperPluginInstanceThrottler( 613 RenderThread::Get()->RecordAction(
604 base::Bind(&PepperPluginInstanceImpl::SetPluginThrottled, 614 base::UserMetricsAction("Flash.PluginInstancePeripheral"));
groby-ooo-7-16 2014/11/04 20:49:19 Can we roll Peripheral, EssentialCrossOrigin, Esse
tommycli 2014/11/04 21:48:29 Done.
605 weak_factory_.GetWeakPtr(), true /* throttled */))); 615
616 if (power_saver_enabled_) {
617 throttler_.reset(new PepperPluginInstanceThrottler(
618 base::Bind(&PepperPluginInstanceImpl::SetPluginThrottled,
619 weak_factory_.GetWeakPtr(), true /* throttled */)));
620 }
606 } else if (cross_origin) { 621 } else if (cross_origin) {
622 RenderThread::Get()->RecordAction(
623 base::UserMetricsAction("Flash.PluginInstanceEssentialCrossOrigin"));
624
607 power_saver_helper->WhitelistContentOrigin(content_origin); 625 power_saver_helper->WhitelistContentOrigin(content_origin);
626 } else {
627 RenderThread::Get()->RecordAction(
628 base::UserMetricsAction("Flash.PluginInstanceEssentialSameOrigin"));
608 } 629 }
609 } 630 }
610 631
611 RendererPpapiHostImpl* host_impl = module_->renderer_ppapi_host(); 632 RendererPpapiHostImpl* host_impl = module_->renderer_ppapi_host();
612 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this); 633 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this);
613 634
614 if (GetContentClient()->renderer() && // NULL in unit tests. 635 if (GetContentClient()->renderer() && // NULL in unit tests.
615 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name())) 636 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name()))
616 external_document_load_ = true; 637 external_document_load_ = true;
617
618 if (IsFlashPlugin(module_.get())) {
619 RenderThread::Get()->RecordAction(
620 base::UserMetricsAction("Flash.PluginInstanceCreated"));
621 }
622 } 638 }
623 639
624 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() { 640 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() {
625 DCHECK(!fullscreen_container_); 641 DCHECK(!fullscreen_container_);
626 642
627 // Notify all the plugin objects of deletion. This will prevent blink from 643 // Notify all the plugin objects of deletion. This will prevent blink from
628 // calling into the plugin any more. 644 // calling into the plugin any more.
629 // 645 //
630 // Swap out the set so we can delete from it (the objects will try to 646 // Swap out the set so we can delete from it (the objects will try to
631 // unregister themselves inside the delete call). 647 // unregister themselves inside the delete call).
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 gfx::Rect caret(text_input_caret_); 1139 gfx::Rect caret(text_input_caret_);
1124 caret.Offset(view_data_.rect.point.x, view_data_.rect.point.y); 1140 caret.Offset(view_data_.rect.point.x, view_data_.rect.point.y);
1125 return caret; 1141 return caret;
1126 } 1142 }
1127 1143
1128 bool PepperPluginInstanceImpl::HandleInputEvent( 1144 bool PepperPluginInstanceImpl::HandleInputEvent(
1129 const blink::WebInputEvent& event, 1145 const blink::WebInputEvent& event,
1130 WebCursorInfo* cursor_info) { 1146 WebCursorInfo* cursor_info) {
1131 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleInputEvent"); 1147 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleInputEvent");
1132 1148
1133 if (event.type == blink::WebInputEvent::MouseUp && power_saver_enabled_) 1149 if (event.type == blink::WebInputEvent::MouseUp && is_peripheral_content_) {
1150 is_peripheral_content_ = false;
1134 power_saver_enabled_ = false; 1151 power_saver_enabled_ = false;
1135 1152
1136 if (plugin_throttled_) { 1153 RenderThread::Get()->RecordAction(
1137 if (event.type == blink::WebInputEvent::MouseUp) 1154 base::UserMetricsAction("Flash.PluginInstanceUnthrottledByClick"));
1155
1156 if (plugin_throttled_) {
1138 SetPluginThrottled(false /* throttled */); 1157 SetPluginThrottled(false /* throttled */);
1139 1158 return true;
1140 return true; 1159 }
1141 } 1160 }
1142 1161
1143 if (!render_frame_) 1162 if (!render_frame_)
1144 return false; 1163 return false;
1145 if (WebInputEvent::isMouseEventType(event.type)) { 1164 if (WebInputEvent::isMouseEventType(event.type)) {
1146 render_frame_->PepperDidReceiveMouseEvent(this); 1165 render_frame_->PepperDidReceiveMouseEvent(this);
1147 } 1166 }
1148 1167
1149 // Don't dispatch input events to crashed plugins. 1168 // Don't dispatch input events to crashed plugins.
1150 if (module()->is_crashed()) 1169 if (module()->is_crashed())
(...skipping 2173 matching lines...) Expand 10 before | Expand all | Expand 10 after
3324 3343
3325 void PepperPluginInstanceImpl::SetPluginThrottled(bool throttled) { 3344 void PepperPluginInstanceImpl::SetPluginThrottled(bool throttled) {
3326 // Do not throttle if we've already disabled power saver. 3345 // Do not throttle if we've already disabled power saver.
3327 if (!power_saver_enabled_ && throttled) 3346 if (!power_saver_enabled_ && throttled)
3328 return; 3347 return;
3329 3348
3330 plugin_throttled_ = throttled; 3349 plugin_throttled_ = throttled;
3331 SendDidChangeView(); 3350 SendDidChangeView();
3332 } 3351 }
3333 3352
3334 void PepperPluginInstanceImpl::DisablePowerSaverAndUnthrottle() { 3353 void PepperPluginInstanceImpl::DisablePowerSaverByRetroactiveWhitelist() {
3335 DCHECK(power_saver_enabled_); 3354 if (!is_peripheral_content_)
3355 return;
3356
3357 is_peripheral_content_ = false;
3336 power_saver_enabled_ = false; 3358 power_saver_enabled_ = false;
3337 SetPluginThrottled(false); 3359 SetPluginThrottled(false);
3360
3361 RenderThread::Get()->RecordAction(
3362 base::UserMetricsAction("Flash.PluginInstanceUnthrottledByWhitelist"));
3338 } 3363 }
3339 3364
3340 } // namespace content 3365 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_plugin_instance_impl.h ('k') | tools/metrics/actions/actions.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698