| 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 #include "content/child/mojo_pipe_received_data.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 |
| 9 namespace content { |
| 10 |
| 11 // static |
| 12 scoped_ptr<RequestPeer::ReceivedData> MojoPipeReceivedData::Create( |
| 13 mojo::DataPipeConsumerHandle source, |
| 14 const void* buffer, |
| 15 uint32_t num_bytes) { |
| 16 return make_scoped_ptr(new MojoPipeReceivedData(source, buffer, num_bytes)); |
| 17 } |
| 18 |
| 19 MojoPipeReceivedData::MojoPipeReceivedData(mojo::DataPipeConsumerHandle source, |
| 20 const void* buffer, |
| 21 uint32_t num_bytes) |
| 22 : num_bytes_(num_bytes) { |
| 23 real_contents_ = make_scoped_ptr(new char[num_bytes_]); |
| 24 memcpy(real_contents_.get(), buffer, num_bytes_); |
| 25 CHECK_EQ(EndReadDataRaw(source, num_bytes_), MOJO_RESULT_OK); |
| 26 } |
| 27 |
| 28 MojoPipeReceivedData::~MojoPipeReceivedData() { |
| 29 // TODO(carlosk): in the final implementation EndReadDataRaw should be called |
| 30 // here. |
| 31 // TODO(carlosk): most probably needs stronger checks to decide if |
| 32 // EndReadDataRaw should be called at all. Is the pointer still valid? Is the |
| 33 // pipe still open? Etc... |
| 34 // CHECK_EQ(EndReadDataRaw(UNSAFEPTR_source_, num_bytes_), MOJO_RESULT_OK); |
| 35 } |
| 36 |
| 37 const char* MojoPipeReceivedData::payload() const { |
| 38 return real_contents_.get(); |
| 39 } |
| 40 |
| 41 int MojoPipeReceivedData::length() const { |
| 42 // TODO(carlosk): Must take care of integer range conversion from uint32_t to |
| 43 // int. |
| 44 return num_bytes_; |
| 45 } |
| 46 |
| 47 int MojoPipeReceivedData::encoded_length() const { |
| 48 // TODO(carlosk): we have to figure out how to send the encoded_length |
| 49 // information from the browser to here as it used to be send along with the |
| 50 // shared memory buffer flow control messages. For now just returning the same |
| 51 // value as length. |
| 52 return num_bytes_; |
| 53 } |
| 54 |
| 55 } // namespace content |
| OLD | NEW |