| 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.h" |
| 6 |
| 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "blimp/common/blob_cache/blob_cache.h" |
| 9 #include "blimp/common/blob_cache/id_util.h" |
| 10 |
| 11 namespace blimp { |
| 12 |
| 13 BlobChannelSender::BlobChannelSender(std::unique_ptr<BlobCache> cache, |
| 14 std::unique_ptr<Delegate> delegate) |
| 15 : cache_(std::move(cache)), delegate_(std::move(delegate)) { |
| 16 DCHECK(cache_); |
| 17 DCHECK(delegate_); |
| 18 } |
| 19 |
| 20 BlobChannelSender::~BlobChannelSender() {} |
| 21 |
| 22 void BlobChannelSender::PutBlob(const BlobId& id, BlobDataPtr data) { |
| 23 DCHECK(data); |
| 24 DCHECK(!id.empty()); |
| 25 |
| 26 if (cache_->Contains(id)) { |
| 27 return; |
| 28 } |
| 29 |
| 30 VLOG(2) << "Put blob: " << BlobIdToString(id); |
| 31 cache_->Put(id, data); |
| 32 } |
| 33 |
| 34 void BlobChannelSender::DeliverBlob(const BlobId& id) { |
| 35 if (!cache_->Contains(id)) { |
| 36 DLOG(FATAL) << "Attempted to push unknown blob: " << BlobIdToString(id); |
| 37 return; |
| 38 } |
| 39 |
| 40 if (receiver_cache_contents_.find(id) != receiver_cache_contents_.end()) { |
| 41 DVLOG(3) << "Suppressed redundant push: " << BlobIdToString(id); |
| 42 return; |
| 43 } |
| 44 receiver_cache_contents_.insert(id); |
| 45 |
| 46 VLOG(2) << "Deliver blob: " << BlobIdToString(id); |
| 47 delegate_->DeliverBlob(id, cache_->Get(id)); |
| 48 } |
| 49 |
| 50 } // namespace blimp |
| OLD | NEW |