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_receiver.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/macros.h" | |
| 9 #include "blimp/common/blob_cache/blob_cache.h" | |
| 10 | |
| 11 namespace blimp { | |
| 12 | |
| 13 BlobChannelReceiver::Delegate::Delegate() {} | |
| 14 | |
| 15 BlobChannelReceiver::Delegate::~Delegate() {} | |
|
Wez
2016/04/21 00:55:02
nit: You can still DCHECK(!receiver.isValid()) dur
Kevin M
2016/04/21 21:24:07
Done.
| |
| 16 | |
| 17 void BlobChannelReceiver::Delegate::SetReceiver(BlobChannelReceiver* receiver) { | |
| 18 receiver_ = receiver; | |
| 19 } | |
| 20 | |
| 21 void BlobChannelReceiver::Delegate::OnBlobReceived(const BlobId& id, | |
| 22 BlobDataPtr data) { | |
| 23 if (receiver_) { | |
| 24 receiver_->OnBlobReceived(id, data); | |
| 25 } | |
| 26 } | |
| 27 | |
| 28 BlobChannelReceiver::BlobChannelReceiver(std::unique_ptr<BlobCache> cache, | |
| 29 std::unique_ptr<Delegate> delegate) | |
| 30 : cache_(std::move(cache)), delegate_(std::move(delegate)) { | |
| 31 DCHECK(cache_); | |
| 32 DCHECK(delegate_); | |
| 33 delegate_->SetReceiver(this); | |
| 34 } | |
| 35 | |
| 36 BlobChannelReceiver::~BlobChannelReceiver() { | |
| 37 delegate_->SetReceiver(nullptr); | |
| 38 } | |
| 39 | |
| 40 BlobDataPtr BlobChannelReceiver::Get(const BlobId& id) { | |
| 41 DVLOG(2) << "Get blob: " << id; | |
| 42 | |
| 43 base::AutoLock lock(lock_); | |
| 44 return cache_->Get(id); | |
| 45 } | |
| 46 | |
| 47 void BlobChannelReceiver::OnBlobReceived(const BlobId& id, BlobDataPtr data) { | |
| 48 DVLOG(2) << "Blob received: " << id; | |
| 49 | |
| 50 base::AutoLock lock(lock_); | |
| 51 cache_->Put(id, data); | |
| 52 } | |
| 53 | |
| 54 } // namespace blimp | |
| OLD | NEW |