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

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

Issue 1887013003: Blimp: Add BlobChannelSender implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blobchannel-blobcache
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_sender.cc
diff --git a/blimp/net/blob_channel/blob_channel_sender.cc b/blimp/net/blob_channel/blob_channel_sender.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6f55d6fcd623b9db06813cec80f5cc12ded30504
--- /dev/null
+++ b/blimp/net/blob_channel/blob_channel_sender.cc
@@ -0,0 +1,49 @@
+// 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_sender.h"
+
+#include "base/strings/string_number_conversions.h"
+#include "blimp/common/blob_cache/blob_cache.h"
+
+namespace blimp {
+
+BlobChannelSender::BlobChannelSender(BlobCache* cache,
+ Delegate* delegate)
+ : cache_(cache), delegate_(delegate) {
+ DCHECK(cache_);
+ DCHECK(delegate_);
+}
+
+BlobChannelSender::~BlobChannelSender() {}
+
+void BlobChannelSender::Put(const BlobId& id, BlobData data) {
+ DCHECK(data.get());
Wez 2016/04/19 00:01:57 nit: Just DCHECK(data) Do you also want to DCHECK
Kevin M 2016/04/19 23:39:23 Done.
+
+ if (cache_->Contains(id)) {
+ return;
+ }
+
+ VLOG(2) << "Put blob: " << base::HexEncode(id.data(), id.size());
+ cache_->Put(id, data);
+}
+
+void BlobChannelSender::Deliver(const BlobId& id) {
+ if (!cache_->Contains(id)) {
+ DLOG(FATAL) << "Attempted to push invalid blob ID: "
+ << base::HexEncode(id.data(), id.size());
+ return;
+ }
+ if (receiver_cache_contents_.find(id) != receiver_cache_contents_.end()) {
+ DVLOG(3) << "Suppressed redundant push: "
+ << base::HexEncode(id.data(), id.size());
+ return;
+ }
+
+ VLOG(2) << "Deliver blob: " << base::HexEncode(id.data(), id.size());
+ delegate_->Deliver(id, cache_->Get(id));
+ receiver_cache_contents_.insert(id);
+}
+
+} // namespace blimp

Powered by Google App Engine
This is Rietveld 408576698