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

Side by Side Diff: chrome/browser/extensions/api/usb/usb_device_resource.cc

Issue 10826273: Allocate a one-byte IOBuffer for transfers that are zero-length. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(std::max(
119 static_cast<size_t>(1), size));
119 if (!input.data.get()) { 120 if (!input.data.get()) {
bryeung 2012/08/13 15:22:28 nit: this if and the one above should be brace-les
120 return buffer; 121 return buffer;
121 } 122 }
122 123
123 memcpy(buffer->data(), input.data->data(), size); 124 memcpy(buffer->data(), input.data->data(), size);
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:
134 return kErrorGeneric; 134 return kErrorGeneric;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698