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 "device/serial/data_source_sender.h" | 5 #include "device/serial/data_source_sender.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 ready_callback_.Reset(); | 83 ready_callback_.Reset(); |
84 error_callback_.Reset(); | 84 error_callback_.Reset(); |
85 } | 85 } |
86 | 86 |
87 DataSourceSender::~DataSourceSender() { | 87 DataSourceSender::~DataSourceSender() { |
88 DCHECK(shut_down_); | 88 DCHECK(shut_down_); |
89 } | 89 } |
90 | 90 |
91 void DataSourceSender::Init(mojo::ScopedDataPipeProducerHandle handle) { | 91 void DataSourceSender::Init(mojo::ScopedDataPipeProducerHandle handle) { |
92 // This should never occur. |handle_| is only valid and |pending_send_| is | 92 // This should never occur. |handle_| is only valid and |pending_send_| is |
93 // only set after Init is called. Receiving an invalid |handle| from the | 93 // only set after Init is called. |
94 // client is also unrecoverable. | 94 if (pending_send_ || handle_.is_valid() || shut_down_) { |
95 if (pending_send_ || handle_.is_valid() || !handle.is_valid() || shut_down_) { | |
96 DispatchFatalError(); | 95 DispatchFatalError(); |
97 return; | 96 return; |
98 } | 97 } |
99 handle_ = handle.Pass(); | 98 handle_ = handle.Pass(); |
100 pending_send_.reset(new PendingSend(this, ready_callback_)); | 99 pending_send_.reset(new PendingSend(this, ready_callback_)); |
101 StartWaiting(); | 100 StartWaiting(); |
102 } | 101 } |
103 | 102 |
104 void DataSourceSender::Resume() { | 103 void DataSourceSender::Resume() { |
105 if (pending_send_ || !handle_.is_valid()) { | 104 if (pending_send_ || !handle_.is_valid()) { |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 int32_t error) { | 239 int32_t error) { |
241 DCHECK(sender_.get()); | 240 DCHECK(sender_.get()); |
242 pending_send_->DoneWithError(bytes_written, error); | 241 pending_send_->DoneWithError(bytes_written, error); |
243 sender_ = NULL; | 242 sender_ = NULL; |
244 pending_send_ = NULL; | 243 pending_send_ = NULL; |
245 buffer_ = NULL; | 244 buffer_ = NULL; |
246 buffer_size_ = 0; | 245 buffer_size_ = 0; |
247 } | 246 } |
248 | 247 |
249 } // namespace device | 248 } // namespace device |
OLD | NEW |