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 <string> |
| 8 #include <unordered_map> |
7 #include <utility> | 9 #include <utility> |
| 10 #include <vector> |
8 | 11 |
| 12 #include "base/memory/ptr_util.h" |
9 #include "blimp/net/blob_channel/blob_channel_sender.h" | 13 #include "blimp/net/blob_channel/blob_channel_sender.h" |
10 #include "mojo/public/cpp/system/buffer.h" | 14 #include "mojo/public/cpp/system/buffer.h" |
11 | 15 |
12 namespace blimp { | 16 namespace blimp { |
13 namespace engine { | 17 namespace engine { |
14 | 18 |
15 BlobChannelService::BlobChannelService(BlobChannelSender* blob_channel_sender, | 19 BlobChannelService::BlobChannelService(BlobChannelSender* blob_channel_sender, |
16 mojom::BlobChannelRequest request) | 20 mojom::BlobChannelRequest request) |
17 : binding_(this, std::move(request)), | 21 : binding_(this, std::move(request)), |
18 blob_channel_sender_(blob_channel_sender) { | 22 blob_channel_sender_(blob_channel_sender) { |
19 DCHECK(blob_channel_sender_); | 23 DCHECK(blob_channel_sender_); |
20 } | 24 } |
21 | 25 |
22 BlobChannelService::~BlobChannelService() {} | 26 BlobChannelService::~BlobChannelService() {} |
23 | 27 |
24 void BlobChannelService::PutBlob(const mojo::String& id, | 28 void BlobChannelService::GetCachedBlobIds( |
| 29 const BlobChannelService::GetCachedBlobIdsCallback& response_callback) { |
| 30 VLOG(1) << "BlobChannel::GetCachedBlobIds called."; |
| 31 std::unordered_map<std::string, bool> cache_state; |
| 32 for (const auto& next_entry : blob_channel_sender_->GetCachedBlobIds()) { |
| 33 cache_state[next_entry.id] = next_entry.was_delivered; |
| 34 } |
| 35 response_callback.Run(std::move(cache_state)); |
| 36 } |
| 37 |
| 38 void BlobChannelService::PutBlob(const std::string& id, |
25 mojo::ScopedSharedBufferHandle data, | 39 mojo::ScopedSharedBufferHandle data, |
26 uint32_t size) { | 40 uint32_t size) { |
27 // Map |data| into the address space and copy out its contents. | 41 // Map |data| into the address space and copy out its contents. |
28 if (!data.is_valid()) { | 42 if (!data.is_valid()) { |
29 LOG(ERROR) << "Invalid data handle received from renderer process."; | 43 LOG(ERROR) << "Invalid data handle received from renderer process."; |
30 return; | 44 return; |
31 } | 45 } |
32 | 46 |
33 if (size > kMaxBlobSizeBytes) { | 47 if (size > kMaxBlobSizeBytes) { |
34 LOG(ERROR) << "Blob size too big: " << size; | 48 LOG(ERROR) << "Blob size too big: " << size; |
35 return; | 49 return; |
36 } | 50 } |
37 | 51 |
38 mojo::ScopedSharedBufferMapping mapping = data->Map(size); | 52 mojo::ScopedSharedBufferMapping mapping = data->Map(size); |
39 CHECK(mapping) << "Failed to mmap region of " << size << " bytes."; | 53 CHECK(mapping) << "Failed to mmap region of " << size << " bytes."; |
40 | 54 |
41 scoped_refptr<BlobData> new_blob(new BlobData); | 55 scoped_refptr<BlobData> new_blob(new BlobData); |
42 new_blob->data.assign(reinterpret_cast<const char*>(mapping.get()), size); | 56 new_blob->data.assign(reinterpret_cast<const char*>(mapping.get()), size); |
43 blob_channel_sender_->PutBlob(id, std::move(new_blob)); | 57 blob_channel_sender_->PutBlob(id, std::move(new_blob)); |
44 } | 58 } |
45 | 59 |
46 void BlobChannelService::DeliverBlob(const mojo::String& id) { | 60 void BlobChannelService::DeliverBlob(const std::string& id) { |
47 blob_channel_sender_->DeliverBlob(id); | 61 blob_channel_sender_->DeliverBlob(id); |
48 } | 62 } |
49 | 63 |
50 // static | 64 // static |
51 void BlobChannelService::Create( | 65 void BlobChannelService::Create( |
52 BlobChannelSender* blob_channel_sender, | 66 BlobChannelSender* blob_channel_sender, |
53 mojo::InterfaceRequest<mojom::BlobChannel> request) { | 67 mojo::InterfaceRequest<mojom::BlobChannel> request) { |
54 // Object lifetime is managed by BlobChannelService's StrongBinding | 68 // Object lifetime is managed by BlobChannelService's StrongBinding |
55 // |binding_|. | 69 // |binding_|. |
56 new BlobChannelService(blob_channel_sender, std::move(request)); | 70 new BlobChannelService(blob_channel_sender, std::move(request)); |
57 } | 71 } |
58 | 72 |
59 } // namespace engine | 73 } // namespace engine |
60 } // namespace blimp | 74 } // namespace blimp |
OLD | NEW |