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..743e445416835d7e9818e420f0042a8c1b895d14 |
| --- /dev/null |
| +++ b/blimp/net/blob_channel/blob_channel_sender.cc |
| @@ -0,0 +1,58 @@ |
| +// 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/net/blob_channel/blob_channel_bindings.h" |
| + |
| +namespace blimp { |
| + |
| +BlobChannelSender::BlobChannelSender(BlobCache* cache, |
| + BlobSenderBindings* bindings) |
| + : cache_(cache), bindings_(bindings) { |
| + DCHECK(cache_); |
| + DCHECK(bindings_); |
| +} |
| + |
| +BlobChannelSender::~BlobChannelSender() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| +} |
| + |
| +void BlobChannelSender::Put(const std::string& id, |
| + std::unique_ptr<std::vector<uint8_t>> data) { |
| + DCHECK(data); |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + |
| + if (cache_->Contains(id)) { |
| + return; |
| + } |
| + |
| + VLOG(2) << "Put blob: " << base::HexEncode(id.data(), id.size()); |
| + scoped_refptr<RefCountedVector> cache_item(new RefCountedVector); |
| + cache_item->data.swap(*data); |
| + cache_->Put(id, cache_item); |
|
Wez
2016/04/15 17:15:16
What is the cache expected to do if it already con
Kevin M
2016/04/15 22:42:57
Drop it. We really don't want to support ID collis
|
| +} |
| + |
| +void BlobChannelSender::Push(const std::string& id) { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + |
| + if (!cache_->Contains(id)) { |
| + DLOG(WARNING) << "Attempted to push invalid blob ID: " |
| + << base::HexEncode(id.data(), id.size()); |
|
Wez
2016/04/15 17:15:16
Why is this only a DLOG(WARNING)? Seems worthy of
Kevin M
2016/04/15 22:42:57
Yeee
|
| + return; |
| + } |
| + if (client_cache_state_.find(id) != client_cache_state_.end()) { |
| + DVLOG(3) << "Suppressed redundant push: " |
| + << base::HexEncode(id.data(), id.size()); |
| + return; |
| + } |
| + |
| + VLOG(2) << "Push blob: " << base::HexEncode(id.data(), id.size()); |
| + bindings_->Send(id, cache_->Get(id)->data); |
| + client_cache_state_.insert(id); |
| +} |
| + |
| +} // namespace blimp |