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_) | 44 BluetoothAPI::Get(browser_context_)->event_router()->AddPairingDelegate( |
45 ->bluetooth_event_router() | 45 details.extension_id); |
46 ->AddPairingDelegate(details.extension_id); | |
47 } | 46 } |
48 | 47 |
49 void BluetoothPrivateAPI::OnListenerRemoved(const EventListenerInfo& details) { | 48 void BluetoothPrivateAPI::OnListenerRemoved(const EventListenerInfo& details) { |
50 BluetoothAPI::Get(browser_context_) | 49 BluetoothAPI::Get(browser_context_)->event_router()->RemovePairingDelegate( |
51 ->bluetooth_event_router() | 50 details.extension_id); |
52 ->RemovePairingDelegate(details.extension_id); | |
53 } | 51 } |
54 | 52 |
55 namespace api { | 53 namespace api { |
56 | 54 |
57 namespace { | 55 namespace { |
58 | 56 |
59 const char kNameProperty[] = "name"; | 57 const char kNameProperty[] = "name"; |
60 const char kPoweredProperty[] = "powered"; | 58 const char kPoweredProperty[] = "powered"; |
61 const char kDiscoverableProperty[] = "discoverable"; | 59 const char kDiscoverableProperty[] = "discoverable"; |
62 | 60 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 ~BluetoothPrivateSetPairingResponseFunction() {} | 213 ~BluetoothPrivateSetPairingResponseFunction() {} |
216 | 214 |
217 bool BluetoothPrivateSetPairingResponseFunction::DoWork( | 215 bool BluetoothPrivateSetPairingResponseFunction::DoWork( |
218 scoped_refptr<device::BluetoothAdapter> adapter) { | 216 scoped_refptr<device::BluetoothAdapter> adapter) { |
219 scoped_ptr<bt_private::SetPairingResponse::Params> params( | 217 scoped_ptr<bt_private::SetPairingResponse::Params> params( |
220 bt_private::SetPairingResponse::Params::Create(*args_)); | 218 bt_private::SetPairingResponse::Params::Create(*args_)); |
221 EXTENSION_FUNCTION_VALIDATE(params.get()); | 219 EXTENSION_FUNCTION_VALIDATE(params.get()); |
222 const bt_private::SetPairingResponseOptions& options = params->options; | 220 const bt_private::SetPairingResponseOptions& options = params->options; |
223 | 221 |
224 BluetoothEventRouter* router = | 222 BluetoothEventRouter* router = |
225 BluetoothAPI::Get(browser_context())->bluetooth_event_router(); | 223 BluetoothAPI::Get(browser_context())->event_router(); |
226 if (!router->GetPairingDelegate(extension_id())) { | 224 if (!router->GetPairingDelegate(extension_id())) { |
227 SetError(kPairingNotEnabled); | 225 SetError(kPairingNotEnabled); |
228 SendResponse(false); | 226 SendResponse(false); |
229 return true; | 227 return true; |
230 } | 228 } |
231 | 229 |
232 const std::string& device_address = options.device.address; | 230 const std::string& device_address = options.device.address; |
233 device::BluetoothDevice* device = adapter->GetDevice(device_address); | 231 device::BluetoothDevice* device = adapter->GetDevice(device_address); |
234 if (!device) { | 232 if (!device) { |
235 SetError(kDeviceNotFoundError); | 233 SetError(kDeviceNotFoundError); |
(...skipping 27 matching lines...) Expand all Loading... |
263 device->SetPasskey(*options.passkey.get()); | 261 device->SetPasskey(*options.passkey.get()); |
264 } | 262 } |
265 | 263 |
266 SendResponse(true); | 264 SendResponse(true); |
267 return true; | 265 return true; |
268 } | 266 } |
269 | 267 |
270 } // namespace api | 268 } // namespace api |
271 | 269 |
272 } // namespace extensions | 270 } // namespace extensions |
OLD | NEW |