| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "blimp/engine/mojo/blob_channel_service.h" | 5 #include "blimp/engine/mojo/blob_channel_service.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "blimp/net/blob_channel/blob_channel_sender.h" | 9 #include "blimp/net/blob_channel/blob_channel_sender.h" |
| 10 #include "mojo/public/cpp/system/buffer.h" |
| 8 | 11 |
| 9 namespace blimp { | 12 namespace blimp { |
| 10 namespace engine { | 13 namespace engine { |
| 11 | 14 |
| 12 BlobChannelService::BlobChannelService(BlobChannelSender* blob_channel_sender, | 15 BlobChannelService::BlobChannelService(BlobChannelSender* blob_channel_sender, |
| 13 mojom::BlobChannelRequest request) | 16 mojom::BlobChannelRequest request) |
| 14 : binding_(this, std::move(request)), | 17 : binding_(this, std::move(request)), |
| 15 blob_channel_sender_(blob_channel_sender) { | 18 blob_channel_sender_(blob_channel_sender) { |
| 16 DCHECK(blob_channel_sender_); | 19 DCHECK(blob_channel_sender_); |
| 17 } | 20 } |
| 18 | 21 |
| 19 BlobChannelService::~BlobChannelService() {} | 22 BlobChannelService::~BlobChannelService() {} |
| 20 | 23 |
| 21 void BlobChannelService::PutBlob(const mojo::String& id, | 24 void BlobChannelService::PutBlob(const mojo::String& id, |
| 22 const mojo::String& data) { | 25 mojo::ScopedSharedBufferHandle data, |
| 23 blob_channel_sender_->PutBlob(id, new BlobData(data)); | 26 uint32_t size) { |
| 27 // Map |data| into the address space and copy out its contents. |
| 28 if (!data.is_valid()) { |
| 29 LOG(ERROR) << "Invalid data handle received from renderer process."; |
| 30 return; |
| 31 } |
| 32 |
| 33 if (size > kMaxBlobSizeBytes) { |
| 34 LOG(ERROR) << "Blob size too big: " << size; |
| 35 return; |
| 36 } |
| 37 |
| 38 mojo::ScopedSharedBufferMapping mapping = data->Map(size); |
| 39 CHECK(mapping) << "Failed to mmap region of " << size << " bytes."; |
| 40 |
| 41 scoped_refptr<BlobData> new_blob(new BlobData); |
| 42 new_blob->data.assign(reinterpret_cast<const char*>(mapping.get()), size); |
| 43 blob_channel_sender_->PutBlob(id, std::move(new_blob)); |
| 24 } | 44 } |
| 25 | 45 |
| 26 void BlobChannelService::DeliverBlob(const mojo::String& id) { | 46 void BlobChannelService::DeliverBlob(const mojo::String& id) { |
| 27 blob_channel_sender_->DeliverBlob(id); | 47 blob_channel_sender_->DeliverBlob(id); |
| 28 } | 48 } |
| 29 | 49 |
| 30 // static | 50 // static |
| 31 void BlobChannelService::Create( | 51 void BlobChannelService::Create( |
| 32 BlobChannelSender* blob_channel_sender, | 52 BlobChannelSender* blob_channel_sender, |
| 33 mojo::InterfaceRequest<mojom::BlobChannel> request) { | 53 mojo::InterfaceRequest<mojom::BlobChannel> request) { |
| 34 // Object lifetime is managed by BlobChannelService's StrongBinding | 54 // Object lifetime is managed by BlobChannelService's StrongBinding |
| 35 // |binding_|. | 55 // |binding_|. |
| 36 new BlobChannelService(blob_channel_sender, std::move(request)); | 56 new BlobChannelService(blob_channel_sender, std::move(request)); |
| 37 } | 57 } |
| 38 | 58 |
| 39 } // namespace engine | 59 } // namespace engine |
| 40 } // namespace blimp | 60 } // namespace blimp |
| OLD | NEW |