Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "blimp/net/blob_channel/blob_channel_receiver.h" | 5 #include "blimp/net/blob_channel/blob_channel_receiver.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "blimp/common/blob_cache/blob_cache.h" | 9 #include "blimp/common/blob_cache/blob_cache.h" |
| 10 | 10 |
| 11 namespace blimp { | 11 namespace blimp { |
| 12 | 12 |
| 13 BlobChannelReceiver::Delegate::Delegate() {} | 13 BlobChannelReceiver::Delegate::Delegate() {} |
| 14 | 14 |
| 15 BlobChannelReceiver::Delegate::~Delegate() { | 15 BlobChannelReceiver::Delegate::~Delegate() { |
| 16 DCHECK(!receiver_); | 16 DCHECK(receiver_); |
| 17 } | 17 } |
| 18 | 18 |
| 19 void BlobChannelReceiver::Delegate::SetReceiver(BlobChannelReceiver* receiver) { | 19 void BlobChannelReceiver::Delegate::SetReceiver(BlobChannelReceiver* receiver) { |
| 20 DCHECK(receiver); | |
| 21 DCHECK(!receiver_); | |
| 22 | |
| 20 receiver_ = receiver; | 23 receiver_ = receiver; |
| 21 } | 24 } |
| 22 | 25 |
| 23 void BlobChannelReceiver::Delegate::OnBlobReceived(const BlobId& id, | 26 void BlobChannelReceiver::Delegate::OnBlobReceived(const BlobId& id, |
| 24 BlobDataPtr data) { | 27 BlobDataPtr data) { |
| 25 if (receiver_) { | 28 receiver_->OnBlobReceived(id, data); |
| 26 receiver_->OnBlobReceived(id, data); | |
| 27 } | |
| 28 } | 29 } |
| 29 | 30 |
| 30 BlobChannelReceiver::BlobChannelReceiver(std::unique_ptr<BlobCache> cache, | 31 BlobChannelReceiver::BlobChannelReceiver() {} |
| 31 std::unique_ptr<Delegate> delegate) | 32 |
| 33 BlobChannelReceiver::~BlobChannelReceiver() {} | |
| 34 | |
| 35 BlobChannelReceiverImpl::BlobChannelReceiverImpl( | |
| 36 std::unique_ptr<BlobCache> cache, | |
| 37 std::unique_ptr<Delegate> delegate) | |
| 32 : cache_(std::move(cache)), delegate_(std::move(delegate)) { | 38 : cache_(std::move(cache)), delegate_(std::move(delegate)) { |
| 33 DCHECK(cache_); | 39 DCHECK(cache_); |
| 40 | |
| 34 delegate_->SetReceiver(this); | 41 delegate_->SetReceiver(this); |
| 35 } | 42 } |
| 36 | 43 |
| 37 BlobChannelReceiver::~BlobChannelReceiver() { | 44 BlobChannelReceiverImpl::~BlobChannelReceiverImpl() {} |
| 38 delegate_->SetReceiver(nullptr); | |
|
Wez
2016/05/20 21:46:17
Did you mean to remove the SetReceiver(nullptr) ca
Kevin M
2016/05/23 20:48:07
Nope, it was just unnecessary, since |delegate_| i
| |
| 39 } | |
| 40 | 45 |
| 41 BlobDataPtr BlobChannelReceiver::Get(const BlobId& id) { | 46 BlobDataPtr BlobChannelReceiverImpl::Get(const BlobId& id) { |
| 42 DVLOG(2) << "Get blob: " << id; | 47 DVLOG(2) << "Get blob: " << id; |
| 43 | 48 |
| 44 base::AutoLock lock(cache_lock_); | 49 base::AutoLock lock(cache_lock_); |
| 45 return cache_->Get(id); | 50 return cache_->Get(id); |
| 46 } | 51 } |
| 47 | 52 |
| 48 void BlobChannelReceiver::OnBlobReceived(const BlobId& id, BlobDataPtr data) { | 53 void BlobChannelReceiverImpl::OnBlobReceived(const BlobId& id, |
| 54 BlobDataPtr data) { | |
| 49 DVLOG(2) << "Blob received: " << id; | 55 DVLOG(2) << "Blob received: " << id; |
| 50 | 56 |
| 51 base::AutoLock lock(cache_lock_); | 57 base::AutoLock lock(cache_lock_); |
| 52 cache_->Put(id, data); | 58 cache_->Put(id, data); |
| 53 } | 59 } |
| 54 | 60 |
| 55 } // namespace blimp | 61 } // namespace blimp |
| OLD | NEW |