Chromium Code Reviews| Index: blimp/net/blob_channel/blob_channel_receiver.cc |
| diff --git a/blimp/net/blob_channel/blob_channel_receiver.cc b/blimp/net/blob_channel/blob_channel_receiver.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..29d294239acc3e6cfcecd148099966daaaa0926c |
| --- /dev/null |
| +++ b/blimp/net/blob_channel/blob_channel_receiver.cc |
| @@ -0,0 +1,54 @@ |
| +// 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_receiver.h" |
| + |
| +#include "base/logging.h" |
| +#include "base/macros.h" |
| +#include "blimp/common/blob_cache/blob_cache.h" |
| + |
| +namespace blimp { |
| + |
| +BlobChannelReceiver::Delegate::Delegate() {} |
| + |
| +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.
|
| + |
| +void BlobChannelReceiver::Delegate::SetReceiver(BlobChannelReceiver* receiver) { |
| + receiver_ = receiver; |
| +} |
| + |
| +void BlobChannelReceiver::Delegate::OnBlobReceived(const BlobId& id, |
| + BlobDataPtr data) { |
| + if (receiver_) { |
| + receiver_->OnBlobReceived(id, data); |
| + } |
| +} |
| + |
| +BlobChannelReceiver::BlobChannelReceiver(std::unique_ptr<BlobCache> cache, |
| + std::unique_ptr<Delegate> delegate) |
| + : cache_(std::move(cache)), delegate_(std::move(delegate)) { |
| + DCHECK(cache_); |
| + DCHECK(delegate_); |
| + delegate_->SetReceiver(this); |
| +} |
| + |
| +BlobChannelReceiver::~BlobChannelReceiver() { |
| + delegate_->SetReceiver(nullptr); |
| +} |
| + |
| +BlobDataPtr BlobChannelReceiver::Get(const BlobId& id) { |
| + DVLOG(2) << "Get blob: " << id; |
| + |
| + base::AutoLock lock(lock_); |
| + return cache_->Get(id); |
| +} |
| + |
| +void BlobChannelReceiver::OnBlobReceived(const BlobId& id, BlobDataPtr data) { |
| + DVLOG(2) << "Blob received: " << id; |
| + |
| + base::AutoLock lock(lock_); |
| + cache_->Put(id, data); |
| +} |
| + |
| +} // namespace blimp |