| 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::ProcessMessage( |
| 19 std::unique_ptr<BlimpMessage> message, |
| 20 const net::CompletionCallback& callback) { |
| 21 if (!message->has_blob_channel()) { |
| 22 DLOG(WARNING) << "BlobChannel message has no |blob_channel| submessage."; |
| 23 callback.Run(net::ERR_INVALID_ARGUMENT); |
| 24 return; |
| 25 } |
| 26 |
| 27 BlobChannelMessage* blob_msg = message->mutable_blob_channel(); |
| 28 if (blob_msg->type() != BlobChannelMessage::TRANSFER_BLOB) { |
| 29 callback.Run(net::ERR_NOT_IMPLEMENTED); |
| 30 return; |
| 31 } |
| 32 |
| 33 if (blob_msg->blob_id().empty()) { |
| 34 callback.Run(net::ERR_INVALID_ARGUMENT); |
| 35 return; |
| 36 } |
| 37 |
| 38 // Create a temporarily non-const BlobData so that we may efficiently reuse |
| 39 // the allocated payload string via string::swap(). |
| 40 // |
| 41 // BlobData becomes const once it is implicitly cast to a BlobDataPtr |
| 42 // during the call to OnBlobReceived(). |
| 43 scoped_refptr<BlobData> blob_data(new BlobData); |
| 44 blob_data->data.swap(*blob_msg->mutable_payload()); |
| 45 OnBlobReceived(blob_msg->blob_id(), blob_data); |
| 46 |
| 47 callback.Run(net::OK); |
| 48 } |
| 49 |
| 50 } // namespace blimp |
| OLD | NEW |