Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2374)

Unified Diff: blimp/net/blob_channel/blob_channel_receiver.cc

Issue 1970463004: Blimp: Add BlobChannel Helium messages and delegate impls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
index 7200dd3219e3b17cb3fb460793c1ff1e4d11181c..da89c2f6b7f8bacad15c46a18e22fb7c49059879 100644
--- a/blimp/net/blob_channel/blob_channel_receiver.cc
+++ b/blimp/net/blob_channel/blob_channel_receiver.cc
@@ -6,46 +6,64 @@
#include "base/logging.h"
#include "base/macros.h"
+#include "base/memory/ptr_util.h"
#include "blimp/common/blob_cache/blob_cache.h"
namespace blimp {
+namespace {
-BlobChannelReceiver::Delegate::Delegate() {}
+// Takes incoming blobs from |delegate_| stores them in |cache_|, and provides
+// callers a getter interface for accessing blobs from |cache_|.
+class BLIMP_NET_EXPORT BlobChannelReceiverImpl : public BlobChannelReceiver {
+ public:
+ BlobChannelReceiverImpl(std::unique_ptr<BlobCache> cache,
+ std::unique_ptr<Delegate> delegate);
+ ~BlobChannelReceiverImpl() override;
-BlobChannelReceiver::Delegate::~Delegate() {
- DCHECK(!receiver_);
-}
+ // BlobChannelReceiver implementation.
+ BlobDataPtr Get(const BlobId& id) override;
+ void OnBlobReceived(const BlobId& id, BlobDataPtr data) override;
-void BlobChannelReceiver::Delegate::SetReceiver(BlobChannelReceiver* receiver) {
- receiver_ = receiver;
-}
+ private:
+ std::unique_ptr<BlobCache> cache_;
+ std::unique_ptr<Delegate> delegate_;
+
+ // Guards against concurrent access to |cache_|.
+ base::Lock cache_lock_;
+
+ DISALLOW_COPY_AND_ASSIGN(BlobChannelReceiverImpl);
+};
-void BlobChannelReceiver::Delegate::OnBlobReceived(const BlobId& id,
- BlobDataPtr data) {
- if (receiver_) {
- receiver_->OnBlobReceived(id, data);
- }
+} // namespace
+
+// static
+std::unique_ptr<BlobChannelReceiver> BlobChannelReceiver::Create(
+ std::unique_ptr<BlobCache> cache,
+ std::unique_ptr<Delegate> delegate) {
+ return base::WrapUnique(
+ new BlobChannelReceiverImpl(std::move(cache), std::move(delegate)));
}
-BlobChannelReceiver::BlobChannelReceiver(std::unique_ptr<BlobCache> cache,
- std::unique_ptr<Delegate> delegate)
+BlobChannelReceiverImpl::BlobChannelReceiverImpl(
+ std::unique_ptr<BlobCache> cache,
+ std::unique_ptr<Delegate> delegate)
: cache_(std::move(cache)), delegate_(std::move(delegate)) {
DCHECK(cache_);
+
delegate_->SetReceiver(this);
}
-BlobChannelReceiver::~BlobChannelReceiver() {
- delegate_->SetReceiver(nullptr);
-}
+BlobChannelReceiverImpl::~BlobChannelReceiverImpl() {}
-BlobDataPtr BlobChannelReceiver::Get(const BlobId& id) {
+BlobDataPtr BlobChannelReceiverImpl::Get(const BlobId& id) {
DVLOG(2) << "Get blob: " << id;
base::AutoLock lock(cache_lock_);
return cache_->Get(id);
}
-void BlobChannelReceiver::OnBlobReceived(const BlobId& id, BlobDataPtr data) {
+void BlobChannelReceiverImpl::OnBlobReceived(const BlobId& id,
+ BlobDataPtr data) {
DVLOG(2) << "Blob received: " << id;
base::AutoLock lock(cache_lock_);
« no previous file with comments | « blimp/net/blob_channel/blob_channel_receiver.h ('k') | blimp/net/blob_channel/blob_channel_receiver_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698