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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 bitrate_(9600), | 82 bitrate_(9600), |
83 event_notifier_(NULL) { | 83 event_notifier_(NULL) { |
84 } | 84 } |
85 | 85 |
86 SerialOpenFunction::~SerialOpenFunction() { | 86 SerialOpenFunction::~SerialOpenFunction() { |
87 } | 87 } |
88 | 88 |
89 bool SerialOpenFunction::Prepare() { | 89 bool SerialOpenFunction::Prepare() { |
90 set_work_thread_id(BrowserThread::FILE); | 90 set_work_thread_id(BrowserThread::FILE); |
91 | 91 |
92 params_ = api::experimental_serial::Open::Params::Create(*args_); | 92 params_ = api::serial::Open::Params::Create(*args_); |
93 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 93 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
94 | 94 |
95 if (params_->options.get()) { | 95 if (params_->options.get()) { |
96 scoped_ptr<DictionaryValue> options = params_->options->ToValue(); | 96 scoped_ptr<DictionaryValue> options = params_->options->ToValue(); |
97 if (options->HasKey(kBitrateKey)) | 97 if (options->HasKey(kBitrateKey)) |
98 EXTENSION_FUNCTION_VALIDATE(options->GetInteger(kBitrateKey, &bitrate_)); | 98 EXTENSION_FUNCTION_VALIDATE(options->GetInteger(kBitrateKey, &bitrate_)); |
99 | 99 |
100 src_id_ = ExtractSrcId(options.get()); | 100 src_id_ = ExtractSrcId(options.get()); |
101 event_notifier_ = CreateEventNotifier(src_id_); | 101 event_notifier_ = CreateEventNotifier(src_id_); |
102 } | 102 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 | 159 |
160 SerialCloseFunction::SerialCloseFunction() { | 160 SerialCloseFunction::SerialCloseFunction() { |
161 } | 161 } |
162 | 162 |
163 SerialCloseFunction::~SerialCloseFunction() { | 163 SerialCloseFunction::~SerialCloseFunction() { |
164 } | 164 } |
165 | 165 |
166 bool SerialCloseFunction::Prepare() { | 166 bool SerialCloseFunction::Prepare() { |
167 set_work_thread_id(BrowserThread::FILE); | 167 set_work_thread_id(BrowserThread::FILE); |
168 | 168 |
169 params_ = api::experimental_serial::Close::Params::Create(*args_); | 169 params_ = api::serial::Close::Params::Create(*args_); |
170 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 170 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
171 | 171 |
172 return true; | 172 return true; |
173 } | 173 } |
174 | 174 |
175 void SerialCloseFunction::Work() { | 175 void SerialCloseFunction::Work() { |
176 bool close_result = false; | 176 bool close_result = false; |
177 SerialConnection* serial_connection = manager_->Get(params_->connection_id); | 177 SerialConnection* serial_connection = manager_->Get(params_->connection_id); |
178 if (serial_connection) { | 178 if (serial_connection) { |
179 serial_connection->Close(); | 179 serial_connection->Close(); |
(...skipping 10 matching lines...) Expand all Loading... |
190 | 190 |
191 SerialReadFunction::SerialReadFunction() { | 191 SerialReadFunction::SerialReadFunction() { |
192 } | 192 } |
193 | 193 |
194 SerialReadFunction::~SerialReadFunction() { | 194 SerialReadFunction::~SerialReadFunction() { |
195 } | 195 } |
196 | 196 |
197 bool SerialReadFunction::Prepare() { | 197 bool SerialReadFunction::Prepare() { |
198 set_work_thread_id(BrowserThread::FILE); | 198 set_work_thread_id(BrowserThread::FILE); |
199 | 199 |
200 params_ = api::experimental_serial::Read::Params::Create(*args_); | 200 params_ = api::serial::Read::Params::Create(*args_); |
201 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 201 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
202 if (params_->bytes_to_read <= 0 || params_->bytes_to_read >= 1024 * 1024) { | 202 if (params_->bytes_to_read <= 0 || params_->bytes_to_read >= 1024 * 1024) { |
203 error_ = kSerialReadInvalidBytesToRead; | 203 error_ = kSerialReadInvalidBytesToRead; |
204 return false; | 204 return false; |
205 } | 205 } |
206 | 206 |
207 return true; | 207 return true; |
208 } | 208 } |
209 | 209 |
210 void SerialReadFunction::Work() { | 210 void SerialReadFunction::Work() { |
(...skipping 24 matching lines...) Expand all Loading... |
235 SerialWriteFunction::SerialWriteFunction() | 235 SerialWriteFunction::SerialWriteFunction() |
236 : io_buffer_(NULL), io_buffer_size_(0) { | 236 : io_buffer_(NULL), io_buffer_size_(0) { |
237 } | 237 } |
238 | 238 |
239 SerialWriteFunction::~SerialWriteFunction() { | 239 SerialWriteFunction::~SerialWriteFunction() { |
240 } | 240 } |
241 | 241 |
242 bool SerialWriteFunction::Prepare() { | 242 bool SerialWriteFunction::Prepare() { |
243 set_work_thread_id(BrowserThread::FILE); | 243 set_work_thread_id(BrowserThread::FILE); |
244 | 244 |
245 params_ = api::experimental_serial::Write::Params::Create(*args_); | 245 params_ = api::serial::Write::Params::Create(*args_); |
246 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 246 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
247 | 247 |
248 io_buffer_size_ = params_->data.size(); | 248 io_buffer_size_ = params_->data.size(); |
249 io_buffer_ = new net::WrappedIOBuffer(params_->data.data()); | 249 io_buffer_ = new net::WrappedIOBuffer(params_->data.data()); |
250 | 250 |
251 return true; | 251 return true; |
252 } | 252 } |
253 | 253 |
254 void SerialWriteFunction::Work() { | 254 void SerialWriteFunction::Work() { |
255 int bytes_written = -1; | 255 int bytes_written = -1; |
(...skipping 14 matching lines...) Expand all Loading... |
270 | 270 |
271 SerialFlushFunction::SerialFlushFunction() { | 271 SerialFlushFunction::SerialFlushFunction() { |
272 } | 272 } |
273 | 273 |
274 SerialFlushFunction::~SerialFlushFunction() { | 274 SerialFlushFunction::~SerialFlushFunction() { |
275 } | 275 } |
276 | 276 |
277 bool SerialFlushFunction::Prepare() { | 277 bool SerialFlushFunction::Prepare() { |
278 set_work_thread_id(BrowserThread::FILE); | 278 set_work_thread_id(BrowserThread::FILE); |
279 | 279 |
280 params_ = api::experimental_serial::Flush::Params::Create(*args_); | 280 params_ = api::serial::Flush::Params::Create(*args_); |
281 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 281 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
282 return true; | 282 return true; |
283 } | 283 } |
284 | 284 |
285 void SerialFlushFunction::Work() { | 285 void SerialFlushFunction::Work() { |
286 bool flush_result = false; | 286 bool flush_result = false; |
287 SerialConnection* serial_connection = manager_->Get(params_->connection_id); | 287 SerialConnection* serial_connection = manager_->Get(params_->connection_id); |
288 if (serial_connection) { | 288 if (serial_connection) { |
289 serial_connection->Flush(); | 289 serial_connection->Flush(); |
290 flush_result = true; | 290 flush_result = true; |
291 } | 291 } |
292 | 292 |
293 SetResult(Value::CreateBooleanValue(flush_result)); | 293 SetResult(Value::CreateBooleanValue(flush_result)); |
294 } | 294 } |
295 | 295 |
296 bool SerialFlushFunction::Respond() { | 296 bool SerialFlushFunction::Respond() { |
297 return true; | 297 return true; |
298 } | 298 } |
299 | 299 |
300 SerialGetControlSignalsFunction::SerialGetControlSignalsFunction() | 300 SerialGetControlSignalsFunction::SerialGetControlSignalsFunction() |
301 : api_response_(false) { | 301 : api_response_(false) { |
302 } | 302 } |
303 | 303 |
304 SerialGetControlSignalsFunction::~SerialGetControlSignalsFunction() { | 304 SerialGetControlSignalsFunction::~SerialGetControlSignalsFunction() { |
305 } | 305 } |
306 | 306 |
307 bool SerialGetControlSignalsFunction::Prepare() { | 307 bool SerialGetControlSignalsFunction::Prepare() { |
308 set_work_thread_id(BrowserThread::FILE); | 308 set_work_thread_id(BrowserThread::FILE); |
309 | 309 |
310 params_ = api::experimental_serial::GetControlSignals::Params::Create( | 310 params_ = api::serial::GetControlSignals::Params::Create( |
311 *args_); | 311 *args_); |
312 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 312 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
313 | 313 |
314 return true; | 314 return true; |
315 } | 315 } |
316 | 316 |
317 void SerialGetControlSignalsFunction::Work() { | 317 void SerialGetControlSignalsFunction::Work() { |
318 DictionaryValue *result = new DictionaryValue(); | 318 DictionaryValue *result = new DictionaryValue(); |
319 SerialConnection* serial_connection = manager_->Get(params_->connection_id); | 319 SerialConnection* serial_connection = manager_->Get(params_->connection_id); |
320 if (serial_connection) { | 320 if (serial_connection) { |
(...skipping 19 matching lines...) Expand all Loading... |
340 | 340 |
341 SerialSetControlSignalsFunction::SerialSetControlSignalsFunction() { | 341 SerialSetControlSignalsFunction::SerialSetControlSignalsFunction() { |
342 } | 342 } |
343 | 343 |
344 SerialSetControlSignalsFunction::~SerialSetControlSignalsFunction() { | 344 SerialSetControlSignalsFunction::~SerialSetControlSignalsFunction() { |
345 } | 345 } |
346 | 346 |
347 bool SerialSetControlSignalsFunction::Prepare() { | 347 bool SerialSetControlSignalsFunction::Prepare() { |
348 set_work_thread_id(BrowserThread::FILE); | 348 set_work_thread_id(BrowserThread::FILE); |
349 | 349 |
350 params_ = api::experimental_serial::SetControlSignals::Params::Create( | 350 params_ = api::serial::SetControlSignals::Params::Create( |
351 *args_); | 351 *args_); |
352 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 352 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
353 | 353 |
354 return true; | 354 return true; |
355 } | 355 } |
356 | 356 |
357 void SerialSetControlSignalsFunction::Work() { | 357 void SerialSetControlSignalsFunction::Work() { |
358 SerialConnection* serial_connection = manager_->Get(params_->connection_id); | 358 SerialConnection* serial_connection = manager_->Get(params_->connection_id); |
359 if (serial_connection) { | 359 if (serial_connection) { |
360 SerialConnection::ControlSignals control_signals = { 0 }; | 360 SerialConnection::ControlSignals control_signals = { 0 }; |
(...skipping 13 matching lines...) Expand all Loading... |
374 error_ = kSerialConnectionNotFoundError; | 374 error_ = kSerialConnectionNotFoundError; |
375 SetResult(Value::CreateBooleanValue(false)); | 375 SetResult(Value::CreateBooleanValue(false)); |
376 } | 376 } |
377 } | 377 } |
378 | 378 |
379 bool SerialSetControlSignalsFunction::Respond() { | 379 bool SerialSetControlSignalsFunction::Respond() { |
380 return true; | 380 return true; |
381 } | 381 } |
382 | 382 |
383 } // namespace extensions | 383 } // namespace extensions |
OLD | NEW |