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 "blimp/net/blob_channel/blob_channel_sender.h" | 7 #include "blimp/net/blob_channel/blob_channel_sender.h" |
8 #include "mojo/public/cpp/system/buffer.h" | |
8 | 9 |
9 namespace blimp { | 10 namespace blimp { |
10 namespace engine { | 11 namespace engine { |
11 | 12 |
12 BlobChannelService::BlobChannelService(BlobChannelSender* blob_channel_sender, | 13 BlobChannelService::BlobChannelService(BlobChannelSender* blob_channel_sender, |
13 mojom::BlobChannelRequest request) | 14 mojom::BlobChannelRequest request) |
14 : binding_(this, std::move(request)), | 15 : binding_(this, std::move(request)), |
15 blob_channel_sender_(blob_channel_sender) { | 16 blob_channel_sender_(blob_channel_sender) { |
16 DCHECK(blob_channel_sender_); | 17 DCHECK(blob_channel_sender_); |
17 } | 18 } |
18 | 19 |
19 BlobChannelService::~BlobChannelService() {} | 20 BlobChannelService::~BlobChannelService() {} |
20 | 21 |
21 void BlobChannelService::PutBlob(const mojo::String& id, | 22 void BlobChannelService::PutBlob(const mojo::String& id, |
22 const mojo::String& data) { | 23 mojo::ScopedSharedBufferHandle data, |
23 blob_channel_sender_->PutBlob(id, new BlobData(data)); | 24 uint32_t size, |
25 const PutBlobCallback& callback) { | |
26 // Map |data| into memory. | |
27 char* blob_buf = nullptr; | |
Wez
2016/06/11 00:16:37
nit: Should this be const char*? We don't really w
Kevin M
2016/06/16 21:00:38
MapBuffer() takes a non-const void*. I'd have to d
| |
28 MojoResult result = | |
29 mojo::MapBuffer(data.get(), 0, size, reinterpret_cast<void**>(&blob_buf), | |
30 MOJO_MAP_BUFFER_FLAG_NONE); | |
31 if (result != MOJO_RESULT_OK) { | |
32 LOG(ERROR) << "Couldn't map buffer for blob ID: " << id; | |
Wez
2016/06/11 00:16:37
It's best not to log unbounded ERRORs - if we fail
maniscalco
2016/06/13 15:23:08
I asked for logging here because I'm operating und
Wez
2016/06/13 23:37:50
TBH I'd expect that both map & unmap should only f
maniscalco
2016/06/16 15:31:34
LOG(FATAL) SGTM
Kevin M
2016/06/16 21:00:38
Done.
| |
33 DLOG(FATAL) << "Exiting."; | |
34 return; | |
35 } | |
36 DCHECK(blob_buf); | |
Wez
2016/06/11 00:16:37
nit: You're about to copy data from |blob_buf|, so
Kevin M
2016/06/16 21:00:38
Done.
| |
37 | |
38 scoped_refptr<BlobData> new_blob(new BlobData); | |
39 new_blob->data.assign(blob_buf, size); | |
40 blob_channel_sender_->PutBlob(id, std::move(new_blob)); | |
Wez
2016/06/11 00:16:37
nit: Use a blank line here to separate the put-blo
Kevin M
2016/06/16 21:00:38
Done.
| |
41 result = mojo::UnmapBuffer(blob_buf); | |
42 if (result != MOJO_RESULT_OK) { | |
43 LOG(ERROR) << "Couldn't unmap buffer for blob ID: " << id | |
44 << " (result code: " << result << ")"; | |
45 DLOG(FATAL) << "Exiting."; | |
46 return; | |
Wez
2016/06/11 00:16:37
This feels like a use-case for CHECK_EQ() - we rea
Kevin M
2016/06/16 21:00:38
Done.
| |
47 } | |
48 | |
49 // Signals the renderer side that we are done with the shared memory |data|. | |
50 callback.Run(); | |
24 } | 51 } |
25 | 52 |
26 void BlobChannelService::DeliverBlob(const mojo::String& id) { | 53 void BlobChannelService::DeliverBlob(const mojo::String& id) { |
27 blob_channel_sender_->DeliverBlob(id); | 54 blob_channel_sender_->DeliverBlob(id); |
28 } | 55 } |
29 | 56 |
30 // static | 57 // static |
31 void BlobChannelService::Create( | 58 void BlobChannelService::Create( |
32 BlobChannelSender* blob_channel_sender, | 59 BlobChannelSender* blob_channel_sender, |
33 mojo::InterfaceRequest<mojom::BlobChannel> request) { | 60 mojo::InterfaceRequest<mojom::BlobChannel> request) { |
34 // Object lifetime is managed by BlobChannelService's StrongBinding | 61 // Object lifetime is managed by BlobChannelService's StrongBinding |
35 // |binding_|. | 62 // |binding_|. |
36 new BlobChannelService(blob_channel_sender, std::move(request)); | 63 new BlobChannelService(blob_channel_sender, std::move(request)); |
37 } | 64 } |
38 | 65 |
39 } // namespace engine | 66 } // namespace engine |
40 } // namespace blimp | 67 } // namespace blimp |
OLD | NEW |