Chromium Code Reviews| Index: content/browser/renderer_host/input/synthetic_gesture_controller.cc |
| diff --git a/content/browser/renderer_host/input/synthetic_gesture_controller.cc b/content/browser/renderer_host/input/synthetic_gesture_controller.cc |
| index 1ab65e7fa8733a96fadce29efaa916fd17701690..d3ffa6a61297ff96d3515a8957a6d617c3d0bd6a 100644 |
| --- a/content/browser/renderer_host/input/synthetic_gesture_controller.cc |
| +++ b/content/browser/renderer_host/input/synthetic_gesture_controller.cc |
| @@ -40,16 +40,35 @@ void SyntheticGestureController::QueueSyntheticGesture( |
| StartGesture(*pending_gesture_queue_.FrontGesture()); |
| } |
| -void SyntheticGestureController::RequestBeginFrame() { |
| +void SyntheticGestureController::RequestBeginFrameIfNecessary() { |
| + if (dispatch_timer_.IsRunning()) |
| + return; |
| delegate_->RequestBeginFrameForSynthesizedInput( |
| base::BindOnce(&SyntheticGestureController::OnBeginFrame, |
| weak_ptr_factory_.GetWeakPtr())); |
| } |
| void SyntheticGestureController::OnBeginFrame() { |
| - // TODO(sad): Instead of dispatching the events immediately, dispatch after an |
| - // offset. |
| - DispatchNextEvent(); |
| + constexpr base::TimeDelta kSynthesizedDispatchDelay = |
|
dtapuska
2017/05/19 18:32:27
I think we need an explanation around why 2 is a *
sadrul
2017/05/19 18:46:03
Added a note. PTAL.
|
| + base::TimeDelta::FromMilliseconds(2); |
| + base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| + FROM_HERE, |
| + base::BindOnce(&SyntheticGestureController::StartTimer, |
| + weak_ptr_factory_.GetWeakPtr()), |
| + kSynthesizedDispatchDelay); |
| +} |
| + |
| +void SyntheticGestureController::StartTimer() { |
| + // TODO(sad): Change the interval to allow sending multiple events per begin |
| + // frame. |
| + dispatch_timer_.Start( |
| + FROM_HERE, base::TimeDelta::FromMicroseconds(16666), |
| + base::BindRepeating( |
| + [](base::WeakPtr<SyntheticGestureController> weak_ptr) { |
| + if (weak_ptr) |
| + weak_ptr->DispatchNextEvent(base::TimeTicks::Now()); |
| + }, |
| + weak_ptr_factory_.GetWeakPtr())); |
| } |
| bool SyntheticGestureController::DispatchNextEvent(base::TimeTicks timestamp) { |
| @@ -63,14 +82,14 @@ bool SyntheticGestureController::DispatchNextEvent(base::TimeTicks timestamp) { |
| timestamp, gesture_target_.get()); |
| if (result == SyntheticGesture::GESTURE_RUNNING) { |
| - RequestBeginFrame(); |
| + RequestBeginFrameIfNecessary(); |
|
dtapuska
2017/05/19 18:32:27
Could this be a DCHECK(dispatch_timer_.IsRunning()
sadrul
2017/05/19 18:46:03
I had a DCHECK() at the beginning of the function
sadrul
2017/05/19 19:02:49
I have gone ahead and added the DCHECK() back, and
|
| return true; |
| } |
| pending_gesture_queue_.mark_current_gesture_complete(result); |
| } |
| if (!delegate_->HasGestureStopped()) { |
| - RequestBeginFrame(); |
| + RequestBeginFrameIfNecessary(); |
|
dtapuska
2017/05/19 18:32:27
same here.
|
| return true; |
| } |
| @@ -78,8 +97,10 @@ bool SyntheticGestureController::DispatchNextEvent(base::TimeTicks timestamp) { |
| pending_gesture_queue_.FrontCallback(), |
| pending_gesture_queue_.current_gesture_result()); |
| pending_gesture_queue_.Pop(); |
| - if (pending_gesture_queue_.IsEmpty()) |
| + if (pending_gesture_queue_.IsEmpty()) { |
| + dispatch_timer_.Stop(); |
| return false; |
| + } |
| StartGesture(*pending_gesture_queue_.FrontGesture()); |
| return true; |
| } |
| @@ -88,7 +109,7 @@ void SyntheticGestureController::StartGesture(const SyntheticGesture& gesture) { |
| TRACE_EVENT_ASYNC_BEGIN0("input,benchmark", |
| "SyntheticGestureController::running", |
| &gesture); |
| - RequestBeginFrame(); |
| + RequestBeginFrameIfNecessary(); |
| } |
| void SyntheticGestureController::StopGesture( |