| Index: content/child/mojo_pipe_received_data.cc
|
| diff --git a/content/child/mojo_pipe_received_data.cc b/content/child/mojo_pipe_received_data.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..6db61d8275fe25c5ff77e6b0f63a2ff9a0a1fe09
|
| --- /dev/null
|
| +++ b/content/child/mojo_pipe_received_data.cc
|
| @@ -0,0 +1,55 @@
|
| +// Copyright 2015 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 "content/child/mojo_pipe_received_data.h"
|
| +
|
| +#include "base/logging.h"
|
| +
|
| +namespace content {
|
| +
|
| +// static
|
| +scoped_ptr<RequestPeer::ReceivedData> MojoPipeReceivedData::Create(
|
| + mojo::DataPipeConsumerHandle source,
|
| + const void* buffer,
|
| + uint32_t num_bytes) {
|
| + return make_scoped_ptr(new MojoPipeReceivedData(source, buffer, num_bytes));
|
| +}
|
| +
|
| +MojoPipeReceivedData::MojoPipeReceivedData(mojo::DataPipeConsumerHandle source,
|
| + const void* buffer,
|
| + uint32_t num_bytes)
|
| + : num_bytes_(num_bytes) {
|
| + real_contents_ = make_scoped_ptr(new char[num_bytes_]);
|
| + memcpy(real_contents_.get(), buffer, num_bytes_);
|
| + CHECK_EQ(EndReadDataRaw(source, num_bytes_), MOJO_RESULT_OK);
|
| +}
|
| +
|
| +MojoPipeReceivedData::~MojoPipeReceivedData() {
|
| + // TODO(carlosk): in the final implementation EndReadDataRaw should be called
|
| + // here.
|
| + // TODO(carlosk): most probably needs stronger checks to decide if
|
| + // EndReadDataRaw should be called at all. Is the pointer still valid? Is the
|
| + // pipe still open? Etc...
|
| + // CHECK_EQ(EndReadDataRaw(UNSAFEPTR_source_, num_bytes_), MOJO_RESULT_OK);
|
| +}
|
| +
|
| +const char* MojoPipeReceivedData::payload() const {
|
| + return real_contents_.get();
|
| +}
|
| +
|
| +int MojoPipeReceivedData::length() const {
|
| + // TODO(carlosk): Must take care of integer range conversion from uint32_t to
|
| + // int.
|
| + return num_bytes_;
|
| +}
|
| +
|
| +int MojoPipeReceivedData::encoded_length() const {
|
| + // TODO(carlosk): we have to figure out how to send the encoded_length
|
| + // information from the browser to here as it used to be send along with the
|
| + // shared memory buffer flow control messages. For now just returning the same
|
| + // value as length.
|
| + return num_bytes_;
|
| +}
|
| +
|
| +} // namespace content
|
|
|