Chromium Code Reviews| 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/net/blob_channel/blob_channel_bindings.h" | |
| 10 | |
| 11 namespace blimp { | |
| 12 | |
| 13 BlobChannelSender::BlobChannelSender(BlobCache* cache, | |
| 14 BlobSenderBindings* bindings) | |
| 15 : cache_(cache), bindings_(bindings) { | |
| 16 DCHECK(cache_); | |
| 17 DCHECK(bindings_); | |
| 18 } | |
| 19 | |
| 20 BlobChannelSender::~BlobChannelSender() { | |
| 21 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 22 } | |
| 23 | |
| 24 void BlobChannelSender::Put(const std::string& id, | |
| 25 std::unique_ptr<std::vector<uint8_t>> data) { | |
| 26 DCHECK(data); | |
| 27 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 28 | |
| 29 if (cache_->Contains(id)) { | |
| 30 return; | |
| 31 } | |
| 32 | |
| 33 VLOG(2) << "Put blob: " << base::HexEncode(id.data(), id.size()); | |
| 34 scoped_refptr<RefCountedVector> cache_item(new RefCountedVector); | |
| 35 cache_item->data.swap(*data); | |
| 36 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
| |
| 37 } | |
| 38 | |
| 39 void BlobChannelSender::Push(const std::string& id) { | |
| 40 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 41 | |
| 42 if (!cache_->Contains(id)) { | |
| 43 DLOG(WARNING) << "Attempted to push invalid blob ID: " | |
| 44 << 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
| |
| 45 return; | |
| 46 } | |
| 47 if (client_cache_state_.find(id) != client_cache_state_.end()) { | |
| 48 DVLOG(3) << "Suppressed redundant push: " | |
| 49 << base::HexEncode(id.data(), id.size()); | |
| 50 return; | |
| 51 } | |
| 52 | |
| 53 VLOG(2) << "Push blob: " << base::HexEncode(id.data(), id.size()); | |
| 54 bindings_->Send(id, cache_->Get(id)->data); | |
| 55 client_cache_state_.insert(id); | |
| 56 } | |
| 57 | |
| 58 } // namespace blimp | |
| OLD | NEW |