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..866b323487c08629331d3cf9776ff857501f86b8 |
| --- /dev/null |
| +++ b/blimp/net/blob_channel/blob_channel_receiver.cc |
| @@ -0,0 +1,56 @@ |
| +// 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() { |
| + DCHECK(!receiver_); |
| +} |
| + |
| +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_); |
|
Wez
2016/05/03 21:32:20
nit: Next line de-refs delegate_, so no need to DC
Kevin M
2016/05/03 22:29:42
Done.
|
| + 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 |