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

Side by Side Diff: chrome/browser/extensions/api/bluetooth/bluetooth_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: Synced. 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/bluetooth/bluetooth_api.h" 5 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h"
6 6
7 #if defined(OS_CHROMEOS) 7 #if defined(OS_CHROMEOS)
8 #include <errno.h> 8 #include <errno.h>
9 #endif 9 #endif
10 10
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 namespace SetOutOfBandPairingData = 66 namespace SetOutOfBandPairingData =
67 extensions::api::experimental_bluetooth::SetOutOfBandPairingData; 67 extensions::api::experimental_bluetooth::SetOutOfBandPairingData;
68 namespace Write = extensions::api::experimental_bluetooth::Write; 68 namespace Write = extensions::api::experimental_bluetooth::Write;
69 69
70 namespace extensions { 70 namespace extensions {
71 namespace api { 71 namespace api {
72 72
73 #if defined(OS_CHROMEOS) 73 #if defined(OS_CHROMEOS)
74 74
75 bool BluetoothIsAvailableFunction::RunImpl() { 75 bool BluetoothIsAvailableFunction::RunImpl() {
76 result_.reset(Value::CreateBooleanValue(GetAdapter(profile())->IsPresent())); 76 SetResult(Value::CreateBooleanValue(GetAdapter(profile())->IsPresent()));
77 return true; 77 return true;
78 } 78 }
79 79
80 bool BluetoothIsPoweredFunction::RunImpl() { 80 bool BluetoothIsPoweredFunction::RunImpl() {
81 result_.reset(Value::CreateBooleanValue(GetAdapter(profile())->IsPowered())); 81 SetResult(Value::CreateBooleanValue(GetAdapter(profile())->IsPowered()));
82 return true; 82 return true;
83 } 83 }
84 84
85 bool BluetoothGetAddressFunction::RunImpl() { 85 bool BluetoothGetAddressFunction::RunImpl() {
86 result_.reset(Value::CreateStringValue(GetAdapter(profile())->address())); 86 SetResult(Value::CreateStringValue(GetAdapter(profile())->address()));
87 return true; 87 return true;
88 } 88 }
89 89
90 BluetoothGetDevicesFunction::BluetoothGetDevicesFunction() 90 BluetoothGetDevicesFunction::BluetoothGetDevicesFunction()
91 : callbacks_pending_(0) {} 91 : callbacks_pending_(0) {}
92 92
93 void BluetoothGetDevicesFunction::AddDeviceIfTrueCallback( 93 void BluetoothGetDevicesFunction::AddDeviceIfTrueCallback(
94 ListValue* list, 94 ListValue* list,
95 const chromeos::BluetoothDevice* device, 95 const chromeos::BluetoothDevice* device,
96 bool shouldAdd) { 96 bool shouldAdd) {
97 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 97 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
98 98
99 if (shouldAdd) 99 if (shouldAdd)
100 list->Append(experimental_bluetooth::BluetoothDeviceToValue(*device)); 100 list->Append(experimental_bluetooth::BluetoothDeviceToValue(*device));
101 101
102 callbacks_pending_--; 102 callbacks_pending_--;
103 if (callbacks_pending_ == -1) 103 if (callbacks_pending_ == -1)
104 SendResponse(true); 104 SendResponse(true);
105 } 105 }
106 106
107 bool BluetoothGetDevicesFunction::RunImpl() { 107 bool BluetoothGetDevicesFunction::RunImpl() {
108 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 108 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
109 109
110 scoped_ptr<GetDevices::Params> params(GetDevices::Params::Create(*args_)); 110 scoped_ptr<GetDevices::Params> params(GetDevices::Params::Create(*args_));
111 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); 111 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL);
112 const experimental_bluetooth::GetDevicesOptions& options = params->options; 112 const experimental_bluetooth::GetDevicesOptions& options = params->options;
113 113
114 ListValue* matches = new ListValue; 114 ListValue* matches = new ListValue;
115 result_.reset(matches); 115 SetResult(matches);
116 116
117 CHECK_EQ(0, callbacks_pending_); 117 CHECK_EQ(0, callbacks_pending_);
118 118
119 chromeos::BluetoothAdapter::DeviceList devices = 119 chromeos::BluetoothAdapter::DeviceList devices =
120 GetMutableAdapter(profile())->GetDevices(); 120 GetMutableAdapter(profile())->GetDevices();
121 for (chromeos::BluetoothAdapter::DeviceList::iterator i = devices.begin(); 121 for (chromeos::BluetoothAdapter::DeviceList::iterator i = devices.begin();
122 i != devices.end(); ++i) { 122 i != devices.end(); ++i) {
123 chromeos::BluetoothDevice* device = *i; 123 chromeos::BluetoothDevice* device = *i;
124 124
125 if (options.uuid.get() != NULL && 125 if (options.uuid.get() != NULL &&
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 178
179 chromeos::BluetoothDevice* device = 179 chromeos::BluetoothDevice* device =
180 GetMutableAdapter(profile())->GetDevice(options.device_address); 180 GetMutableAdapter(profile())->GetDevice(options.device_address);
181 if (!device) { 181 if (!device) {
182 SendResponse(false); 182 SendResponse(false);
183 SetError(kInvalidDevice); 183 SetError(kInvalidDevice);
184 return false; 184 return false;
185 } 185 }
186 186
187 ListValue* services = new ListValue; 187 ListValue* services = new ListValue;
188 result_.reset(services); 188 SetResult(services);
189 189
190 device->GetServiceRecords( 190 device->GetServiceRecords(
191 base::Bind(&BluetoothGetServicesFunction::GetServiceRecordsCallback, 191 base::Bind(&BluetoothGetServicesFunction::GetServiceRecordsCallback,
192 this, 192 this,
193 services), 193 services),
194 base::Bind(&BluetoothGetServicesFunction::OnErrorCallback, 194 base::Bind(&BluetoothGetServicesFunction::OnErrorCallback,
195 this)); 195 this));
196 196
197 return true; 197 return true;
198 } 198 }
199 199
200 void BluetoothConnectFunction::ConnectToServiceCallback( 200 void BluetoothConnectFunction::ConnectToServiceCallback(
201 const chromeos::BluetoothDevice* device, 201 const chromeos::BluetoothDevice* device,
202 const std::string& service_uuid, 202 const std::string& service_uuid,
203 scoped_refptr<chromeos::BluetoothSocket> socket) { 203 scoped_refptr<chromeos::BluetoothSocket> socket) {
204 if (socket.get()) { 204 if (socket.get()) {
205 int socket_id = GetEventRouter(profile())->RegisterSocket(socket); 205 int socket_id = GetEventRouter(profile())->RegisterSocket(socket);
206 206
207 experimental_bluetooth::Socket result_socket; 207 experimental_bluetooth::Socket result_socket;
208 experimental_bluetooth::BluetoothDeviceToApiDevice( 208 experimental_bluetooth::BluetoothDeviceToApiDevice(
209 *device, &result_socket.device); 209 *device, &result_socket.device);
210 result_socket.service_uuid = service_uuid; 210 result_socket.service_uuid = service_uuid;
211 result_socket.id = socket_id; 211 result_socket.id = socket_id;
212 result_.reset(result_socket.ToValue().release()); 212 SetResult(result_socket.ToValue().release());
213 SendResponse(true); 213 SendResponse(true);
214 } else { 214 } else {
215 SetError(kFailedToConnect); 215 SetError(kFailedToConnect);
216 SendResponse(false); 216 SendResponse(false);
217 } 217 }
218 } 218 }
219 219
220 bool BluetoothConnectFunction::RunImpl() { 220 bool BluetoothConnectFunction::RunImpl() {
221 scoped_ptr<Connect::Params> params(Connect::Params::Create(*args_)); 221 scoped_ptr<Connect::Params> params(Connect::Params::Create(*args_));
222 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); 222 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 buffer_size - total_bytes_read); 278 buffer_size - total_bytes_read);
279 errsv = errno; 279 errsv = errno;
280 if (bytes_read <= 0) 280 if (bytes_read <= 0)
281 break; 281 break;
282 282
283 total_bytes_read += bytes_read; 283 total_bytes_read += bytes_read;
284 } 284 }
285 285
286 if (total_bytes_read > 0) { 286 if (total_bytes_read > 0) {
287 success_ = true; 287 success_ = true;
288 result_.reset(base::BinaryValue::Create(all_bytes, total_bytes_read)); 288 SetResult(base::BinaryValue::Create(all_bytes, total_bytes_read));
289 } else { 289 } else {
290 success_ = (errsv == EAGAIN || errsv == EWOULDBLOCK); 290 success_ = (errsv == EAGAIN || errsv == EWOULDBLOCK);
291 free(all_bytes); 291 free(all_bytes);
292 } 292 }
293 293
294 if (!success_) 294 if (!success_)
295 SetError(safe_strerror(errsv)); 295 SetError(safe_strerror(errsv));
296 } 296 }
297 297
298 bool BluetoothReadFunction::Respond() { 298 bool BluetoothReadFunction::Respond() {
(...skipping 26 matching lines...) Expand all
325 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 325 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
326 326
327 if (socket_.get() == NULL) 327 if (socket_.get() == NULL)
328 return; 328 return;
329 329
330 ssize_t bytes_written = write(socket_->fd(), 330 ssize_t bytes_written = write(socket_->fd(),
331 data_to_write_->GetBuffer(), data_to_write_->GetSize()); 331 data_to_write_->GetBuffer(), data_to_write_->GetSize());
332 int errsv = errno; 332 int errsv = errno;
333 333
334 if (bytes_written > 0) { 334 if (bytes_written > 0) {
335 result_.reset(Value::CreateIntegerValue(bytes_written)); 335 SetResult(Value::CreateIntegerValue(bytes_written));
336 success_ = true; 336 success_ = true;
337 } else { 337 } else {
338 result_.reset(0); 338 results_.reset();
339 success_ = (errsv == EAGAIN || errsv == EWOULDBLOCK); 339 success_ = (errsv == EAGAIN || errsv == EWOULDBLOCK);
340 } 340 }
341 341
342 if (!success_) 342 if (!success_)
343 SetError(safe_strerror(errsv)); 343 SetError(safe_strerror(errsv));
344 } 344 }
345 345
346 bool BluetoothWriteFunction::Respond() { 346 bool BluetoothWriteFunction::Respond() {
347 return success_; 347 return success_;
348 } 348 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 base::BinaryValue* randomizer = base::BinaryValue::CreateWithCopiedBuffer( 418 base::BinaryValue* randomizer = base::BinaryValue::CreateWithCopiedBuffer(
419 reinterpret_cast<const char*>(data.randomizer), 419 reinterpret_cast<const char*>(data.randomizer),
420 chromeos::kBluetoothOutOfBandPairingDataSize); 420 chromeos::kBluetoothOutOfBandPairingDataSize);
421 421
422 // TODO(bryeung): convert to experimental_bluetooth::OutOfBandPairingData 422 // TODO(bryeung): convert to experimental_bluetooth::OutOfBandPairingData
423 // when ArrayBuffer support within objects is completed. 423 // when ArrayBuffer support within objects is completed.
424 DictionaryValue* result = new DictionaryValue(); 424 DictionaryValue* result = new DictionaryValue();
425 result->Set("hash", hash); 425 result->Set("hash", hash);
426 result->Set("randomizer", randomizer); 426 result->Set("randomizer", randomizer);
427 427
428 result_.reset(result); 428 SetResult(result);
429 429
430 SendResponse(true); 430 SendResponse(true);
431 } 431 }
432 432
433 void BluetoothGetLocalOutOfBandPairingDataFunction::ErrorCallback() { 433 void BluetoothGetLocalOutOfBandPairingDataFunction::ErrorCallback() {
434 SetError(kCouldNotGetLocalOutOfBandPairingData); 434 SetError(kCouldNotGetLocalOutOfBandPairingData);
435 SendResponse(false); 435 SendResponse(false);
436 } 436 }
437 437
438 bool BluetoothGetLocalOutOfBandPairingDataFunction::RunImpl() { 438 bool BluetoothGetLocalOutOfBandPairingDataFunction::RunImpl() {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 #endif 573 #endif
574 574
575 BluetoothReadFunction::BluetoothReadFunction() {} 575 BluetoothReadFunction::BluetoothReadFunction() {}
576 BluetoothReadFunction::~BluetoothReadFunction() {} 576 BluetoothReadFunction::~BluetoothReadFunction() {}
577 577
578 BluetoothWriteFunction::BluetoothWriteFunction() {} 578 BluetoothWriteFunction::BluetoothWriteFunction() {}
579 BluetoothWriteFunction::~BluetoothWriteFunction() {} 579 BluetoothWriteFunction::~BluetoothWriteFunction() {}
580 580
581 } // namespace api 581 } // namespace api
582 } // namespace extensions 582 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698