OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/edk/system/raw_channel.h" | 5 #include "mojo/edk/system/raw_channel.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <utility> | 10 #include <utility> |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 *set_on_shutdown_ = true; | 215 *set_on_shutdown_ = true; |
216 set_on_shutdown_ = nullptr; | 216 set_on_shutdown_ = nullptr; |
217 } | 217 } |
218 write_stopped_ = true; | 218 write_stopped_ = true; |
219 weak_ptr_factory_.InvalidateWeakPtrs(); | 219 weak_ptr_factory_.InvalidateWeakPtrs(); |
220 | 220 |
221 OnShutdownNoLock(std::move(read_buffer_), std::move(write_buffer_)); | 221 OnShutdownNoLock(std::move(read_buffer_), std::move(write_buffer_)); |
222 } | 222 } |
223 | 223 |
224 // Reminder: This must be thread-safe. | 224 // Reminder: This must be thread-safe. |
225 bool RawChannel::WriteMessage(scoped_ptr<MessageInTransit> message) { | 225 bool RawChannel::WriteMessage(std::unique_ptr<MessageInTransit> message) { |
226 DCHECK(message); | 226 DCHECK(message); |
227 | 227 |
228 MutexLocker locker(&write_mutex_); | 228 MutexLocker locker(&write_mutex_); |
229 if (write_stopped_) | 229 if (write_stopped_) |
230 return false; | 230 return false; |
231 | 231 |
232 if (!write_buffer_->message_queue_.IsEmpty()) { | 232 if (!write_buffer_->message_queue_.IsEmpty()) { |
233 EnqueueMessageNoLock(message.Pass()); | 233 EnqueueMessageNoLock(std::move(message)); |
234 return true; | 234 return true; |
235 } | 235 } |
236 | 236 |
237 EnqueueMessageNoLock(message.Pass()); | 237 EnqueueMessageNoLock(std::move(message)); |
238 DCHECK_EQ(write_buffer_->data_offset_, 0u); | 238 DCHECK_EQ(write_buffer_->data_offset_, 0u); |
239 | 239 |
240 size_t platform_handles_written = 0; | 240 size_t platform_handles_written = 0; |
241 size_t bytes_written = 0; | 241 size_t bytes_written = 0; |
242 IOResult io_result = WriteNoLock(&platform_handles_written, &bytes_written); | 242 IOResult io_result = WriteNoLock(&platform_handles_written, &bytes_written); |
243 if (io_result == IO_PENDING) | 243 if (io_result == IO_PENDING) |
244 return true; | 244 return true; |
245 | 245 |
246 bool result = OnWriteCompletedNoLock(io_result, platform_handles_written, | 246 bool result = OnWriteCompletedNoLock(io_result, platform_handles_written, |
247 bytes_written); | 247 bytes_written); |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 did_fail = !OnWriteCompletedNoLock(io_result, platform_handles_written, | 424 did_fail = !OnWriteCompletedNoLock(io_result, platform_handles_written, |
425 bytes_written); | 425 bytes_written); |
426 } | 426 } |
427 | 427 |
428 if (did_fail) { | 428 if (did_fail) { |
429 CallOnError(Delegate::ERROR_WRITE); | 429 CallOnError(Delegate::ERROR_WRITE); |
430 return; // |this| may have been destroyed in |CallOnError()|. | 430 return; // |this| may have been destroyed in |CallOnError()|. |
431 } | 431 } |
432 } | 432 } |
433 | 433 |
434 void RawChannel::EnqueueMessageNoLock(scoped_ptr<MessageInTransit> message) { | 434 void RawChannel::EnqueueMessageNoLock( |
| 435 std::unique_ptr<MessageInTransit> message) { |
435 write_mutex_.AssertHeld(); | 436 write_mutex_.AssertHeld(); |
436 write_buffer_->message_queue_.AddMessage(message.Pass()); | 437 write_buffer_->message_queue_.AddMessage(std::move(message)); |
437 } | 438 } |
438 | 439 |
439 bool RawChannel::OnReadMessageForRawChannel( | 440 bool RawChannel::OnReadMessageForRawChannel( |
440 const MessageInTransit::View& message_view) { | 441 const MessageInTransit::View& message_view) { |
441 // No non-implementation specific |RawChannel| control messages. | 442 // No non-implementation specific |RawChannel| control messages. |
442 LOG(ERROR) << "Invalid control message (subtype " << message_view.subtype() | 443 LOG(ERROR) << "Invalid control message (subtype " << message_view.subtype() |
443 << ")"; | 444 << ")"; |
444 return false; | 445 return false; |
445 } | 446 } |
446 | 447 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 | 505 |
505 write_stopped_ = true; | 506 write_stopped_ = true; |
506 write_buffer_->message_queue_.Clear(); | 507 write_buffer_->message_queue_.Clear(); |
507 write_buffer_->platform_handles_offset_ = 0; | 508 write_buffer_->platform_handles_offset_ = 0; |
508 write_buffer_->data_offset_ = 0; | 509 write_buffer_->data_offset_ = 0; |
509 return false; | 510 return false; |
510 } | 511 } |
511 | 512 |
512 } // namespace system | 513 } // namespace system |
513 } // namespace mojo | 514 } // namespace mojo |
OLD | NEW |