| 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 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 } | 80 } |
| 81 | 81 |
| 82 ScopedMessagePipeHandle Connector::PassMessagePipe() { | 82 ScopedMessagePipeHandle Connector::PassMessagePipe() { |
| 83 DCHECK(thread_checker_.CalledOnValidThread()); | 83 DCHECK(thread_checker_.CalledOnValidThread()); |
| 84 | 84 |
| 85 CancelWait(); | 85 CancelWait(); |
| 86 MayAutoLock locker(lock_.get()); | 86 MayAutoLock locker(lock_.get()); |
| 87 return std::move(message_pipe_); | 87 return std::move(message_pipe_); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void Connector::RaiseError() { | 90 void Connector::RaiseError(Error error) { |
| 91 DCHECK(thread_checker_.CalledOnValidThread()); | 91 DCHECK(thread_checker_.CalledOnValidThread()); |
| 92 | 92 |
| 93 // If this was a message validation error, notify the system of a bad message. |
| 94 if (error.type() == Error::Type::BAD_MESSAGE) |
| 95 error.message().NotifyBadMessage(error.details()); |
| 96 |
| 93 HandleError(true, true); | 97 HandleError(true, true); |
| 94 } | 98 } |
| 95 | 99 |
| 96 bool Connector::WaitForIncomingMessage(MojoDeadline deadline) { | 100 bool Connector::WaitForIncomingMessage(MojoDeadline deadline) { |
| 97 DCHECK(thread_checker_.CalledOnValidThread()); | 101 DCHECK(thread_checker_.CalledOnValidThread()); |
| 98 | 102 |
| 99 if (error_) | 103 if (error_) |
| 100 return false; | 104 return false; |
| 101 | 105 |
| 102 ResumeIncomingMethodCallProcessing(); | 106 ResumeIncomingMethodCallProcessing(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 128 void Connector::ResumeIncomingMethodCallProcessing() { | 132 void Connector::ResumeIncomingMethodCallProcessing() { |
| 129 DCHECK(thread_checker_.CalledOnValidThread()); | 133 DCHECK(thread_checker_.CalledOnValidThread()); |
| 130 | 134 |
| 131 if (!paused_) | 135 if (!paused_) |
| 132 return; | 136 return; |
| 133 | 137 |
| 134 paused_ = false; | 138 paused_ = false; |
| 135 WaitToReadMore(); | 139 WaitToReadMore(); |
| 136 } | 140 } |
| 137 | 141 |
| 138 bool Connector::Accept(Message* message) { | 142 bool Connector::Accept(Message* message, Error* error) { |
| 139 DCHECK(lock_ || thread_checker_.CalledOnValidThread()); | 143 DCHECK(lock_ || thread_checker_.CalledOnValidThread()); |
| 140 | 144 |
| 141 // It shouldn't hurt even if |error_| may be changed by a different thread at | 145 // It shouldn't hurt even if |error_| may be changed by a different thread at |
| 142 // the same time. The outcome is that we may write into |message_pipe_| after | 146 // the same time. The outcome is that we may write into |message_pipe_| after |
| 143 // encountering an error, which should be fine. | 147 // encountering an error, which should be fine. |
| 144 if (error_) | 148 if (error_) { |
| 149 *error = Error(Error::Type::SEND_FAILED); |
| 145 return false; | 150 return false; |
| 151 } |
| 146 | 152 |
| 147 MayAutoLock locker(lock_.get()); | 153 MayAutoLock locker(lock_.get()); |
| 148 | 154 |
| 149 if (!message_pipe_.is_valid() || drop_writes_) | 155 if (!message_pipe_.is_valid() || drop_writes_) |
| 150 return true; | 156 return true; |
| 151 | 157 |
| 152 MojoResult rv = | 158 MojoResult rv = |
| 153 WriteMessageNew(message_pipe_.get(), message->TakeMojoMessage(), | 159 WriteMessageNew(message_pipe_.get(), message->TakeMojoMessage(), |
| 154 MOJO_WRITE_MESSAGE_FLAG_NONE); | 160 MOJO_WRITE_MESSAGE_FLAG_NONE); |
| 155 | 161 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 172 // regardless of which thread that two-phase read/write is happening | 178 // regardless of which thread that two-phase read/write is happening |
| 173 // on). | 179 // on). |
| 174 // TODO(vtl): I wonder if this should be a |DCHECK()|. (But, until | 180 // TODO(vtl): I wonder if this should be a |DCHECK()|. (But, until |
| 175 // crbug.com/389666, etc. are resolved, this will make tests fail quickly | 181 // crbug.com/389666, etc. are resolved, this will make tests fail quickly |
| 176 // rather than hanging.) | 182 // rather than hanging.) |
| 177 CHECK(false) << "Race condition or other bug detected"; | 183 CHECK(false) << "Race condition or other bug detected"; |
| 178 return false; | 184 return false; |
| 179 default: | 185 default: |
| 180 // This particular write was rejected, presumably because of bad input. | 186 // This particular write was rejected, presumably because of bad input. |
| 181 // The pipe is not necessarily in a bad state. | 187 // The pipe is not necessarily in a bad state. |
| 188 *error = Error(Error::Type::SEND_FAILED); |
| 182 return false; | 189 return false; |
| 183 } | 190 } |
| 184 return true; | 191 return true; |
| 185 } | 192 } |
| 186 | 193 |
| 187 void Connector::AllowWokenUpBySyncWatchOnSameThread() { | 194 void Connector::AllowWokenUpBySyncWatchOnSameThread() { |
| 188 DCHECK(thread_checker_.CalledOnValidThread()); | 195 DCHECK(thread_checker_.CalledOnValidThread()); |
| 189 | 196 |
| 190 allow_woken_up_by_others_ = true; | 197 allow_woken_up_by_others_ = true; |
| 191 | 198 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 bool receiver_result = false; | 266 bool receiver_result = false; |
| 260 | 267 |
| 261 // Detect if |this| was destroyed during message dispatch. Allow for the | 268 // Detect if |this| was destroyed during message dispatch. Allow for the |
| 262 // possibility of re-entering ReadMore() through message dispatch. | 269 // possibility of re-entering ReadMore() through message dispatch. |
| 263 base::WeakPtr<Connector> weak_self = weak_self_; | 270 base::WeakPtr<Connector> weak_self = weak_self_; |
| 264 | 271 |
| 265 Message message; | 272 Message message; |
| 266 const MojoResult rv = ReadMessage(message_pipe_.get(), &message); | 273 const MojoResult rv = ReadMessage(message_pipe_.get(), &message); |
| 267 *read_result = rv; | 274 *read_result = rv; |
| 268 | 275 |
| 269 if (rv == MOJO_RESULT_OK) { | 276 if (rv == MOJO_RESULT_OK && incoming_receiver_) { |
| 270 receiver_result = | 277 Error error(Error::Type::NONE); |
| 271 incoming_receiver_ && incoming_receiver_->Accept(&message); | 278 receiver_result = incoming_receiver_->Accept(&message, &error); |
| 279 if (!receiver_result && error.type() == Error::Type::BAD_MESSAGE) |
| 280 error.message().NotifyBadMessage(error.details()); |
| 272 } | 281 } |
| 273 | 282 |
| 274 if (!weak_self) | 283 if (!weak_self) |
| 275 return false; | 284 return false; |
| 276 | 285 |
| 277 if (rv == MOJO_RESULT_SHOULD_WAIT) | 286 if (rv == MOJO_RESULT_SHOULD_WAIT) |
| 278 return true; | 287 return true; |
| 279 | 288 |
| 280 if (rv != MOJO_RESULT_OK) { | 289 if (rv != MOJO_RESULT_OK) { |
| 281 HandleError(rv != MOJO_RESULT_FAILED_PRECONDITION, false); | 290 HandleError(rv != MOJO_RESULT_FAILED_PRECONDITION, false); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 if (sync_watcher_) | 356 if (sync_watcher_) |
| 348 return; | 357 return; |
| 349 sync_watcher_.reset(new SyncHandleWatcher( | 358 sync_watcher_.reset(new SyncHandleWatcher( |
| 350 message_pipe_.get(), MOJO_HANDLE_SIGNAL_READABLE, | 359 message_pipe_.get(), MOJO_HANDLE_SIGNAL_READABLE, |
| 351 base::Bind(&Connector::OnSyncHandleWatcherHandleReady, | 360 base::Bind(&Connector::OnSyncHandleWatcherHandleReady, |
| 352 base::Unretained(this)))); | 361 base::Unretained(this)))); |
| 353 } | 362 } |
| 354 | 363 |
| 355 } // namespace internal | 364 } // namespace internal |
| 356 } // namespace mojo | 365 } // namespace mojo |
| OLD | NEW |