Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: blimp/engine/mojo/blob_channel_service.cc

Issue 2033013003: Use shared memory for moving data over BlobChannel Mojo interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blobchannel-master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "blimp/net/blob_channel/blob_channel_sender.h" 7 #include "blimp/net/blob_channel/blob_channel_sender.h"
8 8
9 namespace blimp { 9 namespace blimp {
10 namespace engine { 10 namespace engine {
11 11
12 BlobChannelService::BlobChannelService(BlobChannelSender* blob_channel_sender, 12 BlobChannelService::BlobChannelService(BlobChannelSender* blob_channel_sender,
13 mojom::BlobChannelRequest request) 13 mojom::BlobChannelRequest request)
14 : binding_(this, std::move(request)), 14 : binding_(this, std::move(request)),
15 blob_channel_sender_(blob_channel_sender) { 15 blob_channel_sender_(blob_channel_sender) {
16 DCHECK(blob_channel_sender_); 16 DCHECK(blob_channel_sender_);
17 } 17 }
18 18
19 BlobChannelService::~BlobChannelService() {} 19 BlobChannelService::~BlobChannelService() {}
20 20
21 void BlobChannelService::PutBlob(const mojo::String& id, 21 void BlobChannelService::PutBlob(const mojo::String& id,
22 const mojo::String& data) { 22 mojo::ScopedSharedBufferHandle data,
23 blob_channel_sender_->PutBlob(id, new BlobData(data)); 23 uint32_t size,
24 const PutBlobCallback& callback) {
25 // Map |data| into memory.
26 char* blob_buf = nullptr;
27 MojoResult result =
28 mojo::MapBuffer(data.get(), 0, size, reinterpret_cast<void**>(&blob_buf),
maniscalco 2016/06/03 16:43:53 #include "mojo/public/cpp/system/buffer.h" to get
Kevin M 2016/06/03 17:14:57 Done.
29 MOJO_MAP_BUFFER_FLAG_NONE);
30 DCHECK_EQ(MOJO_RESULT_OK, result);
31 DCHECK(blob_buf);
32
33 scoped_refptr<BlobData> new_blob(new BlobData);
34 new_blob->data.assign(blob_buf, size);
35 blob_channel_sender_->PutBlob(id, std::move(new_blob));
36 mojo::UnmapBuffer(blob_buf);
maniscalco 2016/06/03 16:43:53 Check the result of UnmapBuffer?
Kevin M 2016/06/03 17:14:57 OK. I'm using DCHECK w/return so that we don't blo
37
38 // Signals the renderer side that we are done with the shared memory |data|.
39 callback.Run();
24 } 40 }
25 41
26 void BlobChannelService::DeliverBlob(const mojo::String& id) { 42 void BlobChannelService::DeliverBlob(const mojo::String& id) {
27 blob_channel_sender_->DeliverBlob(id); 43 blob_channel_sender_->DeliverBlob(id);
28 } 44 }
29 45
30 // static 46 // static
31 void BlobChannelService::Create( 47 void BlobChannelService::Create(
32 BlobChannelSender* blob_channel_sender, 48 BlobChannelSender* blob_channel_sender,
33 mojo::InterfaceRequest<mojom::BlobChannel> request) { 49 mojo::InterfaceRequest<mojom::BlobChannel> request) {
34 // Object lifetime is managed by BlobChannelService's StrongBinding 50 // Object lifetime is managed by BlobChannelService's StrongBinding
35 // |binding_|. 51 // |binding_|.
36 new BlobChannelService(blob_channel_sender, std::move(request)); 52 new BlobChannelService(blob_channel_sender, std::move(request));
37 } 53 }
38 54
39 } // namespace engine 55 } // namespace engine
40 } // namespace blimp 56 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698