Index: blimp/engine/mojo/blob_channel_service.cc |
diff --git a/blimp/engine/mojo/blob_channel_service.cc b/blimp/engine/mojo/blob_channel_service.cc |
index 0234df60698b3a2c2628537b7e66cfd9ae44bfd9..79a95f6c87d08de7c3fb4b98da8ca3fe7a0dcee7 100644 |
--- a/blimp/engine/mojo/blob_channel_service.cc |
+++ b/blimp/engine/mojo/blob_channel_service.cc |
@@ -5,6 +5,7 @@ |
#include "blimp/engine/mojo/blob_channel_service.h" |
#include "blimp/net/blob_channel/blob_channel_sender.h" |
+#include "mojo/public/cpp/system/buffer.h" |
namespace blimp { |
namespace engine { |
@@ -19,8 +20,34 @@ BlobChannelService::BlobChannelService(BlobChannelSender* blob_channel_sender, |
BlobChannelService::~BlobChannelService() {} |
void BlobChannelService::PutBlob(const mojo::String& id, |
- const mojo::String& data) { |
- blob_channel_sender_->PutBlob(id, new BlobData(data)); |
+ mojo::ScopedSharedBufferHandle data, |
+ uint32_t size, |
+ const PutBlobCallback& callback) { |
+ // Map |data| into memory. |
+ char* blob_buf = nullptr; |
+ MojoResult result = |
+ mojo::MapBuffer(data.get(), 0, size, reinterpret_cast<void**>(&blob_buf), |
+ MOJO_MAP_BUFFER_FLAG_NONE); |
+ if (result != MOJO_RESULT_OK) { |
+ LOG(ERROR) << "Couldn't map buffer for blob ID: " << id; |
+ DLOG(FATAL) << "Exiting."; |
+ return; |
+ } |
+ DCHECK(blob_buf); |
+ |
+ scoped_refptr<BlobData> new_blob(new BlobData); |
+ new_blob->data.assign(blob_buf, size); |
+ blob_channel_sender_->PutBlob(id, std::move(new_blob)); |
+ result = mojo::UnmapBuffer(blob_buf); |
+ if (result != MOJO_RESULT_OK) { |
+ LOG(ERROR) << "Couldn't unmap buffer for blob ID: " << id |
+ << " (result code: " << result << ")"; |
+ DLOG(FATAL) << "Exiting."; |
+ return; |
+ } |
+ |
+ // Signals the renderer side that we are done with the shared memory |data|. |
+ callback.Run(); |
} |
void BlobChannelService::DeliverBlob(const mojo::String& id) { |