Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: chrome/browser/extensions/api/serial/serial_api.cc

Issue 10694106: Added support for multiple parameters to Extension API callbacks. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Review fixes. Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/api/api_resource_controller.h" 8 #include "chrome/browser/extensions/api/api_resource_controller.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 21 matching lines...) Expand all
32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
33 33
34 ListValue* ports = new ListValue(); 34 ListValue* ports = new ListValue();
35 SerialPortEnumerator::StringSet port_names = 35 SerialPortEnumerator::StringSet port_names =
36 SerialPortEnumerator::GenerateValidSerialPortNames(); 36 SerialPortEnumerator::GenerateValidSerialPortNames();
37 SerialPortEnumerator::StringSet::const_iterator i = port_names.begin(); 37 SerialPortEnumerator::StringSet::const_iterator i = port_names.begin();
38 while (i != port_names.end()) { 38 while (i != port_names.end()) {
39 ports->Append(Value::CreateStringValue(*i++)); 39 ports->Append(Value::CreateStringValue(*i++));
40 } 40 }
41 41
42 result_.reset(ports); 42 SetSingleResult(ports);
43 } 43 }
44 44
45 bool SerialGetPortsFunction::Respond() { 45 bool SerialGetPortsFunction::Respond() {
46 return true; 46 return true;
47 } 47 }
48 48
49 // It's a fool's errand to come up with a default bitrate, because we don't get 49 // It's a fool's errand to come up with a default bitrate, because we don't get
50 // to control both sides of the communication. Unless the other side has 50 // to control both sides of the communication. Unless the other side has
51 // implemented auto-bitrate detection (rare), if we pick the wrong rate, then 51 // implemented auto-bitrate detection (rare), if we pick the wrong rate, then
52 // you're gonna have a bad time. Close doesn't count. 52 // you're gonna have a bad time. Close doesn't count.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 99
100 bool open_result = serial_connection->Open(); 100 bool open_result = serial_connection->Open();
101 if (!open_result) { 101 if (!open_result) {
102 serial_connection->Close(); 102 serial_connection->Close();
103 controller()->RemoveSerialConnection(id); 103 controller()->RemoveSerialConnection(id);
104 id = -1; 104 id = -1;
105 } 105 }
106 106
107 DictionaryValue* result = new DictionaryValue(); 107 DictionaryValue* result = new DictionaryValue();
108 result->SetInteger(kConnectionIdKey, id); 108 result->SetInteger(kConnectionIdKey, id);
109 result_.reset(result); 109 SetSingleResult(result);
110 AsyncWorkCompleted(); 110 AsyncWorkCompleted();
111 } else { 111 } else {
112 DictionaryValue* result = new DictionaryValue(); 112 DictionaryValue* result = new DictionaryValue();
113 result->SetInteger(kConnectionIdKey, -1); 113 result->SetInteger(kConnectionIdKey, -1);
114 result_.reset(result); 114 SetSingleResult(result);
115 AsyncWorkCompleted(); 115 AsyncWorkCompleted();
116 } 116 }
117 } 117 }
118 118
119 bool SerialOpenFunction::Respond() { 119 bool SerialOpenFunction::Respond() {
120 return true; 120 return true;
121 } 121 }
122 122
123 SerialCloseFunction::SerialCloseFunction() { 123 SerialCloseFunction::SerialCloseFunction() {
124 } 124 }
(...skipping 12 matching lines...) Expand all
137 void SerialCloseFunction::Work() { 137 void SerialCloseFunction::Work() {
138 bool close_result = false; 138 bool close_result = false;
139 SerialConnection* serial_connection = 139 SerialConnection* serial_connection =
140 controller()->GetSerialConnection(params_->connection_id); 140 controller()->GetSerialConnection(params_->connection_id);
141 if (serial_connection) { 141 if (serial_connection) {
142 serial_connection->Close(); 142 serial_connection->Close();
143 controller()->RemoveSerialConnection(params_->connection_id); 143 controller()->RemoveSerialConnection(params_->connection_id);
144 close_result = true; 144 close_result = true;
145 } 145 }
146 146
147 result_.reset(Value::CreateBooleanValue(close_result)); 147 SetSingleResult(Value::CreateBooleanValue(close_result));
148 } 148 }
149 149
150 bool SerialCloseFunction::Respond() { 150 bool SerialCloseFunction::Respond() {
151 return true; 151 return true;
152 } 152 }
153 153
154 SerialReadFunction::SerialReadFunction() { 154 SerialReadFunction::SerialReadFunction() {
155 } 155 }
156 156
157 SerialReadFunction::~SerialReadFunction() { 157 SerialReadFunction::~SerialReadFunction() {
(...skipping 17 matching lines...) Expand all
175 175
176 DictionaryValue* result = new DictionaryValue(); 176 DictionaryValue* result = new DictionaryValue();
177 177
178 // The API is defined to require a 'data' value, so we will always 178 // The API is defined to require a 'data' value, so we will always
179 // create a BinaryValue, even if it's zero-length. 179 // create a BinaryValue, even if it's zero-length.
180 if (bytes_read < 0) 180 if (bytes_read < 0)
181 bytes_read = 0; 181 bytes_read = 0;
182 result->SetInteger(kBytesReadKey, bytes_read); 182 result->SetInteger(kBytesReadKey, bytes_read);
183 result->Set(kDataKey, base::BinaryValue::CreateWithCopiedBuffer( 183 result->Set(kDataKey, base::BinaryValue::CreateWithCopiedBuffer(
184 reinterpret_cast<char*>(&byte), bytes_read)); 184 reinterpret_cast<char*>(&byte), bytes_read));
185 result_.reset(result); 185 SetSingleResult(result);
186 } 186 }
187 187
188 bool SerialReadFunction::Respond() { 188 bool SerialReadFunction::Respond() {
189 return true; 189 return true;
190 } 190 }
191 191
192 SerialWriteFunction::SerialWriteFunction() 192 SerialWriteFunction::SerialWriteFunction()
193 : io_buffer_(NULL), io_buffer_size_(0) { 193 : io_buffer_(NULL), io_buffer_size_(0) {
194 } 194 }
195 195
(...skipping 16 matching lines...) Expand all
212 int bytes_written = -1; 212 int bytes_written = -1;
213 SerialConnection* serial_connection = 213 SerialConnection* serial_connection =
214 controller()->GetSerialConnection(params_->connection_id); 214 controller()->GetSerialConnection(params_->connection_id);
215 if (serial_connection) 215 if (serial_connection)
216 bytes_written = serial_connection->Write(io_buffer_, io_buffer_size_); 216 bytes_written = serial_connection->Write(io_buffer_, io_buffer_size_);
217 else 217 else
218 error_ = kSerialConnectionNotFoundError; 218 error_ = kSerialConnectionNotFoundError;
219 219
220 DictionaryValue* result = new DictionaryValue(); 220 DictionaryValue* result = new DictionaryValue();
221 result->SetInteger(kBytesWrittenKey, bytes_written); 221 result->SetInteger(kBytesWrittenKey, bytes_written);
222 result_.reset(result); 222 SetSingleResult(result);
223 } 223 }
224 224
225 bool SerialWriteFunction::Respond() { 225 bool SerialWriteFunction::Respond() {
226 return true; 226 return true;
227 } 227 }
228 228
229 SerialFlushFunction::SerialFlushFunction() { 229 SerialFlushFunction::SerialFlushFunction() {
230 } 230 }
231 231
232 SerialFlushFunction::~SerialFlushFunction() { 232 SerialFlushFunction::~SerialFlushFunction() {
233 } 233 }
234 234
235 bool SerialFlushFunction::Prepare() { 235 bool SerialFlushFunction::Prepare() {
236 set_work_thread_id(BrowserThread::FILE); 236 set_work_thread_id(BrowserThread::FILE);
237 237
238 params_ = api::experimental_serial::Flush::Params::Create(*args_); 238 params_ = api::experimental_serial::Flush::Params::Create(*args_);
239 EXTENSION_FUNCTION_VALIDATE(params_.get()); 239 EXTENSION_FUNCTION_VALIDATE(params_.get());
240 return true; 240 return true;
241 } 241 }
242 242
243 void SerialFlushFunction::Work() { 243 void SerialFlushFunction::Work() {
244 bool flush_result = false; 244 bool flush_result = false;
245 SerialConnection* serial_connection = 245 SerialConnection* serial_connection =
246 controller()->GetSerialConnection(params_->connection_id); 246 controller()->GetSerialConnection(params_->connection_id);
247 if (serial_connection) { 247 if (serial_connection) {
248 serial_connection->Flush(); 248 serial_connection->Flush();
249 flush_result = true; 249 flush_result = true;
250 } 250 }
251 251
252 result_.reset(Value::CreateBooleanValue(flush_result)); 252 SetSingleResult(Value::CreateBooleanValue(flush_result));
253 } 253 }
254 254
255 bool SerialFlushFunction::Respond() { 255 bool SerialFlushFunction::Respond() {
256 return true; 256 return true;
257 } 257 }
258 258
259 } // namespace extensions 259 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698