| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 } // namespace | 50 } // namespace |
| 51 | 51 |
| 52 SerialAsyncApiFunction::SerialAsyncApiFunction() | 52 SerialAsyncApiFunction::SerialAsyncApiFunction() |
| 53 : manager_(NULL) { | 53 : manager_(NULL) { |
| 54 } | 54 } |
| 55 | 55 |
| 56 SerialAsyncApiFunction::~SerialAsyncApiFunction() {} | 56 SerialAsyncApiFunction::~SerialAsyncApiFunction() {} |
| 57 | 57 |
| 58 bool SerialAsyncApiFunction::PrePrepare() { | 58 bool SerialAsyncApiFunction::PrePrepare() { |
| 59 manager_ = ApiResourceManager<SerialConnection>::Get(GetProfile()); | 59 manager_ = ApiResourceManager<SerialConnection>::Get(context()); |
| 60 DCHECK(manager_); | 60 DCHECK(manager_); |
| 61 return true; | 61 return true; |
| 62 } | 62 } |
| 63 | 63 |
| 64 bool SerialAsyncApiFunction::Respond() { | 64 bool SerialAsyncApiFunction::Respond() { |
| 65 return error_.empty(); | 65 return error_.empty(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 SerialConnection* SerialAsyncApiFunction::GetSerialConnection( | 68 SerialConnection* SerialAsyncApiFunction::GetSerialConnection( |
| 69 int api_resource_id) { | 69 int api_resource_id) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 SetDefaultScopedPtrValue(options->receive_timeout, kDefaultReceiveTimeout); | 127 SetDefaultScopedPtrValue(options->receive_timeout, kDefaultReceiveTimeout); |
| 128 SetDefaultScopedPtrValue(options->send_timeout, kDefaultSendTimeout); | 128 SetDefaultScopedPtrValue(options->send_timeout, kDefaultSendTimeout); |
| 129 | 129 |
| 130 if (options->data_bits == serial::DATA_BITS_NONE) | 130 if (options->data_bits == serial::DATA_BITS_NONE) |
| 131 options->data_bits = kDefaultDataBits; | 131 options->data_bits = kDefaultDataBits; |
| 132 if (options->parity_bit == serial::PARITY_BIT_NONE) | 132 if (options->parity_bit == serial::PARITY_BIT_NONE) |
| 133 options->parity_bit = kDefaultParityBit; | 133 options->parity_bit = kDefaultParityBit; |
| 134 if (options->stop_bits == serial::STOP_BITS_NONE) | 134 if (options->stop_bits == serial::STOP_BITS_NONE) |
| 135 options->stop_bits = kDefaultStopBits; | 135 options->stop_bits = kDefaultStopBits; |
| 136 | 136 |
| 137 serial_event_dispatcher_ = SerialEventDispatcher::Get(GetProfile()); | 137 serial_event_dispatcher_ = SerialEventDispatcher::Get(context()); |
| 138 DCHECK(serial_event_dispatcher_); | 138 DCHECK(serial_event_dispatcher_); |
| 139 | 139 |
| 140 return true; | 140 return true; |
| 141 } | 141 } |
| 142 | 142 |
| 143 void SerialConnectFunction::AsyncWorkStart() { | 143 void SerialConnectFunction::AsyncWorkStart() { |
| 144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 145 connection_ = CreateSerialConnection(params_->path, extension_->id()); | 145 connection_ = CreateSerialConnection(params_->path, extension_->id()); |
| 146 connection_->Open(base::Bind(&SerialConnectFunction::OnConnected, this)); | 146 connection_->Open(base::Bind(&SerialConnectFunction::OnConnected, this)); |
| 147 } | 147 } |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 } | 290 } |
| 291 | 291 |
| 292 SerialSetPausedFunction::SerialSetPausedFunction() {} | 292 SerialSetPausedFunction::SerialSetPausedFunction() {} |
| 293 | 293 |
| 294 SerialSetPausedFunction::~SerialSetPausedFunction() {} | 294 SerialSetPausedFunction::~SerialSetPausedFunction() {} |
| 295 | 295 |
| 296 bool SerialSetPausedFunction::Prepare() { | 296 bool SerialSetPausedFunction::Prepare() { |
| 297 params_ = serial::SetPaused::Params::Create(*args_); | 297 params_ = serial::SetPaused::Params::Create(*args_); |
| 298 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 298 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 299 | 299 |
| 300 serial_event_dispatcher_ = SerialEventDispatcher::Get(GetProfile()); | 300 serial_event_dispatcher_ = SerialEventDispatcher::Get(context()); |
| 301 DCHECK(serial_event_dispatcher_); | 301 DCHECK(serial_event_dispatcher_); |
| 302 return true; | 302 return true; |
| 303 } | 303 } |
| 304 | 304 |
| 305 void SerialSetPausedFunction::Work() { | 305 void SerialSetPausedFunction::Work() { |
| 306 SerialConnection* connection = GetSerialConnection(params_->connection_id); | 306 SerialConnection* connection = GetSerialConnection(params_->connection_id); |
| 307 if (!connection) { | 307 if (!connection) { |
| 308 error_ = kErrorSerialConnectionNotFound; | 308 error_ = kErrorSerialConnectionNotFound; |
| 309 return; | 309 return; |
| 310 } | 310 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 return; | 417 return; |
| 418 } | 418 } |
| 419 | 419 |
| 420 bool success = connection->SetControlSignals(params_->signals); | 420 bool success = connection->SetControlSignals(params_->signals); |
| 421 results_ = serial::SetControlSignals::Results::Create(success); | 421 results_ = serial::SetControlSignals::Results::Create(success); |
| 422 } | 422 } |
| 423 | 423 |
| 424 } // namespace api | 424 } // namespace api |
| 425 | 425 |
| 426 } // namespace extensions | 426 } // namespace extensions |
| OLD | NEW |