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

Side by Side Diff: mojo/public/cpp/bindings/lib/multiplex_router.cc

Issue 2185723002: Eliminate deferred destruction of AssociatedGroupController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "mojo/public/cpp/bindings/lib/multiplex_router.h" 5 #include "mojo/public/cpp/bindings/lib/multiplex_router.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 Type type; 278 Type type;
279 279
280 private: 280 private:
281 explicit Task(Type in_type) : type(in_type) {} 281 explicit Task(Type in_type) : type(in_type) {}
282 }; 282 };
283 283
284 MultiplexRouter::MultiplexRouter( 284 MultiplexRouter::MultiplexRouter(
285 bool set_interface_id_namesapce_bit, 285 bool set_interface_id_namesapce_bit,
286 ScopedMessagePipeHandle message_pipe, 286 ScopedMessagePipeHandle message_pipe,
287 scoped_refptr<base::SingleThreadTaskRunner> runner) 287 scoped_refptr<base::SingleThreadTaskRunner> runner)
288 : AssociatedGroupController(base::ThreadTaskRunnerHandle::Get()), 288 : set_interface_id_namespace_bit_(set_interface_id_namesapce_bit),
289 set_interface_id_namespace_bit_(set_interface_id_namesapce_bit), 289 task_runner_(runner),
290 header_validator_(this), 290 header_validator_(this),
291 connector_(std::move(message_pipe), 291 connector_(std::move(message_pipe),
292 Connector::MULTI_THREADED_SEND, 292 Connector::MULTI_THREADED_SEND,
293 std::move(runner)), 293 std::move(runner)),
294 control_message_handler_(this), 294 control_message_handler_(this),
295 control_message_proxy_(&connector_), 295 control_message_proxy_(&connector_),
296 next_interface_id_value_(1), 296 next_interface_id_value_(1),
297 posted_to_process_tasks_(false), 297 posted_to_process_tasks_(false),
298 encountered_error_(false), 298 encountered_error_(false),
299 paused_(false), 299 paused_(false),
300 testing_mode_(false) { 300 testing_mode_(false) {
301 DCHECK(task_runner_->BelongsToCurrentThread());
301 // Always participate in sync handle watching, because even if it doesn't 302 // Always participate in sync handle watching, because even if it doesn't
302 // expect sync requests during sync handle watching, it may still need to 303 // expect sync requests during sync handle watching, it may still need to
303 // dispatch messages to associated endpoints on a different thread. 304 // dispatch messages to associated endpoints on a different thread.
304 connector_.AllowWokenUpBySyncWatchOnSameThread(); 305 connector_.AllowWokenUpBySyncWatchOnSameThread();
305 connector_.set_incoming_receiver(&header_validator_); 306 connector_.set_incoming_receiver(&header_validator_);
306 connector_.set_connection_error_handler( 307 connector_.set_connection_error_handler(
307 base::Bind(&MultiplexRouter::OnPipeConnectionError, 308 base::Bind(&MultiplexRouter::OnPipeConnectionError, this));
308 base::Unretained(this)));
yzshen1 2016/07/26 21:21:15 It seems safe to use base::Unretained() here. The
Ken Rockot(use gerrit already) 2016/07/26 22:07:00 Done
309 } 309 }
310 310
311 MultiplexRouter::~MultiplexRouter() { 311 MultiplexRouter::~MultiplexRouter() {
312 base::AutoLock locker(lock_); 312 base::AutoLock locker(lock_);
313 313
314 sync_message_tasks_.clear(); 314 sync_message_tasks_.clear();
315 tasks_.clear(); 315 tasks_.clear();
316 316
317 for (auto iter = endpoints_.begin(); iter != endpoints_.end();) { 317 for (auto iter = endpoints_.begin(); iter != endpoints_.end();) {
318 InterfaceEndpoint* endpoint = iter->second.get(); 318 InterfaceEndpoint* endpoint = iter->second.get();
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 583
584 control_message_proxy_.NotifyPeerEndpointClosed(id); 584 control_message_proxy_.NotifyPeerEndpointClosed(id);
585 585
586 return true; 586 return true;
587 } 587 }
588 588
589 void MultiplexRouter::OnPipeConnectionError() { 589 void MultiplexRouter::OnPipeConnectionError() {
590 DCHECK(thread_checker_.CalledOnValidThread()); 590 DCHECK(thread_checker_.CalledOnValidThread());
591 591
592 scoped_refptr<MultiplexRouter> protector(this); 592 scoped_refptr<MultiplexRouter> protector(this);
593
594 // We explcitly clear the error handler since it has a ref to |this|.
595 connector_.set_connection_error_handler(base::Closure());
596
593 base::AutoLock locker(lock_); 597 base::AutoLock locker(lock_);
594 598
595 encountered_error_ = true; 599 encountered_error_ = true;
596 600
597 for (auto iter = endpoints_.begin(); iter != endpoints_.end();) { 601 for (auto iter = endpoints_.begin(); iter != endpoints_.end();) {
598 InterfaceEndpoint* endpoint = iter->second.get(); 602 InterfaceEndpoint* endpoint = iter->second.get();
599 // Increment the iterator before calling UpdateEndpointStateMayRemove() 603 // Increment the iterator before calling UpdateEndpointStateMayRemove()
600 // because it may remove the corresponding value from the map. 604 // because it may remove the corresponding value from the map.
601 ++iter; 605 ++iter;
602 606
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 *inserted = true; 880 *inserted = true;
877 } else { 881 } else {
878 endpoint = iter->second.get(); 882 endpoint = iter->second.get();
879 } 883 }
880 884
881 return endpoint; 885 return endpoint;
882 } 886 }
883 887
884 } // namespace internal 888 } // namespace internal
885 } // namespace mojo 889 } // namespace mojo
OLDNEW
« mojo/public/cpp/bindings/lib/connector.cc ('K') | « mojo/public/cpp/bindings/lib/multiplex_router.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698