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

Side by Side Diff: chrome/browser/devtools/device/usb/android_usb_browsertest.cc

Issue 580963002: Add a service to track devices selected by the user. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed all of scheib@'s feedback. Created 6 years, 3 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
« no previous file with comments | « apps/saved_devices_service_unittest.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/devtools/device/devtools_android_bridge.h" 8 #include "chrome/browser/devtools/device/devtools_android_bridge.h"
9 #include "chrome/browser/devtools/device/usb/android_usb_device.h" 9 #include "chrome/browser/devtools/device/usb/android_usb_device.h"
10 #include "chrome/browser/devtools/device/usb/usb_device_provider.h" 10 #include "chrome/browser/devtools/device/usb/usb_device_provider.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 : device_(device), 113 : device_(device),
114 remaining_body_length_(0), 114 remaining_body_length_(0),
115 next_local_socket_(0) {} 115 next_local_socket_(0) {}
116 116
117 virtual scoped_refptr<UsbDevice> GetDevice() const OVERRIDE { 117 virtual scoped_refptr<UsbDevice> GetDevice() const OVERRIDE {
118 return device_; 118 return device_;
119 } 119 }
120 120
121 virtual void Close() OVERRIDE { device_ = NULL; } 121 virtual void Close() OVERRIDE { device_ = NULL; }
122 122
123 bool ClaimInterface(const int interface_number) { 123 bool ClaimInterface(int interface_number) {
124 if (device_->claimed_interfaces_.find(interface_number) != 124 if (device_->claimed_interfaces_.find(interface_number) !=
125 device_->claimed_interfaces_.end()) 125 device_->claimed_interfaces_.end())
126 return false; 126 return false;
127 127
128 device_->claimed_interfaces_.insert(interface_number); 128 device_->claimed_interfaces_.insert(interface_number);
129 return true; 129 return true;
130 } 130 }
131 131
132 bool ReleaseInterface(const int interface_number) { 132 bool ReleaseInterface(int interface_number) {
133 if (device_->claimed_interfaces_.find(interface_number) == 133 if (device_->claimed_interfaces_.find(interface_number) ==
134 device_->claimed_interfaces_.end()) 134 device_->claimed_interfaces_.end())
135 return false; 135 return false;
136 136
137 device_->claimed_interfaces_.erase(interface_number); 137 device_->claimed_interfaces_.erase(interface_number);
138 return true; 138 return true;
139 } 139 }
140 140
141 virtual bool SetInterfaceAlternateSetting( 141 virtual bool SetInterfaceAlternateSetting(int interface_number,
142 const int interface_number, 142 int alternate_setting) OVERRIDE {
143 const int alternate_setting) OVERRIDE {
144 return true; 143 return true;
145 } 144 }
146 145
147 virtual bool ResetDevice() OVERRIDE { return true; } 146 virtual bool ResetDevice() OVERRIDE { return true; }
148 147
149 virtual bool GetManufacturer(base::string16* manufacturer) OVERRIDE { 148 virtual bool GetManufacturer(base::string16* manufacturer) OVERRIDE {
150 *manufacturer = base::UTF8ToUTF16(kDeviceManufacturer); 149 *manufacturer = base::UTF8ToUTF16(kDeviceManufacturer);
151 return true; 150 return true;
152 } 151 }
153 152
154 virtual bool GetProduct(base::string16* product) OVERRIDE { 153 virtual bool GetProduct(base::string16* product) OVERRIDE {
155 *product = base::UTF8ToUTF16(kDeviceModel); 154 *product = base::UTF8ToUTF16(kDeviceModel);
156 return true; 155 return true;
157 } 156 }
158 157
159 virtual bool GetSerial(base::string16* serial) OVERRIDE { 158 virtual bool GetSerial(base::string16* serial) OVERRIDE {
160 *serial = base::UTF8ToUTF16(kDeviceSerial); 159 *serial = base::UTF8ToUTF16(kDeviceSerial);
161 return true; 160 return true;
162 } 161 }
163 162
164 // Async IO. Can be called on any thread. 163 // Async IO. Can be called on any thread.
165 virtual void ControlTransfer(const UsbEndpointDirection direction, 164 virtual void ControlTransfer(UsbEndpointDirection direction,
166 const TransferRequestType request_type, 165 TransferRequestType request_type,
167 const TransferRecipient recipient, 166 TransferRecipient recipient,
168 const uint8 request, 167 uint8 request,
169 const uint16 value, 168 uint16 value,
170 const uint16 index, 169 uint16 index,
171 net::IOBuffer* buffer, 170 net::IOBuffer* buffer,
172 const size_t length, 171 size_t length,
173 const unsigned int timeout, 172 unsigned int timeout,
174 const UsbTransferCallback& callback) OVERRIDE {} 173 const UsbTransferCallback& callback) OVERRIDE {}
175 174
176 virtual void BulkTransfer(const UsbEndpointDirection direction, 175 virtual void BulkTransfer(UsbEndpointDirection direction,
177 const uint8 endpoint, 176 uint8 endpoint,
178 net::IOBuffer* buffer, 177 net::IOBuffer* buffer,
179 const size_t length, 178 size_t length,
180 const unsigned int timeout, 179 unsigned int timeout,
181 const UsbTransferCallback& callback) OVERRIDE { 180 const UsbTransferCallback& callback) OVERRIDE {
182 if (direction == device::USB_DIRECTION_OUTBOUND) { 181 if (direction == device::USB_DIRECTION_OUTBOUND) {
183 if (remaining_body_length_ == 0) { 182 if (remaining_body_length_ == 0) {
184 std::vector<uint32> header(6); 183 std::vector<uint32> header(6);
185 memcpy(&header[0], buffer->data(), length); 184 memcpy(&header[0], buffer->data(), length);
186 current_message_ = new AdbMessage(header[0], header[1], header[2], ""); 185 current_message_ = new AdbMessage(header[0], header[1], header[2], "");
187 remaining_body_length_ = header[3]; 186 remaining_body_length_ = header[3];
188 uint32 magic = header[5]; 187 uint32 magic = header[5];
189 if ((current_message_->command ^ 0xffffffff) != magic) { 188 if ((current_message_->command ^ 0xffffffff) != magic) {
190 DCHECK(false) << "Header checksum error"; 189 DCHECK(false) << "Header checksum error";
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 output_buffer_.erase(output_buffer_.begin(), 296 output_buffer_.erase(output_buffer_.begin(),
298 output_buffer_.begin() + query.size); 297 output_buffer_.begin() + query.size);
299 base::MessageLoop::current()->PostTask( 298 base::MessageLoop::current()->PostTask(
300 FROM_HERE, 299 FROM_HERE,
301 base::Bind(query.callback, 300 base::Bind(query.callback,
302 device::USB_TRANSFER_COMPLETED, 301 device::USB_TRANSFER_COMPLETED,
303 query.buffer, 302 query.buffer,
304 query.size)); 303 query.size));
305 } 304 }
306 305
307 virtual void InterruptTransfer(const UsbEndpointDirection direction, 306 virtual void InterruptTransfer(UsbEndpointDirection direction,
308 const uint8 endpoint, 307 uint8 endpoint,
309 net::IOBuffer* buffer, 308 net::IOBuffer* buffer,
310 const size_t length, 309 size_t length,
311 const unsigned int timeout, 310 unsigned int timeout,
312 const UsbTransferCallback& callback) OVERRIDE { 311 const UsbTransferCallback& callback) OVERRIDE {
313 } 312 }
314 313
315 virtual void IsochronousTransfer( 314 virtual void IsochronousTransfer(
316 const UsbEndpointDirection direction, 315 UsbEndpointDirection direction,
317 const uint8 endpoint, 316 uint8 endpoint,
318 net::IOBuffer* buffer, 317 net::IOBuffer* buffer,
319 const size_t length, 318 size_t length,
320 const unsigned int packets, 319 unsigned int packets,
321 const unsigned int packet_length, 320 unsigned int packet_length,
322 const unsigned int timeout, 321 unsigned int timeout,
323 const UsbTransferCallback& callback) OVERRIDE {} 322 const UsbTransferCallback& callback) OVERRIDE {}
324 323
325 protected: 324 protected:
326 virtual ~MockUsbDeviceHandle() {} 325 virtual ~MockUsbDeviceHandle() {}
327 326
328 struct Query { 327 struct Query {
329 UsbTransferCallback callback; 328 UsbTransferCallback callback;
330 scoped_refptr<net::IOBuffer> buffer; 329 scoped_refptr<net::IOBuffer> buffer;
331 size_t size; 330 size_t size;
332 331
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 runner_->Run(); 761 runner_->Run();
763 EXPECT_EQ(2, listener.invoked_); 762 EXPECT_EQ(2, listener.invoked_);
764 EXPECT_EQ(listener.invoked_ - 1, scheduler_invoked_); 763 EXPECT_EQ(listener.invoked_ - 1, scheduler_invoked_);
765 } 764 }
766 765
767 IN_PROC_BROWSER_TEST_F(AndroidUsbTraitsTest, TestDeviceCounting) { 766 IN_PROC_BROWSER_TEST_F(AndroidUsbTraitsTest, TestDeviceCounting) {
768 MockCountListenerForCheckingTraits listener(adb_bridge_); 767 MockCountListenerForCheckingTraits listener(adb_bridge_);
769 adb_bridge_->AddDeviceCountListener(&listener); 768 adb_bridge_->AddDeviceCountListener(&listener);
770 runner_->Run(); 769 runner_->Run();
771 } 770 }
OLDNEW
« no previous file with comments | « apps/saved_devices_service_unittest.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698