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/bluetooth/bluetooth_api.h" | 5 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 scoped_refptr<BluetoothAdapter> adapter) { | 239 scoped_refptr<BluetoothAdapter> adapter) { |
240 bluetooth::AdapterState state; | 240 bluetooth::AdapterState state; |
241 PopulateAdapterState(*adapter.get(), &state); | 241 PopulateAdapterState(*adapter.get(), &state); |
242 SetResult(state.ToValue().release()); | 242 SetResult(state.ToValue().release()); |
243 SendResponse(true); | 243 SendResponse(true); |
244 return true; | 244 return true; |
245 } | 245 } |
246 | 246 |
247 bool BluetoothGetDevicesFunction::DoWork( | 247 bool BluetoothGetDevicesFunction::DoWork( |
248 scoped_refptr<BluetoothAdapter> adapter) { | 248 scoped_refptr<BluetoothAdapter> adapter) { |
249 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 249 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
250 | 250 |
251 base::ListValue* device_list = new base::ListValue; | 251 base::ListValue* device_list = new base::ListValue; |
252 SetResult(device_list); | 252 SetResult(device_list); |
253 | 253 |
254 BluetoothAdapter::DeviceList devices = adapter->GetDevices(); | 254 BluetoothAdapter::DeviceList devices = adapter->GetDevices(); |
255 for (BluetoothAdapter::DeviceList::const_iterator iter = devices.begin(); | 255 for (BluetoothAdapter::DeviceList::const_iterator iter = devices.begin(); |
256 iter != devices.end(); | 256 iter != devices.end(); |
257 ++iter) { | 257 ++iter) { |
258 const BluetoothDevice* device = *iter; | 258 const BluetoothDevice* device = *iter; |
259 DCHECK(device); | 259 DCHECK(device); |
260 | 260 |
261 bluetooth::Device extension_device; | 261 bluetooth::Device extension_device; |
262 bluetooth::BluetoothDeviceToApiDevice(*device, &extension_device); | 262 bluetooth::BluetoothDeviceToApiDevice(*device, &extension_device); |
263 | 263 |
264 device_list->Append(extension_device.ToValue().release()); | 264 device_list->Append(extension_device.ToValue().release()); |
265 } | 265 } |
266 | 266 |
267 SendResponse(true); | 267 SendResponse(true); |
268 | 268 |
269 return true; | 269 return true; |
270 } | 270 } |
271 | 271 |
272 bool BluetoothGetDeviceFunction::DoWork( | 272 bool BluetoothGetDeviceFunction::DoWork( |
273 scoped_refptr<BluetoothAdapter> adapter) { | 273 scoped_refptr<BluetoothAdapter> adapter) { |
274 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 274 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
275 | 275 |
276 scoped_ptr<GetDevice::Params> params(GetDevice::Params::Create(*args_)); | 276 scoped_ptr<GetDevice::Params> params(GetDevice::Params::Create(*args_)); |
277 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 277 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
278 const std::string& device_address = params->device_address; | 278 const std::string& device_address = params->device_address; |
279 | 279 |
280 BluetoothDevice* device = adapter->GetDevice(device_address); | 280 BluetoothDevice* device = adapter->GetDevice(device_address); |
281 if (device) { | 281 if (device) { |
282 bluetooth::Device extension_device; | 282 bluetooth::Device extension_device; |
283 bluetooth::BluetoothDeviceToApiDevice(*device, &extension_device); | 283 bluetooth::BluetoothDeviceToApiDevice(*device, &extension_device); |
284 SetResult(extension_device.ToValue().release()); | 284 SetResult(extension_device.ToValue().release()); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 if (socket_.get() == NULL) { | 356 if (socket_.get() == NULL) { |
357 SetError(kSocketNotFoundError); | 357 SetError(kSocketNotFoundError); |
358 return false; | 358 return false; |
359 } | 359 } |
360 | 360 |
361 success_ = false; | 361 success_ = false; |
362 return true; | 362 return true; |
363 } | 363 } |
364 | 364 |
365 void BluetoothReadFunction::Work() { | 365 void BluetoothReadFunction::Work() { |
366 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 366 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
367 | 367 |
368 if (!socket_.get()) | 368 if (!socket_.get()) |
369 return; | 369 return; |
370 | 370 |
371 scoped_refptr<net::GrowableIOBuffer> buffer(new net::GrowableIOBuffer); | 371 scoped_refptr<net::GrowableIOBuffer> buffer(new net::GrowableIOBuffer); |
372 success_ = socket_->Receive(buffer.get()); | 372 success_ = socket_->Receive(buffer.get()); |
373 if (success_) | 373 if (success_) |
374 SetResult(base::BinaryValue::CreateWithCopiedBuffer(buffer->StartOfBuffer(), | 374 SetResult(base::BinaryValue::CreateWithCopiedBuffer(buffer->StartOfBuffer(), |
375 buffer->offset())); | 375 buffer->offset())); |
376 else | 376 else |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 | 408 |
409 base::BinaryValue* tmp_data; | 409 base::BinaryValue* tmp_data; |
410 EXTENSION_FUNCTION_VALIDATE(options->GetBinary("data", &tmp_data)); | 410 EXTENSION_FUNCTION_VALIDATE(options->GetBinary("data", &tmp_data)); |
411 data_to_write_ = tmp_data; | 411 data_to_write_ = tmp_data; |
412 | 412 |
413 success_ = false; | 413 success_ = false; |
414 return socket_.get() != NULL; | 414 return socket_.get() != NULL; |
415 } | 415 } |
416 | 416 |
417 void BluetoothWriteFunction::Work() { | 417 void BluetoothWriteFunction::Work() { |
418 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 418 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
419 | 419 |
420 if (socket_.get() == NULL) | 420 if (socket_.get() == NULL) |
421 return; | 421 return; |
422 | 422 |
423 scoped_refptr<net::WrappedIOBuffer> wrapped_io_buffer( | 423 scoped_refptr<net::WrappedIOBuffer> wrapped_io_buffer( |
424 new net::WrappedIOBuffer(data_to_write_->GetBuffer())); | 424 new net::WrappedIOBuffer(data_to_write_->GetBuffer())); |
425 scoped_refptr<net::DrainableIOBuffer> drainable_io_buffer( | 425 scoped_refptr<net::DrainableIOBuffer> drainable_io_buffer( |
426 new net::DrainableIOBuffer(wrapped_io_buffer.get(), | 426 new net::DrainableIOBuffer(wrapped_io_buffer.get(), |
427 data_to_write_->GetSize())); | 427 data_to_write_->GetSize())); |
428 success_ = socket_->Send(drainable_io_buffer.get()); | 428 success_ = socket_->Send(drainable_io_buffer.get()); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 adapter, | 575 adapter, |
576 extension_id(), | 576 extension_id(), |
577 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), | 577 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), |
578 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); | 578 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); |
579 | 579 |
580 return true; | 580 return true; |
581 } | 581 } |
582 | 582 |
583 } // namespace api | 583 } // namespace api |
584 } // namespace extensions | 584 } // namespace extensions |
OLD | NEW |