OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/serial/serial_api.h" | 5 #include "chrome/browser/extensions/api/serial/serial_api.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/extensions/api/serial/serial_connection.h" | 10 #include "chrome/browser/extensions/api/serial/serial_connection.h" |
11 #include "chrome/browser/extensions/api/serial/serial_event_dispatcher.h" | 11 #include "chrome/browser/extensions/api/serial/serial_event_dispatcher.h" |
12 #include "chrome/browser/extensions/api/serial/serial_port_enumerator.h" | |
13 #include "chrome/common/extensions/api/serial.h" | 12 #include "chrome/common/extensions/api/serial.h" |
14 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 14 #include "device/serial/serial_device_enumerator.h" |
15 #include "extensions/browser/extension_system.h" | 15 #include "extensions/browser/extension_system.h" |
16 | 16 |
17 using content::BrowserThread; | 17 using content::BrowserThread; |
18 | 18 |
19 namespace extensions { | 19 namespace extensions { |
20 | 20 |
21 namespace api { | 21 namespace api { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 SerialGetDevicesFunction::SerialGetDevicesFunction() {} | 77 SerialGetDevicesFunction::SerialGetDevicesFunction() {} |
78 | 78 |
79 bool SerialGetDevicesFunction::Prepare() { | 79 bool SerialGetDevicesFunction::Prepare() { |
80 set_work_thread_id(BrowserThread::FILE); | 80 set_work_thread_id(BrowserThread::FILE); |
81 return true; | 81 return true; |
82 } | 82 } |
83 | 83 |
84 void SerialGetDevicesFunction::Work() { | 84 void SerialGetDevicesFunction::Work() { |
85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 85 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
86 | 86 |
87 std::vector<linked_ptr<serial::DeviceInfo> > devices; | 87 device::SerialDeviceInfoList devices; |
88 SerialPortEnumerator::StringSet port_names = | 88 scoped_ptr<device::SerialDeviceEnumerator> enumerator = |
89 SerialPortEnumerator::GenerateValidSerialPortNames(); | 89 device::SerialDeviceEnumerator::Create(); |
90 for (SerialPortEnumerator::StringSet::const_iterator iter = | 90 enumerator->GetDevices(&devices); |
91 port_names.begin(); | 91 |
92 iter != port_names.end(); | 92 std::vector<linked_ptr<serial::DeviceInfo> > out_devices; |
| 93 for (device::SerialDeviceInfoList::const_iterator iter = devices.begin(); |
| 94 iter != devices.end(); |
93 ++iter) { | 95 ++iter) { |
| 96 linked_ptr<device::SerialDeviceInfo> device = *iter; |
94 linked_ptr<serial::DeviceInfo> info(new serial::DeviceInfo); | 97 linked_ptr<serial::DeviceInfo> info(new serial::DeviceInfo); |
95 info->path = *iter; | 98 info->path = device->path; |
96 devices.push_back(info); | 99 if (device->vendor_id) |
| 100 info->vendor_id.reset(new int(static_cast<int>(*device->vendor_id))); |
| 101 if (device->product_id) |
| 102 info->product_id.reset(new int(static_cast<int>(*device->product_id))); |
| 103 info->display_name.reset(device->display_name.release()); |
| 104 out_devices.push_back(info); |
97 } | 105 } |
98 results_ = serial::GetDevices::Results::Create(devices); | 106 |
| 107 results_ = serial::GetDevices::Results::Create(out_devices); |
99 } | 108 } |
100 | 109 |
101 SerialConnectFunction::SerialConnectFunction() {} | 110 SerialConnectFunction::SerialConnectFunction() {} |
102 | 111 |
103 SerialConnectFunction::~SerialConnectFunction() {} | 112 SerialConnectFunction::~SerialConnectFunction() {} |
104 | 113 |
105 bool SerialConnectFunction::Prepare() { | 114 bool SerialConnectFunction::Prepare() { |
106 params_ = serial::Connect::Params::Create(*args_); | 115 params_ = serial::Connect::Params::Create(*args_); |
107 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 116 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
108 | 117 |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 return; | 417 return; |
409 } | 418 } |
410 | 419 |
411 bool success = connection->SetControlSignals(params_->signals); | 420 bool success = connection->SetControlSignals(params_->signals); |
412 results_ = serial::SetControlSignals::Results::Create(success); | 421 results_ = serial::SetControlSignals::Results::Create(success); |
413 } | 422 } |
414 | 423 |
415 } // namespace api | 424 } // namespace api |
416 | 425 |
417 } // namespace extensions | 426 } // namespace extensions |
OLD | NEW |