OLD | NEW |
1 // Copyright 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" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 SerialGetDevicesFunction::SerialGetDevicesFunction() {} | 78 SerialGetDevicesFunction::SerialGetDevicesFunction() {} |
79 | 79 |
80 bool SerialGetDevicesFunction::Prepare() { | 80 bool SerialGetDevicesFunction::Prepare() { |
81 set_work_thread_id(BrowserThread::FILE); | 81 set_work_thread_id(BrowserThread::FILE); |
82 return true; | 82 return true; |
83 } | 83 } |
84 | 84 |
85 void SerialGetDevicesFunction::Work() { | 85 void SerialGetDevicesFunction::Work() { |
86 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 86 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
87 | 87 |
88 device::SerialDeviceInfoList devices; | |
89 scoped_ptr<device::SerialDeviceEnumerator> enumerator = | 88 scoped_ptr<device::SerialDeviceEnumerator> enumerator = |
90 device::SerialDeviceEnumerator::Create(); | 89 device::SerialDeviceEnumerator::Create(); |
91 enumerator->GetDevices(&devices); | 90 mojo::Array<device::SerialDeviceInfoPtr> devices = enumerator->GetDevices(); |
92 | 91 results_ = serial::GetDevices::Results::Create( |
93 std::vector<linked_ptr<serial::DeviceInfo> > out_devices; | 92 devices.To<std::vector<linked_ptr<serial::DeviceInfo> > >()); |
94 for (device::SerialDeviceInfoList::const_iterator iter = devices.begin(); | |
95 iter != devices.end(); | |
96 ++iter) { | |
97 linked_ptr<device::SerialDeviceInfo> device = *iter; | |
98 linked_ptr<serial::DeviceInfo> info(new serial::DeviceInfo); | |
99 info->path = device->path; | |
100 if (device->vendor_id) | |
101 info->vendor_id.reset(new int(static_cast<int>(*device->vendor_id))); | |
102 if (device->product_id) | |
103 info->product_id.reset(new int(static_cast<int>(*device->product_id))); | |
104 info->display_name.reset(device->display_name.release()); | |
105 out_devices.push_back(info); | |
106 } | |
107 | |
108 results_ = serial::GetDevices::Results::Create(out_devices); | |
109 } | 93 } |
110 | 94 |
111 SerialConnectFunction::SerialConnectFunction() {} | 95 SerialConnectFunction::SerialConnectFunction() {} |
112 | 96 |
113 SerialConnectFunction::~SerialConnectFunction() {} | 97 SerialConnectFunction::~SerialConnectFunction() {} |
114 | 98 |
115 bool SerialConnectFunction::Prepare() { | 99 bool SerialConnectFunction::Prepare() { |
116 params_ = serial::Connect::Params::Create(*args_); | 100 params_ = serial::Connect::Params::Create(*args_); |
117 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 101 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
118 | 102 |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 return; | 402 return; |
419 } | 403 } |
420 | 404 |
421 bool success = connection->SetControlSignals(params_->signals); | 405 bool success = connection->SetControlSignals(params_->signals); |
422 results_ = serial::SetControlSignals::Results::Create(success); | 406 results_ = serial::SetControlSignals::Results::Create(success); |
423 } | 407 } |
424 | 408 |
425 } // namespace api | 409 } // namespace api |
426 | 410 |
427 } // namespace extensions | 411 } // namespace extensions |
| 412 |
| 413 namespace mojo { |
| 414 |
| 415 // static |
| 416 linked_ptr<extensions::api::serial::DeviceInfo> |
| 417 TypeConverter<device::SerialDeviceInfoPtr, |
| 418 linked_ptr<extensions::api::serial::DeviceInfo> >:: |
| 419 ConvertTo(const device::SerialDeviceInfoPtr& device) { |
| 420 linked_ptr<extensions::api::serial::DeviceInfo> info( |
| 421 new extensions::api::serial::DeviceInfo); |
| 422 info->path = device->path; |
| 423 if (device->has_vendor_id) |
| 424 info->vendor_id.reset(new int(static_cast<int>(device->vendor_id))); |
| 425 if (device->has_product_id) |
| 426 info->product_id.reset(new int(static_cast<int>(device->product_id))); |
| 427 if (device->display_name) |
| 428 info->display_name.reset(new std::string(device->display_name)); |
| 429 return info; |
| 430 } |
| 431 |
| 432 } // namespace mojo |
OLD | NEW |