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/net/blob_channel/blob_channel_sender_impl.h" | 5 #include "blimp/net/blob_channel/blob_channel_sender_impl.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
| 9 #include "base/stl_util.h" |
7 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
8 #include "blimp/common/blob_cache/blob_cache.h" | 11 #include "blimp/common/blob_cache/blob_cache.h" |
9 #include "blimp/common/blob_cache/id_util.h" | 12 #include "blimp/common/blob_cache/id_util.h" |
10 | 13 |
11 namespace blimp { | 14 namespace blimp { |
12 | 15 |
13 BlobChannelSenderImpl::BlobChannelSenderImpl(std::unique_ptr<BlobCache> cache, | 16 BlobChannelSenderImpl::BlobChannelSenderImpl(std::unique_ptr<BlobCache> cache, |
14 std::unique_ptr<Delegate> delegate) | 17 std::unique_ptr<Delegate> delegate) |
15 : cache_(std::move(cache)), delegate_(std::move(delegate)) { | 18 : cache_(std::move(cache)), delegate_(std::move(delegate)) { |
16 DCHECK(cache_); | 19 DCHECK(cache_); |
17 DCHECK(delegate_); | 20 DCHECK(delegate_); |
18 } | 21 } |
19 | 22 |
20 BlobChannelSenderImpl::~BlobChannelSenderImpl() {} | 23 BlobChannelSenderImpl::~BlobChannelSenderImpl() {} |
21 | 24 |
| 25 std::vector<BlobChannelSender::CacheStateEntry> |
| 26 BlobChannelSenderImpl::GetCachedBlobIds() const { |
| 27 const auto cache_state = cache_->GetCachedBlobIds(); |
| 28 std::vector<CacheStateEntry> output; |
| 29 output.reserve(cache_state.size()); |
| 30 for (const std::string& cached_id : cache_state) { |
| 31 CacheStateEntry next_output; |
| 32 next_output.id = cached_id; |
| 33 next_output.was_delivered = |
| 34 ContainsKey(receiver_cache_contents_, cached_id); |
| 35 output.push_back(next_output); |
| 36 } |
| 37 return output; |
| 38 } |
| 39 |
22 void BlobChannelSenderImpl::PutBlob(const BlobId& id, BlobDataPtr data) { | 40 void BlobChannelSenderImpl::PutBlob(const BlobId& id, BlobDataPtr data) { |
23 DCHECK(data); | 41 DCHECK(data); |
24 DCHECK(!id.empty()); | 42 DCHECK(!id.empty()); |
25 | 43 |
26 if (cache_->Contains(id)) { | 44 if (cache_->Contains(id)) { |
27 return; | 45 return; |
28 } | 46 } |
29 | 47 |
30 VLOG(2) << "Put blob: " << BlobIdToString(id); | 48 VLOG(2) << "Put blob: " << BlobIdToString(id); |
31 cache_->Put(id, data); | 49 cache_->Put(id, data); |
32 } | 50 } |
33 | 51 |
34 void BlobChannelSenderImpl::DeliverBlob(const BlobId& id) { | 52 void BlobChannelSenderImpl::DeliverBlob(const BlobId& id) { |
35 if (!cache_->Contains(id)) { | 53 if (!cache_->Contains(id)) { |
36 DLOG(FATAL) << "Attempted to push unknown blob: " << BlobIdToString(id); | 54 DLOG(FATAL) << "Attempted to push unknown blob: " << BlobIdToString(id); |
37 return; | 55 return; |
38 } | 56 } |
39 | 57 |
40 if (receiver_cache_contents_.find(id) != receiver_cache_contents_.end()) { | 58 if (receiver_cache_contents_.find(id) != receiver_cache_contents_.end()) { |
41 DVLOG(3) << "Suppressed redundant push: " << BlobIdToString(id); | 59 DVLOG(3) << "Suppressed redundant push: " << BlobIdToString(id); |
42 return; | 60 return; |
43 } | 61 } |
44 receiver_cache_contents_.insert(id); | 62 receiver_cache_contents_.insert(id); |
45 | 63 |
46 VLOG(2) << "Deliver blob: " << BlobIdToString(id); | 64 VLOG(2) << "Deliver blob: " << BlobIdToString(id); |
47 delegate_->DeliverBlob(id, cache_->Get(id)); | 65 delegate_->DeliverBlob(id, cache_->Get(id)); |
48 } | 66 } |
49 | 67 |
50 } // namespace blimp | 68 } // namespace blimp |
OLD | NEW |