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

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

Issue 11827026: Overhaul JSON Schema Compiler to support a number of features required to (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 11 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
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_api.h" 5 #include "chrome/browser/extensions/api/usb/usb_api.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 static const char* kErrorMalformedParameters = "Error parsing parameters."; 61 static const char* kErrorMalformedParameters = "Error parsing parameters.";
62 static const char* kErrorNoDevice = "No such device."; 62 static const char* kErrorNoDevice = "No such device.";
63 static const char* kErrorPermissionDenied = 63 static const char* kErrorPermissionDenied =
64 "Permission to access device was denied"; 64 "Permission to access device was denied";
65 65
66 static UsbDevice* device_for_test_ = NULL; 66 static UsbDevice* device_for_test_ = NULL;
67 67
68 static bool ConvertDirection(const Direction& input, 68 static bool ConvertDirection(const Direction& input,
69 UsbDevice::TransferDirection* output) { 69 UsbDevice::TransferDirection* output) {
70 switch (input) { 70 switch (input) {
71 case usb::USB_DIRECTION_IN: 71 case usb::DIRECTION_IN:
72 *output = UsbDevice::INBOUND; 72 *output = UsbDevice::INBOUND;
73 return true; 73 return true;
74 case usb::USB_DIRECTION_OUT: 74 case usb::DIRECTION_OUT:
75 *output = UsbDevice::OUTBOUND; 75 *output = UsbDevice::OUTBOUND;
76 return true; 76 return true;
77 default: 77 default:
78 return false; 78 return false;
79 } 79 }
80 NOTREACHED(); 80 NOTREACHED();
81 return false; 81 return false;
82 } 82 }
83 83
84 static bool ConvertRequestType(const RequestType& input, 84 static bool ConvertRequestType(const RequestType& input,
85 UsbDevice::TransferRequestType* output) { 85 UsbDevice::TransferRequestType* output) {
86 switch (input) { 86 switch (input) {
87 case usb::USB_REQUEST_TYPE_STANDARD: 87 case usb::REQUEST_TYPE_STANDARD:
88 *output = UsbDevice::STANDARD; 88 *output = UsbDevice::STANDARD;
89 return true; 89 return true;
90 case usb::USB_REQUEST_TYPE_CLASS: 90 case usb::REQUEST_TYPE_CLASS:
91 *output = UsbDevice::CLASS; 91 *output = UsbDevice::CLASS;
92 return true; 92 return true;
93 case usb::USB_REQUEST_TYPE_VENDOR: 93 case usb::REQUEST_TYPE_VENDOR:
94 *output = UsbDevice::VENDOR; 94 *output = UsbDevice::VENDOR;
95 return true; 95 return true;
96 case usb::USB_REQUEST_TYPE_RESERVED: 96 case usb::REQUEST_TYPE_RESERVED:
97 *output = UsbDevice::RESERVED; 97 *output = UsbDevice::RESERVED;
98 return true; 98 return true;
99 default: 99 default:
100 return false; 100 return false;
101 } 101 }
102 NOTREACHED(); 102 NOTREACHED();
103 return false; 103 return false;
104 } 104 }
105 105
106 static bool ConvertRecipient(const Recipient& input, 106 static bool ConvertRecipient(const Recipient& input,
107 UsbDevice::TransferRecipient* output) { 107 UsbDevice::TransferRecipient* output) {
108 switch (input) { 108 switch (input) {
109 case usb::USB_RECIPIENT_DEVICE: 109 case usb::RECIPIENT_DEVICE:
110 *output = UsbDevice::DEVICE; 110 *output = UsbDevice::DEVICE;
111 return true; 111 return true;
112 case usb::USB_RECIPIENT_INTERFACE: 112 case usb::RECIPIENT_INTERFACE:
113 *output = UsbDevice::INTERFACE; 113 *output = UsbDevice::INTERFACE;
114 return true; 114 return true;
115 case usb::USB_RECIPIENT_ENDPOINT: 115 case usb::RECIPIENT_ENDPOINT:
116 *output = UsbDevice::ENDPOINT; 116 *output = UsbDevice::ENDPOINT;
117 return true; 117 return true;
118 case usb::USB_RECIPIENT_OTHER: 118 case usb::RECIPIENT_OTHER:
119 *output = UsbDevice::OTHER; 119 *output = UsbDevice::OTHER;
120 return true; 120 return true;
121 default: 121 default:
122 return false; 122 return false;
123 } 123 }
124 NOTREACHED(); 124 NOTREACHED();
125 return false; 125 return false;
126 } 126 }
127 127
128 template<class T> 128 template<class T>
129 static bool GetTransferSize(const T& input, size_t* output) { 129 static bool GetTransferSize(const T& input, size_t* output) {
130 if (input.direction == usb::USB_DIRECTION_IN) { 130 if (input.direction == usb::DIRECTION_IN) {
131 const int* length = input.length.get(); 131 const int* length = input.length.get();
132 if (length) { 132 if (length) {
133 *output = *length; 133 *output = *length;
134 return true; 134 return true;
135 } 135 }
136 } else if (input.direction == usb::USB_DIRECTION_OUT) { 136 } else if (input.direction == usb::DIRECTION_OUT) {
137 if (input.data.get()) { 137 if (input.data.get()) {
138 *output = input.data->size(); 138 *output = input.data->size();
139 return true; 139 return true;
140 } 140 }
141 } 141 }
142 return false; 142 return false;
143 } 143 }
144 144
145 template<class T> 145 template<class T>
146 static scoped_refptr<net::IOBuffer> CreateBufferForTransfer(const T& input) { 146 static scoped_refptr<net::IOBuffer> CreateBufferForTransfer(const T& input) {
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 CompleteWithError(kErrorNoDevice); 606 CompleteWithError(kErrorNoDevice);
607 return; 607 return;
608 } 608 }
609 609
610 device->device()->IsochronousTransfer(direction, generic_transfer.endpoint, 610 device->device()->IsochronousTransfer(direction, generic_transfer.endpoint,
611 buffer, size, transfer.packets, transfer.packet_length, 0, base::Bind( 611 buffer, size, transfer.packets, transfer.packet_length, 0, base::Bind(
612 &UsbIsochronousTransferFunction::OnCompleted, this)); 612 &UsbIsochronousTransferFunction::OnCompleted, this));
613 } 613 }
614 614
615 } // namespace extensions 615 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698