| 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 "sky/engine/config.h" | |
| 6 #include "sky/engine/platform/fetcher/DataPipeDrainer.h" | |
| 7 | |
| 8 #include "base/bind.h" | |
| 9 | |
| 10 namespace blink { | |
| 11 | |
| 12 DataPipeDrainer::DataPipeDrainer(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 DataPipeDrainer::~DataPipeDrainer() { | |
| 22 } | |
| 23 | |
| 24 void DataPipeDrainer::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 DataPipeDrainer::WaitForData() { | |
| 43 handle_watcher_.Start(source_.get(), | |
| 44 MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE, | |
| 45 base::Bind(&DataPipeDrainer::WaitComplete, weak_factory_.GetWeakPtr())); | |
| 46 } | |
| 47 | |
| 48 void DataPipeDrainer::WaitComplete(MojoResult result) { | |
| 49 ReadData(); | |
| 50 } | |
| 51 | |
| 52 } // namespace blink | |
| OLD | NEW |