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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 } // namespace | 51 } // namespace |
52 | 52 |
53 SerialAsyncApiFunction::SerialAsyncApiFunction() | 53 SerialAsyncApiFunction::SerialAsyncApiFunction() |
54 : manager_(NULL) { | 54 : manager_(NULL) { |
55 } | 55 } |
56 | 56 |
57 SerialAsyncApiFunction::~SerialAsyncApiFunction() {} | 57 SerialAsyncApiFunction::~SerialAsyncApiFunction() {} |
58 | 58 |
59 bool SerialAsyncApiFunction::PrePrepare() { | 59 bool SerialAsyncApiFunction::PrePrepare() { |
60 manager_ = ApiResourceManager<SerialConnection>::Get(GetProfile()); | 60 manager_ = ApiResourceManager<SerialConnection>::Get(browser_context()); |
61 DCHECK(manager_); | 61 DCHECK(manager_); |
62 return true; | 62 return true; |
63 } | 63 } |
64 | 64 |
65 bool SerialAsyncApiFunction::Respond() { | 65 bool SerialAsyncApiFunction::Respond() { |
66 return error_.empty(); | 66 return error_.empty(); |
67 } | 67 } |
68 | 68 |
69 SerialConnection* SerialAsyncApiFunction::GetSerialConnection( | 69 SerialConnection* SerialAsyncApiFunction::GetSerialConnection( |
70 int api_resource_id) { | 70 int api_resource_id) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 SetDefaultScopedPtrValue(options->receive_timeout, kDefaultReceiveTimeout); | 128 SetDefaultScopedPtrValue(options->receive_timeout, kDefaultReceiveTimeout); |
129 SetDefaultScopedPtrValue(options->send_timeout, kDefaultSendTimeout); | 129 SetDefaultScopedPtrValue(options->send_timeout, kDefaultSendTimeout); |
130 | 130 |
131 if (options->data_bits == serial::DATA_BITS_NONE) | 131 if (options->data_bits == serial::DATA_BITS_NONE) |
132 options->data_bits = kDefaultDataBits; | 132 options->data_bits = kDefaultDataBits; |
133 if (options->parity_bit == serial::PARITY_BIT_NONE) | 133 if (options->parity_bit == serial::PARITY_BIT_NONE) |
134 options->parity_bit = kDefaultParityBit; | 134 options->parity_bit = kDefaultParityBit; |
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(GetProfile()); | 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(BrowserThread::CurrentlyOn(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 } |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 } | 291 } |
292 | 292 |
293 SerialSetPausedFunction::SerialSetPausedFunction() {} | 293 SerialSetPausedFunction::SerialSetPausedFunction() {} |
294 | 294 |
295 SerialSetPausedFunction::~SerialSetPausedFunction() {} | 295 SerialSetPausedFunction::~SerialSetPausedFunction() {} |
296 | 296 |
297 bool SerialSetPausedFunction::Prepare() { | 297 bool SerialSetPausedFunction::Prepare() { |
298 params_ = serial::SetPaused::Params::Create(*args_); | 298 params_ = serial::SetPaused::Params::Create(*args_); |
299 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 299 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
300 | 300 |
301 serial_event_dispatcher_ = SerialEventDispatcher::Get(GetProfile()); | 301 serial_event_dispatcher_ = SerialEventDispatcher::Get(browser_context()); |
302 DCHECK(serial_event_dispatcher_); | 302 DCHECK(serial_event_dispatcher_); |
303 return true; | 303 return true; |
304 } | 304 } |
305 | 305 |
306 void SerialSetPausedFunction::Work() { | 306 void SerialSetPausedFunction::Work() { |
307 SerialConnection* connection = GetSerialConnection(params_->connection_id); | 307 SerialConnection* connection = GetSerialConnection(params_->connection_id); |
308 if (!connection) { | 308 if (!connection) { |
309 error_ = kErrorSerialConnectionNotFound; | 309 error_ = kErrorSerialConnectionNotFound; |
310 return; | 310 return; |
311 } | 311 } |
(...skipping 106 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 |