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

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

Issue 1891083002: Blimp: Add BlobChannelReceiver and bindings interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blobchannel-sender
Patch Set: wez feedback Created 4 years, 8 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
new file mode 100644
index 0000000000000000000000000000000000000000..7200dd3219e3b17cb3fb460793c1ff1e4d11181c
--- /dev/null
+++ b/blimp/net/blob_channel/blob_channel_receiver.cc
@@ -0,0 +1,55 @@
+// 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_);
+ delegate_->SetReceiver(this);
+}
+
+BlobChannelReceiver::~BlobChannelReceiver() {
+ delegate_->SetReceiver(nullptr);
+}
+
+BlobDataPtr BlobChannelReceiver::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) {
+ DVLOG(2) << "Blob received: " << id;
+
+ base::AutoLock lock(cache_lock_);
+ cache_->Put(id, data);
+}
+
+} // namespace blimp
« 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