| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_private_api.h" | 5 #include "chrome/browser/extensions/api/bluetooth/bluetooth_private_api.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" | 10 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 } | 34 } |
| 35 | 35 |
| 36 BluetoothPrivateAPI::~BluetoothPrivateAPI() {} | 36 BluetoothPrivateAPI::~BluetoothPrivateAPI() {} |
| 37 | 37 |
| 38 void BluetoothPrivateAPI::Shutdown() { | 38 void BluetoothPrivateAPI::Shutdown() { |
| 39 ExtensionSystem::Get(browser_context_)->event_router()->UnregisterObserver( | 39 ExtensionSystem::Get(browser_context_)->event_router()->UnregisterObserver( |
| 40 this); | 40 this); |
| 41 } | 41 } |
| 42 | 42 |
| 43 void BluetoothPrivateAPI::OnListenerAdded(const EventListenerInfo& details) { | 43 void BluetoothPrivateAPI::OnListenerAdded(const EventListenerInfo& details) { |
| 44 BluetoothAPI::Get(browser_context_)->event_router()->AddPairingDelegate( | 44 BluetoothAPI::Get(browser_context_) |
| 45 details.extension_id); | 45 ->bluetooth_event_router() |
| 46 ->AddPairingDelegate(details.extension_id); |
| 46 } | 47 } |
| 47 | 48 |
| 48 void BluetoothPrivateAPI::OnListenerRemoved(const EventListenerInfo& details) { | 49 void BluetoothPrivateAPI::OnListenerRemoved(const EventListenerInfo& details) { |
| 49 BluetoothAPI::Get(browser_context_)->event_router()->RemovePairingDelegate( | 50 BluetoothAPI::Get(browser_context_) |
| 50 details.extension_id); | 51 ->bluetooth_event_router() |
| 52 ->RemovePairingDelegate(details.extension_id); |
| 51 } | 53 } |
| 52 | 54 |
| 53 namespace api { | 55 namespace api { |
| 54 | 56 |
| 55 namespace { | 57 namespace { |
| 56 | 58 |
| 57 const char kNameProperty[] = "name"; | 59 const char kNameProperty[] = "name"; |
| 58 const char kPoweredProperty[] = "powered"; | 60 const char kPoweredProperty[] = "powered"; |
| 59 const char kDiscoverableProperty[] = "discoverable"; | 61 const char kDiscoverableProperty[] = "discoverable"; |
| 60 | 62 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 ~BluetoothPrivateSetPairingResponseFunction() {} | 215 ~BluetoothPrivateSetPairingResponseFunction() {} |
| 214 | 216 |
| 215 bool BluetoothPrivateSetPairingResponseFunction::DoWork( | 217 bool BluetoothPrivateSetPairingResponseFunction::DoWork( |
| 216 scoped_refptr<device::BluetoothAdapter> adapter) { | 218 scoped_refptr<device::BluetoothAdapter> adapter) { |
| 217 scoped_ptr<bt_private::SetPairingResponse::Params> params( | 219 scoped_ptr<bt_private::SetPairingResponse::Params> params( |
| 218 bt_private::SetPairingResponse::Params::Create(*args_)); | 220 bt_private::SetPairingResponse::Params::Create(*args_)); |
| 219 EXTENSION_FUNCTION_VALIDATE(params.get()); | 221 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 220 const bt_private::SetPairingResponseOptions& options = params->options; | 222 const bt_private::SetPairingResponseOptions& options = params->options; |
| 221 | 223 |
| 222 BluetoothEventRouter* router = | 224 BluetoothEventRouter* router = |
| 223 BluetoothAPI::Get(browser_context())->event_router(); | 225 BluetoothAPI::Get(browser_context())->bluetooth_event_router(); |
| 224 if (!router->GetPairingDelegate(extension_id())) { | 226 if (!router->GetPairingDelegate(extension_id())) { |
| 225 SetError(kPairingNotEnabled); | 227 SetError(kPairingNotEnabled); |
| 226 SendResponse(false); | 228 SendResponse(false); |
| 227 return true; | 229 return true; |
| 228 } | 230 } |
| 229 | 231 |
| 230 const std::string& device_address = options.device.address; | 232 const std::string& device_address = options.device.address; |
| 231 device::BluetoothDevice* device = adapter->GetDevice(device_address); | 233 device::BluetoothDevice* device = adapter->GetDevice(device_address); |
| 232 if (!device) { | 234 if (!device) { |
| 233 SetError(kDeviceNotFoundError); | 235 SetError(kDeviceNotFoundError); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 261 device->SetPasskey(*options.passkey.get()); | 263 device->SetPasskey(*options.passkey.get()); |
| 262 } | 264 } |
| 263 | 265 |
| 264 SendResponse(true); | 266 SendResponse(true); |
| 265 return true; | 267 return true; |
| 266 } | 268 } |
| 267 | 269 |
| 268 } // namespace api | 270 } // namespace api |
| 269 | 271 |
| 270 } // namespace extensions | 272 } // namespace extensions |
| OLD | NEW |