| 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" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
| 15 #include "mojo/public/cpp/bindings/lib/may_auto_lock.h" | 15 #include "mojo/public/cpp/bindings/lib/may_auto_lock.h" |
| 16 #include "mojo/public/cpp/bindings/sync_handle_watcher.h" | 16 #include "mojo/public/cpp/bindings/sync_handle_watcher.h" |
| 17 #include "mojo/public/cpp/system/wait.h" |
| 17 | 18 |
| 18 namespace mojo { | 19 namespace mojo { |
| 19 | 20 |
| 20 Connector::Connector(ScopedMessagePipeHandle message_pipe, | 21 Connector::Connector(ScopedMessagePipeHandle message_pipe, |
| 21 ConnectorConfig config, | 22 ConnectorConfig config, |
| 22 scoped_refptr<base::SingleThreadTaskRunner> runner) | 23 scoped_refptr<base::SingleThreadTaskRunner> runner) |
| 23 : message_pipe_(std::move(message_pipe)), | 24 : message_pipe_(std::move(message_pipe)), |
| 24 task_runner_(std::move(runner)), | 25 task_runner_(std::move(runner)), |
| 25 weak_factory_(this) { | 26 weak_factory_(this) { |
| 26 if (config == MULTI_THREADED_SEND) | 27 if (config == MULTI_THREADED_SEND) |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 } | 71 } |
| 71 | 72 |
| 72 bool Connector::WaitForIncomingMessage(MojoDeadline deadline) { | 73 bool Connector::WaitForIncomingMessage(MojoDeadline deadline) { |
| 73 DCHECK(thread_checker_.CalledOnValidThread()); | 74 DCHECK(thread_checker_.CalledOnValidThread()); |
| 74 | 75 |
| 75 if (error_) | 76 if (error_) |
| 76 return false; | 77 return false; |
| 77 | 78 |
| 78 ResumeIncomingMethodCallProcessing(); | 79 ResumeIncomingMethodCallProcessing(); |
| 79 | 80 |
| 80 MojoResult rv = | 81 // TODO(rockot): Use a timed Wait here. Nobody uses anything but 0 or |
| 81 Wait(message_pipe_.get(), MOJO_HANDLE_SIGNAL_READABLE, deadline, nullptr); | 82 // INDEFINITE deadlines at present, so we only support those. |
| 82 if (rv == MOJO_RESULT_SHOULD_WAIT || rv == MOJO_RESULT_DEADLINE_EXCEEDED) | 83 DCHECK(deadline == 0 || deadline == MOJO_DEADLINE_INDEFINITE); |
| 84 |
| 85 MojoResult rv = MOJO_RESULT_UNKNOWN; |
| 86 if (deadline == 0 && !message_pipe_->QuerySignalsState().readable()) |
| 83 return false; | 87 return false; |
| 84 if (rv != MOJO_RESULT_OK) { | 88 |
| 85 // Users that call WaitForIncomingMessage() should expect their code to be | 89 if (deadline == MOJO_DEADLINE_INDEFINITE) { |
| 86 // re-entered, so we call the error handler synchronously. | 90 rv = Wait(message_pipe_.get(), MOJO_HANDLE_SIGNAL_READABLE); |
| 87 HandleError(rv != MOJO_RESULT_FAILED_PRECONDITION, false); | 91 if (rv != MOJO_RESULT_OK) { |
| 88 return false; | 92 // Users that call WaitForIncomingMessage() should expect their code to be |
| 93 // re-entered, so we call the error handler synchronously. |
| 94 HandleError(rv != MOJO_RESULT_FAILED_PRECONDITION, false); |
| 95 return false; |
| 96 } |
| 89 } | 97 } |
| 98 |
| 90 ignore_result(ReadSingleMessage(&rv)); | 99 ignore_result(ReadSingleMessage(&rv)); |
| 91 return (rv == MOJO_RESULT_OK); | 100 return (rv == MOJO_RESULT_OK); |
| 92 } | 101 } |
| 93 | 102 |
| 94 void Connector::PauseIncomingMethodCallProcessing() { | 103 void Connector::PauseIncomingMethodCallProcessing() { |
| 95 DCHECK(thread_checker_.CalledOnValidThread()); | 104 DCHECK(thread_checker_.CalledOnValidThread()); |
| 96 | 105 |
| 97 if (paused_) | 106 if (paused_) |
| 98 return; | 107 return; |
| 99 | 108 |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 void Connector::EnsureSyncWatcherExists() { | 379 void Connector::EnsureSyncWatcherExists() { |
| 371 if (sync_watcher_) | 380 if (sync_watcher_) |
| 372 return; | 381 return; |
| 373 sync_watcher_.reset(new SyncHandleWatcher( | 382 sync_watcher_.reset(new SyncHandleWatcher( |
| 374 message_pipe_.get(), MOJO_HANDLE_SIGNAL_READABLE, | 383 message_pipe_.get(), MOJO_HANDLE_SIGNAL_READABLE, |
| 375 base::Bind(&Connector::OnSyncHandleWatcherHandleReady, | 384 base::Bind(&Connector::OnSyncHandleWatcherHandleReady, |
| 376 base::Unretained(this)))); | 385 base::Unretained(this)))); |
| 377 } | 386 } |
| 378 | 387 |
| 379 } // namespace mojo | 388 } // namespace mojo |
| OLD | NEW |