OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/browser/extensions/extension_system.h" | 8 #include "chrome/browser/extensions/extension_system.h" |
9 #include "chrome/browser/extensions/api/serial/serial_connection.h" | 9 #include "chrome/browser/extensions/api/serial/serial_connection.h" |
10 #include "chrome/browser/extensions/api/serial/serial_port_enumerator.h" | 10 #include "chrome/browser/extensions/api/serial/serial_port_enumerator.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 } | 58 } |
59 | 59 |
60 void SerialGetPortsFunction::Work() { | 60 void SerialGetPortsFunction::Work() { |
61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
62 | 62 |
63 base::ListValue* ports = new base::ListValue(); | 63 base::ListValue* ports = new base::ListValue(); |
64 SerialPortEnumerator::StringSet port_names = | 64 SerialPortEnumerator::StringSet port_names = |
65 SerialPortEnumerator::GenerateValidSerialPortNames(); | 65 SerialPortEnumerator::GenerateValidSerialPortNames(); |
66 SerialPortEnumerator::StringSet::const_iterator i = port_names.begin(); | 66 SerialPortEnumerator::StringSet::const_iterator i = port_names.begin(); |
67 while (i != port_names.end()) { | 67 while (i != port_names.end()) { |
68 ports->Append(Value::CreateStringValue(*i++)); | 68 ports->Append(new base::StringValue(*i++)); |
69 } | 69 } |
70 | 70 |
71 SetResult(ports); | 71 SetResult(ports); |
72 } | 72 } |
73 | 73 |
74 bool SerialGetPortsFunction::Respond() { | 74 bool SerialGetPortsFunction::Respond() { |
75 return true; | 75 return true; |
76 } | 76 } |
77 | 77 |
78 // It's a fool's errand to come up with a default bitrate, because we don't get | 78 // It's a fool's errand to come up with a default bitrate, because we don't get |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 void SerialCloseFunction::Work() { | 175 void SerialCloseFunction::Work() { |
176 bool close_result = false; | 176 bool close_result = false; |
177 SerialConnection* serial_connection = GetSerialConnection( | 177 SerialConnection* serial_connection = GetSerialConnection( |
178 params_->connection_id); | 178 params_->connection_id); |
179 if (serial_connection) { | 179 if (serial_connection) { |
180 serial_connection->Close(); | 180 serial_connection->Close(); |
181 RemoveSerialConnection(params_->connection_id); | 181 RemoveSerialConnection(params_->connection_id); |
182 close_result = true; | 182 close_result = true; |
183 } | 183 } |
184 | 184 |
185 SetResult(Value::CreateBooleanValue(close_result)); | 185 SetResult(new base::FundamentalValue(close_result)); |
186 } | 186 } |
187 | 187 |
188 bool SerialCloseFunction::Respond() { | 188 bool SerialCloseFunction::Respond() { |
189 return true; | 189 return true; |
190 } | 190 } |
191 | 191 |
192 SerialReadFunction::SerialReadFunction() { | 192 SerialReadFunction::SerialReadFunction() { |
193 } | 193 } |
194 | 194 |
195 SerialReadFunction::~SerialReadFunction() { | 195 SerialReadFunction::~SerialReadFunction() { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 | 287 |
288 void SerialFlushFunction::Work() { | 288 void SerialFlushFunction::Work() { |
289 bool flush_result = false; | 289 bool flush_result = false; |
290 SerialConnection* serial_connection = GetSerialConnection( | 290 SerialConnection* serial_connection = GetSerialConnection( |
291 params_->connection_id); | 291 params_->connection_id); |
292 if (serial_connection) { | 292 if (serial_connection) { |
293 serial_connection->Flush(); | 293 serial_connection->Flush(); |
294 flush_result = true; | 294 flush_result = true; |
295 } | 295 } |
296 | 296 |
297 SetResult(Value::CreateBooleanValue(flush_result)); | 297 SetResult(new base::FundamentalValue(flush_result)); |
298 } | 298 } |
299 | 299 |
300 bool SerialFlushFunction::Respond() { | 300 bool SerialFlushFunction::Respond() { |
301 return true; | 301 return true; |
302 } | 302 } |
303 | 303 |
304 SerialGetControlSignalsFunction::SerialGetControlSignalsFunction() | 304 SerialGetControlSignalsFunction::SerialGetControlSignalsFunction() |
305 : api_response_(false) { | 305 : api_response_(false) { |
306 } | 306 } |
307 | 307 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 params_->connection_id); | 362 params_->connection_id); |
363 if (serial_connection) { | 363 if (serial_connection) { |
364 SerialConnection::ControlSignals control_signals = { 0 }; | 364 SerialConnection::ControlSignals control_signals = { 0 }; |
365 control_signals.should_set_dtr = params_->options.dtr.get() != NULL; | 365 control_signals.should_set_dtr = params_->options.dtr.get() != NULL; |
366 if (control_signals.should_set_dtr) | 366 if (control_signals.should_set_dtr) |
367 control_signals.dtr = *(params_->options.dtr); | 367 control_signals.dtr = *(params_->options.dtr); |
368 control_signals.should_set_rts = params_->options.rts.get() != NULL; | 368 control_signals.should_set_rts = params_->options.rts.get() != NULL; |
369 if (control_signals.should_set_rts) | 369 if (control_signals.should_set_rts) |
370 control_signals.rts = *(params_->options.rts); | 370 control_signals.rts = *(params_->options.rts); |
371 if (serial_connection->SetControlSignals(control_signals)) { | 371 if (serial_connection->SetControlSignals(control_signals)) { |
372 SetResult(Value::CreateBooleanValue(true)); | 372 SetResult(new base::FundamentalValue(true)); |
373 } else { | 373 } else { |
374 error_ = kErrorSetControlSignalsFailed; | 374 error_ = kErrorSetControlSignalsFailed; |
375 SetResult(Value::CreateBooleanValue(false)); | 375 SetResult(new base::FundamentalValue(false)); |
376 } | 376 } |
377 } else { | 377 } else { |
378 error_ = kSerialConnectionNotFoundError; | 378 error_ = kSerialConnectionNotFoundError; |
379 SetResult(Value::CreateBooleanValue(false)); | 379 SetResult(new base::FundamentalValue(false)); |
380 } | 380 } |
381 } | 381 } |
382 | 382 |
383 bool SerialSetControlSignalsFunction::Respond() { | 383 bool SerialSetControlSignalsFunction::Respond() { |
384 return true; | 384 return true; |
385 } | 385 } |
386 | 386 |
387 } // namespace extensions | 387 } // namespace extensions |
OLD | NEW |