| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/extensions/api/api_resource_controller.h" | 10 #include "chrome/browser/extensions/api/api_resource_controller.h" |
| 11 #include "chrome/browser/extensions/api/serial/serial_connection.h" | 11 #include "chrome/browser/extensions/api/serial/serial_connection.h" |
| 12 | 12 |
| 13 namespace extensions { | 13 namespace extensions { |
| 14 | 14 |
| 15 const char kConnectionIdKey[] = "connectionId"; | 15 const char kConnectionIdKey[] = "connectionId"; |
| 16 const char kDataKey[] = "data"; | 16 const char kDataKey[] = "data"; |
| 17 const char kBytesReadKey[] = "bytesRead"; | 17 const char kBytesReadKey[] = "bytesRead"; |
| 18 const char kBytesWrittenKey[] = "bytesWritten"; | 18 const char kBytesWrittenKey[] = "bytesWritten"; |
| 19 | 19 |
| 20 SerialOpenFunction::SerialOpenFunction() | 20 SerialOpenFunction::SerialOpenFunction() : src_id_(-1) {} |
| 21 : src_id_(-1) { | |
| 22 } | |
| 23 | 21 |
| 24 bool SerialOpenFunction::Prepare() { | 22 bool SerialOpenFunction::Prepare() { |
| 25 size_t argument_position = 0; | 23 size_t argument_position = 0; |
| 26 EXTENSION_FUNCTION_VALIDATE(args_->GetString(argument_position++, &port_)); | 24 EXTENSION_FUNCTION_VALIDATE(args_->GetString(argument_position++, &port_)); |
| 27 src_id_ = ExtractSrcId(argument_position); | 25 src_id_ = ExtractSrcId(argument_position); |
| 28 return true; | 26 return true; |
| 29 } | 27 } |
| 30 | 28 |
| 31 void SerialOpenFunction::Work() { | 29 void SerialOpenFunction::Work() { |
| 32 APIResourceEventNotifier* event_notifier = CreateEventNotifier(src_id_); | 30 APIResourceEventNotifier* event_notifier = CreateEventNotifier(src_id_); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 } | 96 } |
| 99 | 97 |
| 100 bool SerialReadFunction::Respond() { | 98 bool SerialReadFunction::Respond() { |
| 101 return true; | 99 return true; |
| 102 } | 100 } |
| 103 | 101 |
| 104 SerialWriteFunction::SerialWriteFunction() | 102 SerialWriteFunction::SerialWriteFunction() |
| 105 : connection_id_(-1), io_buffer_(NULL) { | 103 : connection_id_(-1), io_buffer_(NULL) { |
| 106 } | 104 } |
| 107 | 105 |
| 108 SerialWriteFunction::~SerialWriteFunction() { | 106 SerialWriteFunction::~SerialWriteFunction() {} |
| 109 } | |
| 110 | 107 |
| 111 bool SerialWriteFunction::Prepare() { | 108 bool SerialWriteFunction::Prepare() { |
| 112 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &connection_id_)); | 109 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &connection_id_)); |
| 113 base::ListValue* data_list_value = NULL; | 110 base::ListValue* data_list_value = NULL; |
| 114 EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &data_list_value)); | 111 EXTENSION_FUNCTION_VALIDATE(args_->GetList(1, &data_list_value)); |
| 115 size_t size = data_list_value->GetSize(); | 112 size_t size = data_list_value->GetSize(); |
| 116 if (size != 0) { | 113 if (size != 0) { |
| 117 io_buffer_ = new net::IOBufferWithSize(size); | 114 io_buffer_ = new net::IOBufferWithSize(size); |
| 118 uint8* data_buffer = | 115 uint8* data_buffer = |
| 119 reinterpret_cast<uint8*>(io_buffer_->data()); | 116 reinterpret_cast<uint8*>(io_buffer_->data()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 141 DictionaryValue* result = new DictionaryValue(); | 138 DictionaryValue* result = new DictionaryValue(); |
| 142 result->SetInteger(kBytesWrittenKey, bytes_written); | 139 result->SetInteger(kBytesWrittenKey, bytes_written); |
| 143 result_.reset(result); | 140 result_.reset(result); |
| 144 } | 141 } |
| 145 | 142 |
| 146 bool SerialWriteFunction::Respond() { | 143 bool SerialWriteFunction::Respond() { |
| 147 return true; | 144 return true; |
| 148 } | 145 } |
| 149 | 146 |
| 150 } // namespace extensions | 147 } // namespace extensions |
| OLD | NEW |