Chromium Code Reviews| Index: blimp/net/blob_channel/blob_channel_sender.cc |
| diff --git a/blimp/net/blob_channel/blob_channel_sender.cc b/blimp/net/blob_channel/blob_channel_sender.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b68abd0c171bdfe0025a054a23a6e0446fbb85ca |
| --- /dev/null |
| +++ b/blimp/net/blob_channel/blob_channel_sender.cc |
| @@ -0,0 +1,51 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "blimp/net/blob_channel/blob_channel_sender.h" |
| + |
| +#include "base/strings/string_number_conversions.h" |
| +#include "blimp/common/blob_cache/blob_cache.h" |
| +#include "blimp/common/blob_cache/id_util.h" |
| + |
| +namespace blimp { |
| + |
| +BlobChannelSender::BlobChannelSender(std::unique_ptr<BlobCache> cache, |
| + std::unique_ptr<Delegate> delegate) |
| + : cache_(std::move(cache)), delegate_(std::move(delegate)) { |
| + DCHECK(cache_); |
| + DCHECK(delegate_); |
| +} |
| + |
| +BlobChannelSender::~BlobChannelSender() {} |
| + |
| +void BlobChannelSender::Put(const BlobId& id, BlobDataPtr data) { |
| + DCHECK(data); |
| + DCHECK(!id.empty()); |
| + |
| + if (cache_->Contains(id)) { |
| + return; |
| + } |
| + |
| + VLOG(2) << "Put blob: " << FormatBlobId(id); |
| + cache_->Put(id, data); |
| +} |
| + |
| +void BlobChannelSender::DeliverBlob(const BlobId& id) { |
| + if (!cache_->Contains(id)) { |
| + DLOG(FATAL) << "Attempted to push unknown blob: " |
| + << FormatBlobId(id); |
| + return; |
| + } |
| + |
| + if (receiver_cache_contents_.find(id) != receiver_cache_contents_.end()) { |
| + DVLOG(3) << "Suppressed redundant push: " << FormatBlobId(id); |
| + return; |
| + } |
| + |
| + VLOG(2) << "Deliver blob: " << FormatBlobId(id); |
| + delegate_->DeliverBlob(id, cache_->Get(id)); |
| + receiver_cache_contents_.insert(id); |
|
Wez
2016/05/03 22:11:05
nit: Suggest moving this to come immediately after
Kevin M
2016/05/03 22:42:57
Done.
|
| +} |
| + |
| +} // namespace blimp |