OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "blimp/net/blob_channel/helium_blob_receiver_delegate.h" |
| 6 |
| 7 #include "blimp/common/blob_cache/blob_cache.h" |
| 8 #include "blimp/common/proto/blimp_message.pb.h" |
| 9 #include "blimp/common/proto/blob_channel.pb.h" |
| 10 #include "net/base/net_errors.h" |
| 11 |
| 12 namespace blimp { |
| 13 |
| 14 HeliumBlobReceiverDelegate::HeliumBlobReceiverDelegate() {} |
| 15 |
| 16 HeliumBlobReceiverDelegate::~HeliumBlobReceiverDelegate() {} |
| 17 |
| 18 void HeliumBlobReceiverDelegate::SetReceiver(BlobChannelReceiver* receiver) { |
| 19 DCHECK(receiver); |
| 20 receiver_ = receiver; |
| 21 } |
| 22 |
| 23 void HeliumBlobReceiverDelegate::ProcessMessage( |
| 24 std::unique_ptr<BlimpMessage> message, |
| 25 const net::CompletionCallback& callback) { |
| 26 if (!message->has_blob_channel()) { |
| 27 DLOG(WARNING) << "BlobChannel message has no |blob_channel| submessage."; |
| 28 callback.Run(net::ERR_INVALID_ARGUMENT); |
| 29 return; |
| 30 } |
| 31 |
| 32 // Take a mutable pointer to the blob_channel message so that we can re-use |
| 33 // its allocated buffers. |
| 34 BlobChannelMessage* blob_msg = message->mutable_blob_channel(); |
| 35 if (blob_msg->type_case() != BlobChannelMessage::TypeCase::kTransferBlob) { |
| 36 callback.Run(net::ERR_NOT_IMPLEMENTED); |
| 37 return; |
| 38 } |
| 39 |
| 40 if (blob_msg->transfer_blob().blob_id().empty()) { |
| 41 callback.Run(net::ERR_INVALID_ARGUMENT); |
| 42 return; |
| 43 } |
| 44 |
| 45 // Create a temporarily non-const BlobData so that we may efficiently reuse |
| 46 // the allocated payload string via string::swap(). |
| 47 scoped_refptr<BlobData> blob_data(new BlobData); |
| 48 blob_data->data.swap(*blob_msg->mutable_transfer_blob()->mutable_payload()); |
| 49 receiver_->OnBlobReceived(blob_msg->transfer_blob().blob_id(), blob_data); |
| 50 |
| 51 callback.Run(net::OK); |
| 52 } |
| 53 |
| 54 } // namespace blimp |
OLD | NEW |