Chromium Code Reviews| 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/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 Loading... | |
| 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_ = true; | |
| 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 return std::move(message_pipe_); |
|
yzshen1
2016/07/26 21:21:15
When the message pipe is transferred, we need to s
Ken Rockot(use gerrit already)
2016/07/26 22:07:00
Done
| |
| 87 } | 89 } |
| 88 | 90 |
| 89 void Connector::RaiseError() { | 91 void Connector::RaiseError() { |
| 90 DCHECK(thread_checker_.CalledOnValidThread()); | 92 DCHECK(thread_checker_.CalledOnValidThread()); |
| 91 | 93 |
| 92 HandleError(true, true); | 94 HandleError(true, true); |
| 93 } | 95 } |
| 94 | 96 |
| 95 bool Connector::WaitForIncomingMessage(MojoDeadline deadline) { | 97 bool Connector::WaitForIncomingMessage(MojoDeadline deadline) { |
| 96 DCHECK(thread_checker_.CalledOnValidThread()); | 98 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 void Connector::EnsureSyncWatcherExists() { | 348 void Connector::EnsureSyncWatcherExists() { |
| 347 if (sync_watcher_) | 349 if (sync_watcher_) |
| 348 return; | 350 return; |
| 349 sync_watcher_.reset(new SyncHandleWatcher( | 351 sync_watcher_.reset(new SyncHandleWatcher( |
| 350 message_pipe_.get(), MOJO_HANDLE_SIGNAL_READABLE, | 352 message_pipe_.get(), MOJO_HANDLE_SIGNAL_READABLE, |
| 351 base::Bind(&Connector::OnSyncHandleWatcherHandleReady, | 353 base::Bind(&Connector::OnSyncHandleWatcherHandleReady, |
| 352 base::Unretained(this)))); | 354 base::Unretained(this)))); |
| 353 } | 355 } |
| 354 | 356 |
| 355 } // namespace mojo | 357 } // namespace mojo |
| OLD | NEW |