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

Side by Side Diff: extensions/browser/api/usb/usb_api.cc

Issue 2689673002: Inline base::BinaryValue into base::Value (Closed)
Patch Set: Rebase Created 3 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/browser/api/usb/usb_api.h" 5 #include "extensions/browser/api/usb/usb_api.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <numeric> 9 #include <numeric>
10 #include <set> 10 #include <set>
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 scoped_refptr<net::IOBuffer> data, 461 scoped_refptr<net::IOBuffer> data,
462 size_t length) { 462 size_t length) {
463 std::unique_ptr<base::DictionaryValue> transfer_info( 463 std::unique_ptr<base::DictionaryValue> transfer_info(
464 new base::DictionaryValue()); 464 new base::DictionaryValue());
465 transfer_info->SetInteger(kResultCodeKey, status); 465 transfer_info->SetInteger(kResultCodeKey, status);
466 466
467 if (data) { 467 if (data) {
468 transfer_info->Set(kDataKey, base::BinaryValue::CreateWithCopiedBuffer( 468 transfer_info->Set(kDataKey, base::BinaryValue::CreateWithCopiedBuffer(
469 data->data(), length)); 469 data->data(), length));
470 } else { 470 } else {
471 transfer_info->Set(kDataKey, new base::BinaryValue()); 471 transfer_info->Set(kDataKey, new base::Value(base::Value::Type::BINARY));
472 } 472 }
473 473
474 if (status == device::USB_TRANSFER_COMPLETED) { 474 if (status == device::USB_TRANSFER_COMPLETED) {
475 Respond(OneArgument(std::move(transfer_info))); 475 Respond(OneArgument(std::move(transfer_info)));
476 } else { 476 } else {
477 std::unique_ptr<base::ListValue> error_args(new base::ListValue()); 477 std::unique_ptr<base::ListValue> error_args(new base::ListValue());
478 error_args->Append(std::move(transfer_info)); 478 error_args->Append(std::move(transfer_info));
479 // Using ErrorWithArguments is discouraged but required to provide the 479 // Using ErrorWithArguments is discouraged but required to provide the
480 // detailed transfer info as the transfer may have partially succeeded. 480 // detailed transfer info as the transfer may have partially succeeded.
481 Respond(ErrorWithArguments(std::move(error_args), 481 Respond(ErrorWithArguments(std::move(error_args),
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after
1234 memcpy(&buffer[buffer_offset], data->data() + data_offset, 1234 memcpy(&buffer[buffer_offset], data->data() + data_offset,
1235 packet.transferred_length); 1235 packet.transferred_length);
1236 } 1236 }
1237 buffer_offset += packet.transferred_length; 1237 buffer_offset += packet.transferred_length;
1238 data_offset += packet.length; 1238 data_offset += packet.length;
1239 } 1239 }
1240 1240
1241 std::unique_ptr<base::DictionaryValue> transfer_info( 1241 std::unique_ptr<base::DictionaryValue> transfer_info(
1242 new base::DictionaryValue()); 1242 new base::DictionaryValue());
1243 transfer_info->SetInteger(kResultCodeKey, status); 1243 transfer_info->SetInteger(kResultCodeKey, status);
1244 transfer_info->Set(kDataKey, 1244 transfer_info->Set(kDataKey, new base::BinaryValue(std::vector<char>(
1245 new base::BinaryValue(std::move(buffer), length)); 1245 buffer.get(), buffer.get() + length)));
1246 if (status == device::USB_TRANSFER_COMPLETED) { 1246 if (status == device::USB_TRANSFER_COMPLETED) {
1247 Respond(OneArgument(std::move(transfer_info))); 1247 Respond(OneArgument(std::move(transfer_info)));
1248 } else { 1248 } else {
1249 std::unique_ptr<base::ListValue> error_args(new base::ListValue()); 1249 std::unique_ptr<base::ListValue> error_args(new base::ListValue());
1250 error_args->Append(std::move(transfer_info)); 1250 error_args->Append(std::move(transfer_info));
1251 // Using ErrorWithArguments is discouraged but required to provide the 1251 // Using ErrorWithArguments is discouraged but required to provide the
1252 // detailed transfer info as the transfer may have partially succeeded. 1252 // detailed transfer info as the transfer may have partially succeeded.
1253 Respond(ErrorWithArguments(std::move(error_args), 1253 Respond(ErrorWithArguments(std::move(error_args),
1254 ConvertTransferStatusToApi(status))); 1254 ConvertTransferStatusToApi(status)));
1255 } 1255 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1289 1289
1290 std::unique_ptr<base::ListValue> error_args(new base::ListValue()); 1290 std::unique_ptr<base::ListValue> error_args(new base::ListValue());
1291 error_args->AppendBoolean(false); 1291 error_args->AppendBoolean(false);
1292 // Using ErrorWithArguments is discouraged but required to maintain 1292 // Using ErrorWithArguments is discouraged but required to maintain
1293 // compatibility with existing applications. 1293 // compatibility with existing applications.
1294 Respond(ErrorWithArguments(std::move(error_args), kErrorResetDevice)); 1294 Respond(ErrorWithArguments(std::move(error_args), kErrorResetDevice));
1295 } 1295 }
1296 } 1296 }
1297 1297
1298 } // namespace extensions 1298 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/socket/socket_api.cc ('k') | extensions/renderer/argument_spec_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698