| 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 "mojo/common/data_pipe_drainer.h" | 5 #include "mojo/common/data_pipe_drainer.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 | 7 |
| 8 namespace mojo { | 8 namespace mojo { |
| 9 namespace common { | 9 namespace common { |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 &buffer, &num_bytes, MOJO_READ_DATA_FLAG_NONE); | 27 &buffer, &num_bytes, MOJO_READ_DATA_FLAG_NONE); |
| 28 if (rv == MOJO_RESULT_OK) { | 28 if (rv == MOJO_RESULT_OK) { |
| 29 client_->OnDataAvailable(buffer, num_bytes); | 29 client_->OnDataAvailable(buffer, num_bytes); |
| 30 EndReadDataRaw(source_.get(), num_bytes); | 30 EndReadDataRaw(source_.get(), num_bytes); |
| 31 WaitForData(); | 31 WaitForData(); |
| 32 } else if (rv == MOJO_RESULT_SHOULD_WAIT) { | 32 } else if (rv == MOJO_RESULT_SHOULD_WAIT) { |
| 33 WaitForData(); | 33 WaitForData(); |
| 34 } else if (rv == MOJO_RESULT_FAILED_PRECONDITION) { | 34 } else if (rv == MOJO_RESULT_FAILED_PRECONDITION) { |
| 35 client_->OnDataComplete(); | 35 client_->OnDataComplete(); |
| 36 } else { | 36 } else { |
| 37 DCHECK(false); | 37 DCHECK(false) << "Unhandled MojoResult: " << rv; |
| 38 } | 38 } |
| 39 } | 39 } |
| 40 | 40 |
| 41 void DataPipeDrainer::WaitForData() { | 41 void DataPipeDrainer::WaitForData() { |
| 42 handle_watcher_.Start(source_.get(), | 42 handle_watcher_.Start(source_.get(), |
| 43 MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE, | 43 MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE, |
| 44 base::Bind(&DataPipeDrainer::WaitComplete, weak_factory_.GetWeakPtr())); | 44 base::Bind(&DataPipeDrainer::WaitComplete, weak_factory_.GetWeakPtr())); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void DataPipeDrainer::WaitComplete(MojoResult result) { | 47 void DataPipeDrainer::WaitComplete(MojoResult result) { |
| 48 ReadData(); | 48 ReadData(); |
| 49 } | 49 } |
| 50 | 50 |
| 51 } // namespace common | 51 } // namespace common |
| 52 } // namespace mojo | 52 } // namespace mojo |
| OLD | NEW |