diff options
author | dgozman <dgozman@chromium.org> | 2015-11-11 20:04:44 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-12 04:05:30 +0000 |
commit | 9d4233f87abdd6547b3f8e35f2e2cdc6dbd4fce6 (patch) | |
tree | eab1096fd5503248b1322f28c4f21a36d03aad97 /content | |
parent | 0aeb458872422ae11a9d69ba3594c37ebe20959c (diff) | |
download | chromium_src-9d4233f87abdd6547b3f8e35f2e2cdc6dbd4fce6.zip chromium_src-9d4233f87abdd6547b3f8e35f2e2cdc6dbd4fce6.tar.gz chromium_src-9d4233f87abdd6547b3f8e35f2e2cdc6dbd4fce6.tar.bz2 |
[DevTools] Throttle device emulation with respect to produced frames.
We do not issue new device emulation command until the frame arrives (guarded by timeout).
BUG=none
Review URL: https://codereview.chromium.org/1436983003
Cr-Commit-Position: refs/heads/master@{#359254}
Diffstat (limited to 'content')
3 files changed, 45 insertions, 6 deletions
diff --git a/content/browser/devtools/protocol/emulation_handler.cc b/content/browser/devtools/protocol/emulation_handler.cc index cae9f00..9659991 100644 --- a/content/browser/devtools/protocol/emulation_handler.cc +++ b/content/browser/devtools/protocol/emulation_handler.cc @@ -35,11 +35,19 @@ ui::GestureProviderConfigType TouchEmulationConfigurationToType( return result; } +// When continuously applying device emulation, we wait for compositor frame +// before applying new values. If the frame does not arrive during this +// timeout, we proceed anyway. +const int kFrameTimeoutMs = 67; + } // namespace EmulationHandler::EmulationHandler(page::PageHandler* page_handler) : touch_emulation_enabled_(false), device_emulation_enabled_(false), + device_emulation_needs_update_(false), + device_emulation_waiting_for_frame_(false), + frame_timer_(new base::Timer(false, false)), page_handler_(page_handler), host_(nullptr) { @@ -59,14 +67,14 @@ void EmulationHandler::SetRenderFrameHost(RenderFrameHostImpl* host) { host_ = host; UpdateTouchEventEmulationState(); - UpdateDeviceEmulationState(); + ApplyDeviceEmulationState(); } void EmulationHandler::Detached() { touch_emulation_enabled_ = false; device_emulation_enabled_ = false; UpdateTouchEventEmulationState(); - UpdateDeviceEmulationState(); + ApplyDeviceEmulationState(); } Response EmulationHandler::SetGeolocationOverride( @@ -192,7 +200,7 @@ Response EmulationHandler::SetDeviceMetricsOverride( device_emulation_enabled_ = true; device_emulation_params_ = params; - UpdateDeviceEmulationState(); + DeviceEmulationNeedsUpdate(); return Response::OK(); } @@ -201,7 +209,7 @@ Response EmulationHandler::ClearDeviceMetricsOverride() { return Response::OK(); device_emulation_enabled_ = false; - UpdateDeviceEmulationState(); + DeviceEmulationNeedsUpdate(); return Response::OK(); } @@ -225,11 +233,31 @@ void EmulationHandler::UpdateTouchEventEmulationState() { GetWebContents()->SetForceDisableOverscrollContent(enabled); } -void EmulationHandler::UpdateDeviceEmulationState() { +void EmulationHandler::DeviceEmulationNeedsUpdate() { + device_emulation_needs_update_ = true; + if (!device_emulation_waiting_for_frame_) + ApplyDeviceEmulationState(); +} + +void EmulationHandler::OnSwapCompositorFrame() { + frame_timer_->Stop(); + device_emulation_waiting_for_frame_ = false; + if (device_emulation_needs_update_) + ApplyDeviceEmulationState(); +} + +void EmulationHandler::ApplyDeviceEmulationState() { + device_emulation_needs_update_ = false; RenderWidgetHostImpl* widget_host = host_ ? host_->GetRenderWidgetHost() : nullptr; if (!widget_host) return; + device_emulation_waiting_for_frame_ = true; + frame_timer_->Start( + FROM_HERE, + base::TimeDelta::FromMilliseconds(kFrameTimeoutMs), + base::Bind(&EmulationHandler::OnSwapCompositorFrame, + base::Unretained(this))); if (device_emulation_enabled_) { widget_host->Send(new ViewMsg_EnableDeviceEmulation( widget_host->GetRoutingID(), device_emulation_params_)); diff --git a/content/browser/devtools/protocol/emulation_handler.h b/content/browser/devtools/protocol/emulation_handler.h index c2a4bd3..4f1e26f 100644 --- a/content/browser/devtools/protocol/emulation_handler.h +++ b/content/browser/devtools/protocol/emulation_handler.h @@ -5,6 +5,7 @@ #ifndef CONTENT_BROWSER_DEVTOOLS_PROTOCOL_EMULATION_HANDLER_H_ #define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_EMULATION_HANDLER_H_ +#include "base/timer/timer.h" #include "content/browser/devtools/protocol/devtools_protocol_dispatcher.h" #include "content/browser/devtools/protocol/page_handler.h" #include "third_party/WebKit/public/web/WebDeviceEmulationParams.h" @@ -32,6 +33,7 @@ class EmulationHandler : public page::PageHandler::ScreencastListener { void SetRenderFrameHost(RenderFrameHostImpl* host); void Detached(); + void OnSwapCompositorFrame(); Response SetGeolocationOverride(double* latitude, double* longitude, @@ -59,13 +61,18 @@ class EmulationHandler : public page::PageHandler::ScreencastListener { private: WebContentsImpl* GetWebContents(); void UpdateTouchEventEmulationState(); - void UpdateDeviceEmulationState(); + + void DeviceEmulationNeedsUpdate(); + void ApplyDeviceEmulationState(); bool touch_emulation_enabled_; std::string touch_emulation_configuration_; bool device_emulation_enabled_; blink::WebDeviceEmulationParams device_emulation_params_; + bool device_emulation_needs_update_; + bool device_emulation_waiting_for_frame_; + scoped_ptr<base::Timer> frame_timer_; page::PageHandler* page_handler_; RenderFrameHostImpl* host_; diff --git a/content/browser/devtools/render_frame_devtools_agent_host.cc b/content/browser/devtools/render_frame_devtools_agent_host.cc index 71ab308..a9e7e7a 100644 --- a/content/browser/devtools/render_frame_devtools_agent_host.cc +++ b/content/browser/devtools/render_frame_devtools_agent_host.cc @@ -723,6 +723,8 @@ void RenderFrameDevToolsAgentHost::OnSwapCompositorFrame( page_handler_->OnSwapCompositorFrame(base::get<1>(param).metadata); if (input_handler_) input_handler_->OnSwapCompositorFrame(base::get<1>(param).metadata); + if (emulation_handler_) + emulation_handler_->OnSwapCompositorFrame(); if (frame_trace_recorder_ && tracing_handler_->did_initiate_recording()) { frame_trace_recorder_->OnSwapCompositorFrame( current_ ? current_->host() : nullptr, @@ -736,6 +738,8 @@ void RenderFrameDevToolsAgentHost::SynchronousSwapCompositorFrame( page_handler_->OnSynchronousSwapCompositorFrame(frame_metadata); if (input_handler_) input_handler_->OnSwapCompositorFrame(frame_metadata); + if (emulation_handler_) + emulation_handler_->OnSwapCompositorFrame(); if (frame_trace_recorder_ && tracing_handler_->did_initiate_recording()) { frame_trace_recorder_->OnSynchronousSwapCompositorFrame( current_ ? current_->host() : nullptr, |