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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 *output = input.data->size(); | 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 } | |
117 | 116 |
118 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(size); | 117 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(std::max( |
asargent_no_longer_on_chrome
2012/08/13 17:37:50
can you include a brief comment here about why we
| |
119 if (!input.data.get()) { | 118 static_cast<size_t>(1), size)); |
119 if (!input.data.get()) | |
120 return buffer; | 120 return buffer; |
121 } | |
122 | 121 |
123 memcpy(buffer->data(), input.data->data(), size); | 122 memcpy(buffer->data(), input.data->data(), size); |
124 | |
125 return buffer; | 123 return buffer; |
126 } | 124 } |
127 | 125 |
128 static const char* ConvertTransferStatusToErrorString( | 126 static const char* ConvertTransferStatusToErrorString( |
129 const UsbTransferStatus status) { | 127 const UsbTransferStatus status) { |
130 switch (status) { | 128 switch (status) { |
131 case USB_TRANSFER_COMPLETED: | 129 case USB_TRANSFER_COMPLETED: |
132 return ""; | 130 return ""; |
133 case USB_TRANSFER_ERROR: | 131 case USB_TRANSFER_ERROR: |
134 return kErrorGeneric; | 132 return kErrorGeneric; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
237 UsbTransferStatus status) { | 235 UsbTransferStatus status) { |
238 if (buffer) { | 236 if (buffer) { |
239 base::BinaryValue* const response_buffer = | 237 base::BinaryValue* const response_buffer = |
240 base::BinaryValue::CreateWithCopiedBuffer(buffer->data(), length); | 238 base::BinaryValue::CreateWithCopiedBuffer(buffer->data(), length); |
241 event_notifier()->OnTransferComplete(status, | 239 event_notifier()->OnTransferComplete(status, |
242 ConvertTransferStatusToErrorString(status), response_buffer); | 240 ConvertTransferStatusToErrorString(status), response_buffer); |
243 } | 241 } |
244 } | 242 } |
245 | 243 |
246 } // namespace extensions | 244 } // namespace extensions |
OLD | NEW |