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

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

Issue 2799093006: Remove base::BinaryValue (Closed)
Patch Set: Rebase Created 3 years, 8 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>
11 #include <string> 11 #include <string>
12 #include <utility> 12 #include <utility>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/barrier_closure.h" 15 #include "base/barrier_closure.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "base/values.h"
17 #include "device/base/device_client.h" 18 #include "device/base/device_client.h"
18 #include "device/usb/usb_descriptors.h" 19 #include "device/usb/usb_descriptors.h"
19 #include "device/usb/usb_device_handle.h" 20 #include "device/usb/usb_device_handle.h"
20 #include "device/usb/usb_service.h" 21 #include "device/usb/usb_service.h"
21 #include "extensions/browser/api/device_permissions_manager.h" 22 #include "extensions/browser/api/device_permissions_manager.h"
22 #include "extensions/browser/api/device_permissions_prompt.h" 23 #include "extensions/browser/api/device_permissions_prompt.h"
23 #include "extensions/browser/api/extensions_api_client.h" 24 #include "extensions/browser/api/extensions_api_client.h"
24 #include "extensions/browser/api/usb/usb_device_resource.h" 25 #include "extensions/browser/api/usb/usb_device_resource.h"
25 #include "extensions/browser/api/usb/usb_guid_map.h" 26 #include "extensions/browser/api/usb/usb_guid_map.h"
26 #include "extensions/browser/extension_system.h" 27 #include "extensions/browser/extension_system.h"
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 } 459 }
459 460
460 void UsbTransferFunction::OnCompleted(UsbTransferStatus status, 461 void UsbTransferFunction::OnCompleted(UsbTransferStatus status,
461 scoped_refptr<net::IOBuffer> data, 462 scoped_refptr<net::IOBuffer> data,
462 size_t length) { 463 size_t length) {
463 std::unique_ptr<base::DictionaryValue> transfer_info( 464 std::unique_ptr<base::DictionaryValue> transfer_info(
464 new base::DictionaryValue()); 465 new base::DictionaryValue());
465 transfer_info->SetInteger(kResultCodeKey, status); 466 transfer_info->SetInteger(kResultCodeKey, status);
466 467
467 if (data) { 468 if (data) {
468 transfer_info->Set(kDataKey, base::BinaryValue::CreateWithCopiedBuffer( 469 transfer_info->Set(
469 data->data(), length)); 470 kDataKey, base::Value::CreateWithCopiedBuffer(data->data(), length));
470 } else { 471 } else {
471 transfer_info->Set(kDataKey, new base::Value(base::Value::Type::BINARY)); 472 transfer_info->Set(kDataKey, new base::Value(base::Value::Type::BINARY));
472 } 473 }
473 474
474 if (status == device::USB_TRANSFER_COMPLETED) { 475 if (status == device::USB_TRANSFER_COMPLETED) {
475 Respond(OneArgument(std::move(transfer_info))); 476 Respond(OneArgument(std::move(transfer_info)));
476 } else { 477 } else {
477 std::unique_ptr<base::ListValue> error_args(new base::ListValue()); 478 std::unique_ptr<base::ListValue> error_args(new base::ListValue());
478 error_args->Append(std::move(transfer_info)); 479 error_args->Append(std::move(transfer_info));
479 // Using ErrorWithArguments is discouraged but required to provide the 480 // Using ErrorWithArguments is discouraged but required to provide the
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 if (data) { 1233 if (data) {
1233 buffer.insert(buffer.end(), data_ptr, 1234 buffer.insert(buffer.end(), data_ptr,
1234 data_ptr + packet.transferred_length); 1235 data_ptr + packet.transferred_length);
1235 data_ptr += packet.length; 1236 data_ptr += packet.length;
1236 } 1237 }
1237 } 1238 }
1238 1239
1239 std::unique_ptr<base::DictionaryValue> transfer_info( 1240 std::unique_ptr<base::DictionaryValue> transfer_info(
1240 new base::DictionaryValue()); 1241 new base::DictionaryValue());
1241 transfer_info->SetInteger(kResultCodeKey, status); 1242 transfer_info->SetInteger(kResultCodeKey, status);
1242 transfer_info->Set(kDataKey, new base::BinaryValue(std::move(buffer))); 1243 transfer_info->Set(kDataKey, new base::Value(std::move(buffer)));
1243 if (status == device::USB_TRANSFER_COMPLETED) { 1244 if (status == device::USB_TRANSFER_COMPLETED) {
1244 Respond(OneArgument(std::move(transfer_info))); 1245 Respond(OneArgument(std::move(transfer_info)));
1245 } else { 1246 } else {
1246 std::unique_ptr<base::ListValue> error_args(new base::ListValue()); 1247 std::unique_ptr<base::ListValue> error_args(new base::ListValue());
1247 error_args->Append(std::move(transfer_info)); 1248 error_args->Append(std::move(transfer_info));
1248 // Using ErrorWithArguments is discouraged but required to provide the 1249 // Using ErrorWithArguments is discouraged but required to provide the
1249 // detailed transfer info as the transfer may have partially succeeded. 1250 // detailed transfer info as the transfer may have partially succeeded.
1250 Respond(ErrorWithArguments(std::move(error_args), 1251 Respond(ErrorWithArguments(std::move(error_args),
1251 ConvertTransferStatusToApi(status))); 1252 ConvertTransferStatusToApi(status)));
1252 } 1253 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 1287
1287 std::unique_ptr<base::ListValue> error_args(new base::ListValue()); 1288 std::unique_ptr<base::ListValue> error_args(new base::ListValue());
1288 error_args->AppendBoolean(false); 1289 error_args->AppendBoolean(false);
1289 // Using ErrorWithArguments is discouraged but required to maintain 1290 // Using ErrorWithArguments is discouraged but required to maintain
1290 // compatibility with existing applications. 1291 // compatibility with existing applications.
1291 Respond(ErrorWithArguments(std::move(error_args), kErrorResetDevice)); 1292 Respond(ErrorWithArguments(std::move(error_args), kErrorResetDevice));
1292 } 1293 }
1293 } 1294 }
1294 1295
1295 } // namespace extensions 1296 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/socket/socket_api.cc ('k') | extensions/browser/api/web_request/upload_data_presenter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698