| 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_consumer_dispatcher.h" | 5 #include "mojo/edk/system/data_pipe_consumer_dispatcher.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 if (initialized) { | 73 if (initialized) { |
| 74 base::AutoLock lock(lock_); | 74 base::AutoLock lock(lock_); |
| 75 InitializeNoLock(); | 75 InitializeNoLock(); |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 | 78 |
| 79 Dispatcher::Type DataPipeConsumerDispatcher::GetType() const { | 79 Dispatcher::Type DataPipeConsumerDispatcher::GetType() const { |
| 80 return Type::DATA_PIPE_CONSUMER; | 80 return Type::DATA_PIPE_CONSUMER; |
| 81 } | 81 } |
| 82 | 82 |
| 83 MojoResult DataPipeConsumerDispatcher::Close() { | 83 MojoResult DataPipeConsumerDispatcher::Close(RequestContext* request_context) { |
| 84 base::AutoLock lock(lock_); | 84 base::AutoLock lock(lock_); |
| 85 DVLOG(1) << "Closing data pipe consumer " << pipe_id_; | 85 DVLOG(1) << "Closing data pipe consumer " << pipe_id_; |
| 86 return CloseNoLock(); | 86 return CloseNoLock(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 MojoResult DataPipeConsumerDispatcher::ReadData(void* elements, | 89 MojoResult DataPipeConsumerDispatcher::ReadData(void* elements, |
| 90 uint32_t* num_bytes, | 90 uint32_t* num_bytes, |
| 91 MojoReadDataFlags flags) { | 91 MojoReadDataFlags flags) { |
| 92 base::AutoLock lock(lock_); | 92 base::AutoLock lock(lock_); |
| 93 if (!shared_ring_buffer_ || in_transit_) | 93 if (!shared_ring_buffer_ || in_transit_) |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 state->bytes_available = bytes_available_; | 309 state->bytes_available = bytes_available_; |
| 310 | 310 |
| 311 ports[0] = control_port_.name(); | 311 ports[0] = control_port_.name(); |
| 312 | 312 |
| 313 buffer_handle_for_transit_ = shared_ring_buffer_->DuplicatePlatformHandle(); | 313 buffer_handle_for_transit_ = shared_ring_buffer_->DuplicatePlatformHandle(); |
| 314 platform_handles[0] = buffer_handle_for_transit_.get(); | 314 platform_handles[0] = buffer_handle_for_transit_.get(); |
| 315 | 315 |
| 316 return true; | 316 return true; |
| 317 } | 317 } |
| 318 | 318 |
| 319 bool DataPipeConsumerDispatcher::BeginTransit() { | 319 bool DataPipeConsumerDispatcher::BeginTransit(RequestContext* request_context) { |
| 320 base::AutoLock lock(lock_); | 320 base::AutoLock lock(lock_); |
| 321 if (in_transit_) | 321 if (in_transit_) |
| 322 return false; | 322 return false; |
| 323 in_transit_ = !in_two_phase_read_; | 323 in_transit_ = !in_two_phase_read_; |
| 324 return in_transit_; | 324 return in_transit_; |
| 325 } | 325 } |
| 326 | 326 |
| 327 void DataPipeConsumerDispatcher::CompleteTransitAndClose() { | 327 void DataPipeConsumerDispatcher::CompleteTransitAndClose( |
| 328 RequestContext* request_context) { |
| 328 node_controller_->SetPortObserver(control_port_, nullptr); | 329 node_controller_->SetPortObserver(control_port_, nullptr); |
| 329 | 330 |
| 330 base::AutoLock lock(lock_); | 331 base::AutoLock lock(lock_); |
| 331 DCHECK(in_transit_); | 332 DCHECK(in_transit_); |
| 332 in_transit_ = false; | 333 in_transit_ = false; |
| 333 transferred_ = true; | 334 transferred_ = true; |
| 334 ignore_result(buffer_handle_for_transit_.release()); | 335 ignore_result(buffer_handle_for_transit_.release()); |
| 335 CloseNoLock(); | 336 CloseNoLock(); |
| 336 } | 337 } |
| 337 | 338 |
| 338 void DataPipeConsumerDispatcher::CancelTransit() { | 339 void DataPipeConsumerDispatcher::CancelTransit( |
| 340 RequestContext* request_context) { |
| 339 base::AutoLock lock(lock_); | 341 base::AutoLock lock(lock_); |
| 340 DCHECK(in_transit_); | 342 DCHECK(in_transit_); |
| 341 in_transit_ = false; | 343 in_transit_ = false; |
| 342 buffer_handle_for_transit_.reset(); | 344 buffer_handle_for_transit_.reset(); |
| 343 UpdateSignalsStateNoLock(); | 345 UpdateSignalsStateNoLock(); |
| 344 } | 346 } |
| 345 | 347 |
| 346 // static | 348 // static |
| 347 scoped_refptr<DataPipeConsumerDispatcher> | 349 scoped_refptr<DataPipeConsumerDispatcher> |
| 348 DataPipeConsumerDispatcher::Deserialize(const void* data, | 350 DataPipeConsumerDispatcher::Deserialize(const void* data, |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 } | 526 } |
| 525 | 527 |
| 526 if (peer_closed_ != was_peer_closed || | 528 if (peer_closed_ != was_peer_closed || |
| 527 bytes_available_ != previous_bytes_available) { | 529 bytes_available_ != previous_bytes_available) { |
| 528 awakable_list_.AwakeForStateChange(GetHandleSignalsStateNoLock()); | 530 awakable_list_.AwakeForStateChange(GetHandleSignalsStateNoLock()); |
| 529 } | 531 } |
| 530 } | 532 } |
| 531 | 533 |
| 532 } // namespace edk | 534 } // namespace edk |
| 533 } // namespace mojo | 535 } // namespace mojo |
| OLD | NEW |