Index: blimp/net/blob_channel/helium_blob_receiver_delegate.cc |
diff --git a/blimp/net/blob_channel/helium_blob_receiver_delegate.cc b/blimp/net/blob_channel/helium_blob_receiver_delegate.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..eb218eb547b5ee906e6ee4b96cd81f1429fdc176 |
--- /dev/null |
+++ b/blimp/net/blob_channel/helium_blob_receiver_delegate.cc |
@@ -0,0 +1,50 @@ |
+// 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/helium_blob_receiver_delegate.h" |
+ |
+#include "blimp/common/blob_cache/blob_cache.h" |
+#include "blimp/common/proto/blimp_message.pb.h" |
+#include "blimp/common/proto/blob_channel.pb.h" |
+#include "net/base/net_errors.h" |
+ |
+namespace blimp { |
+ |
+HeliumBlobReceiverDelegate::HeliumBlobReceiverDelegate() {} |
+ |
+HeliumBlobReceiverDelegate::~HeliumBlobReceiverDelegate() {} |
+ |
+void HeliumBlobReceiverDelegate::ProcessMessage( |
+ std::unique_ptr<BlimpMessage> message, |
+ const net::CompletionCallback& callback) { |
+ if (!message->has_blob_channel()) { |
+ DLOG(WARNING) << "BlobChannel message has no |blob_channel| submessage."; |
+ callback.Run(net::ERR_INVALID_ARGUMENT); |
+ return; |
+ } |
+ |
+ BlobChannelMessage* blob_msg = message->mutable_blob_channel(); |
Wez
2016/05/20 21:46:18
nit: Comment here to explain why you take a mutabl
Kevin M
2016/05/23 20:48:07
Done.
|
+ if (blob_msg->type() != BlobChannelMessage::TRANSFER_BLOB) { |
+ callback.Run(net::ERR_NOT_IMPLEMENTED); |
+ return; |
+ } |
+ |
+ if (blob_msg->blob_id().empty()) { |
+ callback.Run(net::ERR_INVALID_ARGUMENT); |
+ return; |
+ } |
+ |
+ // Create a temporarily non-const BlobData so that we may efficiently reuse |
+ // the allocated payload string via string::swap(). |
+ // |
+ // BlobData becomes const once it is implicitly cast to a BlobDataPtr |
+ // during the call to OnBlobReceived(). |
Wez
2016/05/20 21:46:18
I think the point here is that we don't store it t
Kevin M
2016/05/23 20:48:07
Done.
|
+ scoped_refptr<BlobData> blob_data(new BlobData); |
+ blob_data->data.swap(*blob_msg->mutable_payload()); |
+ OnBlobReceived(blob_msg->blob_id(), blob_data); |
+ |
+ callback.Run(net::OK); |
+} |
+ |
+} // namespace blimp |