| Index: sky/engine/platform/fetcher/DrainDataPipeJob.cpp
|
| diff --git a/sky/engine/platform/fetcher/DrainDataPipeJob.cpp b/sky/engine/platform/fetcher/DrainDataPipeJob.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..b1c1843be4ea30c6526045f4d55a78073f3c634c
|
| --- /dev/null
|
| +++ b/sky/engine/platform/fetcher/DrainDataPipeJob.cpp
|
| @@ -0,0 +1,52 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "config.h"
|
| +#include "platform/fetcher/DrainDataPipeJob.h"
|
| +
|
| +#include "base/bind.h"
|
| +
|
| +namespace blink {
|
| +
|
| +DrainDataPipeJob::DrainDataPipeJob(Client* client,
|
| + mojo::ScopedDataPipeConsumerHandle source)
|
| + : client_(client),
|
| + source_(source.Pass()),
|
| + weak_factory_(this) {
|
| + DCHECK(client_);
|
| + ReadData();
|
| +}
|
| +
|
| +DrainDataPipeJob::~DrainDataPipeJob() {
|
| +}
|
| +
|
| +void DrainDataPipeJob::ReadData() {
|
| + const void* buffer = nullptr;
|
| + uint32_t num_bytes = 0;
|
| + MojoResult rv = BeginReadDataRaw(source_.get(),
|
| + &buffer, &num_bytes, MOJO_READ_DATA_FLAG_NONE);
|
| + if (rv == MOJO_RESULT_OK) {
|
| + client_->OnDataAvailable(buffer, num_bytes);
|
| + EndReadDataRaw(source_.get(), num_bytes);
|
| + WaitForData();
|
| + } else if (rv == MOJO_RESULT_SHOULD_WAIT) {
|
| + WaitForData();
|
| + } else if (rv == MOJO_RESULT_FAILED_PRECONDITION) {
|
| + client_->OnDataComplete();
|
| + } else {
|
| + DCHECK(false);
|
| + }
|
| +}
|
| +
|
| +void DrainDataPipeJob::WaitForData() {
|
| + handle_watcher_.Start(source_.get(),
|
| + MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE,
|
| + base::Bind(&DrainDataPipeJob::WaitComplete, weak_factory_.GetWeakPtr()));
|
| +}
|
| +
|
| +void DrainDataPipeJob::WaitComplete(MojoResult result) {
|
| + ReadData();
|
| +}
|
| +
|
| +} // namespace blink
|
|
|