| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 if (initialized) { | 72 if (initialized) { |
| 73 base::AutoLock lock(lock_); | 73 base::AutoLock lock(lock_); |
| 74 InitializeNoLock(); | 74 InitializeNoLock(); |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 | 77 |
| 78 Dispatcher::Type DataPipeProducerDispatcher::GetType() const { | 78 Dispatcher::Type DataPipeProducerDispatcher::GetType() const { |
| 79 return Type::DATA_PIPE_PRODUCER; | 79 return Type::DATA_PIPE_PRODUCER; |
| 80 } | 80 } |
| 81 | 81 |
| 82 MojoResult DataPipeProducerDispatcher::Close() { | 82 MojoResult DataPipeProducerDispatcher::Close(RequestContext* request_context) { |
| 83 base::AutoLock lock(lock_); | 83 base::AutoLock lock(lock_); |
| 84 DVLOG(1) << "Closing data pipe producer " << pipe_id_; | 84 DVLOG(1) << "Closing data pipe producer " << pipe_id_; |
| 85 return CloseNoLock(); | 85 return CloseNoLock(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 MojoResult DataPipeProducerDispatcher::WriteData(const void* elements, | 88 MojoResult DataPipeProducerDispatcher::WriteData(const void* elements, |
| 89 uint32_t* num_bytes, | 89 uint32_t* num_bytes, |
| 90 MojoWriteDataFlags flags) { | 90 MojoWriteDataFlags flags) { |
| 91 base::AutoLock lock(lock_); | 91 base::AutoLock lock(lock_); |
| 92 if (!shared_ring_buffer_ || in_transit_) | 92 if (!shared_ring_buffer_ || in_transit_) |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 state->available_capacity = available_capacity_; | 291 state->available_capacity = available_capacity_; |
| 292 | 292 |
| 293 ports[0] = control_port_.name(); | 293 ports[0] = control_port_.name(); |
| 294 | 294 |
| 295 buffer_handle_for_transit_ = shared_ring_buffer_->DuplicatePlatformHandle(); | 295 buffer_handle_for_transit_ = shared_ring_buffer_->DuplicatePlatformHandle(); |
| 296 platform_handles[0] = buffer_handle_for_transit_.get(); | 296 platform_handles[0] = buffer_handle_for_transit_.get(); |
| 297 | 297 |
| 298 return true; | 298 return true; |
| 299 } | 299 } |
| 300 | 300 |
| 301 bool DataPipeProducerDispatcher::BeginTransit() { | 301 bool DataPipeProducerDispatcher::BeginTransit(RequestContext* request_context) { |
| 302 base::AutoLock lock(lock_); | 302 base::AutoLock lock(lock_); |
| 303 if (in_transit_) | 303 if (in_transit_) |
| 304 return false; | 304 return false; |
| 305 in_transit_ = !in_two_phase_write_; | 305 in_transit_ = !in_two_phase_write_; |
| 306 return in_transit_; | 306 return in_transit_; |
| 307 } | 307 } |
| 308 | 308 |
| 309 void DataPipeProducerDispatcher::CompleteTransitAndClose() { | 309 void DataPipeProducerDispatcher::CompleteTransitAndClose( |
| 310 RequestContext* request_context) { |
| 310 node_controller_->SetPortObserver(control_port_, nullptr); | 311 node_controller_->SetPortObserver(control_port_, nullptr); |
| 311 | 312 |
| 312 base::AutoLock lock(lock_); | 313 base::AutoLock lock(lock_); |
| 313 DCHECK(in_transit_); | 314 DCHECK(in_transit_); |
| 314 transferred_ = true; | 315 transferred_ = true; |
| 315 in_transit_ = false; | 316 in_transit_ = false; |
| 316 ignore_result(buffer_handle_for_transit_.release()); | 317 ignore_result(buffer_handle_for_transit_.release()); |
| 317 CloseNoLock(); | 318 CloseNoLock(); |
| 318 } | 319 } |
| 319 | 320 |
| 320 void DataPipeProducerDispatcher::CancelTransit() { | 321 void DataPipeProducerDispatcher::CancelTransit( |
| 322 RequestContext* request_context) { |
| 321 base::AutoLock lock(lock_); | 323 base::AutoLock lock(lock_); |
| 322 DCHECK(in_transit_); | 324 DCHECK(in_transit_); |
| 323 in_transit_ = false; | 325 in_transit_ = false; |
| 324 buffer_handle_for_transit_.reset(); | 326 buffer_handle_for_transit_.reset(); |
| 325 awakable_list_.AwakeForStateChange(GetHandleSignalsStateNoLock()); | 327 awakable_list_.AwakeForStateChange(GetHandleSignalsStateNoLock()); |
| 326 } | 328 } |
| 327 | 329 |
| 328 // static | 330 // static |
| 329 scoped_refptr<DataPipeProducerDispatcher> | 331 scoped_refptr<DataPipeProducerDispatcher> |
| 330 DataPipeProducerDispatcher::Deserialize(const void* data, | 332 DataPipeProducerDispatcher::Deserialize(const void* data, |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 } | 504 } |
| 503 | 505 |
| 504 if (peer_closed_ != was_peer_closed || | 506 if (peer_closed_ != was_peer_closed || |
| 505 available_capacity_ != previous_capacity) { | 507 available_capacity_ != previous_capacity) { |
| 506 awakable_list_.AwakeForStateChange(GetHandleSignalsStateNoLock()); | 508 awakable_list_.AwakeForStateChange(GetHandleSignalsStateNoLock()); |
| 507 } | 509 } |
| 508 } | 510 } |
| 509 | 511 |
| 510 } // namespace edk | 512 } // namespace edk |
| 511 } // namespace mojo | 513 } // namespace mojo |
| OLD | NEW |