Chromium Code Reviews| 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 <vector> | |
| 8 | |
| 7 #include "blimp/net/blob_channel/blob_channel_sender.h" | 9 #include "blimp/net/blob_channel/blob_channel_sender.h" |
| 8 | 10 |
| 9 namespace blimp { | 11 namespace blimp { |
| 10 namespace engine { | 12 namespace engine { |
| 11 | 13 |
| 12 BlobChannelService::BlobChannelService(BlobChannelSender* blob_channel_sender, | 14 BlobChannelService::BlobChannelService(BlobChannelSender* blob_channel_sender, |
| 13 mojom::BlobChannelRequest request) | 15 mojom::BlobChannelRequest request) |
| 14 : binding_(this, std::move(request)), | 16 : binding_(this, std::move(request)), |
| 15 blob_channel_sender_(blob_channel_sender) { | 17 blob_channel_sender_(blob_channel_sender) { |
| 16 DCHECK(blob_channel_sender_); | 18 DCHECK(blob_channel_sender_); |
| 17 } | 19 } |
| 18 | 20 |
| 19 BlobChannelService::~BlobChannelService() {} | 21 BlobChannelService::~BlobChannelService() {} |
| 20 | 22 |
| 23 void BlobChannelService::GetCachedBlobIds( | |
| 24 const BlobChannelService::GetCachedBlobIdsCallback& callback) { | |
| 25 VLOG(1) << "BlobChannel::GetCachedBlobIds called."; | |
| 26 | |
| 27 // Pass the Mojo representation of the cache state to |callback|. | |
| 28 std::vector<BlobChannelSender::CacheStateEntry> cache_state = | |
| 29 blob_channel_sender_->GetCachedBlobIds(); | |
| 30 auto output = mojo::Array<mojom::CacheStateEntryPtr>::New(cache_state.size()); | |
| 31 for (size_t i = 0; i < cache_state.size(); ++i) { | |
| 32 mojom::CacheStateEntryPtr converted(mojom::CacheStateEntry::New()); | |
| 33 converted->id.Swap(&cache_state[i].id); | |
| 34 converted->was_delivered = cache_state[i].was_delivered; | |
|
dcheng
2016/06/25 00:55:55
Would it make sense to write a typemap for this ra
| |
| 35 output[i] = std::move(converted); | |
| 36 } | |
| 37 callback.Run(std::move(output)); | |
| 38 } | |
| 39 | |
| 21 void BlobChannelService::PutBlob(const mojo::String& id, | 40 void BlobChannelService::PutBlob(const mojo::String& id, |
| 22 const mojo::String& data) { | 41 const mojo::String& data) { |
| 23 blob_channel_sender_->PutBlob(id, new BlobData(data)); | 42 blob_channel_sender_->PutBlob(id, new BlobData(data)); |
| 24 } | 43 } |
| 25 | 44 |
| 26 void BlobChannelService::DeliverBlob(const mojo::String& id) { | 45 void BlobChannelService::DeliverBlob(const mojo::String& id) { |
| 27 blob_channel_sender_->DeliverBlob(id); | 46 blob_channel_sender_->DeliverBlob(id); |
| 28 } | 47 } |
| 29 | 48 |
| 30 // static | 49 // static |
| 31 void BlobChannelService::Create( | 50 void BlobChannelService::Create( |
| 32 BlobChannelSender* blob_channel_sender, | 51 BlobChannelSender* blob_channel_sender, |
| 33 mojo::InterfaceRequest<mojom::BlobChannel> request) { | 52 mojo::InterfaceRequest<mojom::BlobChannel> request) { |
| 34 // Object lifetime is managed by BlobChannelService's StrongBinding | 53 // Object lifetime is managed by BlobChannelService's StrongBinding |
| 35 // |binding_|. | 54 // |binding_|. |
| 36 new BlobChannelService(blob_channel_sender, std::move(request)); | 55 new BlobChannelService(blob_channel_sender, std::move(request)); |
| 37 } | 56 } |
| 38 | 57 |
| 39 } // namespace engine | 58 } // namespace engine |
| 40 } // namespace blimp | 59 } // namespace blimp |
| OLD | NEW |