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

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

Issue 252663002: Track plugin input event latency (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: change PP_instance to InstanceHandle in StartTrackingLatency Created 6 years, 7 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 (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/stl_util.h" 14 #include "base/stl_util.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/strings/utf_offset_string_conversions.h" 16 #include "base/strings/utf_offset_string_conversions.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #include "cc/base/latency_info_swap_promise.h"
19 #include "cc/layers/texture_layer.h" 20 #include "cc/layers/texture_layer.h"
21 #include "cc/trees/layer_tree_host.h"
20 #include "content/common/content_constants_internal.h" 22 #include "content/common/content_constants_internal.h"
23 #include "content/common/input/web_input_event_traits.h"
21 #include "content/public/common/content_switches.h" 24 #include "content/public/common/content_switches.h"
22 #include "content/public/common/page_zoom.h" 25 #include "content/public/common/page_zoom.h"
23 #include "content/public/renderer/content_renderer_client.h" 26 #include "content/public/renderer/content_renderer_client.h"
27 #include "content/renderer/gpu/render_widget_compositor.h"
24 #include "content/renderer/pepper/common.h" 28 #include "content/renderer/pepper/common.h"
25 #include "content/renderer/pepper/content_decryptor_delegate.h" 29 #include "content/renderer/pepper/content_decryptor_delegate.h"
26 #include "content/renderer/pepper/event_conversion.h" 30 #include "content/renderer/pepper/event_conversion.h"
27 #include "content/renderer/pepper/fullscreen_container.h" 31 #include "content/renderer/pepper/fullscreen_container.h"
28 #include "content/renderer/pepper/gfx_conversion.h" 32 #include "content/renderer/pepper/gfx_conversion.h"
29 #include "content/renderer/pepper/host_dispatcher_wrapper.h" 33 #include "content/renderer/pepper/host_dispatcher_wrapper.h"
30 #include "content/renderer/pepper/host_globals.h" 34 #include "content/renderer/pepper/host_globals.h"
31 #include "content/renderer/pepper/message_channel.h" 35 #include "content/renderer/pepper/message_channel.h"
32 #include "content/renderer/pepper/npapi_glue.h" 36 #include "content/renderer/pepper/npapi_glue.h"
33 #include "content/renderer/pepper/pepper_browser_connection.h" 37 #include "content/renderer/pepper/pepper_browser_connection.h"
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 virtual bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event) 399 virtual bool HandleMouseLockedInputEvent(const blink::WebMouseEvent& event)
396 OVERRIDE { 400 OVERRIDE {
397 plugin_->HandleMouseLockedInputEvent(event); 401 plugin_->HandleMouseLockedInputEvent(event);
398 return true; 402 return true;
399 } 403 }
400 404
401 private: 405 private:
402 PepperPluginInstanceImpl* plugin_; 406 PepperPluginInstanceImpl* plugin_;
403 }; 407 };
404 408
409 void InitLatencyInfo(ui::LatencyInfo* new_latency,
410 const ui::LatencyInfo* old_latency,
411 blink::WebInputEvent::Type type,
412 int64 input_sequence) {
413 new_latency->AddLatencyNumber(
414 ui::INPUT_EVENT_LATENCY_BEGIN_PLUGIN_COMPONENT,
415 0,
416 input_sequence);
417 new_latency->TraceEventType(WebInputEventTraits::GetName(type));
418 if (old_latency) {
419 new_latency->CopyLatencyFrom(*old_latency,
420 ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT);
421 new_latency->CopyLatencyFrom(*old_latency,
422 ui::INPUT_EVENT_LATENCY_UI_COMPONENT);
423 }
424 }
425
405 } // namespace 426 } // namespace
406 427
407 // static 428 // static
408 PepperPluginInstanceImpl* PepperPluginInstanceImpl::Create( 429 PepperPluginInstanceImpl* PepperPluginInstanceImpl::Create(
409 RenderFrameImpl* render_frame, 430 RenderFrameImpl* render_frame,
410 PluginModule* module, 431 PluginModule* module,
411 WebPluginContainer* container, 432 WebPluginContainer* container,
412 const GURL& plugin_url) { 433 const GURL& plugin_url) {
413 base::Callback<const void*(const char*)> get_plugin_interface_func = 434 base::Callback<const void*(const char*)> get_plugin_interface_func =
414 base::Bind(&PluginModule::GetPluginInterface, module); 435 base::Bind(&PluginModule::GetPluginInterface, module);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 text_input_caret_bounds_(0, 0, 0, 0), 550 text_input_caret_bounds_(0, 0, 0, 0),
530 text_input_caret_set_(false), 551 text_input_caret_set_(false),
531 selection_caret_(0), 552 selection_caret_(0),
532 selection_anchor_(0), 553 selection_anchor_(0),
533 pending_user_gesture_(0.0), 554 pending_user_gesture_(0.0),
534 document_loader_(NULL), 555 document_loader_(NULL),
535 external_document_load_(false), 556 external_document_load_(false),
536 npp_(new NPP_t), 557 npp_(new NPP_t),
537 isolate_(v8::Isolate::GetCurrent()), 558 isolate_(v8::Isolate::GetCurrent()),
538 is_deleted_(false), 559 is_deleted_(false),
560 last_input_number_(0),
561 is_tracking_latency_(false),
539 view_change_weak_ptr_factory_(this), 562 view_change_weak_ptr_factory_(this),
540 weak_factory_(this) { 563 weak_factory_(this) {
541 pp_instance_ = HostGlobals::Get()->AddInstance(this); 564 pp_instance_ = HostGlobals::Get()->AddInstance(this);
542 565
543 memset(&current_print_settings_, 0, sizeof(current_print_settings_)); 566 memset(&current_print_settings_, 0, sizeof(current_print_settings_));
544 module_->InstanceCreated(this); 567 module_->InstanceCreated(this);
545 568
546 if (render_frame) { // NULL in tests 569 if (render_frame) { // NULL in tests
547 render_frame->render_view()->PepperInstanceCreated(this); 570 render_frame->render_view()->PepperInstanceCreated(this);
548 // Bind a callback now so that we can inform the RenderViewImpl when we are 571 // Bind a callback now so that we can inform the RenderViewImpl when we are
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
1084 // event. This allows out-of-process plugins to respond to the user 1107 // event. This allows out-of-process plugins to respond to the user
1085 // gesture after processing has finished here. 1108 // gesture after processing has finished here.
1086 if (WebUserGestureIndicator::isProcessingUserGesture()) { 1109 if (WebUserGestureIndicator::isProcessingUserGesture()) {
1087 pending_user_gesture_ = 1110 pending_user_gesture_ =
1088 ppapi::EventTimeToPPTimeTicks(event.timeStampSeconds); 1111 ppapi::EventTimeToPPTimeTicks(event.timeStampSeconds);
1089 pending_user_gesture_token_ = 1112 pending_user_gesture_token_ =
1090 WebUserGestureIndicator::currentUserGestureToken(); 1113 WebUserGestureIndicator::currentUserGestureToken();
1091 pending_user_gesture_token_.setOutOfProcess(); 1114 pending_user_gesture_token_.setOutOfProcess();
1092 } 1115 }
1093 1116
1117 const ui::LatencyInfo* current_event_latency_info = NULL;
1118 if (render_frame_->GetRenderWidget()) {
1119 current_event_latency_info =
1120 render_frame_->GetRenderWidget()->current_event_latency_info();
1121 }
1122
1094 // Each input event may generate more than one PP_InputEvent. 1123 // Each input event may generate more than one PP_InputEvent.
1095 for (size_t i = 0; i < events.size(); i++) { 1124 for (size_t i = 0; i < events.size(); i++) {
1125 if (is_tracking_latency_) {
1126 InitLatencyInfo(&events[i].latency_info,
1127 current_event_latency_info,
1128 event.type,
1129 last_input_number_++);
1130 }
1096 if (filtered_input_event_mask_ & event_class) 1131 if (filtered_input_event_mask_ & event_class)
1097 events[i].is_filtered = true; 1132 events[i].is_filtered = true;
1098 else 1133 else
1099 rv = true; // Unfiltered events are assumed to be handled. 1134 rv = true; // Unfiltered events are assumed to be handled.
1100 scoped_refptr<PPB_InputEvent_Shared> event_resource( 1135 scoped_refptr<PPB_InputEvent_Shared> event_resource(
1101 new PPB_InputEvent_Shared( 1136 new PPB_InputEvent_Shared(
1102 ppapi::OBJECT_IS_IMPL, pp_instance(), events[i])); 1137 ppapi::OBJECT_IS_IMPL, pp_instance(), events[i]));
1103 1138
1104 rv |= PP_ToBool(plugin_input_event_interface_->HandleInputEvent( 1139 rv |= PP_ToBool(plugin_input_event_interface_->HandleInputEvent(
1105 pp_instance(), event_resource->pp_resource())); 1140 pp_instance(), event_resource->pp_resource()));
(...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after
1976 scoped_ptr<cc::SingleReleaseCallback>* release_callback, 2011 scoped_ptr<cc::SingleReleaseCallback>* release_callback,
1977 bool use_shared_memory) { 2012 bool use_shared_memory) {
1978 if (!bound_graphics_2d_platform_) 2013 if (!bound_graphics_2d_platform_)
1979 return false; 2014 return false;
1980 return bound_graphics_2d_platform_->PrepareTextureMailbox(mailbox, 2015 return bound_graphics_2d_platform_->PrepareTextureMailbox(mailbox,
1981 release_callback); 2016 release_callback);
1982 } 2017 }
1983 2018
1984 void PepperPluginInstanceImpl::OnDestruct() { render_frame_ = NULL; } 2019 void PepperPluginInstanceImpl::OnDestruct() { render_frame_ = NULL; }
1985 2020
2021 void PepperPluginInstanceImpl::AddLatencyInfo(
2022 const std::vector<ui::LatencyInfo>& latency_info) {
2023 if (render_frame_ && render_frame_->GetRenderWidget()) {
2024 RenderWidgetCompositor* compositor =
2025 render_frame_->GetRenderWidget()->compositor();
2026 if (compositor) {
2027 for (size_t i = 0; i < latency_info.size(); i++) {
2028 scoped_ptr<cc::SwapPromise> swap_promise(
2029 new cc::LatencyInfoSwapPromise(latency_info[i]));
2030 compositor->QueueSwapPromise(swap_promise.Pass());
2031 }
2032 }
2033 }
2034 }
2035
1986 void PepperPluginInstanceImpl::AddPluginObject(PluginObject* plugin_object) { 2036 void PepperPluginInstanceImpl::AddPluginObject(PluginObject* plugin_object) {
1987 DCHECK(live_plugin_objects_.find(plugin_object) == 2037 DCHECK(live_plugin_objects_.find(plugin_object) ==
1988 live_plugin_objects_.end()); 2038 live_plugin_objects_.end());
1989 live_plugin_objects_.insert(plugin_object); 2039 live_plugin_objects_.insert(plugin_object);
1990 } 2040 }
1991 2041
1992 void PepperPluginInstanceImpl::RemovePluginObject(PluginObject* plugin_object) { 2042 void PepperPluginInstanceImpl::RemovePluginObject(PluginObject* plugin_object) {
1993 // Don't actually verify that the object is in the set since during module 2043 // Don't actually verify that the object is in the set since during module
1994 // deletion we'll be in the process of freeing them. 2044 // deletion we'll be in the process of freeing them.
1995 live_plugin_objects_.erase(plugin_object); 2045 live_plugin_objects_.erase(plugin_object);
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
2485 return ValidateRequestInputEvents(true, event_classes); 2535 return ValidateRequestInputEvents(true, event_classes);
2486 } 2536 }
2487 2537
2488 void PepperPluginInstanceImpl::ClearInputEventRequest(PP_Instance instance, 2538 void PepperPluginInstanceImpl::ClearInputEventRequest(PP_Instance instance,
2489 uint32_t event_classes) { 2539 uint32_t event_classes) {
2490 input_event_mask_ &= ~(event_classes); 2540 input_event_mask_ &= ~(event_classes);
2491 filtered_input_event_mask_ &= ~(event_classes); 2541 filtered_input_event_mask_ &= ~(event_classes);
2492 RequestInputEventsHelper(event_classes); 2542 RequestInputEventsHelper(event_classes);
2493 } 2543 }
2494 2544
2545 void PepperPluginInstanceImpl::StartTrackingLatency(PP_Instance instance) {
2546 if (module_->permissions().HasPermission(ppapi::PERMISSION_PRIVATE))
2547 is_tracking_latency_ = true;
2548 }
2549
2495 void PepperPluginInstanceImpl::ZoomChanged(PP_Instance instance, 2550 void PepperPluginInstanceImpl::ZoomChanged(PP_Instance instance,
2496 double factor) { 2551 double factor) {
2497 // We only want to tell the page to change its zoom if the whole page is the 2552 // We only want to tell the page to change its zoom if the whole page is the
2498 // plugin. If we're in an iframe, then don't do anything. 2553 // plugin. If we're in an iframe, then don't do anything.
2499 if (!IsFullPagePlugin()) 2554 if (!IsFullPagePlugin())
2500 return; 2555 return;
2501 container()->zoomLevelChanged(content::ZoomFactorToZoomLevel(factor)); 2556 container()->zoomLevelChanged(content::ZoomFactorToZoomLevel(factor));
2502 } 2557 }
2503 2558
2504 void PepperPluginInstanceImpl::ZoomLimitsChanged(PP_Instance instance, 2559 void PepperPluginInstanceImpl::ZoomLimitsChanged(PP_Instance instance,
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
3134 // Running out-of-process. Initiate an IPC call to notify the plugin 3189 // Running out-of-process. Initiate an IPC call to notify the plugin
3135 // process. 3190 // process.
3136 ppapi::proxy::HostDispatcher* dispatcher = 3191 ppapi::proxy::HostDispatcher* dispatcher =
3137 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); 3192 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance());
3138 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( 3193 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad(
3139 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data)); 3194 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data));
3140 } 3195 }
3141 } 3196 }
3142 3197
3143 } // namespace content 3198 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698