| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2015 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 #ifndef CONTENT_CHILD_MOJO_PIPI_RECEIVED_DATA_ |
| 6 #define CONTENT_CHILD_MOJO_PIPI_RECEIVED_DATA_ |
| 7 |
| 8 #include "content/public/child/request_peer.h" |
| 9 #include "mojo/public/cpp/system/data_pipe.h" |
| 10 |
| 11 // This class implements a minimal RequestPeer::ReceivedData for consuming data |
| 12 // from a Mojo pipe. |
| 13 // |
| 14 // This is based off of: |
| 15 // * mojo/common/data_pipe_drainer.cc for consuming a Mojo data pipe. |
| 16 // * content/child/shared_memory_received_data_factory.h for ReceivedData |
| 17 // implementation. |
| 18 // |
| 19 // TODO(carlosk): We might need a factory model as well like it's done in |
| 20 // SharedMemoryReceivedDataFactory to handle the case of the pipe being closed |
| 21 // while there are results floating around. This is a problem similar to the one |
| 22 // with the buffer on the browser side. |
| 23 |
| 24 namespace content { |
| 25 |
| 26 class MojoPipeReceivedData final : public RequestPeer::ReceivedData { |
| 27 public: |
| 28 static scoped_ptr<RequestPeer::ReceivedData> Create( |
| 29 mojo::DataPipeConsumerHandle source, |
| 30 const void* buffer, |
| 31 uint32_t num_bytes); |
| 32 |
| 33 ~MojoPipeReceivedData() override; |
| 34 |
| 35 // RequestPeer::ReceivedData implementation. |
| 36 const char* payload() const override; |
| 37 int length() const override; |
| 38 int encoded_length() const override; |
| 39 |
| 40 private: |
| 41 MojoPipeReceivedData(mojo::DataPipeConsumerHandle source, |
| 42 const void* buffer, |
| 43 uint32_t num_bytes); |
| 44 |
| 45 // TODO(carlosk): to be safer and simpler I'm making a copy of the data to a |
| 46 // intermediary buffer. Final implementation should hold the internal Mojo |
| 47 // buffer alive until being destroyed. |
| 48 // TODO(carlosk): we need to hold a reference to the source pipe to be able to |
| 49 // get then later release the internal Mojo buffer with the data (instead of |
| 50 // having an extra step of copying it out into another buffer). This *might* |
| 51 // also be required to stop the producer of sending more data while we haven't |
| 52 // consumed the current bundle (otherwise how does Mojo know about this at |
| 53 // all?). |
| 54 // The problems is that we don't want its ownership. Maybe we should switch to |
| 55 // using a linked_ptr shared with the ResourceLoader (instead of |
| 56 // ScopedDataPipeConsumerHandle). This might be enough to make so that we |
| 57 // don't need a factory as described above. |
| 58 // mojo::DataPipeConsumerHandle UNSAFEPTR_source_; |
| 59 // const void* const buffer_; |
| 60 const uint32_t num_bytes_; |
| 61 scoped_ptr<char> real_contents_; |
| 62 |
| 63 DISALLOW_COPY_AND_ASSIGN(MojoPipeReceivedData); |
| 64 }; |
| 65 |
| 66 } // namespace content |
| 67 |
| 68 #endif // CONTENT_CHILD_MOJO_PIPI_RECEIVED_DATA_ |
| OLD | NEW |