| 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_event_router.h" | 5 #include "extensions/browser/api/bluetooth/bluetooth_event_router.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 return; | 192 return; |
| 193 } | 193 } |
| 194 | 194 |
| 195 // extension is already running discovery, update it's discovery filter | 195 // extension is already running discovery, update it's discovery filter |
| 196 iter->second->SetDiscoveryFilter(std::move(discovery_filter), callback, | 196 iter->second->SetDiscoveryFilter(std::move(discovery_filter), callback, |
| 197 error_callback); | 197 error_callback); |
| 198 } | 198 } |
| 199 | 199 |
| 200 BluetoothApiPairingDelegate* BluetoothEventRouter::GetPairingDelegate( | 200 BluetoothApiPairingDelegate* BluetoothEventRouter::GetPairingDelegate( |
| 201 const std::string& extension_id) { | 201 const std::string& extension_id) { |
| 202 return ContainsKey(pairing_delegate_map_, extension_id) | 202 return base::ContainsKey(pairing_delegate_map_, extension_id) |
| 203 ? pairing_delegate_map_[extension_id] | 203 ? pairing_delegate_map_[extension_id] |
| 204 : nullptr; | 204 : nullptr; |
| 205 } | 205 } |
| 206 | 206 |
| 207 void BluetoothEventRouter::OnAdapterInitialized( | 207 void BluetoothEventRouter::OnAdapterInitialized( |
| 208 const device::BluetoothAdapterFactory::AdapterCallback& callback, | 208 const device::BluetoothAdapterFactory::AdapterCallback& callback, |
| 209 scoped_refptr<device::BluetoothAdapter> adapter) { | 209 scoped_refptr<device::BluetoothAdapter> adapter) { |
| 210 if (!adapter_.get()) { | 210 if (!adapter_.get()) { |
| 211 adapter_ = adapter; | 211 adapter_ = adapter; |
| 212 adapter_->AddObserver(this); | 212 adapter_->AddObserver(this); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 234 } | 234 } |
| 235 AddPairingDelegateImpl(extension_id); | 235 AddPairingDelegateImpl(extension_id); |
| 236 } | 236 } |
| 237 | 237 |
| 238 void BluetoothEventRouter::AddPairingDelegateImpl( | 238 void BluetoothEventRouter::AddPairingDelegateImpl( |
| 239 const std::string& extension_id) { | 239 const std::string& extension_id) { |
| 240 if (!adapter_.get()) { | 240 if (!adapter_.get()) { |
| 241 LOG(ERROR) << "Unable to get adapter for extension_id: " << extension_id; | 241 LOG(ERROR) << "Unable to get adapter for extension_id: " << extension_id; |
| 242 return; | 242 return; |
| 243 } | 243 } |
| 244 if (ContainsKey(pairing_delegate_map_, extension_id)) { | 244 if (base::ContainsKey(pairing_delegate_map_, extension_id)) { |
| 245 // For WebUI there may be more than one page open to the same url | 245 // For WebUI there may be more than one page open to the same url |
| 246 // (e.g. chrome://settings). These will share the same pairing delegate. | 246 // (e.g. chrome://settings). These will share the same pairing delegate. |
| 247 VLOG(1) << "Pairing delegate already exists for extension_id: " | 247 VLOG(1) << "Pairing delegate already exists for extension_id: " |
| 248 << extension_id; | 248 << extension_id; |
| 249 return; | 249 return; |
| 250 } | 250 } |
| 251 BluetoothApiPairingDelegate* delegate = | 251 BluetoothApiPairingDelegate* delegate = |
| 252 new BluetoothApiPairingDelegate(browser_context_); | 252 new BluetoothApiPairingDelegate(browser_context_); |
| 253 DCHECK(adapter_.get()); | 253 DCHECK(adapter_.get()); |
| 254 adapter_->AddPairingDelegate( | 254 adapter_->AddPairingDelegate( |
| 255 delegate, device::BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); | 255 delegate, device::BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH); |
| 256 pairing_delegate_map_[extension_id] = delegate; | 256 pairing_delegate_map_[extension_id] = delegate; |
| 257 } | 257 } |
| 258 | 258 |
| 259 void BluetoothEventRouter::RemovePairingDelegate( | 259 void BluetoothEventRouter::RemovePairingDelegate( |
| 260 const std::string& extension_id) { | 260 const std::string& extension_id) { |
| 261 if (ContainsKey(pairing_delegate_map_, extension_id)) { | 261 if (base::ContainsKey(pairing_delegate_map_, extension_id)) { |
| 262 BluetoothApiPairingDelegate* delegate = pairing_delegate_map_[extension_id]; | 262 BluetoothApiPairingDelegate* delegate = pairing_delegate_map_[extension_id]; |
| 263 if (adapter_.get()) | 263 if (adapter_.get()) |
| 264 adapter_->RemovePairingDelegate(delegate); | 264 adapter_->RemovePairingDelegate(delegate); |
| 265 pairing_delegate_map_.erase(extension_id); | 265 pairing_delegate_map_.erase(extension_id); |
| 266 delete delegate; | 266 delete delegate; |
| 267 MaybeReleaseAdapter(); | 267 MaybeReleaseAdapter(); |
| 268 } | 268 } |
| 269 } | 269 } |
| 270 | 270 |
| 271 void BluetoothEventRouter::AdapterPresentChanged( | 271 void BluetoothEventRouter::AdapterPresentChanged( |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 } | 467 } |
| 468 | 468 |
| 469 void BluetoothEventRouter::OnExtensionUnloaded( | 469 void BluetoothEventRouter::OnExtensionUnloaded( |
| 470 content::BrowserContext* browser_context, | 470 content::BrowserContext* browser_context, |
| 471 const Extension* extension, | 471 const Extension* extension, |
| 472 UnloadedExtensionInfo::Reason reason) { | 472 UnloadedExtensionInfo::Reason reason) { |
| 473 CleanUpForExtension(extension->id()); | 473 CleanUpForExtension(extension->id()); |
| 474 } | 474 } |
| 475 | 475 |
| 476 } // namespace extensions | 476 } // namespace extensions |
| OLD | NEW |