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