| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 #include "platform/fetcher/DrainDataPipeJob.h" |
| 7 |
| 8 #include "base/bind.h" |
| 9 |
| 10 namespace blink { |
| 11 |
| 12 DrainDataPipeJob::DrainDataPipeJob(Client* client, |
| 13 mojo::ScopedDataPipeConsumerHandle source) |
| 14 : client_(client), |
| 15 source_(source.Pass()), |
| 16 weak_factory_(this) { |
| 17 DCHECK(client_); |
| 18 ReadData(); |
| 19 } |
| 20 |
| 21 DrainDataPipeJob::~DrainDataPipeJob() { |
| 22 } |
| 23 |
| 24 void DrainDataPipeJob::ReadData() { |
| 25 const void* buffer = nullptr; |
| 26 uint32_t num_bytes = 0; |
| 27 MojoResult rv = BeginReadDataRaw(source_.get(), |
| 28 &buffer, &num_bytes, MOJO_READ_DATA_FLAG_NONE); |
| 29 if (rv == MOJO_RESULT_OK) { |
| 30 client_->OnDataAvailable(buffer, num_bytes); |
| 31 EndReadDataRaw(source_.get(), num_bytes); |
| 32 WaitForData(); |
| 33 } else if (rv == MOJO_RESULT_SHOULD_WAIT) { |
| 34 WaitForData(); |
| 35 } else if (rv == MOJO_RESULT_FAILED_PRECONDITION) { |
| 36 client_->OnDataComplete(); |
| 37 } else { |
| 38 DCHECK(false); |
| 39 } |
| 40 } |
| 41 |
| 42 void DrainDataPipeJob::WaitForData() { |
| 43 handle_watcher_.Start(source_.get(), |
| 44 MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE, |
| 45 base::Bind(&DrainDataPipeJob::WaitComplete, weak_factory_.GetWeakPtr())); |
| 46 } |
| 47 |
| 48 void DrainDataPipeJob::WaitComplete(MojoResult result) { |
| 49 ReadData(); |
| 50 } |
| 51 |
| 52 } // namespace blink |
| OLD | NEW |