| Index: content/child/mojo_pipe_received_data.h
|
| diff --git a/content/child/mojo_pipe_received_data.h b/content/child/mojo_pipe_received_data.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..c7314f50c8933cd7706dddda8debe1a0dd2420e4
|
| --- /dev/null
|
| +++ b/content/child/mojo_pipe_received_data.h
|
| @@ -0,0 +1,68 @@
|
| +// 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.
|
| +
|
| +#ifndef CONTENT_CHILD_MOJO_PIPI_RECEIVED_DATA_
|
| +#define CONTENT_CHILD_MOJO_PIPI_RECEIVED_DATA_
|
| +
|
| +#include "content/public/child/request_peer.h"
|
| +#include "mojo/public/cpp/system/data_pipe.h"
|
| +
|
| +// This class implements a minimal RequestPeer::ReceivedData for consuming data
|
| +// from a Mojo pipe.
|
| +//
|
| +// This is based off of:
|
| +// * mojo/common/data_pipe_drainer.cc for consuming a Mojo data pipe.
|
| +// * content/child/shared_memory_received_data_factory.h for ReceivedData
|
| +// implementation.
|
| +//
|
| +// TODO(carlosk): We might need a factory model as well like it's done in
|
| +// SharedMemoryReceivedDataFactory to handle the case of the pipe being closed
|
| +// while there are results floating around. This is a problem similar to the one
|
| +// with the buffer on the browser side.
|
| +
|
| +namespace content {
|
| +
|
| +class MojoPipeReceivedData final : public RequestPeer::ReceivedData {
|
| + public:
|
| + static scoped_ptr<RequestPeer::ReceivedData> Create(
|
| + mojo::DataPipeConsumerHandle source,
|
| + const void* buffer,
|
| + uint32_t num_bytes);
|
| +
|
| + ~MojoPipeReceivedData() override;
|
| +
|
| + // RequestPeer::ReceivedData implementation.
|
| + const char* payload() const override;
|
| + int length() const override;
|
| + int encoded_length() const override;
|
| +
|
| + private:
|
| + MojoPipeReceivedData(mojo::DataPipeConsumerHandle source,
|
| + const void* buffer,
|
| + uint32_t num_bytes);
|
| +
|
| + // TODO(carlosk): to be safer and simpler I'm making a copy of the data to a
|
| + // intermediary buffer. Final implementation should hold the internal Mojo
|
| + // buffer alive until being destroyed.
|
| + // TODO(carlosk): we need to hold a reference to the source pipe to be able to
|
| + // get then later release the internal Mojo buffer with the data (instead of
|
| + // having an extra step of copying it out into another buffer). This *might*
|
| + // also be required to stop the producer of sending more data while we haven't
|
| + // consumed the current bundle (otherwise how does Mojo know about this at
|
| + // all?).
|
| + // The problems is that we don't want its ownership. Maybe we should switch to
|
| + // using a linked_ptr shared with the ResourceLoader (instead of
|
| + // ScopedDataPipeConsumerHandle). This might be enough to make so that we
|
| + // don't need a factory as described above.
|
| + // mojo::DataPipeConsumerHandle UNSAFEPTR_source_;
|
| + // const void* const buffer_;
|
| + const uint32_t num_bytes_;
|
| + scoped_ptr<char> real_contents_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(MojoPipeReceivedData);
|
| +};
|
| +
|
| +} // namespace content
|
| +
|
| +#endif // CONTENT_CHILD_MOJO_PIPI_RECEIVED_DATA_
|
|
|