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

Side by Side Diff: device/test/usb_test_gadget_impl.cc

Issue 1542163002: Switch to standard integer types in device/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: win Created 5 years 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 | « device/test/test_device_client.cc ('k') | device/udev_linux/udev.cc » ('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 "device/test/usb_test_gadget.h" 5 #include "device/test/usb_test_gadget.h"
6 6
7 #include <stddef.h>
8 #include <stdint.h>
9
7 #include <string> 10 #include <string>
8 #include <vector> 11 #include <vector>
9 12
10 #include "base/command_line.h" 13 #include "base/command_line.h"
11 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
12 #include "base/files/file.h" 15 #include "base/files/file.h"
13 #include "base/files/file_path.h" 16 #include "base/files/file_path.h"
14 #include "base/logging.h" 17 #include "base/logging.h"
15 #include "base/macros.h" 18 #include "base/macros.h"
16 #include "base/memory/ref_counted.h" 19 #include "base/memory/ref_counted.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 }; 65 };
63 66
64 namespace { 67 namespace {
65 68
66 static const char kCommandLineSwitch[] = "enable-gadget-tests"; 69 static const char kCommandLineSwitch[] = "enable-gadget-tests";
67 static const int kReenumeratePeriod = 100; // 0.1 seconds 70 static const int kReenumeratePeriod = 100; // 0.1 seconds
68 71
69 struct UsbTestGadgetConfiguration { 72 struct UsbTestGadgetConfiguration {
70 UsbTestGadget::Type type; 73 UsbTestGadget::Type type;
71 const char* http_resource; 74 const char* http_resource;
72 uint16 product_id; 75 uint16_t product_id;
73 }; 76 };
74 77
75 static const struct UsbTestGadgetConfiguration kConfigurations[] = { 78 static const struct UsbTestGadgetConfiguration kConfigurations[] = {
76 {UsbTestGadget::DEFAULT, "/unconfigure", 0x58F0}, 79 {UsbTestGadget::DEFAULT, "/unconfigure", 0x58F0},
77 {UsbTestGadget::KEYBOARD, "/keyboard/configure", 0x58F1}, 80 {UsbTestGadget::KEYBOARD, "/keyboard/configure", 0x58F1},
78 {UsbTestGadget::MOUSE, "/mouse/configure", 0x58F2}, 81 {UsbTestGadget::MOUSE, "/mouse/configure", 0x58F2},
79 {UsbTestGadget::HID_ECHO, "/hid_echo/configure", 0x58F3}, 82 {UsbTestGadget::HID_ECHO, "/hid_echo/configure", 0x58F3},
80 {UsbTestGadget::ECHO, "/echo/configure", 0x58F4}, 83 {UsbTestGadget::ECHO, "/echo/configure", 0x58F4},
81 }; 84 };
82 85
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 } 197 }
195 198
196 class UsbGadgetFactory : public UsbService::Observer, 199 class UsbGadgetFactory : public UsbService::Observer,
197 public net::URLFetcherDelegate { 200 public net::URLFetcherDelegate {
198 public: 201 public:
199 UsbGadgetFactory(scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) 202 UsbGadgetFactory(scoped_refptr<base::SingleThreadTaskRunner> io_task_runner)
200 : observer_(this), weak_factory_(this) { 203 : observer_(this), weak_factory_(this) {
201 usb_service_ = DeviceClient::Get()->GetUsbService(); 204 usb_service_ = DeviceClient::Get()->GetUsbService();
202 request_context_getter_ = new URLRequestContextGetter(io_task_runner); 205 request_context_getter_ = new URLRequestContextGetter(io_task_runner);
203 206
204 static uint32 next_session_id; 207 static uint32_t next_session_id;
205 base::ProcessId process_id = base::GetCurrentProcId(); 208 base::ProcessId process_id = base::GetCurrentProcId();
206 session_id_ = base::StringPrintf("%d-%d", process_id, next_session_id++); 209 session_id_ = base::StringPrintf("%d-%d", process_id, next_session_id++);
207 210
208 observer_.Add(usb_service_); 211 observer_.Add(usb_service_);
209 } 212 }
210 213
211 ~UsbGadgetFactory() override {} 214 ~UsbGadgetFactory() override {}
212 215
213 scoped_ptr<UsbTestGadget> WaitForDevice() { 216 scoped_ptr<UsbTestGadget> WaitForDevice() {
214 EnumerateDevices(); 217 EnumerateDevices();
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 private: 420 private:
418 void OnDevicesEnumerated( 421 void OnDevicesEnumerated(
419 const std::vector<scoped_refptr<UsbDevice>>& devices) { 422 const std::vector<scoped_refptr<UsbDevice>>& devices) {
420 for (const scoped_refptr<UsbDevice>& device : devices) { 423 for (const scoped_refptr<UsbDevice>& device : devices) {
421 OnDeviceAdded(device); 424 OnDeviceAdded(device);
422 } 425 }
423 } 426 }
424 427
425 void OnDeviceAdded(scoped_refptr<UsbDevice> device) override { 428 void OnDeviceAdded(scoped_refptr<UsbDevice> device) override {
426 if (device->vendor_id() == 0x18D1 && !device->serial_number().empty()) { 429 if (device->vendor_id() == 0x18D1 && !device->serial_number().empty()) {
427 const uint16 product_id = device->product_id(); 430 const uint16_t product_id = device->product_id();
428 if (product_id_ == -1) { 431 if (product_id_ == -1) {
429 bool found = false; 432 bool found = false;
430 for (size_t i = 0; i < arraysize(kConfigurations); ++i) { 433 for (size_t i = 0; i < arraysize(kConfigurations); ++i) {
431 if (product_id == kConfigurations[i].product_id) { 434 if (product_id == kConfigurations[i].product_id) {
432 found = true; 435 found = true;
433 break; 436 break;
434 } 437 }
435 } 438 }
436 if (!found) { 439 if (!found) {
437 return; 440 return;
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 return false; 611 return false;
609 } 612 }
610 613
611 DeviceAddListener add_listener(usb_service_, device_address_, -1); 614 DeviceAddListener add_listener(usb_service_, device_address_, -1);
612 device_ = add_listener.WaitForAdd(); 615 device_ = add_listener.WaitForAdd();
613 DCHECK(device_.get()); 616 DCHECK(device_.get());
614 return true; 617 return true;
615 } 618 }
616 619
617 } // namespace device 620 } // namespace device
OLDNEW
« no previous file with comments | « device/test/test_device_client.cc ('k') | device/udev_linux/udev.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698