| 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/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api_factory.h" | 10 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api_factory.h" |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 | 240 |
| 241 SetResult(profiles); | 241 SetResult(profiles); |
| 242 SendResponse(true); | 242 SendResponse(true); |
| 243 | 243 |
| 244 return true; | 244 return true; |
| 245 } | 245 } |
| 246 | 246 |
| 247 bool BluetoothGetAdapterStateFunction::DoWork( | 247 bool BluetoothGetAdapterStateFunction::DoWork( |
| 248 scoped_refptr<BluetoothAdapter> adapter) { | 248 scoped_refptr<BluetoothAdapter> adapter) { |
| 249 bluetooth::AdapterState state; | 249 bluetooth::AdapterState state; |
| 250 PopulateAdapterState(*adapter, &state); | 250 PopulateAdapterState(*adapter.get(), &state); |
| 251 SetResult(state.ToValue().release()); | 251 SetResult(state.ToValue().release()); |
| 252 SendResponse(true); | 252 SendResponse(true); |
| 253 return true; | 253 return true; |
| 254 } | 254 } |
| 255 | 255 |
| 256 BluetoothGetDevicesFunction::BluetoothGetDevicesFunction() | 256 BluetoothGetDevicesFunction::BluetoothGetDevicesFunction() |
| 257 : device_events_sent_(0) {} | 257 : device_events_sent_(0) {} |
| 258 | 258 |
| 259 void BluetoothGetDevicesFunction::DispatchDeviceSearchResult( | 259 void BluetoothGetDevicesFunction::DispatchDeviceSearchResult( |
| 260 const BluetoothDevice& device) { | 260 const BluetoothDevice& device) { |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 return true; | 440 return true; |
| 441 } | 441 } |
| 442 | 442 |
| 443 void BluetoothReadFunction::Work() { | 443 void BluetoothReadFunction::Work() { |
| 444 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 444 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 445 | 445 |
| 446 if (!socket_.get()) | 446 if (!socket_.get()) |
| 447 return; | 447 return; |
| 448 | 448 |
| 449 scoped_refptr<net::GrowableIOBuffer> buffer(new net::GrowableIOBuffer); | 449 scoped_refptr<net::GrowableIOBuffer> buffer(new net::GrowableIOBuffer); |
| 450 success_ = socket_->Receive(buffer); | 450 success_ = socket_->Receive(buffer.get()); |
| 451 if (success_) | 451 if (success_) |
| 452 SetResult(base::BinaryValue::CreateWithCopiedBuffer(buffer->StartOfBuffer(), | 452 SetResult(base::BinaryValue::CreateWithCopiedBuffer(buffer->StartOfBuffer(), |
| 453 buffer->offset())); | 453 buffer->offset())); |
| 454 else | 454 else |
| 455 SetError(socket_->GetLastErrorMessage()); | 455 SetError(socket_->GetLastErrorMessage()); |
| 456 } | 456 } |
| 457 | 457 |
| 458 bool BluetoothReadFunction::Respond() { | 458 bool BluetoothReadFunction::Respond() { |
| 459 return success_; | 459 return success_; |
| 460 } | 460 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 | 494 |
| 495 void BluetoothWriteFunction::Work() { | 495 void BluetoothWriteFunction::Work() { |
| 496 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 496 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
| 497 | 497 |
| 498 if (socket_.get() == NULL) | 498 if (socket_.get() == NULL) |
| 499 return; | 499 return; |
| 500 | 500 |
| 501 scoped_refptr<net::WrappedIOBuffer> wrapped_io_buffer( | 501 scoped_refptr<net::WrappedIOBuffer> wrapped_io_buffer( |
| 502 new net::WrappedIOBuffer(data_to_write_->GetBuffer())); | 502 new net::WrappedIOBuffer(data_to_write_->GetBuffer())); |
| 503 scoped_refptr<net::DrainableIOBuffer> drainable_io_buffer( | 503 scoped_refptr<net::DrainableIOBuffer> drainable_io_buffer( |
| 504 new net::DrainableIOBuffer(wrapped_io_buffer, data_to_write_->GetSize())); | 504 new net::DrainableIOBuffer(wrapped_io_buffer.get(), |
| 505 success_ = socket_->Send(drainable_io_buffer); | 505 data_to_write_->GetSize())); |
| 506 success_ = socket_->Send(drainable_io_buffer.get()); |
| 506 if (success_) { | 507 if (success_) { |
| 507 if (drainable_io_buffer->BytesConsumed() > 0) | 508 if (drainable_io_buffer->BytesConsumed() > 0) |
| 508 SetResult( | 509 SetResult( |
| 509 Value::CreateIntegerValue(drainable_io_buffer->BytesConsumed())); | 510 Value::CreateIntegerValue(drainable_io_buffer->BytesConsumed())); |
| 510 else | 511 else |
| 511 results_.reset(); | 512 results_.reset(); |
| 512 } else { | 513 } else { |
| 513 SetError(socket_->GetLastErrorMessage()); | 514 SetError(socket_->GetLastErrorMessage()); |
| 514 } | 515 } |
| 515 } | 516 } |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 adapter->StopDiscovering( | 665 adapter->StopDiscovering( |
| 665 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), | 666 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), |
| 666 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); | 667 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); |
| 667 } | 668 } |
| 668 | 669 |
| 669 return true; | 670 return true; |
| 670 } | 671 } |
| 671 | 672 |
| 672 } // namespace api | 673 } // namespace api |
| 673 } // namespace extensions | 674 } // namespace extensions |
| OLD | NEW |