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

Side by Side Diff: content/browser/renderer_host/input/synthetic_gesture_controller.cc

Issue 2856423002: input: Change how synthesized events are dispatched in telemetry tests. (Closed)
Patch Set: . Created 3 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/browser/renderer_host/input/synthetic_gesture_controller.h" 5 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/threading/thread_task_runner_handle.h"
9 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
10 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" 11 #include "content/browser/renderer_host/input/synthetic_gesture_target.h"
11 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" 12 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h"
12 #include "content/common/input_messages.h" 13 #include "content/common/input_messages.h"
13 #include "content/public/browser/render_widget_host.h" 14 #include "content/public/browser/render_widget_host.h"
14 15
15 namespace content { 16 namespace content {
16 17
17 SyntheticGestureController::SyntheticGestureController( 18 SyntheticGestureController::SyntheticGestureController(
18 std::unique_ptr<SyntheticGestureTarget> gesture_target) 19 std::unique_ptr<SyntheticGestureTarget> gesture_target,
19 : gesture_target_(std::move(gesture_target)) {} 20 BeginFrameRequestCallback begin_frame_callback)
21 : gesture_target_(std::move(gesture_target)),
22 begin_frame_callback_(std::move(begin_frame_callback)),
23 weak_ptr_factory_(this) {}
20 24
21 SyntheticGestureController::~SyntheticGestureController() {} 25 SyntheticGestureController::~SyntheticGestureController() {}
22 26
23 void SyntheticGestureController::QueueSyntheticGesture( 27 void SyntheticGestureController::QueueSyntheticGesture(
24 std::unique_ptr<SyntheticGesture> synthetic_gesture, 28 std::unique_ptr<SyntheticGesture> synthetic_gesture,
25 const OnGestureCompleteCallback& completion_callback) { 29 const OnGestureCompleteCallback& completion_callback) {
26 DCHECK(synthetic_gesture); 30 DCHECK(synthetic_gesture);
27 31
28 bool was_empty = pending_gesture_queue_.IsEmpty(); 32 bool was_empty = pending_gesture_queue_.IsEmpty();
29 33
30 pending_gesture_queue_.Push(std::move(synthetic_gesture), 34 pending_gesture_queue_.Push(std::move(synthetic_gesture),
31 completion_callback); 35 completion_callback);
32 36
33 if (was_empty) 37 if (was_empty)
34 StartGesture(*pending_gesture_queue_.FrontGesture()); 38 StartGesture(*pending_gesture_queue_.FrontGesture());
35 } 39 }
36 40
37 void SyntheticGestureController::Flush(base::TimeTicks timestamp) { 41 void SyntheticGestureController::OnBeginFrame() {
42 // TODO(sad): Instead of dispatching the events immediately, dispatch after an
43 // offset.
44 DispatchNextEvent();
45 }
46
47 bool SyntheticGestureController::DispatchNextEvent(base::TimeTicks timestamp) {
38 TRACE_EVENT0("input", "SyntheticGestureController::Flush"); 48 TRACE_EVENT0("input", "SyntheticGestureController::Flush");
39 if (pending_gesture_queue_.IsEmpty()) 49 if (pending_gesture_queue_.IsEmpty())
40 return; 50 return false;
41
42 if (pending_gesture_result_)
dtapuska 2017/05/16 14:39:41 Doesn't removing the pending_gesture_result_ not c
dtapuska 2017/05/16 14:40:52 Ugh; no this submitted the wrong comment. I looke
sadrul 2017/05/16 17:35:05 Yep, done.
43 return;
44 51
45 SyntheticGesture* gesture = pending_gesture_queue_.FrontGesture(); 52 SyntheticGesture* gesture = pending_gesture_queue_.FrontGesture();
dtapuska 2017/05/16 14:39:41 Do we need this variable on the stack? I feel some
sadrul 2017/05/16 17:35:05 Done.
46 SyntheticGesture::Result result = 53 SyntheticGesture::Result result =
47 gesture->ForwardInputEvents(timestamp, gesture_target_.get()); 54 gesture->ForwardInputEvents(timestamp, gesture_target_.get());
48 55
49 if (result == SyntheticGesture::GESTURE_RUNNING) { 56 if (result == SyntheticGesture::GESTURE_RUNNING) {
50 gesture_target_->SetNeedsFlush(); 57 begin_frame_callback_.Run(
51 return; 58 base::BindOnce(&SyntheticGestureController::OnBeginFrame,
59 weak_ptr_factory_.GetWeakPtr()));
60 return true;
52 } 61 }
53 62
54 // It's possible that all events generated by the gesture have been fully
55 // dispatched at this point, in which case |OnDidFlushInput()| was called
56 // before |pending_gesture_result_| was initialized. Requesting another flush
57 // will trigger the necessary gesture-ending call to |OnDidFlushInput()|.
58 pending_gesture_result_.reset(new SyntheticGesture::Result(result));
59 gesture_target_->SetNeedsFlush();
60 }
61
62 void SyntheticGestureController::OnDidFlushInput() {
63 if (!pending_gesture_result_)
64 return;
65
66 DCHECK(!pending_gesture_queue_.IsEmpty());
67 auto pending_gesture_result = std::move(pending_gesture_result_);
68 StopGesture(*pending_gesture_queue_.FrontGesture(), 63 StopGesture(*pending_gesture_queue_.FrontGesture(),
69 pending_gesture_queue_.FrontCallback(), 64 pending_gesture_queue_.FrontCallback(), result);
70 *pending_gesture_result);
71 pending_gesture_queue_.Pop(); 65 pending_gesture_queue_.Pop();
72 66 if (pending_gesture_queue_.IsEmpty())
73 if (!pending_gesture_queue_.IsEmpty()) 67 return false;
74 StartGesture(*pending_gesture_queue_.FrontGesture()); 68 StartGesture(*pending_gesture_queue_.FrontGesture());
69 return true;
75 } 70 }
76 71
77 void SyntheticGestureController::StartGesture(const SyntheticGesture& gesture) { 72 void SyntheticGestureController::StartGesture(const SyntheticGesture& gesture) {
78 TRACE_EVENT_ASYNC_BEGIN0("input,benchmark", 73 TRACE_EVENT_ASYNC_BEGIN0("input,benchmark",
79 "SyntheticGestureController::running", 74 "SyntheticGestureController::running",
80 &gesture); 75 &gesture);
81 gesture_target_->SetNeedsFlush(); 76 begin_frame_callback_.Run(
77 base::BindOnce(&SyntheticGestureController::OnBeginFrame,
78 weak_ptr_factory_.GetWeakPtr()));
82 } 79 }
83 80
84 void SyntheticGestureController::StopGesture( 81 void SyntheticGestureController::StopGesture(
85 const SyntheticGesture& gesture, 82 const SyntheticGesture& gesture,
86 const OnGestureCompleteCallback& completion_callback, 83 const OnGestureCompleteCallback& completion_callback,
87 SyntheticGesture::Result result) { 84 SyntheticGesture::Result result) {
88 DCHECK_NE(result, SyntheticGesture::GESTURE_RUNNING); 85 DCHECK_NE(result, SyntheticGesture::GESTURE_RUNNING);
89 TRACE_EVENT_ASYNC_END0("input,benchmark", 86 TRACE_EVENT_ASYNC_END0("input,benchmark",
90 "SyntheticGestureController::running", 87 "SyntheticGestureController::running",
91 &gesture); 88 &gesture);
92 89
93 completion_callback.Run(result); 90 completion_callback.Run(result);
94 } 91 }
95 92
96 SyntheticGestureController::GestureAndCallbackQueue::GestureAndCallbackQueue() { 93 SyntheticGestureController::GestureAndCallbackQueue::GestureAndCallbackQueue() {
97 } 94 }
98 95
99 SyntheticGestureController::GestureAndCallbackQueue:: 96 SyntheticGestureController::GestureAndCallbackQueue::
100 ~GestureAndCallbackQueue() { 97 ~GestureAndCallbackQueue() {
101 } 98 }
102 99
103 } // namespace content 100 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698