| 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 "extensions/browser/api/bluetooth/bluetooth_api.h" | 5 #include "extensions/browser/api/bluetooth/bluetooth_api.h" |
| 6 | 6 |
| 7 #include <memory> |
| 7 #include <string> | 8 #include <string> |
| 9 #include <utility> |
| 8 | 10 |
| 9 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 10 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 11 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 12 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 13 #include "device/bluetooth/bluetooth_adapter.h" | 15 #include "device/bluetooth/bluetooth_adapter.h" |
| 14 #include "device/bluetooth/bluetooth_device.h" | 16 #include "device/bluetooth/bluetooth_device.h" |
| 15 #include "extensions/browser/api/bluetooth/bluetooth_api_utils.h" | 17 #include "extensions/browser/api/bluetooth/bluetooth_api_utils.h" |
| 16 #include "extensions/browser/api/bluetooth/bluetooth_event_router.h" | 18 #include "extensions/browser/api/bluetooth/bluetooth_event_router.h" |
| 17 #include "extensions/browser/event_router.h" | 19 #include "extensions/browser/event_router.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 SendResponse(true); | 110 SendResponse(true); |
| 109 return true; | 111 return true; |
| 110 } | 112 } |
| 111 | 113 |
| 112 BluetoothGetDevicesFunction::~BluetoothGetDevicesFunction() {} | 114 BluetoothGetDevicesFunction::~BluetoothGetDevicesFunction() {} |
| 113 | 115 |
| 114 bool BluetoothGetDevicesFunction::DoWork( | 116 bool BluetoothGetDevicesFunction::DoWork( |
| 115 scoped_refptr<BluetoothAdapter> adapter) { | 117 scoped_refptr<BluetoothAdapter> adapter) { |
| 116 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 118 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 117 | 119 |
| 118 base::ListValue* device_list = new base::ListValue; | 120 std::unique_ptr<base::ListValue> device_list(new base::ListValue); |
| 119 SetResult(device_list); | |
| 120 | 121 |
| 121 BluetoothAdapter::DeviceList devices = adapter->GetDevices(); | 122 BluetoothAdapter::DeviceList devices = adapter->GetDevices(); |
| 122 for (BluetoothAdapter::DeviceList::const_iterator iter = devices.begin(); | 123 for (BluetoothAdapter::DeviceList::const_iterator iter = devices.begin(); |
| 123 iter != devices.end(); | 124 iter != devices.end(); |
| 124 ++iter) { | 125 ++iter) { |
| 125 const BluetoothDevice* device = *iter; | 126 const BluetoothDevice* device = *iter; |
| 126 DCHECK(device); | 127 DCHECK(device); |
| 127 | 128 |
| 128 bluetooth::Device extension_device; | 129 bluetooth::Device extension_device; |
| 129 bluetooth::BluetoothDeviceToApiDevice(*device, &extension_device); | 130 bluetooth::BluetoothDeviceToApiDevice(*device, &extension_device); |
| 130 | 131 |
| 131 device_list->Append(extension_device.ToValue().release()); | 132 device_list->Append(extension_device.ToValue().release()); |
| 132 } | 133 } |
| 133 | 134 |
| 135 SetResult(std::move(device_list)); |
| 134 SendResponse(true); | 136 SendResponse(true); |
| 135 | 137 |
| 136 return true; | 138 return true; |
| 137 } | 139 } |
| 138 | 140 |
| 139 BluetoothGetDeviceFunction::~BluetoothGetDeviceFunction() {} | 141 BluetoothGetDeviceFunction::~BluetoothGetDeviceFunction() {} |
| 140 | 142 |
| 141 bool BluetoothGetDeviceFunction::DoWork( | 143 bool BluetoothGetDeviceFunction::DoWork( |
| 142 scoped_refptr<BluetoothAdapter> adapter) { | 144 scoped_refptr<BluetoothAdapter> adapter) { |
| 143 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 145 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 144 | 146 |
| 145 std::unique_ptr<GetDevice::Params> params(GetDevice::Params::Create(*args_)); | 147 std::unique_ptr<GetDevice::Params> params(GetDevice::Params::Create(*args_)); |
| 146 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 148 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
| 147 | 149 |
| 148 BluetoothDevice* device = adapter->GetDevice(params->device_address); | 150 BluetoothDevice* device = adapter->GetDevice(params->device_address); |
| 149 if (device) { | 151 if (device) { |
| 150 bluetooth::Device extension_device; | 152 bluetooth::Device extension_device; |
| 151 bluetooth::BluetoothDeviceToApiDevice(*device, &extension_device); | 153 bluetooth::BluetoothDeviceToApiDevice(*device, &extension_device); |
| 152 SetResult(extension_device.ToValue().release()); | 154 SetResult(extension_device.ToValue()); |
| 153 SendResponse(true); | 155 SendResponse(true); |
| 154 } else { | 156 } else { |
| 155 SetError(kInvalidDevice); | 157 SetError(kInvalidDevice); |
| 156 SendResponse(false); | 158 SendResponse(false); |
| 157 } | 159 } |
| 158 | 160 |
| 159 return false; | 161 return false; |
| 160 } | 162 } |
| 161 | 163 |
| 162 void BluetoothStartDiscoveryFunction::OnSuccessCallback() { | 164 void BluetoothStartDiscoveryFunction::OnSuccessCallback() { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 ->StopDiscoverySession( | 196 ->StopDiscoverySession( |
| 195 adapter.get(), GetExtensionId(), | 197 adapter.get(), GetExtensionId(), |
| 196 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), | 198 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), |
| 197 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); | 199 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); |
| 198 | 200 |
| 199 return true; | 201 return true; |
| 200 } | 202 } |
| 201 | 203 |
| 202 } // namespace api | 204 } // namespace api |
| 203 } // namespace extensions | 205 } // namespace extensions |
| OLD | NEW |