| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 } | 76 } |
| 77 | 77 |
| 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(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 86 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 87 | 87 |
| 88 device::SerialDeviceInfoList devices; | 88 device::SerialDeviceInfoList devices; |
| 89 scoped_ptr<device::SerialDeviceEnumerator> enumerator = | 89 scoped_ptr<device::SerialDeviceEnumerator> enumerator = |
| 90 device::SerialDeviceEnumerator::Create(); | 90 device::SerialDeviceEnumerator::Create(); |
| 91 enumerator->GetDevices(&devices); | 91 enumerator->GetDevices(&devices); |
| 92 | 92 |
| 93 std::vector<linked_ptr<serial::DeviceInfo> > out_devices; | 93 std::vector<linked_ptr<serial::DeviceInfo> > out_devices; |
| 94 for (device::SerialDeviceInfoList::const_iterator iter = devices.begin(); | 94 for (device::SerialDeviceInfoList::const_iterator iter = devices.begin(); |
| 95 iter != devices.end(); | 95 iter != devices.end(); |
| 96 ++iter) { | 96 ++iter) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 if (options->stop_bits == serial::STOP_BITS_NONE) | 135 if (options->stop_bits == serial::STOP_BITS_NONE) |
| 136 options->stop_bits = kDefaultStopBits; | 136 options->stop_bits = kDefaultStopBits; |
| 137 | 137 |
| 138 serial_event_dispatcher_ = SerialEventDispatcher::Get(browser_context()); | 138 serial_event_dispatcher_ = SerialEventDispatcher::Get(browser_context()); |
| 139 DCHECK(serial_event_dispatcher_); | 139 DCHECK(serial_event_dispatcher_); |
| 140 | 140 |
| 141 return true; | 141 return true; |
| 142 } | 142 } |
| 143 | 143 |
| 144 void SerialConnectFunction::AsyncWorkStart() { | 144 void SerialConnectFunction::AsyncWorkStart() { |
| 145 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 145 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 146 connection_ = CreateSerialConnection(params_->path, extension_->id()); | 146 connection_ = CreateSerialConnection(params_->path, extension_->id()); |
| 147 connection_->Open(base::Bind(&SerialConnectFunction::OnConnected, this)); | 147 connection_->Open(base::Bind(&SerialConnectFunction::OnConnected, this)); |
| 148 } | 148 } |
| 149 | 149 |
| 150 void SerialConnectFunction::OnConnected(bool success) { | 150 void SerialConnectFunction::OnConnected(bool success) { |
| 151 DCHECK(connection_); | 151 DCHECK(connection_); |
| 152 | 152 |
| 153 if (success) { | 153 if (success) { |
| 154 if (!connection_->Configure(*params_->options.get())) { | 154 if (!connection_->Configure(*params_->options.get())) { |
| 155 connection_->Close(); | 155 connection_->Close(); |
| 156 delete connection_; | 156 delete connection_; |
| 157 connection_ = NULL; | 157 connection_ = NULL; |
| 158 } | 158 } |
| 159 } else { | 159 } else { |
| 160 delete connection_; | 160 delete connection_; |
| 161 connection_ = NULL; | 161 connection_ = NULL; |
| 162 } | 162 } |
| 163 | 163 |
| 164 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 164 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 165 base::Bind(&SerialConnectFunction::FinishConnect, | 165 base::Bind(&SerialConnectFunction::FinishConnect, |
| 166 this)); | 166 this)); |
| 167 } | 167 } |
| 168 | 168 |
| 169 void SerialConnectFunction::FinishConnect() { | 169 void SerialConnectFunction::FinishConnect() { |
| 170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 170 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 171 if (!connection_) { | 171 if (!connection_) { |
| 172 error_ = kErrorConnectFailed; | 172 error_ = kErrorConnectFailed; |
| 173 } else { | 173 } else { |
| 174 int id = manager_->Add(connection_); | 174 int id = manager_->Add(connection_); |
| 175 serial::ConnectionInfo info; | 175 serial::ConnectionInfo info; |
| 176 info.connection_id = id; | 176 info.connection_id = id; |
| 177 if (connection_->GetInfo(&info)) { | 177 if (connection_->GetInfo(&info)) { |
| 178 serial_event_dispatcher_->PollConnection(extension_->id(), id); | 178 serial_event_dispatcher_->PollConnection(extension_->id(), id); |
| 179 results_ = serial::Connect::Results::Create(info); | 179 results_ = serial::Connect::Results::Create(info); |
| 180 } else { | 180 } else { |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 return; | 418 return; |
| 419 } | 419 } |
| 420 | 420 |
| 421 bool success = connection->SetControlSignals(params_->signals); | 421 bool success = connection->SetControlSignals(params_->signals); |
| 422 results_ = serial::SetControlSignals::Results::Create(success); | 422 results_ = serial::SetControlSignals::Results::Create(success); |
| 423 } | 423 } |
| 424 | 424 |
| 425 } // namespace api | 425 } // namespace api |
| 426 | 426 |
| 427 } // namespace extensions | 427 } // namespace extensions |
| OLD | NEW |