| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "mojo/edk/embedder/embedder_internal.h" | 10 #include "mojo/edk/embedder/embedder_internal.h" |
| 11 #include "mojo/edk/embedder/platform_shared_buffer.h" | 11 #include "mojo/edk/embedder/platform_shared_buffer.h" |
| 12 #include "mojo/edk/embedder/platform_support.h" | 12 #include "mojo/edk/embedder/platform_support.h" |
| 13 #include "mojo/edk/system/configuration.h" | 13 #include "mojo/edk/system/configuration.h" |
| 14 #include "mojo/edk/system/data_pipe.h" | 14 #include "mojo/edk/system/data_pipe.h" |
| 15 | 15 |
| 16 namespace mojo { | 16 namespace mojo { |
| 17 namespace edk { | 17 namespace edk { |
| 18 | 18 |
| 19 void DataPipeProducerDispatcher::Init( | 19 void DataPipeProducerDispatcher::Init( |
| 20 ScopedPlatformHandle message_pipe, | 20 ScopedPlatformHandle message_pipe, |
| 21 char* serialized_write_buffer, size_t serialized_write_buffer_size) { | 21 char* serialized_write_buffer, size_t serialized_write_buffer_size) { |
| 22 if (message_pipe.is_valid()) { | 22 if (message_pipe.is_valid()) { |
| 23 channel_ = RawChannel::Create(message_pipe.Pass()); | 23 channel_ = RawChannel::Create(message_pipe.Pass()); |
| 24 channel_->SetSerializedData( | 24 channel_->SetSerializedData( |
| 25 nullptr, 0u, serialized_write_buffer, serialized_write_buffer_size); | 25 nullptr, 0u, serialized_write_buffer, serialized_write_buffer_size); |
| 26 internal::g_io_thread_task_runner->PostTask( | 26 internal::g_io_thread_task_runner->PostTask( |
| 27 FROM_HERE, base::Bind(&DataPipeProducerDispatcher::InitOnIO, this)); | 27 FROM_HERE, base::Bind(&DataPipeProducerDispatcher::InitOnIO, this)); |
| 28 } else { |
| 29 error_ = true; |
| 28 } | 30 } |
| 29 } | 31 } |
| 30 | 32 |
| 31 void DataPipeProducerDispatcher::InitOnIO() { | 33 void DataPipeProducerDispatcher::InitOnIO() { |
| 32 base::AutoLock locker(lock()); | 34 base::AutoLock locker(lock()); |
| 33 if (channel_) | 35 if (channel_) |
| 34 channel_->Init(this); | 36 channel_->Init(this); |
| 35 } | 37 } |
| 36 | 38 |
| 37 void DataPipeProducerDispatcher::CloseOnIO() { | 39 void DataPipeProducerDispatcher::CloseOnIO() { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 65 scoped_refptr<PlatformSharedBuffer> shared_buffer; | 67 scoped_refptr<PlatformSharedBuffer> shared_buffer; |
| 66 scoped_ptr<PlatformSharedBufferMapping> mapping; | 68 scoped_ptr<PlatformSharedBufferMapping> mapping; |
| 67 if (shared_memory_size) { | 69 if (shared_memory_size) { |
| 68 shared_buffer = internal::g_platform_support->CreateSharedBufferFromHandle( | 70 shared_buffer = internal::g_platform_support->CreateSharedBufferFromHandle( |
| 69 shared_memory_size, shared_memory_handle.Pass()); | 71 shared_memory_size, shared_memory_handle.Pass()); |
| 70 mapping = shared_buffer->Map(0, shared_memory_size); | 72 mapping = shared_buffer->Map(0, shared_memory_size); |
| 71 serialized_write_buffer = static_cast<char*>(mapping->GetBase()); | 73 serialized_write_buffer = static_cast<char*>(mapping->GetBase()); |
| 72 serialized_write_buffer_size = shared_memory_size; | 74 serialized_write_buffer_size = shared_memory_size; |
| 73 } | 75 } |
| 74 | 76 |
| 75 if (platform_handle.is_valid()) { | 77 rv->Init(platform_handle.Pass(), serialized_write_buffer, |
| 76 rv->Init(platform_handle.Pass(), serialized_write_buffer, | 78 serialized_write_buffer_size); |
| 77 serialized_write_buffer_size); | |
| 78 } | |
| 79 return rv; | 79 return rv; |
| 80 } | 80 } |
| 81 | 81 |
| 82 DataPipeProducerDispatcher::DataPipeProducerDispatcher( | 82 DataPipeProducerDispatcher::DataPipeProducerDispatcher( |
| 83 const MojoCreateDataPipeOptions& options) | 83 const MojoCreateDataPipeOptions& options) |
| 84 : options_(options), channel_(nullptr), error_(false) { | 84 : options_(options), channel_(nullptr), error_(false) { |
| 85 } | 85 } |
| 86 | 86 |
| 87 DataPipeProducerDispatcher::~DataPipeProducerDispatcher() { | 87 DataPipeProducerDispatcher::~DataPipeProducerDispatcher() { |
| 88 // |Close()|/|CloseImplNoLock()| should have taken care of the channel. | 88 // |Close()|/|CloseImplNoLock()| should have taken care of the channel. |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 case ERROR_WRITE: | 327 case ERROR_WRITE: |
| 328 // Write errors are slightly notable: they probably shouldn't happen under | 328 // Write errors are slightly notable: they probably shouldn't happen under |
| 329 // normal operation (but maybe the other side crashed). | 329 // normal operation (but maybe the other side crashed). |
| 330 LOG(WARNING) << "DataPipeProducerDispatcher write error"; | 330 LOG(WARNING) << "DataPipeProducerDispatcher write error"; |
| 331 break; | 331 break; |
| 332 } | 332 } |
| 333 | 333 |
| 334 error_ = true; | 334 error_ = true; |
| 335 if (started_transport_.Try()) { | 335 if (started_transport_.Try()) { |
| 336 base::AutoLock locker(lock()); | 336 base::AutoLock locker(lock()); |
| 337 // We can get two OnError callbacks before the post task below completes. |
| 338 // Although RawChannel still has a pointer to this object until Shutdown is |
| 339 // called, that is safe since this class always does a PostTask to the IO |
| 340 // thread to self destruct. |
| 341 if (!channel_) |
| 342 return; |
| 343 |
| 337 awakable_list_.AwakeForStateChange(GetHandleSignalsStateImplNoLock()); | 344 awakable_list_.AwakeForStateChange(GetHandleSignalsStateImplNoLock()); |
| 338 | 345 |
| 339 base::MessageLoop::current()->PostTask( | 346 base::MessageLoop::current()->PostTask( |
| 340 FROM_HERE, | 347 FROM_HERE, |
| 341 base::Bind(&RawChannel::Shutdown, base::Unretained(channel_))); | 348 base::Bind(&RawChannel::Shutdown, base::Unretained(channel_))); |
| 342 channel_ = nullptr; | 349 channel_ = nullptr; |
| 343 started_transport_.Release(); | 350 started_transport_.Release(); |
| 344 } else { | 351 } else { |
| 345 // We must be waiting to call ReleaseHandle. It will call Shutdown. | 352 // We must be waiting to call ReleaseHandle. It will call Shutdown. |
| 346 } | 353 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 373 } | 380 } |
| 374 | 381 |
| 375 offset += message_num_bytes; | 382 offset += message_num_bytes; |
| 376 } | 383 } |
| 377 | 384 |
| 378 return true; | 385 return true; |
| 379 } | 386 } |
| 380 | 387 |
| 381 } // namespace edk | 388 } // namespace edk |
| 382 } // namespace mojo | 389 } // namespace mojo |
| OLD | NEW |