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

Side by Side Diff: mojo/public/cpp/bindings/lib/connector.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 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 "mojo/public/cpp/bindings/connector.h" 5 #include "mojo/public/cpp/bindings/connector.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 29 matching lines...) Expand all
40 }; 40 };
41 41
42 } // namespace 42 } // namespace
43 43
44 // ---------------------------------------------------------------------------- 44 // ----------------------------------------------------------------------------
45 45
46 Connector::Connector(ScopedMessagePipeHandle message_pipe, 46 Connector::Connector(ScopedMessagePipeHandle message_pipe,
47 ConnectorConfig config, 47 ConnectorConfig config,
48 scoped_refptr<base::SingleThreadTaskRunner> runner) 48 scoped_refptr<base::SingleThreadTaskRunner> runner)
49 : message_pipe_(std::move(message_pipe)), 49 : message_pipe_(std::move(message_pipe)),
50 incoming_receiver_(nullptr),
51 task_runner_(std::move(runner)), 50 task_runner_(std::move(runner)),
52 handle_watcher_(task_runner_), 51 handle_watcher_(task_runner_),
53 error_(false),
54 drop_writes_(false),
55 enforce_errors_from_incoming_receiver_(true),
56 paused_(false),
57 lock_(config == MULTI_THREADED_SEND ? new base::Lock : nullptr), 52 lock_(config == MULTI_THREADED_SEND ? new base::Lock : nullptr),
58 allow_woken_up_by_others_(false),
59 sync_handle_watcher_callback_count_(0),
60 weak_factory_(this) { 53 weak_factory_(this) {
61 weak_self_ = weak_factory_.GetWeakPtr(); 54 weak_self_ = weak_factory_.GetWeakPtr();
62 // Even though we don't have an incoming receiver, we still want to monitor 55 // Even though we don't have an incoming receiver, we still want to monitor
63 // the message pipe to know if is closed or encounters an error. 56 // the message pipe to know if is closed or encounters an error.
64 WaitToReadMore(); 57 WaitToReadMore();
65 } 58 }
66 59
67 Connector::~Connector() { 60 Connector::~Connector() {
61 {
62 // Allow for quick destruction on any thread if the pipe is already closed.
63 base::AutoLock lock(connected_lock_);
64 if (!connected_)
65 return;
66 }
67
68 DCHECK(thread_checker_.CalledOnValidThread()); 68 DCHECK(thread_checker_.CalledOnValidThread());
69
70 CancelWait(); 69 CancelWait();
71 } 70 }
72 71
73 void Connector::CloseMessagePipe() { 72 void Connector::CloseMessagePipe() {
74 DCHECK(thread_checker_.CalledOnValidThread()); 73 DCHECK(thread_checker_.CalledOnValidThread());
75 74
76 CancelWait(); 75 CancelWait();
77 MayAutoLock locker(lock_.get()); 76 MayAutoLock locker(lock_.get());
78 message_pipe_.reset(); 77 message_pipe_.reset();
78
79 base::AutoLock lock(connected_lock_);
80 connected_ = false;
79 } 81 }
80 82
81 ScopedMessagePipeHandle Connector::PassMessagePipe() { 83 ScopedMessagePipeHandle Connector::PassMessagePipe() {
82 DCHECK(thread_checker_.CalledOnValidThread()); 84 DCHECK(thread_checker_.CalledOnValidThread());
83 85
84 CancelWait(); 86 CancelWait();
85 MayAutoLock locker(lock_.get()); 87 MayAutoLock locker(lock_.get());
86 return std::move(message_pipe_); 88 ScopedMessagePipeHandle message_pipe = std::move(message_pipe_);
yzshen1 2016/07/26 22:11:30 this should be returned.
89
90 base::AutoLock lock(connected_lock_);
91 connected_ = false;
87 } 92 }
88 93
89 void Connector::RaiseError() { 94 void Connector::RaiseError() {
90 DCHECK(thread_checker_.CalledOnValidThread()); 95 DCHECK(thread_checker_.CalledOnValidThread());
91 96
92 HandleError(true, true); 97 HandleError(true, true);
93 } 98 }
94 99
95 bool Connector::WaitForIncomingMessage(MojoDeadline deadline) { 100 bool Connector::WaitForIncomingMessage(MojoDeadline deadline) {
96 DCHECK(thread_checker_.CalledOnValidThread()); 101 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 void Connector::EnsureSyncWatcherExists() { 351 void Connector::EnsureSyncWatcherExists() {
347 if (sync_watcher_) 352 if (sync_watcher_)
348 return; 353 return;
349 sync_watcher_.reset(new SyncHandleWatcher( 354 sync_watcher_.reset(new SyncHandleWatcher(
350 message_pipe_.get(), MOJO_HANDLE_SIGNAL_READABLE, 355 message_pipe_.get(), MOJO_HANDLE_SIGNAL_READABLE,
351 base::Bind(&Connector::OnSyncHandleWatcherHandleReady, 356 base::Bind(&Connector::OnSyncHandleWatcherHandleReady,
352 base::Unretained(this)))); 357 base::Unretained(this))));
353 } 358 }
354 359
355 } // namespace mojo 360 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/associated_group_controller.cc ('k') | mojo/public/cpp/bindings/lib/multiplex_router.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698