| 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/edk/system/data_pipe_producer_dispatcher.h" | 5 #include "mojo/edk/system/data_pipe_producer_dispatcher.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/logging.h" | 10 #include "base/logging.h" |
| 9 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 10 #include "mojo/edk/embedder/embedder_internal.h" | 12 #include "mojo/edk/embedder/embedder_internal.h" |
| 11 #include "mojo/edk/embedder/platform_shared_buffer.h" | 13 #include "mojo/edk/embedder/platform_shared_buffer.h" |
| 12 #include "mojo/edk/embedder/platform_support.h" | 14 #include "mojo/edk/embedder/platform_support.h" |
| 13 #include "mojo/edk/system/configuration.h" | 15 #include "mojo/edk/system/configuration.h" |
| 14 #include "mojo/edk/system/data_pipe.h" | 16 #include "mojo/edk/system/data_pipe.h" |
| 15 | 17 |
| 16 namespace mojo { | 18 namespace mojo { |
| 17 namespace edk { | 19 namespace edk { |
| 18 | 20 |
| 19 void DataPipeProducerDispatcher::Init( | 21 void DataPipeProducerDispatcher::Init( |
| 20 ScopedPlatformHandle message_pipe, | 22 ScopedPlatformHandle message_pipe, |
| 21 char* serialized_write_buffer, size_t serialized_write_buffer_size) { | 23 char* serialized_write_buffer, size_t serialized_write_buffer_size) { |
| 22 if (message_pipe.is_valid()) { | 24 if (message_pipe.is_valid()) { |
| 23 channel_ = RawChannel::Create(message_pipe.Pass()); | 25 channel_ = RawChannel::Create(std::move(message_pipe)); |
| 24 channel_->SetSerializedData( | 26 channel_->SetSerializedData( |
| 25 nullptr, 0u, serialized_write_buffer, serialized_write_buffer_size, | 27 nullptr, 0u, serialized_write_buffer, serialized_write_buffer_size, |
| 26 nullptr, nullptr); | 28 nullptr, nullptr); |
| 27 internal::g_io_thread_task_runner->PostTask( | 29 internal::g_io_thread_task_runner->PostTask( |
| 28 FROM_HERE, base::Bind(&DataPipeProducerDispatcher::InitOnIO, this)); | 30 FROM_HERE, base::Bind(&DataPipeProducerDispatcher::InitOnIO, this)); |
| 29 } else { | 31 } else { |
| 30 error_ = true; | 32 error_ = true; |
| 31 } | 33 } |
| 32 } | 34 } |
| 33 | 35 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 62 &shared_memory_handle, &shared_memory_size); | 64 &shared_memory_handle, &shared_memory_size); |
| 63 | 65 |
| 64 scoped_refptr<DataPipeProducerDispatcher> rv(Create(options)); | 66 scoped_refptr<DataPipeProducerDispatcher> rv(Create(options)); |
| 65 | 67 |
| 66 char* serialized_write_buffer = nullptr; | 68 char* serialized_write_buffer = nullptr; |
| 67 size_t serialized_write_buffer_size = 0; | 69 size_t serialized_write_buffer_size = 0; |
| 68 scoped_refptr<PlatformSharedBuffer> shared_buffer; | 70 scoped_refptr<PlatformSharedBuffer> shared_buffer; |
| 69 scoped_ptr<PlatformSharedBufferMapping> mapping; | 71 scoped_ptr<PlatformSharedBufferMapping> mapping; |
| 70 if (shared_memory_size) { | 72 if (shared_memory_size) { |
| 71 shared_buffer = internal::g_platform_support->CreateSharedBufferFromHandle( | 73 shared_buffer = internal::g_platform_support->CreateSharedBufferFromHandle( |
| 72 shared_memory_size, shared_memory_handle.Pass()); | 74 shared_memory_size, std::move(shared_memory_handle)); |
| 73 mapping = shared_buffer->Map(0, shared_memory_size); | 75 mapping = shared_buffer->Map(0, shared_memory_size); |
| 74 serialized_write_buffer = static_cast<char*>(mapping->GetBase()); | 76 serialized_write_buffer = static_cast<char*>(mapping->GetBase()); |
| 75 serialized_write_buffer_size = shared_memory_size; | 77 serialized_write_buffer_size = shared_memory_size; |
| 76 } | 78 } |
| 77 | 79 |
| 78 rv->Init(platform_handle.Pass(), serialized_write_buffer, | 80 rv->Init(std::move(platform_handle), serialized_write_buffer, |
| 79 serialized_write_buffer_size); | 81 serialized_write_buffer_size); |
| 80 return rv; | 82 return rv; |
| 81 } | 83 } |
| 82 | 84 |
| 83 DataPipeProducerDispatcher::DataPipeProducerDispatcher( | 85 DataPipeProducerDispatcher::DataPipeProducerDispatcher( |
| 84 const MojoCreateDataPipeOptions& options) | 86 const MojoCreateDataPipeOptions& options) |
| 85 : options_(options), channel_(nullptr), error_(false), serialized_(false) { | 87 : options_(options), channel_(nullptr), error_(false), serialized_(false) { |
| 86 } | 88 } |
| 87 | 89 |
| 88 DataPipeProducerDispatcher::~DataPipeProducerDispatcher() { | 90 DataPipeProducerDispatcher::~DataPipeProducerDispatcher() { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 105 } | 107 } |
| 106 | 108 |
| 107 scoped_refptr<Dispatcher> | 109 scoped_refptr<Dispatcher> |
| 108 DataPipeProducerDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() { | 110 DataPipeProducerDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() { |
| 109 lock().AssertAcquired(); | 111 lock().AssertAcquired(); |
| 110 | 112 |
| 111 SerializeInternal(); | 113 SerializeInternal(); |
| 112 | 114 |
| 113 scoped_refptr<DataPipeProducerDispatcher> rv = Create(options_); | 115 scoped_refptr<DataPipeProducerDispatcher> rv = Create(options_); |
| 114 serialized_write_buffer_.swap(rv->serialized_write_buffer_); | 116 serialized_write_buffer_.swap(rv->serialized_write_buffer_); |
| 115 rv->serialized_platform_handle_ = serialized_platform_handle_.Pass(); | 117 rv->serialized_platform_handle_ = std::move(serialized_platform_handle_); |
| 116 rv->serialized_ = true; | 118 rv->serialized_ = true; |
| 117 return scoped_refptr<Dispatcher>(rv.get()); | 119 return scoped_refptr<Dispatcher>(rv.get()); |
| 118 } | 120 } |
| 119 | 121 |
| 120 MojoResult DataPipeProducerDispatcher::WriteDataImplNoLock( | 122 MojoResult DataPipeProducerDispatcher::WriteDataImplNoLock( |
| 121 const void* elements, | 123 const void* elements, |
| 122 uint32_t* num_bytes, | 124 uint32_t* num_bytes, |
| 123 MojoWriteDataFlags flags) { | 125 MojoWriteDataFlags flags) { |
| 124 lock().AssertAcquired(); | 126 lock().AssertAcquired(); |
| 125 if (InTwoPhaseWrite()) | 127 if (InTwoPhaseWrite()) |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 scoped_refptr<PlatformSharedBuffer> shared_buffer( | 283 scoped_refptr<PlatformSharedBuffer> shared_buffer( |
| 282 internal::g_platform_support->CreateSharedBuffer( | 284 internal::g_platform_support->CreateSharedBuffer( |
| 283 shared_memory_size)); | 285 shared_memory_size)); |
| 284 scoped_ptr<PlatformSharedBufferMapping> mapping( | 286 scoped_ptr<PlatformSharedBufferMapping> mapping( |
| 285 shared_buffer->Map(0, shared_memory_size)); | 287 shared_buffer->Map(0, shared_memory_size)); |
| 286 memcpy(mapping->GetBase(), &serialized_write_buffer_[0], | 288 memcpy(mapping->GetBase(), &serialized_write_buffer_[0], |
| 287 shared_memory_size); | 289 shared_memory_size); |
| 288 shared_memory_handle.reset(shared_buffer->PassPlatformHandle().release()); | 290 shared_memory_handle.reset(shared_buffer->PassPlatformHandle().release()); |
| 289 } | 291 } |
| 290 | 292 |
| 291 DataPipe::EndSerialize( | 293 DataPipe::EndSerialize(options_, std::move(serialized_platform_handle_), |
| 292 options_, | 294 std::move(shared_memory_handle), shared_memory_size, |
| 293 serialized_platform_handle_.Pass(), | 295 destination, actual_size, platform_handles); |
| 294 shared_memory_handle.Pass(), shared_memory_size, | |
| 295 destination, actual_size, platform_handles); | |
| 296 CloseImplNoLock(); | 296 CloseImplNoLock(); |
| 297 return true; | 297 return true; |
| 298 } | 298 } |
| 299 | 299 |
| 300 void DataPipeProducerDispatcher::TransportStarted() { | 300 void DataPipeProducerDispatcher::TransportStarted() { |
| 301 started_transport_.Acquire(); | 301 started_transport_.Acquire(); |
| 302 } | 302 } |
| 303 | 303 |
| 304 void DataPipeProducerDispatcher::TransportEnded() { | 304 void DataPipeProducerDispatcher::TransportEnded() { |
| 305 started_transport_.Release(); | 305 started_transport_.Release(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 DCHECK_GT(max_message_num_bytes, 0u); | 366 DCHECK_GT(max_message_num_bytes, 0u); |
| 367 | 367 |
| 368 uint32_t offset = 0; | 368 uint32_t offset = 0; |
| 369 while (offset < num_bytes) { | 369 while (offset < num_bytes) { |
| 370 uint32_t message_num_bytes = | 370 uint32_t message_num_bytes = |
| 371 std::min(static_cast<uint32_t>(max_message_num_bytes), | 371 std::min(static_cast<uint32_t>(max_message_num_bytes), |
| 372 num_bytes - offset); | 372 num_bytes - offset); |
| 373 scoped_ptr<MessageInTransit> message(new MessageInTransit( | 373 scoped_ptr<MessageInTransit> message(new MessageInTransit( |
| 374 MessageInTransit::Type::MESSAGE, message_num_bytes, | 374 MessageInTransit::Type::MESSAGE, message_num_bytes, |
| 375 static_cast<const char*>(elements) + offset)); | 375 static_cast<const char*>(elements) + offset)); |
| 376 if (!channel_->WriteMessage(message.Pass())) { | 376 if (!channel_->WriteMessage(std::move(message))) { |
| 377 error_ = true; | 377 error_ = true; |
| 378 return false; | 378 return false; |
| 379 } | 379 } |
| 380 | 380 |
| 381 offset += message_num_bytes; | 381 offset += message_num_bytes; |
| 382 } | 382 } |
| 383 | 383 |
| 384 return true; | 384 return true; |
| 385 } | 385 } |
| 386 | 386 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 398 CHECK(fds.empty()); | 398 CHECK(fds.empty()); |
| 399 if (write_error) | 399 if (write_error) |
| 400 serialized_platform_handle_.reset(); | 400 serialized_platform_handle_.reset(); |
| 401 channel_ = nullptr; | 401 channel_ = nullptr; |
| 402 } | 402 } |
| 403 serialized_ = true; | 403 serialized_ = true; |
| 404 } | 404 } |
| 405 | 405 |
| 406 } // namespace edk | 406 } // namespace edk |
| 407 } // namespace mojo | 407 } // namespace mojo |
| OLD | NEW |