OLD | NEW |
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/lib/connector.h" | 5 #include "mojo/public/cpp/bindings/lib/connector.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> |
8 | 9 |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
12 | 13 |
13 namespace mojo { | 14 namespace mojo { |
14 namespace internal { | 15 namespace internal { |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
(...skipping 19 matching lines...) Expand all Loading... |
37 }; | 38 }; |
38 | 39 |
39 } // namespace | 40 } // namespace |
40 | 41 |
41 // ---------------------------------------------------------------------------- | 42 // ---------------------------------------------------------------------------- |
42 | 43 |
43 Connector::Connector(ScopedMessagePipeHandle message_pipe, | 44 Connector::Connector(ScopedMessagePipeHandle message_pipe, |
44 ConnectorConfig config, | 45 ConnectorConfig config, |
45 const MojoAsyncWaiter* waiter) | 46 const MojoAsyncWaiter* waiter) |
46 : waiter_(waiter), | 47 : waiter_(waiter), |
47 message_pipe_(message_pipe.Pass()), | 48 message_pipe_(std::move(message_pipe)), |
48 incoming_receiver_(nullptr), | 49 incoming_receiver_(nullptr), |
49 async_wait_id_(0), | 50 async_wait_id_(0), |
50 error_(false), | 51 error_(false), |
51 drop_writes_(false), | 52 drop_writes_(false), |
52 enforce_errors_from_incoming_receiver_(true), | 53 enforce_errors_from_incoming_receiver_(true), |
53 paused_(false), | 54 paused_(false), |
54 destroyed_flag_(nullptr), | 55 destroyed_flag_(nullptr), |
55 lock_(config == MULTI_THREADED_SEND ? new base::Lock : nullptr) { | 56 lock_(config == MULTI_THREADED_SEND ? new base::Lock : nullptr) { |
56 // Even though we don't have an incoming receiver, we still want to monitor | 57 // Even though we don't have an incoming receiver, we still want to monitor |
57 // the message pipe to know if is closed or encounters an error. | 58 // the message pipe to know if is closed or encounters an error. |
58 WaitToReadMore(); | 59 WaitToReadMore(); |
59 } | 60 } |
60 | 61 |
61 Connector::~Connector() { | 62 Connector::~Connector() { |
62 DCHECK(thread_checker_.CalledOnValidThread()); | 63 DCHECK(thread_checker_.CalledOnValidThread()); |
63 | 64 |
64 if (destroyed_flag_) | 65 if (destroyed_flag_) |
65 *destroyed_flag_ = true; | 66 *destroyed_flag_ = true; |
66 | 67 |
67 CancelWait(); | 68 CancelWait(); |
68 } | 69 } |
69 | 70 |
70 void Connector::CloseMessagePipe() { | 71 void Connector::CloseMessagePipe() { |
71 DCHECK(thread_checker_.CalledOnValidThread()); | 72 DCHECK(thread_checker_.CalledOnValidThread()); |
72 | 73 |
73 CancelWait(); | 74 CancelWait(); |
74 MayAutoLock locker(lock_.get()); | 75 MayAutoLock locker(lock_.get()); |
75 Close(message_pipe_.Pass()); | 76 Close(std::move(message_pipe_)); |
76 } | 77 } |
77 | 78 |
78 ScopedMessagePipeHandle Connector::PassMessagePipe() { | 79 ScopedMessagePipeHandle Connector::PassMessagePipe() { |
79 DCHECK(thread_checker_.CalledOnValidThread()); | 80 DCHECK(thread_checker_.CalledOnValidThread()); |
80 | 81 |
81 CancelWait(); | 82 CancelWait(); |
82 MayAutoLock locker(lock_.get()); | 83 MayAutoLock locker(lock_.get()); |
83 return message_pipe_.Pass(); | 84 return std::move(message_pipe_); |
84 } | 85 } |
85 | 86 |
86 void Connector::RaiseError() { | 87 void Connector::RaiseError() { |
87 DCHECK(thread_checker_.CalledOnValidThread()); | 88 DCHECK(thread_checker_.CalledOnValidThread()); |
88 | 89 |
89 HandleError(true, true); | 90 HandleError(true, true); |
90 } | 91 } |
91 | 92 |
92 bool Connector::WaitForIncomingMessage(MojoDeadline deadline) { | 93 bool Connector::WaitForIncomingMessage(MojoDeadline deadline) { |
93 DCHECK(thread_checker_.CalledOnValidThread()); | 94 DCHECK(thread_checker_.CalledOnValidThread()); |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 if (paused_) { | 288 if (paused_) { |
288 // If the user has paused receiving messages, we shouldn't call the error | 289 // If the user has paused receiving messages, we shouldn't call the error |
289 // handler right away. We need to wait until the user starts receiving | 290 // handler right away. We need to wait until the user starts receiving |
290 // messages again. | 291 // messages again. |
291 force_async_handler = true; | 292 force_async_handler = true; |
292 } | 293 } |
293 | 294 |
294 if (force_pipe_reset) { | 295 if (force_pipe_reset) { |
295 CancelWait(); | 296 CancelWait(); |
296 MayAutoLock locker(lock_.get()); | 297 MayAutoLock locker(lock_.get()); |
297 Close(message_pipe_.Pass()); | 298 Close(std::move(message_pipe_)); |
298 MessagePipe dummy_pipe; | 299 MessagePipe dummy_pipe; |
299 message_pipe_ = dummy_pipe.handle0.Pass(); | 300 message_pipe_ = std::move(dummy_pipe.handle0); |
300 } else { | 301 } else { |
301 CancelWait(); | 302 CancelWait(); |
302 } | 303 } |
303 | 304 |
304 if (force_async_handler) { | 305 if (force_async_handler) { |
305 // |dummy_pipe.handle1| has been destructed. Reading the pipe will | 306 // |dummy_pipe.handle1| has been destructed. Reading the pipe will |
306 // eventually cause a read error on |message_pipe_| and set error state. | 307 // eventually cause a read error on |message_pipe_| and set error state. |
307 if (!paused_) | 308 if (!paused_) |
308 WaitToReadMore(); | 309 WaitToReadMore(); |
309 } else { | 310 } else { |
310 error_ = true; | 311 error_ = true; |
311 connection_error_handler_.Run(); | 312 connection_error_handler_.Run(); |
312 } | 313 } |
313 } | 314 } |
314 | 315 |
315 } // namespace internal | 316 } // namespace internal |
316 } // namespace mojo | 317 } // namespace mojo |
OLD | NEW |