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 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 | 35 |
36 namespace bluetooth = core_api::bluetooth; | 36 namespace bluetooth = core_api::bluetooth; |
37 namespace bt_private = core_api::bluetooth_private; | 37 namespace bt_private = core_api::bluetooth_private; |
38 | 38 |
39 BluetoothEventRouter::BluetoothEventRouter(content::BrowserContext* context) | 39 BluetoothEventRouter::BluetoothEventRouter(content::BrowserContext* context) |
40 : browser_context_(context), | 40 : browser_context_(context), |
41 adapter_(NULL), | 41 adapter_(NULL), |
42 num_event_listeners_(0), | 42 num_event_listeners_(0), |
43 extension_registry_observer_(this), | 43 extension_registry_observer_(this), |
44 weak_ptr_factory_(this) { | 44 weak_ptr_factory_(this) { |
45 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 45 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
46 DCHECK(browser_context_); | 46 DCHECK(browser_context_); |
47 registrar_.Add(this, | 47 registrar_.Add(this, |
48 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 48 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
49 content::Source<content::BrowserContext>(browser_context_)); | 49 content::Source<content::BrowserContext>(browser_context_)); |
50 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_)); | 50 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context_)); |
51 } | 51 } |
52 | 52 |
53 BluetoothEventRouter::~BluetoothEventRouter() { | 53 BluetoothEventRouter::~BluetoothEventRouter() { |
54 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 54 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
55 if (adapter_.get()) { | 55 if (adapter_.get()) { |
56 adapter_->RemoveObserver(this); | 56 adapter_->RemoveObserver(this); |
57 adapter_ = NULL; | 57 adapter_ = NULL; |
58 } | 58 } |
59 CleanUpAllExtensions(); | 59 CleanUpAllExtensions(); |
60 } | 60 } |
61 | 61 |
62 bool BluetoothEventRouter::IsBluetoothSupported() const { | 62 bool BluetoothEventRouter::IsBluetoothSupported() const { |
63 return adapter_.get() || | 63 return adapter_.get() || |
64 device::BluetoothAdapterFactory::IsBluetoothAdapterAvailable(); | 64 device::BluetoothAdapterFactory::IsBluetoothAdapterAvailable(); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 adapter_->RemovePairingDelegate(delegate); | 218 adapter_->RemovePairingDelegate(delegate); |
219 pairing_delegate_map_.erase(extension_id); | 219 pairing_delegate_map_.erase(extension_id); |
220 delete delegate; | 220 delete delegate; |
221 MaybeReleaseAdapter(); | 221 MaybeReleaseAdapter(); |
222 } | 222 } |
223 } | 223 } |
224 | 224 |
225 void BluetoothEventRouter::AdapterPresentChanged( | 225 void BluetoothEventRouter::AdapterPresentChanged( |
226 device::BluetoothAdapter* adapter, | 226 device::BluetoothAdapter* adapter, |
227 bool present) { | 227 bool present) { |
228 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 228 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
229 if (adapter != adapter_.get()) { | 229 if (adapter != adapter_.get()) { |
230 DVLOG(1) << "Ignoring event for adapter " << adapter->GetAddress(); | 230 DVLOG(1) << "Ignoring event for adapter " << adapter->GetAddress(); |
231 return; | 231 return; |
232 } | 232 } |
233 DispatchAdapterStateEvent(); | 233 DispatchAdapterStateEvent(); |
234 } | 234 } |
235 | 235 |
236 void BluetoothEventRouter::AdapterPoweredChanged( | 236 void BluetoothEventRouter::AdapterPoweredChanged( |
237 device::BluetoothAdapter* adapter, | 237 device::BluetoothAdapter* adapter, |
238 bool has_power) { | 238 bool has_power) { |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 } | 414 } |
415 | 415 |
416 void BluetoothEventRouter::OnExtensionUnloaded( | 416 void BluetoothEventRouter::OnExtensionUnloaded( |
417 content::BrowserContext* browser_context, | 417 content::BrowserContext* browser_context, |
418 const Extension* extension, | 418 const Extension* extension, |
419 UnloadedExtensionInfo::Reason reason) { | 419 UnloadedExtensionInfo::Reason reason) { |
420 CleanUpForExtension(extension->id()); | 420 CleanUpForExtension(extension->id()); |
421 } | 421 } |
422 | 422 |
423 } // namespace extensions | 423 } // namespace extensions |
OLD | NEW |