Chromium Code Reviews| 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 // Take a mutable pointer to the blob_channel message so that we can re-use | |
| 28 // its allocated buffers. | |
| 29 BlobChannelMessage* blob_msg = message->mutable_blob_channel(); | |
| 30 if (blob_msg->type_case() != BlobChannelMessage::TypeCase::kTransferBlob) { | |
| 31 callback.Run(net::ERR_NOT_IMPLEMENTED); | |
| 32 return; | |
| 33 } | |
| 34 | |
| 35 if (blob_msg->transfer_blob().blob_id().empty()) { | |
| 36 callback.Run(net::ERR_INVALID_ARGUMENT); | |
| 37 return; | |
| 38 } | |
| 39 | |
| 40 // Create a temporarily non-const BlobData so that we may efficiently reuse | |
| 41 // the allocated payload string via string::swap(). | |
| 42 // The data is not stored as a BlobDataPtr because its contents are const. | |
|
Wez
2016/05/24 01:18:40
Confusing; I though the point was that we need its
Kevin M
2016/05/25 00:06:33
I think the first two lines summarize what it is I
| |
| 43 scoped_refptr<BlobData> blob_data(new BlobData); | |
| 44 blob_data->data.swap(*blob_msg->mutable_transfer_blob()->mutable_payload()); | |
| 45 OnBlobReceived(blob_msg->transfer_blob().blob_id(), blob_data); | |
| 46 | |
| 47 callback.Run(net::OK); | |
| 48 } | |
| 49 | |
| 50 } // namespace blimp | |
| OLD | NEW |