| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/extensions/api/usb/usb_device_resource.h" | 5 #include "chrome/browser/extensions/api/usb/usb_device_resource.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 template<class T> | 94 template<class T> |
| 95 static bool GetTransferSize(const T& input, size_t* output) { | 95 static bool GetTransferSize(const T& input, size_t* output) { |
| 96 if (input.direction == kDirectionIn) { | 96 if (input.direction == kDirectionIn) { |
| 97 const int* length = input.length.get(); | 97 const int* length = input.length.get(); |
| 98 if (length) { | 98 if (length) { |
| 99 *output = *length; | 99 *output = *length; |
| 100 return true; | 100 return true; |
| 101 } | 101 } |
| 102 } else if (input.direction == kDirectionOut) { | 102 } else if (input.direction == kDirectionOut) { |
| 103 if (input.data.get()) { | 103 if (input.data.get()) { |
| 104 *output = input.data->GetSize(); | 104 *output = input.data->size(); |
| 105 return true; | 105 return true; |
| 106 } | 106 } |
| 107 } | 107 } |
| 108 return false; | 108 return false; |
| 109 } | 109 } |
| 110 | 110 |
| 111 template<class T> | 111 template<class T> |
| 112 static scoped_refptr<net::IOBuffer> CreateBufferForTransfer(const T& input) { | 112 static scoped_refptr<net::IOBuffer> CreateBufferForTransfer(const T& input) { |
| 113 size_t size = 0; | 113 size_t size = 0; |
| 114 if (!GetTransferSize(input, &size)) { | 114 if (!GetTransferSize(input, &size)) { |
| 115 return NULL; | 115 return NULL; |
| 116 } | 116 } |
| 117 | 117 |
| 118 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(size); | 118 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(size); |
| 119 if (!input.data.get()) { | 119 if (!input.data.get()) { |
| 120 return buffer; | 120 return buffer; |
| 121 } | 121 } |
| 122 | 122 |
| 123 memcpy(buffer->data(), input.data->GetBuffer(), size); | 123 memcpy(buffer->data(), input.data->data(), size); |
| 124 | 124 |
| 125 return buffer; | 125 return buffer; |
| 126 } | 126 } |
| 127 | 127 |
| 128 static const char* ConvertTransferStatusToErrorString( | 128 static const char* ConvertTransferStatusToErrorString( |
| 129 const UsbTransferStatus status) { | 129 const UsbTransferStatus status) { |
| 130 switch (status) { | 130 switch (status) { |
| 131 case USB_TRANSFER_COMPLETED: | 131 case USB_TRANSFER_COMPLETED: |
| 132 return ""; | 132 return ""; |
| 133 case USB_TRANSFER_ERROR: | 133 case USB_TRANSFER_ERROR: |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 UsbTransferStatus status) { | 237 UsbTransferStatus status) { |
| 238 if (buffer) { | 238 if (buffer) { |
| 239 base::BinaryValue* const response_buffer = | 239 base::BinaryValue* const response_buffer = |
| 240 base::BinaryValue::CreateWithCopiedBuffer(buffer->data(), length); | 240 base::BinaryValue::CreateWithCopiedBuffer(buffer->data(), length); |
| 241 event_notifier()->OnTransferComplete(status, | 241 event_notifier()->OnTransferComplete(status, |
| 242 ConvertTransferStatusToErrorString(status), response_buffer); | 242 ConvertTransferStatusToErrorString(status), response_buffer); |
| 243 } | 243 } |
| 244 } | 244 } |
| 245 | 245 |
| 246 } // namespace extensions | 246 } // namespace extensions |
| OLD | NEW |