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

Side by Side Diff: content/renderer/input/input_event_filter.cc

Issue 2765583002: Teach main thread event queue about closures. (Closed)
Patch Set: Fix Mac issue Created 3 years, 8 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/renderer/input/input_event_filter.h" 5 #include "content/renderer/input/input_event_filter.h"
6 6
7 #include <tuple> 7 #include <tuple>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 input_handler_manager_ = input_handler_manager; 72 input_handler_manager_ = input_handler_manager;
73 } 73 }
74 74
75 void InputEventFilter::RegisterRoutingID(int routing_id) { 75 void InputEventFilter::RegisterRoutingID(int routing_id) {
76 base::AutoLock locked(routes_lock_); 76 base::AutoLock locked(routes_lock_);
77 routes_.insert(routing_id); 77 routes_.insert(routing_id);
78 route_queues_[routing_id] = new MainThreadEventQueue( 78 route_queues_[routing_id] = new MainThreadEventQueue(
79 routing_id, this, main_task_runner_, renderer_scheduler_); 79 routing_id, this, main_task_runner_, renderer_scheduler_);
80 } 80 }
81 81
82 void InputEventFilter::AssociateRenderFrameRoutingID(
83 int render_frame_routing_id,
84 int render_view_routing_id) {
85 base::AutoLock locked(routes_lock_);
86 DCHECK(routes_.find(render_view_routing_id) != routes_.end());
87 associated_routes_[render_frame_routing_id] = render_view_routing_id;
88 }
89
82 void InputEventFilter::UnregisterRoutingID(int routing_id) { 90 void InputEventFilter::UnregisterRoutingID(int routing_id) {
83 base::AutoLock locked(routes_lock_); 91 base::AutoLock locked(routes_lock_);
84 routes_.erase(routing_id); 92 routes_.erase(routing_id);
85 route_queues_.erase(routing_id); 93 route_queues_.erase(routing_id);
94 associated_routes_.erase(routing_id);
86 } 95 }
87 96
88 void InputEventFilter::DidOverscroll(int routing_id, 97 void InputEventFilter::DidOverscroll(int routing_id,
89 const DidOverscrollParams& params) { 98 const DidOverscrollParams& params) {
90 SendMessage(std::unique_ptr<IPC::Message>( 99 SendMessage(std::unique_ptr<IPC::Message>(
91 new InputHostMsg_DidOverscroll(routing_id, params))); 100 new InputHostMsg_DidOverscroll(routing_id, params)));
92 } 101 }
93 102
94 void InputEventFilter::DidStopFlinging(int routing_id) { 103 void InputEventFilter::DidStopFlinging(int routing_id) {
95 SendMessage(base::MakeUnique<InputHostMsg_DidStopFlinging>(routing_id)); 104 SendMessage(base::MakeUnique<InputHostMsg_DidStopFlinging>(routing_id));
96 } 105 }
97 106
107 void InputEventFilter::QueueClosureForMainThreadEventQueue(
108 int routing_id,
109 const base::Closure& closure) {
110 DCHECK(target_task_runner_->BelongsToCurrentThread());
111 RouteQueueMap::iterator iter = route_queues_.find(routing_id);
112 if (iter != route_queues_.end()) {
113 iter->second->QueueClosure(closure);
114 return;
115 }
116 main_task_runner_->PostTask(FROM_HERE, closure);
mustaq 2017/03/29 14:47:07 Does it worth adding a comment on when this line i
dtapuska 2017/03/29 20:08:14 Done.
117 }
118
98 void InputEventFilter::DispatchNonBlockingEventToMainThread( 119 void InputEventFilter::DispatchNonBlockingEventToMainThread(
99 int routing_id, 120 int routing_id,
100 ui::WebScopedInputEvent event, 121 ui::WebScopedInputEvent event,
101 const ui::LatencyInfo& latency_info) { 122 const ui::LatencyInfo& latency_info) {
102 DCHECK(target_task_runner_->BelongsToCurrentThread()); 123 DCHECK(target_task_runner_->BelongsToCurrentThread());
103 RouteQueueMap::iterator iter = route_queues_.find(routing_id); 124 RouteQueueMap::iterator iter = route_queues_.find(routing_id);
104 if (iter != route_queues_.end()) { 125 if (iter != route_queues_.end()) {
105 iter->second->HandleEvent(std::move(event), latency_info, 126 iter->second->HandleEvent(std::move(event), latency_info,
106 DISPATCH_TYPE_NON_BLOCKING, 127 DISPATCH_TYPE_NON_BLOCKING,
107 INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING); 128 INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 190
170 // If TimeTicks is not consistent across processes we cannot use the event's 191 // If TimeTicks is not consistent across processes we cannot use the event's
171 // platform timestamp in this process. Instead the time that the event is 192 // platform timestamp in this process. Instead the time that the event is
172 // received on the IO thread is used as the event's timestamp. 193 // received on the IO thread is used as the event's timestamp.
173 base::TimeTicks received_time; 194 base::TimeTicks received_time;
174 if (!base::TimeTicks::IsConsistentAcrossProcesses()) 195 if (!base::TimeTicks::IsConsistentAcrossProcesses())
175 received_time = base::TimeTicks::Now(); 196 received_time = base::TimeTicks::Now();
176 197
177 TRACE_EVENT0("input", "InputEventFilter::OnMessageReceived::InputMessage"); 198 TRACE_EVENT0("input", "InputEventFilter::OnMessageReceived::InputMessage");
178 199
200 int routing_id = message.routing_id();
179 { 201 {
180 base::AutoLock locked(routes_lock_); 202 base::AutoLock locked(routes_lock_);
181 if (routes_.find(message.routing_id()) == routes_.end()) 203 if (routes_.find(routing_id) == routes_.end()) {
182 return false; 204 auto associated_routing_id = associated_routes_.find(routing_id);
205 if (associated_routing_id == associated_routes_.end() ||
206 routes_.find(associated_routing_id->second) == routes_.end())
207 return false;
208 routing_id = associated_routing_id->second;
209 }
183 } 210 }
184 211
185 bool postedTask = target_task_runner_->PostTask( 212 bool postedTask = target_task_runner_->PostTask(
186 FROM_HERE, base::Bind(&InputEventFilter::ForwardToHandler, this, message, 213 FROM_HERE, base::Bind(&InputEventFilter::ForwardToHandler, this,
187 received_time)); 214 routing_id, message, received_time));
188 LOG_IF(WARNING, !postedTask) << "PostTask failed"; 215 LOG_IF(WARNING, !postedTask) << "PostTask failed";
189 return true; 216 return true;
190 } 217 }
191 218
192 InputEventFilter::~InputEventFilter() {} 219 InputEventFilter::~InputEventFilter() {}
193 220
194 void InputEventFilter::ForwardToHandler(const IPC::Message& message, 221 void InputEventFilter::ForwardToHandler(int associated_routing_id,
222 const IPC::Message& message,
195 base::TimeTicks received_time) { 223 base::TimeTicks received_time) {
196 DCHECK(input_handler_manager_); 224 DCHECK(input_handler_manager_);
197 DCHECK(target_task_runner_->BelongsToCurrentThread()); 225 DCHECK(target_task_runner_->BelongsToCurrentThread());
198 TRACE_EVENT1("input", "InputEventFilter::ForwardToHandler", 226 TRACE_EVENT1("input", "InputEventFilter::ForwardToHandler",
199 "message_type", GetInputMessageTypeName(message)); 227 "message_type", GetInputMessageTypeName(message));
200 228
201 if (message.type() != InputMsg_HandleInputEvent::ID) { 229 if (message.type() != InputMsg_HandleInputEvent::ID) {
202 TRACE_EVENT_INSTANT0( 230 TRACE_EVENT_INSTANT0(
203 "input", 231 "input",
204 "InputEventFilter::ForwardToHandler::ForwardToMainListener", 232 "InputEventFilter::ForwardToHandler::ForwardToMainListener",
205 TRACE_EVENT_SCOPE_THREAD); 233 TRACE_EVENT_SCOPE_THREAD);
206 CHECK(main_task_runner_->PostTask(FROM_HERE, 234 input_handler_manager_->QueueClosureForMainThreadEventQueue(
207 base::Bind(main_listener_, message))) 235 associated_routing_id, base::Bind(main_listener_, message));
208 << "PostTask failed";
209 return; 236 return;
210 } 237 }
211 238
212 int routing_id = message.routing_id();
213 InputMsg_HandleInputEvent::Param params; 239 InputMsg_HandleInputEvent::Param params;
214 if (!InputMsg_HandleInputEvent::Read(&message, &params)) 240 if (!InputMsg_HandleInputEvent::Read(&message, &params))
215 return; 241 return;
216 ui::WebScopedInputEvent event = 242 ui::WebScopedInputEvent event =
217 ui::WebInputEventTraits::Clone(*std::get<0>(params)); 243 ui::WebInputEventTraits::Clone(*std::get<0>(params));
218 ui::LatencyInfo latency_info = std::get<2>(params); 244 ui::LatencyInfo latency_info = std::get<2>(params);
219 InputEventDispatchType dispatch_type = std::get<3>(params); 245 InputEventDispatchType dispatch_type = std::get<3>(params);
220 246
247 // Input Events are always sent to the RenderView routing ID
248 // so it should be the same as the message routing ID.
249 DCHECK(associated_routing_id == message.routing_id());
221 DCHECK(event); 250 DCHECK(event);
222 DCHECK(dispatch_type == DISPATCH_TYPE_BLOCKING || 251 DCHECK(dispatch_type == DISPATCH_TYPE_BLOCKING ||
223 dispatch_type == DISPATCH_TYPE_NON_BLOCKING); 252 dispatch_type == DISPATCH_TYPE_NON_BLOCKING);
224 253
225 if (!received_time.is_null()) 254 if (!received_time.is_null())
226 event->setTimeStampSeconds(ui::EventTimeStampToSeconds(received_time)); 255 event->setTimeStampSeconds(ui::EventTimeStampToSeconds(received_time));
227 256
228 input_handler_manager_->HandleInputEvent( 257 input_handler_manager_->HandleInputEvent(
229 routing_id, std::move(event), latency_info, 258 associated_routing_id, std::move(event), latency_info,
230 base::Bind(&InputEventFilter::DidForwardToHandlerAndOverscroll, this, 259 base::Bind(&InputEventFilter::DidForwardToHandlerAndOverscroll, this,
231 routing_id, dispatch_type)); 260 associated_routing_id, dispatch_type));
232 }; 261 };
233 262
234 void InputEventFilter::DidForwardToHandlerAndOverscroll( 263 void InputEventFilter::DidForwardToHandlerAndOverscroll(
235 int routing_id, 264 int routing_id,
236 InputEventDispatchType dispatch_type, 265 InputEventDispatchType dispatch_type,
237 InputEventAckState ack_state, 266 InputEventAckState ack_state,
238 ui::WebScopedInputEvent event, 267 ui::WebScopedInputEvent event,
239 const ui::LatencyInfo& latency_info, 268 const ui::LatencyInfo& latency_info,
240 std::unique_ptr<DidOverscrollParams> overscroll_params) { 269 std::unique_ptr<DidOverscrollParams> overscroll_params) {
241 bool send_ack = dispatch_type == DISPATCH_TYPE_BLOCKING; 270 bool send_ack = dispatch_type == DISPATCH_TYPE_BLOCKING;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 return; 347 return;
319 } 348 }
320 349
321 CHECK(target_task_runner_->PostTask( 350 CHECK(target_task_runner_->PostTask(
322 FROM_HERE, 351 FROM_HERE,
323 base::Bind(&InputEventFilter::NeedsMainFrame, this, routing_id))) 352 base::Bind(&InputEventFilter::NeedsMainFrame, this, routing_id)))
324 << "PostTask failed"; 353 << "PostTask failed";
325 } 354 }
326 355
327 } // namespace content 356 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698